5127df5fastandaccurate: PDE solver benchmarks, laplace-dirichlet-2d with MFS and Nystrom DLP solversJeremy Magland 1/**
2 * Pack the command-line bundle as an npm tarball and put it in dist/,
3 * where the page is deployed, so that
4 *
5 * npx https://concept-collection.github.io/fastandaccurate/cli.tgz
6 *
7 * installs and runs it anywhere node 20+ is. Nothing goes to the npm
8 * registry: npm installs a tarball from a URL as happily as from a name,
9 * and this way the command line is always the same commit as the site.
10 * (npx caches by the exact URL string, so the site offers the URL with a
11 * ?v=<commit> suffix to make each deployment a fresh install.)
12 *
13 * Usage: node scripts/pack-cli.mjs (after vite build --config vite.cli.config.ts)
14 */
15import { execFileSync } from "node:child_process";
16import {
17 mkdtemp,
18 copyFile,
19 writeFile,
20 readFile,
21 rm,
22 mkdir,
23} from "node:fs/promises";
24import { glob } from "node:fs/promises";
25import { tmpdir } from "node:os";
26import { join, dirname, relative } from "node:path";
28const root = new URL("..", import.meta.url).pathname;
29const pkg = JSON.parse(await readFile(join(root, "package.json"), "utf8"));
31const manifest = {
32 name: "fastandaccurate-cli",
33 version: pkg.version,
34 description:
35 "Run fastandaccurate PDE-solver benchmarks from the command line",
36 license: "Apache-2.0",
37 type: "module",
38 engines: { node: ">=20" },
39 bin: { fastandaccurate: "launch.cjs" },
40};
42const stage = await mkdtemp(join(tmpdir(), "fastandaccurate-cli-"));
43try {
44 await copyFile(join(root, "dist-cli/main.js"), join(stage, "main.js"));
45 await copyFile(join(root, "scripts/cli-launcher.cjs"), join(stage, "launch.cjs"));
46 // The MATLAB sources, preserved under src/ so the CLI's source-root
47 // probe finds them beside the bundle.
48 for await (const entry of glob("src/{problems,solvers}/**/*.m", { cwd: root })) {
49 const rel = relative(root, join(root, entry));
50 await mkdir(join(stage, dirname(rel)), { recursive: true });
51 await copyFile(join(root, rel), join(stage, rel));
52 }
53 await writeFile(
54 join(stage, "package.json"),
55 `${JSON.stringify(manifest, null, 2)}\n`
56 );
57 const out = execFileSync(
58 "npm",
59 ["pack", "--silent", "--pack-destination", stage],
60 { cwd: stage, encoding: "utf8" }
61 ).trim();
62 await mkdir(join(root, "dist"), { recursive: true });
63 await copyFile(join(stage, out), join(root, "dist/cli.tgz"));
64 console.log(`dist/cli.tgz (${manifest.name} ${manifest.version})`);
65} finally {
66 await rm(stage, { recursive: true, force: true });
67}