build(router): make the build.js script portable to g3
This commit is contained in:
parent
6acc99729c
commit
3a40cd79f0
|
@ -23,19 +23,22 @@ var PRELUDE = '(function(){\n';
|
||||||
var POSTLUDE = '\n}());\n';
|
var POSTLUDE = '\n}());\n';
|
||||||
|
|
||||||
function main(modulesDirectory) {
|
function main(modulesDirectory) {
|
||||||
|
|
||||||
var angular1RouterModuleDirectory = modulesDirectory + '/angular1_router';
|
var angular1RouterModuleDirectory = modulesDirectory + '/angular1_router';
|
||||||
|
|
||||||
var facades = fs.readFileSync(angular1RouterModuleDirectory + '/lib/facades.es5', 'utf8');
|
var facades = fs.readFileSync(
|
||||||
var directives = fs.readFileSync(angular1RouterModuleDirectory + '/src/ng_outlet.ts', 'utf8');
|
angular1RouterModuleDirectory + '/lib/facades.es5', 'utf8');
|
||||||
var moduleTemplate = fs.readFileSync(angular1RouterModuleDirectory + '/src/module_template.js', 'utf8');
|
var directives = fs.readFileSync(
|
||||||
|
angular1RouterModuleDirectory + '/src/ng_outlet.ts', 'utf8');
|
||||||
|
var moduleTemplate = fs.readFileSync(
|
||||||
|
angular1RouterModuleDirectory + '/src/module_template.js', 'utf8');
|
||||||
|
|
||||||
var dir = modulesDirectory + '/angular2/src/router/';
|
var dir = modulesDirectory + '/angular2/src/router/';
|
||||||
var sharedCode = files.reduce(function (prev, file) {
|
var sharedCode = files.reduce(function (prev, file) {
|
||||||
return prev + transform(fs.readFileSync(dir + file, 'utf8'));
|
return prev + transform(fs.readFileSync(dir + file, 'utf8'));
|
||||||
}, '');
|
}, '');
|
||||||
|
|
||||||
var out = moduleTemplate.replace('//{{FACADES}}', facades).replace('//{{SHARED_CODE}}', sharedCode);
|
var out = moduleTemplate.replace('//{{FACADES}}', facades)
|
||||||
|
.replace('//{{SHARED_CODE}}', sharedCode);
|
||||||
return PRELUDE + transform(directives) + out + POSTLUDE;
|
return PRELUDE + transform(directives) + out + POSTLUDE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,5 +73,25 @@ module.exports = function (modulesDirectory, outputDirectory) {
|
||||||
if (!fs.existsSync(outputDirectory)) {
|
if (!fs.existsSync(outputDirectory)) {
|
||||||
fs.mkdirSync(outputDirectory);
|
fs.mkdirSync(outputDirectory);
|
||||||
}
|
}
|
||||||
fs.writeFileSync(outputDirectory + '/angular_1_router.js', main(modulesDirectory));
|
fs.writeFileSync(
|
||||||
|
outputDirectory + '/angular_1_router.js', main(modulesDirectory));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// CLI entry point
|
||||||
|
if (require.main === module) {
|
||||||
|
try {
|
||||||
|
var args = process.argv;
|
||||||
|
args.shift(); // node
|
||||||
|
args.shift(); // scriptfile.js
|
||||||
|
if (args.length < 2) {
|
||||||
|
console.log("usage: $0 outFile path/to/modules");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
var outfile = args.shift();
|
||||||
|
var directory = args.shift();
|
||||||
|
fs.writeFileSync(outfile, main(directory));
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.message);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue