Files
openclaw/scripts/sync-plugin-sdk-exports.mts
T
Peter Steinberger c70aee247e refactor(scripts): migrate JavaScript tools to TypeScript (#121005)
* refactor(scripts): migrate JavaScript tools to TypeScript

* fix(ci): keep changed-scope preflight zero-install

* fix(ci): preserve zero-install script owners

* fix(ci): complete script migration follow-through

* fix(release): keep stable closeout zero-install

* fix(scripts): preserve standalone execution boundaries

* fix(scripts): repair standalone loader boundaries

* fix(scripts): normalize gateway observation ids

* fix(scripts): keep Docker packager standalone

* test(scripts): preserve rebase cleanup helpers

* test(sessions): use tracked temp directory
2026-08-09 07:21:35 -07:00

50 lines
1.7 KiB
TypeScript

#!/usr/bin/env node
// Regenerates package.json plugin-sdk export entries from the canonical entry list.
import fs from "node:fs";
import path from "node:path";
import { buildPluginSdkPackageExports } from "./lib/plugin-sdk-entries.mts";
const checkOnly = process.argv.includes("--check");
const packageJsonPath = path.join(process.cwd(), "package.json");
const packageJson: Record<string, unknown> & { exports?: Record<string, unknown> } = JSON.parse(
fs.readFileSync(packageJsonPath, "utf8"),
);
const currentExports = packageJson.exports ?? {};
const syncedPluginSdkExports = buildPluginSdkPackageExports();
const nextExports: typeof currentExports = {};
let insertedPluginSdkExports = false;
for (const [key, value] of Object.entries(currentExports)) {
if (key.startsWith("./plugin-sdk")) {
if (!insertedPluginSdkExports) {
Object.assign(nextExports, syncedPluginSdkExports);
insertedPluginSdkExports = true;
}
continue;
}
nextExports[key] = value;
if (key === "." && !insertedPluginSdkExports) {
Object.assign(nextExports, syncedPluginSdkExports);
insertedPluginSdkExports = true;
}
}
if (!insertedPluginSdkExports) {
Object.assign(nextExports, syncedPluginSdkExports);
}
const nextExportsJson = JSON.stringify(nextExports);
const currentExportsJson = JSON.stringify(currentExports);
if (checkOnly) {
if (currentExportsJson !== nextExportsJson) {
console.error("plugin-sdk exports out of sync. Run `pnpm plugin-sdk:sync-exports`.");
process.exit(1);
}
console.log("plugin-sdk exports synced.");
process.exit(0);
}
packageJson.exports = nextExports;
fs.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`, "utf8");