Skip to content

Commit 6cac4fa

Browse files
committed
Use terriajs-server gulp task from terriajs
1 parent 3680c36 commit 6cac4fa

1 file changed

Lines changed: 2 additions & 57 deletions

File tree

gulpfile.js

Lines changed: 2 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var fs = require("fs");
1111
var gulp = require("gulp");
1212
var path = require("path");
1313
var PluginError = require("plugin-error");
14+
var terriajsServerGulpTask = require("terriajs/buildprocess/terriajsServerGulpTask");
1415

1516
var watchOptions = {
1617
interval: 1000
@@ -284,63 +285,7 @@ function checkForDuplicateCesium() {
284285
}
285286
}
286287

287-
gulp.task("terriajs-server", function (done) {
288-
// E.g. gulp terriajs-server --terriajsServerArg port=4000 --terriajsServerArg verbose=true
289-
// or gulp dev --terriajsServerArg port=3000
290-
const { spawn } = require("child_process");
291-
const minimist = require("minimist");
292-
// Arguments written in skewer-case can cause problems (unsure why), so stick to camelCase
293-
const options = minimist(process.argv.slice(2), {
294-
string: ["terriajsServerArg"],
295-
default: { terriajsServerArg: [] }
296-
});
297-
298-
const logFile = fs.openSync("./terriajs-server.log", "w");
299-
const serverArgs = Array.isArray(options.terriajsServerArg)
300-
? options.terriajsServerArg
301-
: [options.terriajsServerArg];
302-
const child = spawn(
303-
"node",
304-
[
305-
require.resolve("terriajs-server/terriajs-server.js"),
306-
...serverArgs.map((arg) => `--${arg}`)
307-
],
308-
{ detached: true, stdio: ["ignore", logFile, logFile] }
309-
);
310-
child.on("exit", (exitCode, signal) => {
311-
done(
312-
new Error(
313-
"terriajs-server quit" +
314-
(exitCode !== null ? ` with exit code: ${exitCode}` : "") +
315-
(signal ? ` from signal: ${signal}` : "") +
316-
"\nCheck terriajs-server.log for more information."
317-
)
318-
);
319-
});
320-
child.on("spawn", () => {
321-
console.log("terriajs-server started - see terriajs-server.log for logs");
322-
});
323-
// Intercept SIGINT, SIGTERM and SIGHUP, cleanup terriajs-server and re-send signal
324-
// May fail to catch some relevant signals on Windows
325-
// SIGINT: ctrl+c
326-
// SIGTERM: kill <pid>
327-
// SIGHUP: terminal closed
328-
process.once("SIGINT", () => {
329-
child.kill("SIGTERM");
330-
process.kill(process.pid, "SIGINT");
331-
});
332-
process.once("SIGTERM", () => {
333-
child.kill("SIGTERM");
334-
process.kill(process.pid, "SIGTERM");
335-
});
336-
process.once("SIGHUP", () => {
337-
child.kill("SIGTERM");
338-
process.kill(process.pid, "SIGHUP");
339-
});
340-
process.on("exit", () => {
341-
child.kill("SIGTERM");
342-
});
343-
});
288+
gulp.task("terriajs-server", terriajsServerGulpTask(3001));
344289

345290
gulp.task("build", gulp.series("copy-terriajs-assets", "build-app"));
346291
gulp.task("release", gulp.series("copy-terriajs-assets", "release-app"));

0 commit comments

Comments
 (0)