2026-07-15 17:43:52 +08:00
|
|
|
import { readFile } from "node:fs/promises";
|
2026-07-14 01:12:05 +00:00
|
|
|
import { dirname, join } from "node:path";
|
|
|
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
|
|
2026-07-15 17:43:52 +08:00
|
|
|
import { ensureGeneratedFile } from "./lib/generated-file.mjs";
|
|
|
|
|
|
|
|
|
|
const arguments_ = new Set(process.argv.slice(2));
|
|
|
|
|
for (const argument of arguments_)
|
|
|
|
|
if (argument !== "--check")
|
|
|
|
|
throw new Error(`Unknown package metadata option: ${argument}`);
|
2026-07-14 21:08:09 +00:00
|
|
|
|
2026-07-14 01:12:05 +00:00
|
|
|
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
|
|
|
const packageJson = JSON.parse(
|
|
|
|
|
await readFile(join(root, "package.json"), "utf8"),
|
|
|
|
|
);
|
|
|
|
|
const lock = JSON.parse(
|
|
|
|
|
await readFile(join(root, "package-lock.json"), "utf8"),
|
|
|
|
|
);
|
|
|
|
|
const skill = await readFile(
|
2026-10-10 14:20:22 +08:00
|
|
|
join(root, ".agents/skills/reverse-engineer-anything/SKILL.md"),
|
2026-07-14 01:12:05 +00:00
|
|
|
"utf8",
|
|
|
|
|
);
|
|
|
|
|
const skillVersion = /^\s{2}version:\s*"([^"]+)"\s*$/mu.exec(skill)?.[1];
|
|
|
|
|
if (skillVersion === undefined)
|
2026-07-17 00:35:19 +00:00
|
|
|
throw new Error("Missing reverse-engineer-anything skill metadata version");
|
2026-07-14 01:12:05 +00:00
|
|
|
const versionOf = (name) => {
|
|
|
|
|
const value = lock.packages?.[`node_modules/${name}`]?.version;
|
|
|
|
|
if (typeof value !== "string")
|
|
|
|
|
throw new Error(`Missing locked ${name} version`);
|
|
|
|
|
return value;
|
|
|
|
|
};
|
|
|
|
|
const source = `/** Generated from package.json and package-lock.json; do not edit. */
|
|
|
|
|
export const PACKAGE_METADATA = {
|
|
|
|
|
name: ${JSON.stringify(packageJson.name)},
|
2026-07-20 13:43:36 +00:00
|
|
|
version: ${JSON.stringify(packageJson.version)}, // x-release-please-version
|
2026-07-14 01:12:05 +00:00
|
|
|
serverSdkVersion: ${JSON.stringify(versionOf("@modelcontextprotocol/server"))},
|
|
|
|
|
clientSdkVersion: ${JSON.stringify(versionOf("@modelcontextprotocol/client"))},
|
|
|
|
|
coreSdkVersion: ${JSON.stringify(versionOf("@modelcontextprotocol/core"))},
|
|
|
|
|
skillVersion: ${JSON.stringify(skillVersion)},
|
|
|
|
|
} as const;
|
|
|
|
|
`;
|
2026-07-14 21:08:09 +00:00
|
|
|
const outputPath = join(root, "src/generatedPackageMetadata.ts");
|
2026-07-15 17:43:52 +08:00
|
|
|
await ensureGeneratedFile({
|
|
|
|
|
path: outputPath,
|
|
|
|
|
source,
|
|
|
|
|
check: arguments_.has("--check"),
|
2026-07-22 14:58:41 +00:00
|
|
|
generateCommand: "npm run metadata:generate",
|
2026-07-15 17:43:52 +08:00
|
|
|
});
|