forked from code-yeongyu/oh-my-openagent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostinstall.mjs
More file actions
75 lines (64 loc) · 2.08 KB
/
postinstall.mjs
File metadata and controls
75 lines (64 loc) · 2.08 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
// postinstall.mjs
// Runs after npm install to verify OpenCode version compatibility
import { createRequire } from "node:module";
const require = createRequire(import.meta.url);
const MIN_OPENCODE_VERSION = "1.4.0";
/**
* Parse version string into numeric parts
* @param {string} version
* @returns {number[]}
*/
function parseVersion(version) {
return version
.replace(/^v/, "")
.split("-")[0]
.split(".")
.map((part) => Number.parseInt(part, 10) || 0);
}
/**
* Compare two version strings
* @param {string} current
* @param {string} minimum
* @returns {boolean} true if current >= minimum
*/
function compareVersions(current, minimum) {
const currentParts = parseVersion(current);
const minimumParts = parseVersion(minimum);
const length = Math.max(currentParts.length, minimumParts.length);
for (let index = 0; index < length; index++) {
const currentPart = currentParts[index] ?? 0;
const minimumPart = minimumParts[index] ?? 0;
if (currentPart > minimumPart) return true;
if (currentPart < minimumPart) return false;
}
return true;
}
/**
* Check if opencode version meets minimum requirement
* @returns {{ok: boolean, version: string | null}}
*/
function checkOpenCodeVersion() {
try {
const result = require("child_process").execSync("opencode --version", {
encoding: "utf-8",
stdio: ["pipe", "pipe", "ignore"],
});
const version = result.trim();
const ok = compareVersions(version, MIN_OPENCODE_VERSION);
return { ok, version };
} catch {
return { ok: true, version: null };
}
}
function main() {
// Check opencode version requirement
const versionCheck = checkOpenCodeVersion();
if (versionCheck.version && !versionCheck.ok) {
console.warn(`\u26a0 oh-my-china requires OpenCode >= ${MIN_OPENCODE_VERSION}`);
console.warn(` Detected: ${versionCheck.version}`);
console.warn(` Please update OpenCode to avoid compatibility issues.`);
}
console.log(`\u2713 oh-my-china installed successfully`);
console.log(` Add "oh-my-china" to the plugin array in your opencode.json`);
}
main();