chore(build): Migrate build.js.dev fully to broccoli.
The previous change did the ES6 transpile, now we add ES5. The sourcemaps are broken, but were also broken previously. We'll address that separately.
This commit is contained in:
parent
69c3bff086
commit
a3097aaf05
|
@ -0,0 +1,28 @@
|
|||
var Funnel = require('broccoli-funnel');
|
||||
var mergeTrees = require('broccoli-merge-trees');
|
||||
var stew = require('broccoli-stew');
|
||||
var TraceurCompiler = require('./tools/broccoli/traceur');
|
||||
|
||||
var modulesTree = new Funnel('modules', {include: ['**/**'], destDir: '/'});
|
||||
|
||||
// First, use Traceur to transpile original sources to ES6
|
||||
var es6DevTree = new TraceurCompiler(modulesTree, '.es6', {
|
||||
sourceMaps: true,
|
||||
annotations: true, // parse annotations
|
||||
types: true, // parse types
|
||||
script: false, // parse as a module
|
||||
memberVariables: true, // parse class fields
|
||||
modules: 'instantiate',
|
||||
typeAssertionModule: 'rtts_assert/rtts_assert',
|
||||
typeAssertions: true,
|
||||
outputLanguage: 'es6'
|
||||
});
|
||||
es6DevTree = stew.rename(es6DevTree, function(relativePath) {
|
||||
return relativePath.replace(/\.(js|es6)\.map$/, '.map').replace(/\.js$/, '.es6');
|
||||
});
|
||||
|
||||
// Call Traceur again to lower the ES6 build tree to ES5
|
||||
var es5DevTree = new TraceurCompiler(es6DevTree, '.js', {modules: 'instantiate', sourceMaps: true});
|
||||
es5DevTree = stew.rename(es5DevTree, '.es6.map', '.js.map');
|
||||
|
||||
module.exports = mergeTrees([stew.mv(es6DevTree, 'js/dev/es6'), stew.mv(es5DevTree, 'js/dev/es5')]);
|
38
Brocfile.js
38
Brocfile.js
|
@ -1,38 +0,0 @@
|
|||
/**
|
||||
* Build pipeline for Angular2.
|
||||
* First time setup:
|
||||
* $ npm install --global broccoli-cli
|
||||
*/
|
||||
var merge = require('merge');
|
||||
var TraceurCompiler = require('./tools/broccoli/traceur');
|
||||
var Funnel = require('broccoli-funnel');
|
||||
var stew = require('broccoli-stew');
|
||||
|
||||
var _COMPILER_CONFIG_JS_DEFAULT = {
|
||||
sourceMaps: true,
|
||||
annotations: true, // parse annotations
|
||||
types: true, // parse types
|
||||
script: false, // parse as a module
|
||||
memberVariables: true, // parse class fields
|
||||
modules: 'instantiate'
|
||||
};
|
||||
|
||||
var modulesTree = new Funnel('modules', {include: ['**/**'], destDir: '/'});
|
||||
|
||||
var transpiledTree = new TraceurCompiler(modulesTree, merge(true, _COMPILER_CONFIG_JS_DEFAULT, {
|
||||
typeAssertionModule: 'rtts_assert/rtts_assert',
|
||||
typeAssertions: true,
|
||||
outputLanguage: 'es6'
|
||||
}));
|
||||
|
||||
transpiledTree = stew.rename(transpiledTree, function(relativePath) {
|
||||
return relativePath.replace(/\.(js|es6)\.map$/, '.map')
|
||||
.replace(/\.js$/, '.es6');
|
||||
});
|
||||
transpiledTree = stew.mv(transpiledTree, 'js/dev/es6')
|
||||
|
||||
//transpiledTree = stew.log(transpiledTree);
|
||||
|
||||
|
||||
module.exports = transpiledTree;
|
||||
|
20
gulpfile.js
20
gulpfile.js
|
@ -280,10 +280,6 @@ var CONFIG = {
|
|||
};
|
||||
CONFIG.test.js.cjs = CONFIG.test.js.cjs.map(function(s) {return CONFIG.dest.js.cjs + s});
|
||||
|
||||
gulp.task('broccoli', function() {
|
||||
return broccoliBuild(require('./Brocfile.js'), path.join('js', 'dev'));
|
||||
});
|
||||
|
||||
// ------------
|
||||
// clean
|
||||
|
||||
|
@ -348,12 +344,8 @@ gulp.task('build/transpile.js.dev.es5', function() {
|
|||
});
|
||||
});
|
||||
|
||||
gulp.task('build/transpile.js.dev', function(done) {
|
||||
runSequence(
|
||||
// broccoli runs the ES6 version of this task
|
||||
'build/transpile.js.dev.es5',
|
||||
done
|
||||
);
|
||||
gulp.task('broccoli.js.dev', function() {
|
||||
return broccoliBuild(require('./Brocfile-js_dev.js'), path.join('js', 'dev'));
|
||||
});
|
||||
|
||||
gulp.task('build/transpile.js.prod.es6', transpile(gulp, gulpPlugins, {
|
||||
|
@ -803,8 +795,8 @@ gulp.task('build.dart', function(done) {
|
|||
|
||||
gulp.task('build.js.dev', function(done) {
|
||||
runSequence(
|
||||
'broccoli',
|
||||
['build/transpile.js.dev', 'build/html.js.dev', 'build/copy.js.dev', 'build/multicopy.js.dev.es6'],
|
||||
'broccoli.js.dev',
|
||||
['build/html.js.dev', 'build/copy.js.dev', 'build/multicopy.js.dev.es6'],
|
||||
'build/checkCircularDependencies',
|
||||
done
|
||||
);
|
||||
|
@ -902,10 +894,10 @@ gulp.task('bundle.js.dev.deps', ['bundle.js.dev'], function() {
|
|||
.pipe(gulp.dest('dist/bundle'));
|
||||
});
|
||||
|
||||
gulp.task('build.js', ['build.js.dev', 'build.js.prod', 'build.js.cjs', 'bundle.js.deps']);
|
||||
|
||||
gulp.task('bundle.js.deps', ['bundle.js.prod.deps', 'bundle.js.dev.deps', 'bundle.js.min.deps']);
|
||||
|
||||
gulp.task('build.js', ['build.js.dev', 'build.js.prod', 'build.js.cjs']);
|
||||
|
||||
gulp.task('clean', ['build/clean.js', 'build/clean.dart', 'build/clean.docs']);
|
||||
|
||||
gulp.task('build', ['build.js', 'build.dart']);
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
"bower": "^1.3.12",
|
||||
"broccoli": "^0.15.3",
|
||||
"broccoli-funnel": "^0.2.3",
|
||||
"broccoli-merge-trees": "^0.2.1",
|
||||
"broccoli-stew": "^0.2.1",
|
||||
"broccoli-writer": "^0.1.1",
|
||||
"canonical-path": "0.0.2",
|
||||
|
|
|
@ -13,9 +13,11 @@ var Writer = require('broccoli-writer');
|
|||
var xtend = require('xtend');
|
||||
var TraceurFilter = (function (_super) {
|
||||
__extends(TraceurFilter, _super);
|
||||
function TraceurFilter(inputTree, options) {
|
||||
function TraceurFilter(inputTree, destExtension, options) {
|
||||
if (destExtension === void 0) { destExtension = '.js'; }
|
||||
if (options === void 0) { options = {}; }
|
||||
this.inputTree = inputTree;
|
||||
this.destExtension = destExtension;
|
||||
this.options = options;
|
||||
}
|
||||
TraceurFilter.prototype.write = function (readTree, destDir) {
|
||||
|
@ -33,8 +35,10 @@ var TraceurFilter = (function (_super) {
|
|||
};
|
||||
var sourcecode = fs.readFileSync(path.join(srcDir, filepath), fsOpts);
|
||||
var result = traceur.compile(options, filepath, sourcecode);
|
||||
result.js = result.js + '\n//# sourceMappingURL=./' + path.basename(filepath).replace(/\.\w+$/, '.map');
|
||||
var destFilepath = filepath.replace(/\.\w+$/, '.es6');
|
||||
// TODO: we should fix the sourceMappingURL written by Traceur instead of overriding
|
||||
// (but we might switch to typescript first)
|
||||
result.js = result.js + '\n//# sourceMappingURL=./' + path.basename(filepath).replace(/\.es6$/, '') + (_this.destExtension === '.js' ? '.js.map' : '.map');
|
||||
var destFilepath = filepath.replace(/\.\w+$/, _this.destExtension);
|
||||
var destFile = path.join(destDir, destFilepath);
|
||||
fse.mkdirsSync(path.dirname(destFile));
|
||||
var destMap = path.join(destDir, filepath + '.map');
|
||||
|
|
|
@ -7,37 +7,43 @@ var Writer = require('broccoli-writer');
|
|||
var xtend = require('xtend');
|
||||
|
||||
class TraceurFilter extends Writer {
|
||||
constructor(private inputTree, private options = {}) {}
|
||||
constructor(private inputTree, private destExtension: string = '.js', private options = {}) {}
|
||||
|
||||
write(readTree, destDir) {
|
||||
return readTree(this.inputTree)
|
||||
.then(srcDir => {
|
||||
walkSync(srcDir)
|
||||
.filter(filepath => {
|
||||
var extension = path.extname(filepath).toLowerCase();
|
||||
return extension === '.js' || extension === '.es6';
|
||||
})
|
||||
.map(filepath => {
|
||||
var options = xtend({filename: filepath}, this.options);
|
||||
.then(srcDir => {
|
||||
walkSync(srcDir)
|
||||
.filter(filepath =>
|
||||
{
|
||||
var extension = path.extname(filepath).toLowerCase();
|
||||
return extension === '.js' || extension === '.es6';
|
||||
})
|
||||
.map(filepath => {
|
||||
var options = xtend({filename: filepath}, this.options);
|
||||
|
||||
var fsOpts = {encoding: 'utf-8'};
|
||||
var sourcecode = fs.readFileSync(path.join(srcDir, filepath), fsOpts);
|
||||
var fsOpts = {encoding: 'utf-8'};
|
||||
var sourcecode = fs.readFileSync(path.join(srcDir, filepath), fsOpts);
|
||||
|
||||
var result = traceur.compile(options, filepath, sourcecode);
|
||||
var result = traceur.compile(options, filepath, sourcecode);
|
||||
|
||||
result.js = result.js + '\n//# sourceMappingURL=./' + path.basename(filepath).replace(/\.\w+$/, '.map');
|
||||
// TODO: we should fix the sourceMappingURL written by Traceur instead of overriding
|
||||
// (but we might switch to typescript first)
|
||||
result.js = result.js + '\n//# sourceMappingURL=./' +
|
||||
path.basename(filepath).replace(/\.es6$/, '') +
|
||||
(this.destExtension === '.js' ? '.js.map' : '.map');
|
||||
|
||||
var destFilepath = filepath.replace(/\.\w+$/, '.es6');
|
||||
var destFile = path.join(destDir, destFilepath);
|
||||
fse.mkdirsSync(path.dirname(destFile));
|
||||
var destMap = path.join(destDir, filepath + '.map');
|
||||
var destFilepath = filepath.replace(/\.\w+$/, this.destExtension);
|
||||
var destFile = path.join(destDir, destFilepath);
|
||||
fse.mkdirsSync(path.dirname(destFile));
|
||||
var destMap = path.join(destDir, filepath + '.map');
|
||||
|
||||
|
||||
fs.writeFileSync(destFile, result.js, fsOpts);
|
||||
result.sourceMap.file = destFilepath;
|
||||
fs.writeFileSync(destMap, JSON.stringify(result.sourceMap), fsOpts);
|
||||
});
|
||||
});
|
||||
fs.writeFileSync(destFile, result.js, fsOpts);
|
||||
|
||||
result.sourceMap.file = destFilepath;
|
||||
fs.writeFileSync(destMap, JSON.stringify(result.sourceMap), fsOpts);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue