#!/usr/bin/env node // Release flow for the ofsaver extension: // node scripts/release.mjs [patch|minor|major|none] // Bumps the version (manifest.json is the source of truth, content.js's // ofsaverV marker is kept in sync), rebuilds ofsaver-extension.zip into the // landing repo's public/ (served by the site), then commits, tags vX.Y.Z and // pushes both repos. import { readFileSync, writeFileSync, existsSync, mkdirSync, cpSync, rmSync } from "node:fs"; import { execSync } from "node:child_process"; import path from "node:path"; import { fileURLToPath } from "node:url"; const root = path.dirname(path.dirname(fileURLToPath(import.meta.url))); const ext = path.join(root, "ext"); const landing = path.resolve(root, "..", "landing"); const landingPublic = path.join(landing, "public"); const bump = process.argv[2] ?? "patch"; if (!["patch", "minor", "major", "none"].includes(bump)) { console.error("usage: node scripts/release.mjs [patch|minor|major|none]"); process.exit(1); } const manifestPath = path.join(ext, "manifest.json"); const manifest = JSON.parse(readFileSync(manifestPath, "utf8")); let [maj, min, pat] = manifest.version.split(".").map(Number); if (bump === "patch") pat += 1; else if (bump === "minor") { min += 1; pat = 0; } else if (bump === "major") { maj += 1; min = 0; pat = 0; } const version = `${maj}.${min}.${pat}`; manifest.version = version; writeFileSync(manifestPath, JSON.stringify(manifest, null, 2) + "\n"); const contentPath = path.join(ext, "content.js"); const content = readFileSync(contentPath, "utf8"); writeFileSync(contentPath, content.replace(/dataset\.ofsaverV = "[^"]+"/, `dataset.ofsaverV = "${version}"`)); // zip: ofsaver/ folder at the archive root (matches the site's install steps) const staging = path.join(root, ".release-tmp"); rmSync(staging, { recursive: true, force: true }); mkdirSync(staging, { recursive: true }); cpSync(ext, path.join(staging, "ofsaver"), { recursive: true }); execSync(`find '${staging}' -name .DS_Store -delete`); mkdirSync(landingPublic, { recursive: true }); execSync(`cd '${staging}' && zip -qr '${path.join(landingPublic, "ofsaver-extension.zip")}' ofsaver`); rmSync(staging, { recursive: true, force: true }); const run = (cmd, cwd = root) => execSync(cmd, { cwd, stdio: "inherit" }); run("git add -A"); run(`git commit -m "v${version}\n\nCo-Authored-By: Claude Code " || true`); run(`git tag v${version}`); run("git push origin main"); run(`git push origin v${version}`); if (existsSync(path.join(landing, ".git"))) { run("git add -A", landing); run(`git commit -m "extension v${version}\n\nCo-Authored-By: Claude Code " || true`, landing); run("git push origin main", landing); } console.log(`released ${version}`);