forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(build): Add traceur transpiler for broccoli.
This exactly reproduces the output tree from one of the gulp tasks, which is now removed. Next step is to migrate another sibling task to broccoli.
- Loading branch information
Showing
6 changed files
with
188 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* 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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
var fs = require('fs'); | ||
var fse = require('fs-extra'); | ||
var path = require('path'); | ||
var traceur = require('../../transpiler'); | ||
var walkSync = require('walk-sync'); | ||
var Writer = require('broccoli-writer'); | ||
var xtend = require('xtend'); | ||
|
||
class TraceurFilter extends Writer { | ||
constructor(private inputTree, 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); | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
module.exports = TraceurFilter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters