chore: fix spacing output of inline script

test-unit-sauce
Brian Ford 10 years ago
parent f81ebb4701
commit 7421f9196f

@ -2,13 +2,14 @@
// This is a really dumb naive approach that only supports `module.exports =` // This is a really dumb naive approach that only supports `module.exports =`
var fs = require('fs'); var fs = require('fs');
var r = new RegExp("( *).*?require\\('(.+?)'\\)", 'g'); var r = new RegExp("( *)(.*?)require\\('(.+?)'\\)", 'g');
module.exports = function () { module.exports = function () {
var debug = fs.readFileSync(__dirname + '/../content-scripts/inject.js', 'utf8'); var debug = fs.readFileSync(__dirname + '/../content-scripts/inject.js', 'utf8');
var out = debug.replace(r, function (match, before, file) { var out = debug.replace(r, function (match, whitespace, before, file) {
return ex(file, before); return whitespace + '// exported from ' + file + '\n' +
whitespace + before + ex(whitespace, file);
}); });
fs.writeFileSync(__dirname + '/../content-scripts/inject.build.js', out); fs.writeFileSync(__dirname + '/../content-scripts/inject.build.js', out);
@ -16,19 +17,18 @@ module.exports = function () {
// takes the contents of a file, wraps it in a closure // takes the contents of a file, wraps it in a closure
// and returns the result // and returns the result
function ex (file, whitespace) { function ex (whitespace, file) {
var contents = fs.readFileSync(__dirname + '/../content-scripts/' + file, 'utf8'); var contents = fs.readFileSync(__dirname + '/../content-scripts/' + file, 'utf8');
contents = contents.replace('module.exports = ', 'return '); contents = contents.replace('module.exports = ', 'return ');
contents = ['// exported from ' + file, contents = ['(function () {'].
'(function () {'].
concat(contents.split('\n'). concat(contents.split('\n').
map(function (line) { map(function (line) {
return ' ' + line; return ' ' + line;
})). }).
concat(['}())']). concat(['}())']).
map(function (line) { map(function (line) {
return whitespace + line; return whitespace + line;
}).join('\n'); })).join('\n');
return contents; return contents;
} }