chore: fix modules/build.dart/pubspec

This was failing on Travis because the `pub install` would run before
copying of `pubspec.yml` happened. In fact, I don’t understand how this
worked at all because `gulp.dest` seems to be not forwarding files and
so anything after `gulp.dest` does not get called at all.

Here is the failing Travis build:
https://travis-ci.org/angular/angular/builds/40005692

This changes `modules/build.dart/pubspec` task to use `gulp-changed`
instead of a custom implementation and use a wrapper around `gulp.dest`
to forward files.
This commit is contained in:
Vojta Jina 2014-11-04 16:37:28 -08:00
parent d8aa4fbb70
commit 4a753926b4
2 changed files with 28 additions and 22 deletions

View File

@ -18,6 +18,7 @@ var shell = require('gulp-shell');
var spawn = require('child_process').spawn; var spawn = require('child_process').spawn;
var through2 = require('through2'); var through2 = require('through2');
var watch = require('gulp-watch'); var watch = require('gulp-watch');
var changed = require('gulp-changed');
var js2es5Options = { var js2es5Options = {
sourceMaps: true, sourceMaps: true,
@ -44,6 +45,8 @@ var js2dartOptions = {
outputLanguage: 'dart' outputLanguage: 'dart'
}; };
var PUB_CMD = process.platform === 'win32' ? 'pub.bat' : 'pub';
var gulpTraceur = require('./tools/transpiler/gulp-traceur'); var gulpTraceur = require('./tools/transpiler/gulp-traceur');
// --------- // ---------
@ -92,29 +95,14 @@ gulp.task('modules/build.dart/src', function() {
gulp.task('modules/build.dart/pubspec', function(done) { gulp.task('modules/build.dart/pubspec', function(done) {
var outputDir = sourceTypeConfigs.dart.outputDir; var outputDir = sourceTypeConfigs.dart.outputDir;
return gulp.src('modules/*/pubspec.yaml') return gulp.src('modules/*/pubspec.yaml')
.pipe(changed(outputDir)) // Only forward files that changed.
.pipe(gulpDestWithForward(outputDir))
.pipe(through2.obj(function(file, enc, done) { .pipe(through2.obj(function(file, enc, done) {
var targetFile = path.join(outputDir, file.relative); // After a `pubspec.yml` is copied, we run `pub install`.
if (fs.existsSync(targetFile)) { spawn(PUB_CMD, ['get'], {
file.previousContents = fs.readFileSync(targetFile);
} else {
file.previousContents = '';
}
this.push(file);
done();
}))
.pipe(gulp.dest(outputDir))
.pipe(through2.obj(function(file, enc, done) {
if (file.previousContents.toString() !== file.contents.toString()) {
console.log(file.path + ' changed, calling pub get');
var pubCmd = (process.platform === "win32" ? "pub.bat" : "pub");
var stream = spawn(pubCmd, ['get'], {
stdio: [process.stdin, process.stdout, process.stderr], stdio: [process.stdin, process.stdout, process.stderr],
cwd: path.dirname(file.path) cwd: path.dirname(file.path)
}); }).on('close', done);
stream.on('close', done);
} else {
done();
}
})); }));
}); });
@ -160,6 +148,23 @@ function createModuleTask(sourceTypeConfig) {
return mergeStreams(transpile, copy, html); return mergeStreams(transpile, copy, html);
} }
// Act as `gulp.dest()` but does forward the files to the next stream.
// I believe this is how `gulp.dest` should work.
function gulpDestWithForward(destDir) {
var stream = gulp.dest(destDir);
var originalTransform = stream._transform;
stream._transform = function(file, enc, done) {
return originalTransform.call(this, file, enc, function() {
stream.push(file);
done();
});
};
return stream;
}
// ------------------ // ------------------
// ANALYZE // ANALYZE

View File

@ -12,6 +12,7 @@
"systemjs": "^0.9.1", "systemjs": "^0.9.1",
"angular-benchpress": "^0.1.3", "angular-benchpress": "^0.1.3",
"gulp": "^3.8.8", "gulp": "^3.8.8",
"gulp-changed": "^1.0.0",
"gulp-rename": "^1.2.0", "gulp-rename": "^1.2.0",
"gulp-watch": "^1.0.3", "gulp-watch": "^1.0.3",
"gulp-shell": "^0.2.10", "gulp-shell": "^0.2.10",