From 2670b1787214829a33d993772c73a44d21ea87ea Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Thu, 19 Jan 2017 06:11:35 -0800 Subject: [PATCH] On Win32, write out default .hyper.js as CRLF so Notepad doesn't have a fit (#1383) * On Win32, write out default .hyper.js as CRLF so Notepad doesn't have a fit * Fix hwhoops * Add explanatory comment --- app/config.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/config.js b/app/config.js index d42d50f5..ca244ba2 100644 --- a/app/config.js +++ b/app/config.js @@ -84,6 +84,13 @@ function exec(str) { return true; } +// This method will take text formatted as Unix line endings and transform it +// to text formatted with DOS line endings. We do this because the default +// text editor on Windows (notepad) doesn't Deal with LF files. Still. In 2017. +function crlfify(str) { + return str.split('\n').map(x => x.indexOf('\r') < 0 ? x : `${x}\r`).join('\n'); +} + exports.subscribe = function (fn) { watchers.push(fn); return () => { @@ -110,9 +117,12 @@ exports.init = function () { try { console.log('attempting to write default config to', path); exec(defaultConfig); - writeFileSync(path, defaultConfig); + + writeFileSync( + path, + process.platform === 'win32' ? crlfify(defaultConfig.toString()) : defaultConfig); } catch (err) { - throw new Error(`Failed to write config to ${path}`); + throw new Error(`Failed to write config to ${path}: ${err.message}`); } } watch();