#!/usr/bin/env bun import { readFileSync, writeFileSync } from "node:fs"; import { join } from "node:path"; import { execSync } from "node:child_process"; const ROOT = join(import.meta.dirname, ".."); const pkgPath = join(ROOT, "package.json"); const pkg = JSON.parse(readFileSync(pkgPath, "utf-8")); const currentVersion: string = pkg.version; const input = process.argv[2]?.trim(); if (!input) { console.error("Usage: bun run bump "); console.error(`Current version: ${currentVersion}`); process.exit(1); } let nextVersion = input.replace(/^v/, ""); if (input === "patch" || input === "minor" || input === "major") { const [major, minor, patch] = currentVersion.split(".").map(Number); if (input === "patch") nextVersion = `${major}.${minor}.${patch + 1}`; if (input === "minor") nextVersion = `${major}.${minor + 1}.0`; if (input === "major") nextVersion = `${major + 1}.0.0`; } if (!/^\d+\.\d+\.\d+(-[a-zA-Z0-9.]+)?$/.test(nextVersion)) { console.error(`Invalid SemVer format: '${nextVersion}'`); process.exit(1); } console.log(`==> Bumping version: ${currentVersion} -> ${nextVersion}`); // 1. package.json pkg.version = nextVersion; writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n"); console.log("āœ“ Updated package.json"); // 2. .zcode-plugin/plugin.json const pluginPath = join(ROOT, ".zcode-plugin", "plugin.json"); const plugin = JSON.parse(readFileSync(pluginPath, "utf-8")); plugin.version = nextVersion; writeFileSync(pluginPath, JSON.stringify(plugin, null, 2) + "\n"); console.log("āœ“ Updated .zcode-plugin/plugin.json"); // 3. skills/seal-home/SKILL.md const skillPath = join(ROOT, "skills", "seal-home", "SKILL.md"); let skillContent = readFileSync(skillPath, "utf-8"); skillContent = skillContent.replace(/description: "v[\d.]+: /g, `description: "v${nextVersion}: `); skillContent = skillContent.replace(/version: [\d.]+/g, `version: ${nextVersion}`); skillContent = skillContent.replace(/# Seal Home \(v[\d.]+\)/g, `# Seal Home (v${nextVersion})`); skillContent = skillContent.replace(/\(v[\d.]+\)/g, `(v${nextVersion})`); writeFileSync(skillPath, skillContent); console.log("āœ“ Updated skills/seal-home/SKILL.md"); // 4. openapi/openapi.yaml const openapiPath = join(ROOT, "openapi", "openapi.yaml"); let openapiContent = readFileSync(openapiPath, "utf-8"); openapiContent = openapiContent.replace(/version: [\d.]+/g, `version: ${nextVersion}`); writeFileSync(openapiPath, openapiContent); console.log("āœ“ Updated openapi/openapi.yaml"); // 5. Rebuild bundles console.log("==> Rebuilding OpenAPI and plugin bundles..."); execSync("bun run openapi:bundle", { cwd: ROOT, stdio: "inherit" }); execSync("bun run build:plugin", { cwd: ROOT, stdio: "inherit" }); console.log("\nšŸŽ‰ Successfully bumped version to " + nextVersion + "!"); console.log("\nNext steps to publish:"); console.log(` 1. Update CHANGELOG.md`); console.log(` 2. git commit -am "Release v${nextVersion}: "`); console.log(` 3. git tag -a v${nextVersion} -m "šŸš€ "`); console.log(` 4. git push origin master --tags && git push home master --tags\n`);