import { mkdir, cp, access, rm } from "node:fs/promises"; import { execFileSync } from "node:child_process"; import { resolve } from "node:path"; import { fileURLToPath } from "node:url"; import { packagePlugin } from "./packagePlugin.mjs"; const root = fileURLToPath(new URL("../", import.meta.url)); const pluginRepos = process.env.RUNESTONE_PLUGIN_REPOS || resolve(root, ".."); const formulasRoot = resolve(process.env.RUNESTONE_TABLE_FORMULAS_ROOT || resolve(pluginRepos, "RuneStone_Table_Formulas")); const formulasBuild = resolve(formulasRoot, "scripts/build.mjs"); try { await access(formulasBuild); } catch { throw new Error("Clone RuneStone_Table_Formulas beside RuneStone, or set RUNESTONE_PLUGIN_REPOS or RUNESTONE_TABLE_FORMULAS_ROOT. Install its dependencies before building plugins."); } execFileSync(process.execPath, [formulasBuild], { cwd: formulasRoot, stdio: "inherit" }); const formulasOutput = resolve(root, "plugin-packages/table-formulas"); // Remove the previous build, so deleted plugin files do not stay in the package. await rm(formulasOutput, { recursive: true, force: true }); await mkdir(formulasOutput, { recursive: true }); await cp(resolve(formulasRoot, "dist/plugin"), formulasOutput, { recursive: true }); console.log(await packagePlugin(formulasOutput, resolve(formulasRoot, "releases")));