openmct/rebundle.js
2016-01-07 10:45:00 -08:00

41 lines
1020 B
JavaScript

// Temporary utility script to rewrite bundle.json
// files as bundle.js files.
var glob = require('glob'),
fs = require('fs'),
header = fs.readFileSync('header.txt', 'utf8');
function indent(str) {
return str.split('\n').map(function (line, index) {
return index === 0 ? line : (' ' + line);
}).filter(function (line) {
return line.trim().length > 0;
}).join('\n');
}
function rebundle(file) {
var plainJson = fs.readFileSync(file, 'utf8'),
bundleName = file.replace("/bundle.json", ""),
outputFile = file.replace(".json", ".js"),
contents = [
header,
" legacyRegistry.register(\"",
bundleName,
"\", ",
indent(plainJson),
");\n",
"});\n"
].join('');
fs.writeFileSync(outputFile, contents, 'utf8');
}
glob('**/bundle.json', {}, function (err, files) {
if (err) {
console.log(err);
return;
}
files.forEach(rebundle);
});