This repository has been archived by the owner on Apr 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
163 lines (131 loc) · 4.05 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
"use strict";
// NB: This gulp file is intended to be used with Gulp 4.x and won't
// work with Gulp 3.x or below.
var _ = require("lodash"),
argv = require('yargs').argv,
gulp = require("gulp"),
helpers = require("./build-helpers/gulp"),
production = require("./build-helpers/production"),
watch = helpers.watch(gulp);
/* Config vars */
var config = {
htmlGlobs: ["html/**/*.html"],
htmlOut: "pub", // HTML goes to root rather than subdir
assetMap: {
"img/**/*.*": "pub/img",
"img/favicon.ico": "pub",
"./node_modules/font-awesome/fonts/*.*": "pub/fonts"
},
jsGlobs: ["js/**/*.js"],
jsBundles: [
"bundles/react-page-vendor.js",
"bundles/timestats-vendor.js"
],
jsOut: "pub/js",
jasmineDir: "pub/jasmine",
tsCommonGlobs: [
"ts/lib/**/*.{ts,tsx}"
],
tsProjects: [
"ts/manage.js/tsconfig.json",
"ts/now.js/tsconfig.json",
// "ts/test.js/tsconfig.json", // Disable -> use ts var to run
"ts/time.js/tsconfig.json"
],
lessGlobs: [
"less/**/*.{css,less}",
"./node_modules/font-awesome/css/font-awesome.css"
],
lessOut: "pub/css",
pubDir: "pub",
serverPort: 5001,
liveReloadPort: 35729
};
// Test-related targets
if (argv.ts && argv.ts === "ts/test.js/tsconfig.json") {
config.jsBundles.push("bundles/test-vendor.js");
}
/* Gulp tasks */
gulp.task("build-less", function() {
return helpers.less(config.lessGlobs, config.lessOut);
});
gulp.task("watch-less", watch(config.lessGlobs, "build-less"));
gulp.task("build-jasmine", function() {
return helpers.jasmine(config.jasmineDir);
});
gulp.task("build-js", function() {
return helpers.js(config.jsGlobs, config.jsOut);
});
gulp.task("watch-js", watch(config.jsGlobs, "build-js"));
// Focus on one project with the 'ts' flag
var projects = argv.ts ? [argv.ts] : config.tsProjects;
var ts = helpers.typescript(projects,
config.tsCommonGlobs,
config.jsOut);
gulp.task("build-ts", ts.build);
gulp.task("watch-ts", ts.watch);
gulp.task("build-assets", function() {
return helpers.assets(config.assetMap);
});
gulp.task("watch-assets", watch(_.keys(config.assetMap), "build-assets"));
gulp.task("build-html", function() {
let globs = config.htmlGlobs;
if (production.isSet()) {
globs = globs.concat(["!html/**/test*"]);
}
return helpers.html(globs, config.htmlOut);
});
gulp.task("watch-html", watch(config.htmlGlobs, "build-html"));
gulp.task("build-bundles", function() {
return helpers.bundle(config.jsBundles, config.jsOut);
});
// NB: Watching Browserify bundles just means passing an extra boolean to
// build step. Gulp's watcher is not required.
gulp.task("watch-bundles", function() {
return helpers.bundle(config.jsBundles, config.jsOut, true);
});
gulp.task("server", function(cb) {
return helpers.server(config.pubDir, cb, {
port: config.serverPort,
liveReloadPort: config.liveReloadPort
});
});
/*
Build tasks that involve revisioning with MD5 hashes before the other stuff
so that we can replace as appropriate.
Note that we're currently not MD5-hashing assets, only JS and CSS, since
our assets don't change that often and additional hashing would require
that we also update references to those assets within our JS and CSS
files before hashing those files and replacing those references in HTML.
*/
gulp.task("build", gulp.series(
gulp.parallel(
"build-js",
"build-bundles",
"build-ts",
"build-less"
),
gulp.parallel(
"build-assets",
"build-jasmine",
"build-html"
)
));
gulp.task("clean", function() {
return helpers.clean(config.pubDir);
});
gulp.task("production", helpers.setProduction);
gulp.task("build-production", gulp.series("production", "clean", "build"));
gulp.task("watch", gulp.series("build",
gulp.parallel(
"server",
"watch-html",
"watch-assets",
"watch-js",
// "watch-bundles", // Skipping since bundling is expensive
// If you need to re-bundle, clean and restart.
"watch-ts",
"watch-less"
)
));
gulp.task("default", gulp.series("build"));