build(router): refactor angular1 router build script

This commit is contained in:
Brian Ford 2016-01-29 13:28:59 -08:00 committed by Alex Eagle
parent 99e6500a2d
commit 6acc99729c
2 changed files with 20 additions and 13 deletions

View File

@ -627,7 +627,11 @@ gulp.task('!test.unit.router/karma-run', function(done) {
}); });
}); });
gulp.task('buildRouter.dev', function() { buildRouter(); }); gulp.task('buildRouter.dev', function() {
var modulesSrcDir = __dirname + '/modules';
var distDir = __dirname + '/dist';
buildRouter(modulesSrcDir, distDir);
});
gulp.task('test.unit.dart', function(done) { gulp.task('test.unit.dart', function(done) {
printModulesWarning(); printModulesWarning();

View File

@ -21,18 +21,22 @@ var files = [
var PRELUDE = '(function(){\n'; var PRELUDE = '(function(){\n';
var POSTLUDE = '\n}());\n'; var POSTLUDE = '\n}());\n';
var FACADES = fs.readFileSync(__dirname + '/lib/facades.es5', 'utf8');
var DIRECTIVES = fs.readFileSync(__dirname + '/src/ng_outlet.ts', 'utf8');
var moduleTemplate = fs.readFileSync(__dirname + '/src/module_template.js', 'utf8');
function main() { function main(modulesDirectory) {
var dir = __dirname + '/../angular2/src/router/';
var angular1RouterModuleDirectory = modulesDirectory + '/angular1_router';
var facades = fs.readFileSync(angular1RouterModuleDirectory + '/lib/facades.es5', '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 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;
} }
/* /*
@ -62,10 +66,9 @@ function isFacadeModule(modulePath) {
modulePath === 'angular2/src/core/reflection/reflection'; modulePath === 'angular2/src/core/reflection/reflection';
} }
module.exports = function () { module.exports = function (modulesDirectory, outputDirectory) {
var dist = __dirname + '/../../dist'; if (!fs.existsSync(outputDirectory)) {
if (!fs.existsSync(dist)) { fs.mkdirSync(outputDirectory);
fs.mkdirSync(dist);
} }
fs.writeFileSync(dist + '/angular_1_router.js', main()); fs.writeFileSync(outputDirectory + '/angular_1_router.js', main(modulesDirectory));
}; };