forked from github/copilot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinject-cli-version.mjs
More file actions
50 lines (43 loc) · 1.74 KB
/
Copy pathinject-cli-version.mjs
File metadata and controls
50 lines (43 loc) · 1.74 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
#!/usr/bin/env node
/**
* inject-cli-version.mjs
*
* Reads the pinned Copilot CLI version from nodejs/package.json and
* writes it into python/copilot/_cli_version.py, replacing the `CLI_VERSION = None`
* sentinel with the concrete version string.
*
* Run from the repository root:
* node python/scripts/inject-cli-version.mjs
*/
import { readFileSync, writeFileSync } from "fs";
import { join, dirname } from "path";
import { fileURLToPath } from "url";
const __dirname = dirname(fileURLToPath(import.meta.url));
const repoRoot = join(__dirname, "..", "..");
const packagePath = join(repoRoot, "nodejs", "package.json");
const packageJson = JSON.parse(readFileSync(packagePath, "utf-8"));
const version = packageJson.copilotCliVersion;
if (!version) {
console.error("Error: Could not find copilotCliVersion in nodejs/package.json");
process.exit(1);
}
console.log(`Injecting CLI_VERSION = "${version}"`);
// Patch _cli_version.py
const versionFile = join(__dirname, "..", "copilot", "_cli_version.py");
let content = readFileSync(versionFile, "utf-8");
const sentinel = 'CLI_VERSION: str | None = None';
const replacement = `CLI_VERSION: str | None = "${version}"`;
if (!content.includes(sentinel)) {
// Check if already injected
if (content.includes(`CLI_VERSION: str | None = "`)) {
console.log("CLI_VERSION already injected, updating...");
content = content.replace(/CLI_VERSION: str \| None = ".*?"/, `CLI_VERSION: str | None = "${version}"`);
} else {
console.error(`Error: Could not find sentinel '${sentinel}' in _cli_version.py`);
process.exit(1);
}
} else {
content = content.replace(sentinel, replacement);
}
writeFileSync(versionFile, content);
console.log(`Done. _cli_version.py now has CLI_VERSION = "${version}"`);