-
Notifications
You must be signed in to change notification settings - Fork 197
Expand file tree
/
Copy pathcheck-plugin-version-pr.ts
More file actions
executable file
·76 lines (62 loc) · 2.09 KB
/
Copy pathcheck-plugin-version-pr.ts
File metadata and controls
executable file
·76 lines (62 loc) · 2.09 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env node
/**
* PR Plugin Version Check
*
* Validates that all plugin.json files use the "0.0.0-placeholder" version.
* Real versions are stamped at build time by NBGV, so the source should
* never contain a real version number.
*/
import * as fs from "node:fs";
import * as path from "node:path";
import { fileURLToPath } from "node:url";
const PLUGIN_PATHS = [
"plugin/.plugin/plugin.json",
"plugin/.claude-plugin/plugin.json",
"plugin/.cursor-plugin/plugin.json"
] as const;
const EXPECTED_VERSION = "0.0.0-placeholder";
interface PluginConfig {
version: string;
[key: string]: unknown;
}
/**
* Check that all plugin.json files have the placeholder version.
*/
function checkPluginVersionPlaceholders(): void {
const repoRoot = path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
"../.."
);
let hasErrors = false;
for (const pluginPath of PLUGIN_PATHS) {
const fullPath = path.resolve(repoRoot, pluginPath);
if (!fs.existsSync(fullPath)) {
console.log(` ℹ️ ${pluginPath} not found, skipping...`);
continue;
}
const content = fs.readFileSync(fullPath, "utf8");
const json: PluginConfig = JSON.parse(content);
if (json.version === EXPECTED_VERSION) {
console.log(` ✅ ${pluginPath}: version is "${EXPECTED_VERSION}"`);
} else {
console.error(` ❌ ${pluginPath}: expected version "${EXPECTED_VERSION}", found "${json.version}"`);
hasErrors = true;
}
}
if (hasErrors) {
console.error("\n❌ Plugin version check failed!");
console.error(" Plugin versions are stamped automatically at build time by NBGV.");
console.error(` Source files must always use "${EXPECTED_VERSION}".\n`);
process.exit(1);
} else {
console.log("\n✅ All plugin.json files have the correct placeholder version.");
}
}
function main(): void {
console.log("🔍 Checking plugin.json versions are placeholders...\n");
checkPluginVersionPlaceholders();
}
if (fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) {
main();
}
export { checkPluginVersionPlaceholders, type PluginConfig };