Files
2026-03-26 15:54:25 -07:00

83 lines
2.7 KiB
JavaScript
Executable File

#!/usr/bin/env node
import { execSync } from "child_process";
import { readFileSync, writeFileSync } from "fs";
import { dirname, join } from "path";
import { fileURLToPath } from "url";
const __dirname = dirname(fileURLToPath(import.meta.url));
const projectRoot = join(__dirname, "..");
const cliDir = join(projectRoot, "cli");
const marketplaceJsonPath = join(projectRoot, ".claude-plugin", "marketplace.json");
const codexPluginManifestPath = join(
projectRoot,
"plugins",
"dev-browser",
".codex-plugin",
"plugin.json"
);
const packageJson = JSON.parse(readFileSync(join(projectRoot, "package.json"), "utf8"));
const version = packageJson.version;
const cargoTomlPath = join(cliDir, "Cargo.toml");
let cargoToml = readFileSync(cargoTomlPath, "utf8");
const versionLine = `version = "${version}"`;
const versionPattern = /^version\s*=\s*"[^"]*"$/m;
if (!versionPattern.test(cargoToml)) {
console.error("Could not find the version field in cli/Cargo.toml.");
process.exit(1);
}
if (!cargoToml.includes(versionLine)) {
cargoToml = cargoToml.replace(versionPattern, versionLine);
writeFileSync(cargoTomlPath, cargoToml);
console.log(`Updated cli/Cargo.toml to version ${version}.`);
try {
execSync("cargo update -p dev-browser --offline", {
cwd: cliDir,
stdio: "pipe",
});
console.log("Updated cli/Cargo.lock.");
} catch {
try {
execSync("cargo update -p dev-browser", {
cwd: cliDir,
stdio: "pipe",
});
console.log("Updated cli/Cargo.lock.");
} catch (error) {
console.warn(`Warning: Could not update cli/Cargo.lock: ${error.message}`);
}
}
} else {
console.log(`cli/Cargo.toml already matches package.json version ${version}.`);
}
const marketplaceJson = JSON.parse(readFileSync(marketplaceJsonPath, "utf8"));
if (!marketplaceJson.metadata) {
marketplaceJson.metadata = {};
}
if (marketplaceJson.metadata.version !== version) {
marketplaceJson.metadata.version = version;
writeFileSync(marketplaceJsonPath, `${JSON.stringify(marketplaceJson, null, 2)}\n`);
console.log(`Updated .claude-plugin/marketplace.json to version ${version}.`);
} else {
console.log(`.claude-plugin/marketplace.json already matches package.json version ${version}.`);
}
const codexPluginManifest = JSON.parse(readFileSync(codexPluginManifestPath, "utf8"));
if (codexPluginManifest.version !== version) {
codexPluginManifest.version = version;
writeFileSync(codexPluginManifestPath, `${JSON.stringify(codexPluginManifest, null, 2)}\n`);
console.log(`Updated plugins/dev-browser/.codex-plugin/plugin.json to version ${version}.`);
} else {
console.log(
`plugins/dev-browser/.codex-plugin/plugin.json already matches package.json version ${version}.`
);
}