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:
@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user