-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.mjs
More file actions
92 lines (80 loc) · 2.24 KB
/
build.mjs
File metadata and controls
92 lines (80 loc) · 2.24 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
91
92
import { NodeModulesExternal } from "@finos/perspective-esbuild-plugin/external.js";
import { build } from "@finos/perspective-esbuild-plugin/build.js";
import { transform } from "lightningcss";
import { getarg } from "./tools/getarg.mjs";
import fs from "fs";
import cpy from "cpy";
const DEBUG = getarg("--debug");
const COMMON_DEFINE = {
global: "window",
"process.env.DEBUG": `${DEBUG}`,
};
const BUILD = [
{
define: COMMON_DEFINE,
entryPoints: ["src/ts/index.ts"],
plugins: [NodeModulesExternal()],
format: "esm",
loader: {
".css": "text",
".html": "text",
},
outfile: "dist/esm/index.js",
},
{
define: COMMON_DEFINE,
entryPoints: ["src/ts/index.ts"],
plugins: [],
format: "esm",
loader: {
".css": "text",
".html": "text",
},
outfile: "dist/cdn/index.js",
},
];
async function compile_css() {
const process_path = (path) => {
const outpath = path.replace("src/css", "dist/css");
fs.mkdirSync(outpath, { recursive: true });
fs.readdirSync(path, { withFileTypes: true }).forEach((entry) => {
const input = `${path}/${entry.name}`;
const output = `${outpath}/${entry.name}`;
if (entry.isDirectory()) {
process_path(input);
} else if (entry.isFile() && entry.name.endsWith(".css")) {
const source = fs.readFileSync(input);
const { code } = transform({
filename: entry.name,
code: source,
minify: !DEBUG,
sourceMap: false,
});
fs.writeFileSync(output, code);
}
});
};
process_path("src/css");
}
async function copy_html() {
fs.mkdirSync("dist/html", { recursive: true });
cpy("src/html/*", "dist/html");
// also copy to top level
cpy("src/html/*", "dist/");
}
async function copy_img() {
fs.mkdirSync("dist/img", { recursive: true });
cpy("src/img/*", "dist/img");
}
async function copy_to_python() {
fs.mkdirSync("../python_template_cppjswasm/extension", { recursive: true });
cpy("dist/**/*", "../python_template_cppjswasm/extension");
}
async function build_all() {
await compile_css();
await copy_html();
await copy_img();
await Promise.all(BUILD.map(build)).catch(() => process.exit(1));
await copy_to_python();
}
build_all();