The problem with gulp pipeline is that it replaces /src/ with /lib/ in filenames as a regex replace operation. The regex only worked for Unix before. Here we add a 2nd regex accomodate Windows backslashes and choose between the two by looking if we're using path.win32. The Unix regex is changed to only match the package/*/src. This seemingly has no effect on the build. Fixes T6855
52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
JavaScript
var plumber = require("gulp-plumber");
|
|
var through = require("through2");
|
|
var chalk = require("chalk");
|
|
var newer = require("gulp-newer");
|
|
var babel = require("gulp-babel");
|
|
var watch = require("gulp-watch");
|
|
var gutil = require("gulp-util");
|
|
var gulp = require("gulp");
|
|
var path = require("path");
|
|
|
|
var scripts = "./packages/*/src/**/*.js";
|
|
var dest = "packages";
|
|
|
|
var srcEx, libFragment;
|
|
|
|
if (path.win32 === path) {
|
|
srcEx = /(packages\\[^\\]+)\\src\\/;
|
|
libFragment = "$1\\lib\\";
|
|
} else {
|
|
srcEx = new RegExp("(packages/[^/]+)/src/");
|
|
libFragment = "$1/lib/";
|
|
}
|
|
|
|
gulp.task("default", ["build"]);
|
|
|
|
gulp.task("build", function () {
|
|
return gulp.src(scripts)
|
|
.pipe(plumber({
|
|
errorHandler: function (err) {
|
|
gutil.log(err.stack);
|
|
}
|
|
}))
|
|
.pipe(through.obj(function (file, enc, callback) {
|
|
file._path = file.path;
|
|
file.path = file.path.replace(srcEx, libFragment);
|
|
callback(null, file);
|
|
}))
|
|
.pipe(newer(dest))
|
|
.pipe(through.obj(function (file, enc, callback) {
|
|
gutil.log("Compiling", "'" + chalk.cyan(file._path) + "'...");
|
|
callback(null, file);
|
|
}))
|
|
.pipe(babel())
|
|
.pipe(gulp.dest(dest));
|
|
});
|
|
|
|
gulp.task("watch", ["build"], function (callback) {
|
|
watch(scripts, function () {
|
|
gulp.start("build");
|
|
});
|
|
});
|