-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
compile_examples.mjs
61 lines (49 loc) · 1.4 KB
/
compile_examples.mjs
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
import { spawn } from "node:child_process";
import { existsSync } from "node:fs";
import { readdir } from "node:fs/promises";
import { resolve } from "node:path";
const examplesFolder = "examples";
for (const exampleName of await readdir(examplesFolder)) {
const folder = resolve(examplesFolder, exampleName);
{
console.error(`Testing ${exampleName}`);
const proc = spawn("cargo test", {
cwd: folder,
shell: true,
});
proc.stdout.on("data", buf => console.log(String(buf)));
// proc.stderr.on("data", buf => console.error(String(buf)));
await new Promise((resolve, _) => {
proc.on("exit", () => {
if (proc.exitCode > 0) {
console.error(`${exampleName} FAILED`);
process.exit(1);
}
else {
resolve();
}
})
});
}
if (existsSync(resolve(folder, ".run"))) {
console.error(`Running ${exampleName}`);
const proc = spawn("cargo run", {
cwd: folder,
shell: true,
});
proc.stdout.on("data", buf => console.log(String(buf)));
proc.stderr.on("data", buf => console.error(String(buf)));
await new Promise((resolve, _) => {
proc.on("exit", () => {
if (proc.exitCode > 0) {
console.error(`${exampleName} FAILED`);
process.exit(1);
}
else {
resolve();
}
})
});
}
console.error(`${exampleName} OK`);
}