forked from babel/minify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
66 lines (56 loc) · 1.55 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"use strict";
const through = require("through2");
const chalk = require("chalk");
const newer = require("gulp-newer");
const babel = require("gulp-babel");
const log = require("fancy-log");
const gulp = require("gulp");
const path = require("path");
const build = gulp.series(buildPackages, buildUtils);
const watch = gulp.series(build, () => {
const scripts = [
getBuildConfig("packages").scripts,
getBuildConfig("utils").scripts
];
gulp.watch(scripts, { debounceDelay: 200 }, build).on("error", () => {});
});
function buildPackages() {
return getBuildTask(getBuildConfig("packages"));
}
function buildUtils() {
return getBuildTask(getBuildConfig("utils"));
}
exports.build = build;
exports.watch = watch;
exports.buildPackages = buildPackages;
exports.buildUtils = buildUtils;
function getBuildTask({ scripts, dest }) {
return gulp
.src(scripts)
.pipe(
through.obj((file, enc, callback) => {
file._path = file.path;
file.path = path.resolve(file.base, swapSrcWithLib(file.relative));
callback(null, file);
})
)
.pipe(newer(dest))
.pipe(
through.obj((file, enc, callback) => {
log("Compiling", "'" + chalk.cyan(file._path) + "'...");
callback(null, file);
})
)
.pipe(babel())
.pipe(gulp.dest(dest));
}
function getBuildConfig(dir) {
const scripts = `./${dir}/*/src/**/*.js`;
const dest = dir;
return { scripts, dest };
}
function swapSrcWithLib(srcPath) {
const parts = srcPath.split(path.sep);
parts[1] = "lib";
return parts.join(path.sep);
}