-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.mjs
71 lines (67 loc) · 1.67 KB
/
build.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
62
63
64
65
66
67
68
69
70
71
import * as esbuild from "esbuild";
import * as fs from "node:fs/promises";
async function main(watch) {
const ctx = await esbuild.context({
entryPoints: ["srcts/index.ts"],
bundle: true,
outfile: "dist/index.js",
});
try {
if (!watch) {
if (!(await build(ctx))) {
process.exit(1);
}
} else {
await build(ctx);
const watcher = fs.watch("srcts", { recursive: true });
for await (const { eventType, filename } of watcher) {
console.error(`Rebuilding (${filename})`);
await build(ctx);
}
}
} finally {
await ctx.dispose();
}
}
async function build(ctx) {
const start = Date.now();
try {
try {
const result = await ctx.rebuild();
if (result.errors.length > 0) {
console.error(result.errors);
return false;
}
// Succeeded with warnings
if (result.warnings.length > 0) {
console.error(result.warnings);
}
} catch (e) {
console.error(e);
return false;
}
// We don't expect this to fail. If it throws, let it crash the process.
await postBuild();
return true;
} finally {
console.error("Build took " + (Date.now() - start) + "ms");
}
}
async function postBuild() {
await fs.cp("dist", "python-package/shinymedia/dist", {
recursive: true,
errorOnExist: false,
preserveTimestamps: true,
});
await fs.cp("dist", "r-package/inst/dist", {
recursive: true,
errorOnExist: false,
preserveTimestamps: true,
});
await fs.cp("dist", "docs/lib/shinymedia/", {
recursive: true,
errorOnExist: false,
preserveTimestamps: true,
});
}
await main(process.argv.includes("--watch"));