-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Gulpfile.js
77 lines (69 loc) · 2.07 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
67
68
69
70
71
72
73
74
75
76
77
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 srcEx, libFragment;
if (path.win32 === path) {
srcEx = /(packages\\[^\\]+)\\src\\/;
libFragment = "$1\\lib\\";
} else {
srcEx = new RegExp("(packages/[^/]+)/src/");
libFragment = "$1/lib/";
}
var mapToDest = function (path) { return path.replace(srcEx, libFragment); };
var 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));
});
// TODO: remove this section
// temporarily just copying the old code since watch isn't working
var dest = "packages";
gulp.task("build-watch", 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-watch"], function (callback) {
watch(scripts, {debounceDelay: 200}, function () {
gulp.start("build-watch");
});
});