|
1 | | -import { NodeModulesExternal } from "@finos/perspective-esbuild-plugin/external.js"; |
2 | | -import { build } from "@finos/perspective-esbuild-plugin/build.js"; |
3 | | -import { transform } from "lightningcss"; |
| 1 | +import { bundle } from "./tools/bundle.mjs"; |
| 2 | +import { bundle_css } from "./tools/css.mjs"; |
| 3 | +import { node_modules_external } from "./tools/externals.mjs"; |
4 | 4 | import { getarg } from "./tools/getarg.mjs"; |
| 5 | + |
| 6 | +import { transform } from "lightningcss"; |
5 | 7 | import fs from "fs"; |
6 | 8 | import cpy from "cpy"; |
7 | 9 |
|
8 | | -const DEBUG = getarg("--debug"); |
9 | | - |
10 | | -const COMMON_DEFINE = { |
11 | | - global: "window", |
12 | | - "process.env.DEBUG": `${DEBUG}`, |
13 | | -}; |
14 | | - |
15 | | -const BUILD = [ |
| 10 | +const BUNDLES = [ |
16 | 11 | { |
17 | | - define: COMMON_DEFINE, |
18 | 12 | entryPoints: ["src/ts/index.ts"], |
19 | | - plugins: [NodeModulesExternal()], |
20 | | - format: "esm", |
21 | | - loader: { |
22 | | - ".css": "text", |
23 | | - ".html": "text", |
24 | | - }, |
| 13 | + plugins: [node_modules_external()], |
25 | 14 | outfile: "dist/esm/index.js", |
26 | 15 | }, |
27 | 16 | { |
28 | | - define: COMMON_DEFINE, |
29 | 17 | entryPoints: ["src/ts/index.ts"], |
30 | | - plugins: [], |
31 | | - format: "esm", |
32 | | - loader: { |
33 | | - ".css": "text", |
34 | | - ".html": "text", |
35 | | - }, |
36 | 18 | outfile: "dist/cdn/index.js", |
37 | 19 | }, |
38 | 20 | ]; |
39 | 21 |
|
40 | | -async function compile_css() { |
41 | | - const process_path = (path) => { |
42 | | - const outpath = path.replace("src/css", "dist/css"); |
43 | | - fs.mkdirSync(outpath, { recursive: true }); |
44 | | - |
45 | | - fs.readdirSync(path, { withFileTypes: true }).forEach((entry) => { |
46 | | - const input = `${path}/${entry.name}`; |
47 | | - const output = `${outpath}/${entry.name}`; |
48 | | - |
49 | | - if (entry.isDirectory()) { |
50 | | - process_path(input); |
51 | | - } else if (entry.isFile() && entry.name.endsWith(".css")) { |
52 | | - const source = fs.readFileSync(input); |
53 | | - const { code } = transform({ |
54 | | - filename: entry.name, |
55 | | - code: source, |
56 | | - minify: !DEBUG, |
57 | | - sourceMap: false, |
58 | | - }); |
59 | | - fs.writeFileSync(output, code); |
60 | | - } |
61 | | - }); |
62 | | - }; |
| 22 | +async function build() { |
| 23 | + // Bundle css |
| 24 | + await bundle_css(); |
63 | 25 |
|
64 | | - process_path("src/css"); |
65 | | -} |
66 | | - |
67 | | -async function copy_html() { |
| 26 | + // Copy HTML |
68 | 27 | fs.mkdirSync("dist/html", { recursive: true }); |
69 | 28 | cpy("src/html/*", "dist/html"); |
70 | | - // also copy to top level |
71 | 29 | cpy("src/html/*", "dist/"); |
72 | | -} |
73 | 30 |
|
74 | | -async function copy_img() { |
| 31 | + // Copy images |
75 | 32 | fs.mkdirSync("dist/img", { recursive: true }); |
76 | 33 | cpy("src/img/*", "dist/img"); |
77 | | -} |
78 | 34 |
|
79 | | -async function copy_to_python() { |
| 35 | + await Promise.all(BUNDLES.map(bundle)).catch(() => process.exit(1)); |
| 36 | + |
| 37 | + // Copy from dist to python |
80 | 38 | fs.mkdirSync("../python_template_cppjswasm/extension", { recursive: true }); |
81 | 39 | cpy("dist/**/*", "../python_template_cppjswasm/extension"); |
82 | 40 | } |
83 | 41 |
|
84 | | -async function build_all() { |
85 | | - await compile_css(); |
86 | | - await copy_html(); |
87 | | - await copy_img(); |
88 | | - await Promise.all(BUILD.map(build)).catch(() => process.exit(1)); |
89 | | - await copy_to_python(); |
90 | | -} |
91 | | - |
92 | | -build_all(); |
| 42 | +build(); |
0 commit comments