Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .copier-answers.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Changes here will be overwritten by Copier
_commit: 9b579a3
_commit: 9498b78
_src_path: https://github.com/python-project-templates/base.git
add_docs: true
add_extension: cppjswasm
Expand Down
82 changes: 16 additions & 66 deletions js/build.mjs
Original file line number Diff line number Diff line change
@@ -1,92 +1,42 @@
import { NodeModulesExternal } from "@finos/perspective-esbuild-plugin/external.js";
import { build } from "@finos/perspective-esbuild-plugin/build.js";
import { transform } from "lightningcss";
import { bundle } from "./tools/bundle.mjs";
import { bundle_css } from "./tools/css.mjs";
import { node_modules_external } from "./tools/externals.mjs";
import { getarg } from "./tools/getarg.mjs";

import { transform } from "lightningcss";
import fs from "fs";
import cpy from "cpy";

const DEBUG = getarg("--debug");

const COMMON_DEFINE = {
global: "window",
"process.env.DEBUG": `${DEBUG}`,
};

const BUILD = [
const BUNDLES = [
{
define: COMMON_DEFINE,
entryPoints: ["src/ts/index.ts"],
plugins: [NodeModulesExternal()],
format: "esm",
loader: {
".css": "text",
".html": "text",
},
plugins: [node_modules_external()],
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);
}
});
};
async function build() {
// Bundle css
await bundle_css();

process_path("src/css");
}

async function copy_html() {
// 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() {
// Copy images
fs.mkdirSync("dist/img", { recursive: true });
cpy("src/img/*", "dist/img");
}

async function copy_to_python() {
await Promise.all(BUNDLES.map(bundle)).catch(() => process.exit(1));

// Copy from dist 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();
build();
5 changes: 2 additions & 3 deletions js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@
},
"dependencies": {},
"devDependencies": {
"@finos/perspective-esbuild-plugin": "^3.2.1",
"@playwright/test": "^1.59.0",
"@playwright/test": "^1.59.1",
"cpy": "^13.2.1",
"esbuild": "^0.27.2",
"esbuild": "^0.27.3",
"lightningcss": "^1.29.3",
"http-server": "^14.1.1",
"nodemon": "^3.1.10",
Expand Down
111 changes: 2 additions & 109 deletions js/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading