55 lines
1.4 KiB
JavaScript
55 lines
1.4 KiB
JavaScript
"use strict";
|
|
|
|
const plumber = require("gulp-plumber");
|
|
const through = require("through2");
|
|
const chalk = require("chalk");
|
|
const newer = require("gulp-newer");
|
|
const babel = require("gulp-babel");
|
|
const watch = require("gulp-watch");
|
|
const gutil = require("gulp-util");
|
|
const gulp = require("gulp");
|
|
const path = require("path");
|
|
|
|
const scripts = "./packages/*/src/**/*.js";
|
|
let srcEx, libFragment;
|
|
|
|
if (path.win32 === path) {
|
|
srcEx = /(packages\\[^\\]+)\\src\\/;
|
|
libFragment = "$1\\lib\\";
|
|
} else {
|
|
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("build", function () {
|
|
return gulp.src(scripts)
|
|
.pipe(plumber({
|
|
errorHandler: function (err) {
|
|
gutil.log(err.stack);
|
|
},
|
|
}))
|
|
.pipe(newer({ map: mapToDest }))
|
|
.pipe(through.obj(function (file, enc, callback) {
|
|
gutil.log("Compiling", "'" + chalk.cyan(file.path) + "'...");
|
|
callback(null, file);
|
|
}))
|
|
.pipe(babel())
|
|
.pipe(through.obj(function (file, enc, callback) {
|
|
file._path = file.path;
|
|
file.path = mapToDest(file.path);
|
|
callback(null, file);
|
|
}))
|
|
.pipe(gulp.dest(dest));
|
|
});
|
|
|
|
gulp.task("watch", ["build"], function () {
|
|
watch(scripts, { debounceDelay: 200 }, function () {
|
|
gulp.start("build");
|
|
});
|
|
});
|