Newer
Older
bugtrail / packages / extension / scripts / package.mjs
import { execSync } from "node:child_process";
import { createRequire } from "node:module";
import { mkdirSync, rmSync } from "node:fs";
import { dirname, join } from "node:path";

/**
 * Zips the built extension targets into the web panel's public dir so caddy
 * serves them from the download page (stable names, overwritten per release).
 * Usage: node scripts/package.mjs
 */
const require = createRequire(import.meta.url);
const { version } = require("../package.json");
const extDir = new URL("..", import.meta.url).pathname;
const outDir = join(extDir, "..", "web", "public", "ext");

mkdirSync(outDir, { recursive: true });
for (const target of ["chrome", "firefox"]) {
  const out = join(outDir, `bugtrail-${target}.zip`);
  rmSync(out, { force: true });
  // zip the directory contents (manifest at the archive root) so the unpacked
  // folder can be loaded directly via "Load unpacked"
  execSync(`zip -qr ${JSON.stringify(out)} .`, { cwd: join(extDir, "dist", target), stdio: "inherit" });
  console.log(`packaged bugtrail-${target} v${version} -> ${out}`);
}