|
1 | 1 | #!/usr/bin/env node |
2 | 2 | |
3 | | -import fs from "node:fs/promises"; |
4 | | -import path from "node:path"; |
5 | | -import { fileURLToPath } from "node:url"; |
6 | | -import { build } from "esbuild"; |
| 3 | +import { buildDiffsViewerRuntime } from "../../../scripts/build-diffs-viewer-runtime.mjs"; |
7 | 4 | |
8 | | -const extensionRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); |
9 | | -const repoRoot = path.resolve(extensionRoot, "../.."); |
10 | | -const outputPath = path.join(extensionRoot, "assets/viewer-runtime.js"); |
11 | | - |
12 | | -await fs.mkdir(path.dirname(outputPath), { recursive: true }); |
13 | | - |
14 | | -const result = await build({ |
15 | | -entryPoints: [path.join(extensionRoot, "src/viewer-client.ts")], |
16 | | -bundle: true, |
17 | | -platform: "browser", |
18 | | -target: "es2020", |
19 | | -format: "esm", |
20 | | -minify: true, |
21 | | -legalComments: "none", |
22 | | -outfile: outputPath, |
23 | | -write: false, |
24 | | -plugins: [ |
25 | | -{ |
26 | | -name: "openclaw-diffs-curated-shiki", |
27 | | -setup(buildContext) { |
28 | | -buildContext.onResolve({ filter: /^shiki$/ }, () => ({ |
29 | | -path: path.join(repoRoot, "scripts/diffs-shiki-curated.ts"), |
30 | | -})); |
31 | | -}, |
32 | | -}, |
33 | | -], |
34 | | -}); |
35 | | - |
36 | | -const outputFile = result.outputFiles?.[0]; |
37 | | -if (!outputFile) { |
38 | | -throw new Error("esbuild did not produce extensions/diffs/assets/viewer-runtime.js"); |
39 | | -} |
40 | | - |
41 | | -const runtime = outputFile.text.replace(/[ \t]+$/gm, ""); |
42 | | -let previousRuntime = null; |
43 | | -try { |
44 | | -previousRuntime = await fs.readFile(outputPath, "utf8"); |
45 | | -} catch (error) { |
46 | | -if (error?.code !== "ENOENT") { |
47 | | -throw error; |
48 | | -} |
49 | | -} |
50 | | - |
51 | | -if (previousRuntime !== runtime) { |
52 | | -await fs.writeFile(outputPath, runtime); |
53 | | -} |
| 5 | +await buildDiffsViewerRuntime("curated"); |