-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.mjs
More file actions
56 lines (47 loc) · 1.38 KB
/
Copy pathbuild.mjs
File metadata and controls
56 lines (47 loc) · 1.38 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
import { bundle } from "./tools/bundle.mjs";
import { bundle_css } from "./tools/css.mjs";
import { node_modules_external } from "./tools/externals.mjs";
import fs from "fs";
import cpy from "cpy";
const BUNDLES = [
{
entryPoints: ["src/ts/index.ts"],
plugins: [node_modules_external()],
outfile: "dist/esm/index.js",
},
{
entryPoints: ["src/ts/index.ts"],
outfile: "dist/cdn/index.js",
},
];
async function build() {
if (fs.existsSync("dist")) {
for (const entry of fs.readdirSync("dist")) {
if (entry !== "pkg") {
fs.rmSync(`dist/${entry}`, { recursive: true, force: true });
}
}
}
fs.rmSync("../python_template_cppjswasm/extension", {
recursive: true,
force: true,
});
// Bundle css
await bundle_css();
// Copy HTML
await cpy("src/html/*", "dist/");
// Copy images
if (fs.existsSync("src/img")) {
fs.mkdirSync("dist/img", { recursive: true });
await cpy("src/img/*", "dist/img");
}
await Promise.all(BUNDLES.map(bundle)).catch(() => process.exit(1));
// Copy servable assets to python extension (exclude esm/)
fs.mkdirSync("../python_template_cppjswasm/extension", { recursive: true });
await cpy("dist/**/*", "../python_template_cppjswasm/extension", {
filter: (file) =>
!file.relativePath.startsWith("esm/") &&
!file.relativePath.startsWith("dist/esm/"),
});
}
await build();