From e4a68061ae0c1360aa2773abaa0827e935ebdf45 Mon Sep 17 00:00:00 2001 From: Brian Ford Date: Tue, 1 Apr 2014 15:44:13 -0700 Subject: [PATCH] chore: fix whitespace in inline.js --- scripts/inline.js | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/scripts/inline.js b/scripts/inline.js index ebead0a..83f64f9 100644 --- a/scripts/inline.js +++ b/scripts/inline.js @@ -2,26 +2,33 @@ // This is a really dumb naive approach that only supports `module.exports =` var fs = require('fs'); +var r = new RegExp("( *).*?require\\('(.+?)'\\)", 'g'); -var debug = fs.readFileSync(__dirname + '/../content-scripts/inject.js', 'utf8'); +module.exports = function () { + var debug = fs.readFileSync(__dirname + '/../content-scripts/inject.js', 'utf8'); -var r = new RegExp("require\\('(.+?)'\\)", 'g'); + var out = debug.replace(r, function (match, before, file) { + return ex(file, before); + }); -var out = debug.replace(r, function (match, file) { - return ex(file); -}); - -fs.writeFileSync(__dirname + '/../content-scripts/inject.build.js', out); + fs.writeFileSync(__dirname + '/../content-scripts/inject.build.js', out); +}; // takes the contents of a file, wraps it in a closure // and returns the result -function ex (file) { - contents = fs.readFileSync(__dirname + '/../content-scripts/' + file, 'utf8'); +function ex (file, whitespace) { + var contents = fs.readFileSync(__dirname + '/../content-scripts/' + file, 'utf8'); contents = contents.replace('module.exports = ', 'return '); - contents = '(function () {\n' + - '// exported from ' + file + '\n' + - contents + '\n' + - '}())'; + contents = ['// exported from ' + file, + '(function () {']. + concat(contents.split('\n'). + map(function (line) { + return ' ' + line; + })). + concat(['}())']). + map(function (line) { + return whitespace + line; + }).join('\n'); return contents; -} +} \ No newline at end of file