Skip to content

Commit

Permalink
chore(build): Migrate build.js.dev fully to broccoli.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexeagle committed Apr 9, 2015
1 parent 69c3bff commit a3097aa
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 83 deletions.
28 changes: 28 additions & 0 deletions Brocfile-js_dev.js
Original file line number Diff line number Diff line change
@@ -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 changes: 0 additions & 38 deletions Brocfile.js

This file was deleted.

20 changes: 6 additions & 14 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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, {
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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']);
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 7 additions & 3 deletions tools/broccoli/traceur/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 34 additions & 28 deletions tools/broccoli/traceur/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

var fsOpts = {encoding: 'utf-8'};
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');
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);
});
});
.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 result = traceur.compile(options, filepath, sourcecode);

// 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');


fs.writeFileSync(destFile, result.js, fsOpts);

result.sourceMap.file = destFilepath;
fs.writeFileSync(destMap, JSON.stringify(result.sourceMap), fsOpts);
});
});
}
}

Expand Down

0 comments on commit a3097aa

Please sign in to comment.