chore(build): compile the .ts broccoli tools.

This avoids having to check in the compiled .js files.
This commit is contained in:
Alex Eagle 2015-04-10 16:45:24 -07:00
parent 6ce085a21a
commit 2ed7622239
9 changed files with 35 additions and 137 deletions

View File

@ -1,8 +1,8 @@
var Funnel = require('broccoli-funnel'); var Funnel = require('broccoli-funnel');
var mergeTrees = require('broccoli-merge-trees'); var mergeTrees = require('broccoli-merge-trees');
var stew = require('broccoli-stew'); var stew = require('broccoli-stew');
var TraceurCompiler = require('./tools/broccoli/traceur'); var TraceurCompiler = require('./dist/broccoli/traceur');
var TypescriptCompiler = require('./tools/broccoli/typescript'); var TypescriptCompiler = require('./dist/broccoli/typescript');
var renderLodashTemplate = require('broccoli-lodash'); var renderLodashTemplate = require('broccoli-lodash');
var modulesTree = new Funnel( var modulesTree = new Funnel(

View File

@ -2,7 +2,7 @@ var Funnel = require('broccoli-funnel');
var flatten = require('broccoli-flatten'); var flatten = require('broccoli-flatten');
var mergeTrees = require('broccoli-merge-trees'); var mergeTrees = require('broccoli-merge-trees');
var stew = require('broccoli-stew'); var stew = require('broccoli-stew');
var TraceurCompiler = require('./tools/broccoli/traceur'); var TraceurCompiler = require('./dist/broccoli/traceur');
var replace = require('broccoli-replace'); var replace = require('broccoli-replace');
var htmlReplace = require('./tools/broccoli/html-replace'); var htmlReplace = require('./tools/broccoli/html-replace');
var path = require('path'); var path = require('path');

View File

@ -2,7 +2,7 @@ var Funnel = require('broccoli-funnel');
var flatten = require('broccoli-flatten'); var flatten = require('broccoli-flatten');
var mergeTrees = require('broccoli-merge-trees'); var mergeTrees = require('broccoli-merge-trees');
var stew = require('broccoli-stew'); var stew = require('broccoli-stew');
var TraceurCompiler = require('./tools/broccoli/traceur'); var TraceurCompiler = require('./dist/broccoli/traceur');
var replace = require('broccoli-replace'); var replace = require('broccoli-replace');
var htmlReplace = require('./tools/broccoli/html-replace'); var htmlReplace = require('./tools/broccoli/html-replace');
var path = require('path'); var path = require('path');

View File

@ -737,11 +737,17 @@ gulp.task('build.dart', function(done) {
); );
}); });
gulp.task('broccoli.js.dev', function() { gulp.task('build.broccoli.tools', function() {
var tsResult = gulp.src('tools/broccoli/**/*.ts')
.pipe(tsc({ target: 'ES5', module: 'commonjs' }));
return tsResult.js.pipe(gulp.dest('dist/broccoli'));
});
gulp.task('broccoli.js.dev', ['build.broccoli.tools'], function() {
return broccoliBuild(require('./Brocfile-js_dev.js'), path.join('js', 'dev')); return broccoliBuild(require('./Brocfile-js_dev.js'), path.join('js', 'dev'));
}); });
gulp.task('broccoli.js.prod', function() { gulp.task('broccoli.js.prod', ['build.broccoli.tools'], function() {
return broccoliBuild(require('./Brocfile-js_prod.js'), path.join('js', 'prod')); return broccoliBuild(require('./Brocfile-js_prod.js'), path.join('js', 'prod'));
}); });
@ -755,7 +761,7 @@ gulp.task('build.js.dev', function(done) {
gulp.task('build.js.prod', ['broccoli.js.prod']); gulp.task('build.js.prod', ['broccoli.js.prod']);
gulp.task('broccoli.js.cjs', function() { gulp.task('broccoli.js.cjs', ['build.broccoli.tools'], function() {
return broccoliBuild(require('./Brocfile-js_cjs.js'), path.join('js', 'cjs')); return broccoliBuild(require('./Brocfile-js_cjs.js'), path.join('js', 'cjs'));
}); });
gulp.task('build.js.cjs', function(done) { gulp.task('build.js.cjs', function(done) {

View File

@ -20,7 +20,7 @@
"url": "https://github.com/angular/angular.git" "url": "https://github.com/angular/angular.git"
}, },
"scripts": { "scripts": {
"preinstall": "npm install tsd && tsd update --config modules/angular2/tsd.json", "preinstall": "npm install tsd && tsd update --config modules/angular2/tsd.json && tsd update --config tools/tsd.json",
"postinstall": "webdriver-manager update && bower install && gulp pubget.dart", "postinstall": "webdriver-manager update && bower install && gulp pubget.dart",
"test": "gulp test.all.js && gulp test.all.dart" "test": "gulp test.all.js && gulp test.all.dart"
}, },

View File

@ -1,56 +0,0 @@
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
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');
var TraceurFilter = (function (_super) {
__extends(TraceurFilter, _super);
function TraceurFilter(inputTree, destExtension, destSourceMapExtension, options) {
if (options === void 0) { options = {}; }
this.inputTree = inputTree;
this.destExtension = destExtension;
this.destSourceMapExtension = destSourceMapExtension;
this.options = options;
}
TraceurFilter.prototype.write = function (readTree, destDir) {
var _this = this;
return readTree(this.inputTree).then(function (srcDir) {
walkSync(srcDir).filter(function (filepath) {
var extension = path.extname(filepath).toLowerCase();
return extension === '.js' || extension === '.es6' || extension === '.cjs';
}).map(function (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)
var mapFilepath = filepath.replace(/\.\w+$/, '') + _this.destSourceMapExtension;
result.js = result.js + ("\n//# sourceMappingURL=./" + path.basename(mapFilepath));
var destFilepath = filepath.replace(/\.\w+$/, _this.destExtension);
var destFile = path.join(destDir, destFilepath);
fse.mkdirsSync(path.dirname(destFile));
fs.writeFileSync(destFile, result.js, fsOpts);
var destMap = path.join(destDir, mapFilepath);
result.sourceMap.file = destFilepath;
fs.writeFileSync(destMap, JSON.stringify(result.sourceMap), fsOpts);
});
});
};
TraceurFilter.RUNTIME_PATH = traceur.RUNTIME_PATH;
return TraceurFilter;
})(Writer);
module.exports = TraceurFilter;
//# sourceMappingURL=index.js.map

View File

@ -1,16 +1,21 @@
var fs = require('fs'); /// <reference path="../broccoli-writer.d.ts" />
var fse = require('fs-extra'); /// <reference path="../../typings/fs-extra/fs-extra.d.ts" />
var path = require('path'); /// <reference path="../../typings/node/node.d.ts" />
var traceur = require('../../transpiler'); import fs = require('fs');
import fse = require('fs-extra');
import path = require('path');
var traceur = require('../../../tools/transpiler');
var walkSync = require('walk-sync'); var walkSync = require('walk-sync');
var Writer = require('broccoli-writer'); import Writer = require('broccoli-writer');
var xtend = require('xtend'); var xtend = require('xtend');
class TraceurFilter extends Writer { class TraceurFilter extends Writer {
static RUNTIME_PATH = traceur.RUNTIME_PATH; static RUNTIME_PATH = traceur.RUNTIME_PATH;
constructor(private inputTree, private destExtension: string, constructor(private inputTree, private destExtension: string,
private destSourceMapExtension: string, private options = {}) {} private destSourceMapExtension: string, private options = {}) {
super();
}
write(readTree, destDir) { write(readTree, destDir) {
return readTree(this.inputTree) return readTree(this.inputTree)

View File

@ -1,61 +0,0 @@
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var fs = require('fs');
var path = require('path');
var ts = require('typescript');
var walkSync = require('walk-sync');
var Writer = require('broccoli-writer');
var xtend = require('xtend');
var TSCompiler = (function (_super) {
__extends(TSCompiler, _super);
function TSCompiler(inputTree, options) {
if (options === void 0) { options = {}; }
_super.call(this, inputTree, options);
this.inputTree = inputTree;
this.options = options;
}
TSCompiler.prototype.write = function (readTree, destDir) {
var options = xtend({
outDir: destDir
}, this.options);
if (this.options.outDir) {
options.outDir = path.resolve(destDir, options.outDir);
}
if (options.out) {
options.out = path.resolve(destDir, options.out);
}
options.target = ts.ScriptTarget[options.target];
return readTree(this.inputTree).then(function (srcDir) {
var files = walkSync(srcDir).filter(function (filepath) {
return path.extname(filepath).toLowerCase() === '.ts';
}).map(function (filepath) {
return path.resolve(srcDir, filepath);
});
if (files.length > 0) {
var program = ts.createProgram(files, options);
var emitResult = program.emit();
var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
var errMsg = '';
allDiagnostics.forEach(function (diagnostic) {
var message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
if (!diagnostic.file) {
errMsg += "\n" + message;
return;
}
var _a = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start), line = _a.line, character = _a.character;
errMsg += "\n" + diagnostic.file.fileName + " (" + (line + 1) + "," + (character + 1) + "): " + message;
});
if (emitResult.emitSkipped) {
throw new Error(errMsg);
}
}
});
};
return TSCompiler;
})(Writer);
module.exports = TSCompiler;
//# sourceMappingURL=index.js.map

View File

@ -1,12 +1,16 @@
var fs = require('fs'); /// <reference path="../broccoli-writer.d.ts" />
var path = require('path'); /// <reference path="../../typings/node/node.d.ts" />
var ts = require('typescript'); /// <reference path="../../../node_modules/typescript/bin/typescript.d.ts" />
import fs = require('fs');
import path = require('path');
import ts = require('typescript');
var walkSync = require('walk-sync'); var walkSync = require('walk-sync');
var Writer = require('broccoli-writer'); import Writer = require('broccoli-writer');
var xtend = require('xtend'); var xtend = require('xtend');
class TSCompiler extends Writer { class TSCompiler extends Writer {
constructor(private inputTree, private options = {}) { super(inputTree, options); } constructor(private inputTree, private options: ts.CompilerOptions = {}) { super(); }
write(readTree, destDir) { write(readTree, destDir) {
var options: ts.CompilerOptions = xtend({outDir: destDir}, this.options); var options: ts.CompilerOptions = xtend({outDir: destDir}, this.options);
@ -16,7 +20,7 @@ class TSCompiler extends Writer {
if (options.out) { if (options.out) {
options.out = path.resolve(destDir, options.out); options.out = path.resolve(destDir, options.out);
} }
options.target = ts.ScriptTarget[options.target]; options.target = (<any>ts).ScriptTarget[options.target];
return readTree(this.inputTree) return readTree(this.inputTree)
.then(srcDir => { .then(srcDir => {
var files = walkSync(srcDir) var files = walkSync(srcDir)