singularity-forge/scripts/sync-pkg-version.cjs

35 lines
1.4 KiB
JavaScript
Raw Normal View History

#!/usr/bin/env node
/**
* Sync pkg/package.json version with the installed @mariozechner/pi-coding-agent version.
*
* sf-run sets PI_PACKAGE_DIR=pkg/ so that pi's config.js reads piConfig from
* pkg/package.json (for branding: name="sf", configDir=".sf"). However, config.js
* also reads `version` from that same file and uses it for the update check
* (comparing against npm registry). If pkg/package.json has a stale version,
* pi's update banner fires even when the user is already on the latest release.
*
* This script reads the actual installed pi-coding-agent version and writes it
* into pkg/package.json so VERSION is always correct at publish time.
*/
2026-05-05 14:31:16 +02:00
const { readFileSync, writeFileSync } = require("fs");
const { resolve, join } = require("path");
2026-05-05 14:31:16 +02:00
const root = resolve(__dirname, "..");
const piPkgPath = join(root, "packages", "pi-coding-agent", "package.json");
const sfPkgPath = join(root, "pkg", "package.json");
2026-05-05 14:31:16 +02:00
const piPkg = JSON.parse(readFileSync(piPkgPath, "utf-8"));
const sfPkg = JSON.parse(readFileSync(sfPkgPath, "utf-8"));
if (sfPkg.version !== piPkg.version) {
2026-05-05 14:31:16 +02:00
console.log(
`[sync-pkg-version] Updating pkg/package.json version: ${sfPkg.version}${piPkg.version}`,
);
sfPkg.version = piPkg.version;
writeFileSync(sfPkgPath, JSON.stringify(sfPkg, null, 2) + "\n");
} else {
2026-05-05 14:31:16 +02:00
console.log(
`[sync-pkg-version] pkg/package.json version already matches: ${piPkg.version}`,
);
}