chore(gulp): Skip Dart tasks when the SDK is not detected

fixes #268
This commit is contained in:
Victor Berchet 2014-12-03 15:21:57 +01:00
parent 65242fbd6d
commit 5857c9f767
2 changed files with 49 additions and 20 deletions

View File

@ -13,6 +13,7 @@ var readline = require('readline');
var runSequence = require('run-sequence'); var runSequence = require('run-sequence');
var spawn = require('child_process').spawn; var spawn = require('child_process').spawn;
var through2 = require('through2'); var through2 = require('through2');
var which = require('which');
var js2es5Options = { var js2es5Options = {
sourceMaps: true, sourceMaps: true,
@ -41,7 +42,35 @@ var js2dartOptions = {
outputLanguage: 'dart' outputLanguage: 'dart'
}; };
var PUB_CMD = process.platform === 'win32' ? 'pub.bat' : 'pub'; var DART_SDK = false;
try {
which.sync('dart');
console.log('Dart SDK detected');
if (process.platform === 'win32') {
DART_SDK = {
PUB: 'pub.bat',
ANALYZER: 'dartanalyzer.bat'
};
} else {
DART_SDK = {
PUB: 'pub',
ANALYZER: 'dartanalyzer'
};
}
} catch (e) {
console.log('Dart SDK is not available, Dart tasks will be skipped.');
var gulpTaskFn = gulp.task.bind(gulp);
gulp.task = function (name, deps, fn) {
if (name.indexOf('.dart') === -1) {
return gulpTaskFn(name, deps, fn);
} else {
return gulpTaskFn(name, function() {
console.log('Dart SDK is not available. Skipping task: ' + name);
});
}
};
}
var gulpTraceur = require('./tools/transpiler/gulp-traceur'); var gulpTraceur = require('./tools/transpiler/gulp-traceur');
@ -105,7 +134,7 @@ gulp.task('modules/build.dart/pubspec', function() {
return streamToPromise(changedStream) return streamToPromise(changedStream)
.then(function() { .then(function() {
return Q.all(files.map(function(file) { return Q.all(files.map(function(file) {
return processToPromise(spawn(PUB_CMD, ['get'], { return processToPromise(spawn(DART_SDK.PUB, ['get'], {
stdio: 'inherit', stdio: 'inherit',
cwd: path.dirname(file) cwd: path.dirname(file)
})); }));
@ -178,7 +207,7 @@ function createModuleTask(sourceTypeConfig) {
// ------------------ // ------------------
// ANALYZE // ANALYZE
gulp.task('analyze/dartanalyzer', function(done) { gulp.task('analyze/analyzer.dart', function(done) {
var pubSpecs = [].slice.call(glob.sync('build/dart/*/pubspec.yaml', { var pubSpecs = [].slice.call(glob.sync('build/dart/*/pubspec.yaml', {
cwd: __dirname cwd: __dirname
})); }));
@ -205,8 +234,7 @@ gulp.task('analyze/dartanalyzer', function(done) {
})); }));
function analyze(dirName, done) { function analyze(dirName, done) {
var dartanalyzerCmd = (process.platform === "win32" ? "dartanalyzer.bat" : "dartanalyzer"); var stream = spawn(DART_SDK.ANALYZER, ['--fatal-warnings', tempFile], {
var stream = spawn(dartanalyzerCmd, ['--fatal-warnings', tempFile], {
// inherit stdin and stderr, but filter stdout // inherit stdin and stderr, but filter stdout
stdio: [process.stdin, 'pipe', process.stderr], stdio: [process.stdin, 'pipe', process.stderr],
cwd: dirName cwd: dirName
@ -348,7 +376,7 @@ gulp.task('serve', function() {
}); });
gulp.task('examples/pub.serve', function(done) { gulp.task('examples/pub.serve', function(done) {
spawn(PUB_CMD, ['serve'], {cwd: 'build/dart/examples', stdio: 'inherit'}) spawn(DART_SDK.PUB, ['serve'], {cwd: 'build/dart/examples', stdio: 'inherit'})
.on('done', done); .on('done', done);
}); });
@ -364,10 +392,10 @@ gulp.task('build', function(done) {
// parallel // parallel
['jsRuntime/build', 'modules/build.dart', 'modules/build.dev.js'], ['jsRuntime/build', 'modules/build.dart', 'modules/build.dev.js'],
// sequential // sequential
'analyze/dartanalyzer' 'analyze/analyzer.dart'
); );
}); });
gulp.task('analyze', function(done) { gulp.task('analyze', function(done) {
runSequence('analyze/dartanalyzer'); runSequence('analyze/analyzer.dart');
}); });

View File

@ -8,30 +8,31 @@
"author": "Tobias Bosch <tbosch@google.com>", "author": "Tobias Bosch <tbosch@google.com>",
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"es6-module-loader": "^0.9.2",
"systemjs": "^0.9.1",
"angular-benchpress": "^0.1.3", "angular-benchpress": "^0.1.3",
"karma-cli": "^0.0.4", "es6-module-loader": "^0.9.2",
"event-stream": "^3.1.5",
"glob": "^4.0.6",
"gulp-connect": "~1.0.5",
"gulp-rimraf": "^0.1.0",
"karma": "^0.12.23", "karma": "^0.12.23",
"karma-chrome-launcher": "^0.1.4", "karma-chrome-launcher": "^0.1.4",
"karma-cli": "^0.0.4",
"karma-dart": "^0.2.8", "karma-dart": "^0.2.8",
"karma-jasmine": "^0.2.2", "karma-jasmine": "^0.2.2",
"merge": "^1.2.0", "merge": "^1.2.0",
"q": "^1.0.1", "q": "^1.0.1",
"through2": "^0.6.1",
"event-stream": "^3.1.5",
"gulp-connect": "~1.0.5",
"gulp-rimraf": "^0.1.0",
"run-sequence": "^0.3.6", "run-sequence": "^0.3.6",
"glob": "^4.0.6", "systemjs": "^0.9.1",
"traceur": "0.0.74" "through2": "^0.6.1",
"traceur": "0.0.74",
"which": "~1"
}, },
"devDependencies": { "devDependencies": {
"gulp": "^3.8.8", "gulp": "^3.8.8",
"gulp-changed": "^1.0.0", "gulp-changed": "^1.0.0",
"gulp-rename": "^1.2.0", "gulp-ejs": "^0.3.1",
"gulp-shell": "^0.2.10",
"gulp-load-plugins": "^0.7.1", "gulp-load-plugins": "^0.7.1",
"gulp-ejs": "^0.3.1" "gulp-rename": "^1.2.0",
"gulp-shell": "^0.2.10"
} }
} }