forked from TerriaJS/terriajs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
328 lines (284 loc) · 9.06 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
/*eslint-env node*/
/*eslint no-sync: 0*/
"use strict";
// Every module required-in here must be a `dependency` in package.json, not just a `devDependency`,
// so that our postinstall script (which runs `gulp post-npm-install`) is able to run without
// the devDependencies available. Individual tasks, other than `post-npm-install` and any tasks it
// calls, may require in `devDependency` modules locally.
var gulp = require("gulp");
gulp.task("build-specs", function (done) {
var runWebpack = require("./buildprocess/runWebpack.js");
var webpack = require("webpack");
var webpackConfig = require("./buildprocess/webpack.config.make.js")(
false,
true
);
runWebpack(webpack, webpackConfig, done);
});
gulp.task("release-specs", function (done) {
var runWebpack = require("./buildprocess/runWebpack.js");
var webpack = require("webpack");
var webpackConfig = require("./buildprocess/webpack.config.make.js")(
false,
false
);
runWebpack(webpack, webpackConfig, done);
});
gulp.task("watch-specs", function (done) {
var watchWebpack = require("./buildprocess/watchWebpack");
var webpack = require("webpack");
var webpackConfig = require("./buildprocess/webpack.config.make.js")(
false,
true
);
watchWebpack(webpack, webpackConfig, done);
});
gulp.task("lint", function (done) {
var runExternalModule = require("./buildprocess/runExternalModule");
runExternalModule("eslint/bin/eslint.js", [
"lib",
"test",
"--ext",
".jsx,.js,.ts,.tsx",
"--ignore-pattern",
"lib/ThirdParty",
"--max-warnings",
"481" // TODO: Bring this back to 0
]);
done();
});
gulp.task("reference-guide", function (done) {
var runExternalModule = require("./buildprocess/runExternalModule");
runExternalModule("jsdoc/jsdoc.js", [
"./lib",
"-c",
"./buildprocess/jsdoc.json"
]);
done();
});
gulp.task("copy-cesium-workers", function () {
var path = require("path");
var cesiumPackage = require.resolve("terriajs-cesium/package.json");
var cesiumRoot = path.dirname(cesiumPackage);
var cesiumWorkersRoot = path.join(cesiumRoot, "Build", "Workers");
return gulp
.src([path.join(cesiumWorkersRoot, "**")], {
base: cesiumWorkersRoot
})
.pipe(gulp.dest("wwwroot/build/Cesium/build/Workers"));
});
gulp.task("copy-cesium-thirdparty", function () {
var path = require("path");
var cesiumPackage = require.resolve("terriajs-cesium/package.json");
var cesiumRoot = path.dirname(cesiumPackage);
var cesiumThirdPartyRoot = path.join(cesiumRoot, "Source", "ThirdParty");
return gulp
.src([path.join(cesiumThirdPartyRoot, "**")], {
base: cesiumThirdPartyRoot
})
.pipe(gulp.dest("wwwroot/build/Cesium/build/ThirdParty"));
});
gulp.task("copy-cesium-source-assets", function () {
var path = require("path");
var cesiumPackage = require.resolve("terriajs-cesium/package.json");
var cesiumRoot = path.dirname(cesiumPackage);
var cesiumAssetsRoot = path.join(cesiumRoot, "Source", "Assets");
return gulp
.src([path.join(cesiumAssetsRoot, "**")], {
base: cesiumAssetsRoot
})
.pipe(gulp.dest("wwwroot/build/Cesium/build/Assets"));
});
gulp.task("test-browserstack", function (done) {
runKarma("./buildprocess/karma-browserstack.conf.js", done);
});
gulp.task("test-saucelabs", function (done) {
runKarma("./buildprocess/karma-saucelabs.conf.js", done);
});
gulp.task("test-firefox", function (done) {
runKarma("./buildprocess/karma-firefox.conf.js", done);
});
gulp.task("test-travis", function (done) {
if (process.env.SAUCE_ACCESS_KEY) {
runKarma("./buildprocess/karma-saucelabs.conf.js", done);
} else {
console.log(
"SauceLabs testing is not available for pull requests outside the main repo; using local headless Firefox instead."
);
runKarma("./buildprocess/karma-firefox.conf.js", done);
}
});
gulp.task("test", function (done) {
runKarma("./buildprocess/karma-local.conf.js", done);
});
function runKarma(configFile, done) {
var karma = require("karma").Server;
var path = require("path");
karma.start(
{
configFile: path.join(__dirname, configFile)
},
function (e) {
return done(e);
}
);
}
gulp.task("code-attribution", function userAttribution(done) {
var spawnSync = require("child_process").spawnSync;
var result = spawnSync(
"yarn",
["licenses generate-disclaimer > doc/acknowledgements/attributions.md"],
{
stdio: "inherit",
shell: true
}
);
if (result.status !== 0) {
throw new Error(
"Generating code attribution exited with an error.\n" +
result.stderr.toString(),
{ showStack: false }
);
}
done();
});
gulp.task("build-for-doc-generation", function buildForDocGeneration(done) {
var runWebpack = require("./buildprocess/runWebpack.js");
var webpack = require("webpack");
var webpackConfig = require("./buildprocess/webpack-tools.config.js")();
runWebpack(webpack, webpackConfig, done);
});
gulp.task(
"render-guide",
gulp.series(
function copyToBuild(done) {
const fse = require("fs-extra");
fse.copySync("doc", "build/doc");
done();
},
function generateMemberPages(done) {
const fse = require("fs-extra");
const PluginError = require("plugin-error");
const spawnSync = require("child_process").spawnSync;
fse.mkdirpSync("build/doc/connecting-to-data/catalog-type-details");
const result = spawnSync("node", ["generateDocs.js"], {
cwd: "build",
stdio: "inherit",
shell: false
});
if (result.status !== 0) {
throw new PluginError(
"user-doc",
"Generating catalog members pages exited with an error.",
{ showStack: false }
);
}
done();
},
function mkdocs(done) {
const PluginError = require("plugin-error");
const spawnSync = require("child_process").spawnSync;
const result = spawnSync(
"mkdocs",
["build", "--clean", "--config-file", "mkdocs.yml"],
{
cwd: "build",
stdio: "inherit",
shell: false
}
);
if (result.status !== 0) {
throw new PluginError(
"user-doc",
`Mkdocs exited with an error. Maybe you didn't install mkdocs and other python dependencies in requirements.txt - see https://docs.terria.io/guide/contributing/development-environment/#documentation?`,
{
showStack: false
}
);
}
done();
}
)
);
gulp.task(
"docs",
gulp.series(
gulp.parallel("code-attribution", "build-for-doc-generation"),
"render-guide",
function docs(done) {
var fse = require("fs-extra");
fse.copySync("doc/index-redirect.html", "wwwroot/doc/index.html");
done();
}
)
);
gulp.task("terriajs-server", function (done) {
// E.g. gulp terriajs-server --terriajsServerArg port=4000 --terriajsServerArg verbose=true
// or gulp dev --terriajsServerArg port=3000
const { spawn } = require("child_process");
const fs = require("fs");
const minimist = require("minimist");
const knownOptions = {
string: ["terriajsServerArg"],
default: {
terriajsServerArg: []
}
};
const options = minimist(process.argv.slice(2), knownOptions);
const logFile = fs.openSync("./terriajs-server.log", "a");
const serverArgs = Array.isArray(options.terriajsServerArg)
? options.terriajsServerArg
: [options.terriajsServerArg];
// Spawn detached - attached does not make terriajs-server
// quit when the gulp task is stopped
const child = spawn(
"node",
[
"./node_modules/.bin/terriajs-server",
"--port=3002",
...serverArgs.map((arg) => `--${arg}`)
],
{ detached: true, stdio: ["ignore", logFile, logFile] }
);
child.on("exit", (exitCode, signal) => {
done(
new Error(
"terriajs-server quit" +
(exitCode !== null ? ` with exit code: ${exitCode}` : "") +
(signal ? ` from signal: ${signal}` : "") +
"\nCheck terriajs-server.log for more information."
)
);
});
// Intercept SIGINT, SIGTERM and SIGHUP, cleanup terriajs-server and re-send signal
// May fail to catch some relevant signals on Windows
// SIGINT: ctrl+c
// SIGTERM: kill <pid>
// SIGHUP: terminal closed
process.once("SIGINT", () => {
child.kill("SIGTERM");
process.kill(process.pid, "SIGINT");
});
process.once("SIGTERM", () => {
child.kill("SIGTERM");
process.kill(process.pid, "SIGTERM");
});
process.once("SIGHUP", () => {
child.kill("SIGTERM");
process.kill(process.pid, "SIGHUP");
});
});
gulp.task(
"copy-cesium-assets",
gulp.series(
"copy-cesium-source-assets",
"copy-cesium-workers",
"copy-cesium-thirdparty"
)
);
gulp.task("build", gulp.series("copy-cesium-assets", "build-specs"));
gulp.task("release", gulp.series("copy-cesium-assets", "release-specs"));
gulp.task("watch", gulp.series("copy-cesium-assets", "watch-specs"));
gulp.task("dev", gulp.parallel("terriajs-server", "watch"));
gulp.task("post-npm-install", gulp.series("copy-cesium-assets"));
gulp.task("default", gulp.series("lint", "build"));