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:
parent
d8aa4fbb70
commit
4a753926b4
45
gulpfile.js
45
gulpfile.js
|
@ -18,6 +18,7 @@ var shell = require('gulp-shell');
|
|||
var spawn = require('child_process').spawn;
|
||||
var through2 = require('through2');
|
||||
var watch = require('gulp-watch');
|
||||
var changed = require('gulp-changed');
|
||||
|
||||
var js2es5Options = {
|
||||
sourceMaps: true,
|
||||
|
@ -44,6 +45,8 @@ var js2dartOptions = {
|
|||
outputLanguage: 'dart'
|
||||
};
|
||||
|
||||
var PUB_CMD = process.platform === 'win32' ? 'pub.bat' : 'pub';
|
||||
|
||||
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) {
|
||||
var outputDir = sourceTypeConfigs.dart.outputDir;
|
||||
return gulp.src('modules/*/pubspec.yaml')
|
||||
.pipe(changed(outputDir)) // Only forward files that changed.
|
||||
.pipe(gulpDestWithForward(outputDir))
|
||||
.pipe(through2.obj(function(file, enc, done) {
|
||||
var targetFile = path.join(outputDir, file.relative);
|
||||
if (fs.existsSync(targetFile)) {
|
||||
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'], {
|
||||
// After a `pubspec.yml` is copied, we run `pub install`.
|
||||
spawn(PUB_CMD, ['get'], {
|
||||
stdio: [process.stdin, process.stdout, process.stderr],
|
||||
cwd: path.dirname(file.path)
|
||||
});
|
||||
stream.on('close', done);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
}).on('close', done);
|
||||
}));
|
||||
});
|
||||
|
||||
|
@ -160,6 +148,23 @@ function createModuleTask(sourceTypeConfig) {
|
|||
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
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
"systemjs": "^0.9.1",
|
||||
"angular-benchpress": "^0.1.3",
|
||||
"gulp": "^3.8.8",
|
||||
"gulp-changed": "^1.0.0",
|
||||
"gulp-rename": "^1.2.0",
|
||||
"gulp-watch": "^1.0.3",
|
||||
"gulp-shell": "^0.2.10",
|
||||
|
|
Loading…
Reference in New Issue