Files
plugins/packages/page-usage-board/scripts/build-echarts.mjs
T
orinsid 545ed66e74 page-usage-board: a usage dashboard page (#844)
Adds @magpie-community/page-usage-board: a usage dashboard page with its
own zero-dependency local service (quota cards with expiry tiers, TTFT,
7x24 heatmap, optional remote attribution).

Reviewed at 8ca2562: the author's 80137b0 plus a maintainer merge of main
(registry entry re-appended after upstream's newer packages).
Since the 6b2625d review: [::1] in MAGPIE_ADDR stays IPv6 loopback (only
0.0.0.0/[::] map to 127.0.0.1), the config-dir test compares real paths
so it passes on macOS, and the registry-block test tolerates CRLF.

Run on mote at 8ca2562: packages/page-usage-board `bun test` 36 pass,
`node --test test/*.test.mjs` 36 pass; `bun scripts/check.mjs` all ok.
Not tried this round: the page in a live magpie window.
2026-11-10 10:36:04 +08:00

41 lines
1.8 KiB
JavaScript

// Reproducible build of the vendored ECharts bundle (custom build: bar/line/pie/heatmap only).
//
// npm run build:echarts # rebuild static/echarts.min.js from build/echarts-entry.mjs
//
// The output must stay byte-identical, so this script IS the build definition.
// Verify locally after any change:
// node scripts/build-echarts.mjs && git diff --exit-code static/echarts.min.js
// Pins: echarts@5.5.1, esbuild per devDependencies (exact) and package-lock.json.
//
// - no --global-name: the entry assigns window.echarts directly (with --global-name the
// iife gets wrapped in "var echarts=…" and the default export nests under .default);
// - the provenance banner below is prepended, so it is part of the reproducible output.
import { createHash } from 'node:crypto';
import { readFileSync, statSync, writeFileSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { build } from 'esbuild';
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const outfile = path.join(root, 'static', 'echarts.min.js');
const BANNER =
'/* Apache ECharts v5.5.1 custom build (bar/line/pie/heatmap + tooltip/legend/grid/dataZoom/visualMap/axisPointer). ' +
'Copyright 2018-2026 Apache Software Foundation, Apache-2.0. See NOTICE. */\n';
const result = await build({
entryPoints: [path.join(root, 'build', 'echarts-entry.mjs')],
bundle: true,
minify: true,
outfile,
write: false,
logLevel: 'warning',
});
const js = result.outputFiles[0].text;
writeFileSync(outfile, BANNER + js);
const sha = createHash('sha256').update(readFileSync(outfile)).digest('hex');
const kb = Math.round(statSync(outfile).size / 1024);
console.log(`static/echarts.min.js rebuilt: ${kb} KiB sha256=${sha.slice(0, 16)}…`);