|
| 1 | +// Builds the installable .ablx into ./release/ — kept out of the repo root and |
| 2 | +// git-ignored. The .ablx is the *shippable* artifact (a ZIP of manifest.json + |
| 3 | +// the built dist/extension.js) that users drag into Live's Extensions prefs; |
| 4 | +// dist/ holds the intermediate bundle that this packages. Run via |
| 5 | +// `npm run package` (which builds first). Pass `--reveal` to open the file in |
| 6 | +// Finder, ready to drag in: `npm run package -- --reveal`. |
| 7 | +import { execFileSync } from "node:child_process"; |
| 8 | +import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync } from "node:fs"; |
| 9 | +import { join } from "node:path"; |
| 10 | + |
| 11 | +const OUT_DIR = "release"; |
| 12 | + |
| 13 | +function fail(msg) { |
| 14 | + console.error(`\n package: ${msg}\n`); |
| 15 | + process.exit(1); |
| 16 | +} |
| 17 | + |
| 18 | +const manifest = JSON.parse(readFileSync("manifest.json", "utf8")); |
| 19 | +if (!existsSync(manifest.entry)) { |
| 20 | + fail(`${manifest.entry} not found — run \`npm run build\` first (or just \`npm run package\`).`); |
| 21 | +} |
| 22 | + |
| 23 | +// Match extensions-cli's own naming so the file is identical to its default, |
| 24 | +// only relocated: "<name with spaces → dashes>-<version>.ablx". |
| 25 | +const ablxName = `${(manifest.name || "extension").replace(/\s+/gu, "-")}-${manifest.version || "0.0.0"}.ablx`; |
| 26 | +const outPath = join(OUT_DIR, ablxName); |
| 27 | + |
| 28 | +// One artifact per build: clear stale .ablx files so we never ship the wrong one. |
| 29 | +mkdirSync(OUT_DIR, { recursive: true }); |
| 30 | +for (const f of readdirSync(OUT_DIR)) { |
| 31 | + if (f.endsWith(".ablx")) rmSync(join(OUT_DIR, f)); |
| 32 | +} |
| 33 | + |
| 34 | +const cliBin = join("node_modules", ".bin", process.platform === "win32" ? "extensions-cli.cmd" : "extensions-cli"); |
| 35 | +// Suppress the CLI's bare path print (stdout); surface its errors (stderr). |
| 36 | +execFileSync(cliBin, ["package", "-o", outPath], { stdio: ["ignore", "ignore", "inherit"] }); |
| 37 | + |
| 38 | +const sizeMB = (statSync(outPath).size / 1024 / 1024).toFixed(2); |
| 39 | +console.log(`\n package: ${manifest.name} ${manifest.version} → ${outPath} (${sizeMB} MB)`); |
| 40 | +console.log(` install: drag it onto Live → Preferences → Extensions (Developer Mode off).\n`); |
| 41 | + |
| 42 | +if (process.argv.includes("--reveal")) { |
| 43 | + if (process.platform === "darwin") execFileSync("open", ["-R", outPath]); |
| 44 | + else console.log(" package: --reveal is macOS-only; skipped."); |
| 45 | +} |
0 commit comments