Repository navigation
Expand file tree
/
Copy pathsync-plugin-version.ts
More file actions
49 lines (42 loc) · 1.57 KB
/
Copy pathsync-plugin-version.ts
File metadata and controls
49 lines (42 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { readFile, writeFile } from "node:fs/promises";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
const defaultPackageRoot = resolve(
dirname(fileURLToPath(import.meta.url)),
"..",
);
const pluginManifestPaths = [
".codex-plugin/plugin.json",
".claude-plugin/plugin.json",
] as const;
function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
async function readJsonObject(path: string): Promise<Record<string, unknown>> {
const parsed: unknown = JSON.parse(await readFile(path, "utf8"));
if (!isRecord(parsed)) throw new Error(`${path}: expected a JSON object`);
return parsed;
}
export async function syncPluginVersion(
packageRoot = defaultPackageRoot,
): Promise<string> {
const packageManifestPath = resolve(packageRoot, "package.json");
const packageManifest = await readJsonObject(packageManifestPath);
const version = packageManifest.version;
if (typeof version !== "string" || !version) {
throw new Error(`${packageManifestPath}: version is required`);
}
await Promise.all(
pluginManifestPaths.map(async (relativePath) => {
const path = resolve(packageRoot, relativePath);
const manifest = await readJsonObject(path);
manifest.version = version;
await writeFile(path, `${JSON.stringify(manifest, null, 2)}\n`);
}),
);
return version;
}
if (process.argv[1] === fileURLToPath(import.meta.url)) {
const version = await syncPluginVersion();
process.stdout.write(`Synchronized Sim plugin manifests to ${version}.\n`);
}