-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserve-apps.mjs
More file actions
90 lines (77 loc) · 2.27 KB
/
serve-apps.mjs
File metadata and controls
90 lines (77 loc) · 2.27 KB
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
import { execSync, spawn } from "node:child_process";
import { existsSync } from "node:fs";
import { resolve } from "node:path";
const APPS = {
"air-quality-dashboard": 5174,
"building-footprints": 5175,
"fire-tracker": 5176,
"forest-change-viewer": 5177,
"land-cover-explorer": 5178,
"no2-viewer": 5179,
"precipitation-viewer": 5180,
"sea-surface-temp": 5181,
"wind-globe": 5182,
"earthquake-arcs": 5183,
"coastal-explorer": 5184,
};
const args = process.argv.slice(2);
if (args.length === 0) {
console.log("\nAvailable test apps:\n");
for (const [name, port] of Object.entries(APPS)) {
console.log(` ${name.padEnd(26)} http://localhost:${port}/`);
}
console.log("\nUsage:");
console.log(" node serve-apps.mjs <app-name> [app-name...]");
console.log(" node serve-apps.mjs --all\n");
process.exit(0);
}
const requested = args.includes("--all")
? Object.keys(APPS)
: args;
const invalid = requested.filter((name) => !(name in APPS));
if (invalid.length) {
console.error(`Unknown app(s): ${invalid.join(", ")}`);
console.error(`Available: ${Object.keys(APPS).join(", ")}`);
process.exit(1);
}
for (const name of requested) {
const dir = resolve("tests", name);
if (!existsSync(dir)) {
console.error(`Directory not found: ${dir}`);
process.exit(1);
}
}
console.log("Building @maptool/core...\n");
execSync("npm run build", { stdio: "inherit" });
console.log("");
const children = [];
for (const name of requested) {
const port = APPS[name];
const child = spawn("npx", ["vite", "--port", String(port)], {
cwd: resolve("tests", name),
stdio: ["ignore", "pipe", "pipe"],
});
const prefix = `[${name}]`;
child.stdout.on("data", (data) => {
for (const line of data.toString().split("\n").filter(Boolean)) {
console.log(`${prefix} ${line}`);
}
});
child.stderr.on("data", (data) => {
for (const line of data.toString().split("\n").filter(Boolean)) {
console.error(`${prefix} ${line}`);
}
});
child.on("exit", (code) => {
console.log(`${prefix} exited (code ${code})`);
});
children.push(child);
}
process.on("SIGINT", () => {
for (const child of children) child.kill();
process.exit(0);
});
process.on("SIGTERM", () => {
for (const child of children) child.kill();
process.exit(0);
});