Ensure that incremental builds work with 'gulp build'. (#5561)

This commit is contained in:
Logan Smyth 2017-03-28 15:18:12 -07:00 committed by GitHub
parent 4bf8e4d08d
commit d3497348b8

View File

@ -10,41 +10,39 @@ const gutil = require("gulp-util");
const gulp = require("gulp"); const gulp = require("gulp");
const path = require("path"); const path = require("path");
const base = path.join(__dirname, "packages");
const scripts = "./packages/*/src/**/*.js"; const scripts = "./packages/*/src/**/*.js";
let srcEx, libFragment;
if (path.win32 === path) { function swapSrcWithLib(srcPath) {
srcEx = /(packages\\[^\\]+)\\src\\/; const parts = srcPath.split(path.sep);
libFragment = "$1\\lib\\"; parts[1] = "lib";
} else { return parts.join(path.sep);
srcEx = new RegExp("(packages/[^/]+)/src/");
libFragment = "$1/lib/";
} }
const mapToDest = function (path) { return path.replace(srcEx, libFragment); };
const dest = "packages";
gulp.task("default", ["build"]); gulp.task("default", ["build"]);
gulp.task("build", function () { gulp.task("build", function () {
return gulp.src(scripts) return gulp.src(scripts, { base: base })
.pipe(plumber({ .pipe(plumber({
errorHandler: function (err) { errorHandler: function (err) {
gutil.log(err.stack); gutil.log(err.stack);
}, },
})) }))
.pipe(newer({ map: mapToDest })) .pipe(newer({
dest: base,
map: swapSrcWithLib,
}))
.pipe(through.obj(function (file, enc, callback) { .pipe(through.obj(function (file, enc, callback) {
gutil.log("Compiling", "'" + chalk.cyan(file.path) + "'..."); gutil.log("Compiling", "'" + chalk.cyan(file.relative) + "'...");
callback(null, file); callback(null, file);
})) }))
.pipe(babel()) .pipe(babel())
.pipe(through.obj(function (file, enc, callback) { .pipe(through.obj(function (file, enc, callback) {
file._path = file.path; // Passing 'file.relative' because newer() above uses a relative path and this keeps it consistent.
file.path = mapToDest(file.path); file.path = path.resolve(file.base, swapSrcWithLib(file.relative));
callback(null, file); callback(null, file);
})) }))
.pipe(gulp.dest(dest)); .pipe(gulp.dest(base));
}); });
gulp.task("watch", ["build"], function () { gulp.task("watch", ["build"], function () {