MCPcopy Create free account
hub / github.com/cortexkit/magic-context / comparePiVersion

Function comparePiVersion

packages/cli/src/commands/setup-pi.ts:97–110  ·  view source on GitHub ↗

* Compare two semver-ish strings (X.Y.Z, ignores any pre-release or build * suffix). Returns -1 if `a < b`, 0 if equal, 1 if `a > b`. Returns 0 when * either string can't be parsed (we conservatively assume "good enough" so * a parse failure doesn't block the user with a phantom upgrade prompt).

(a: string, b: string)

Source from the content-addressed store, hash-verified

95 * a parse failure doesn't block the user with a phantom upgrade prompt).
96 */
97function comparePiVersion(a: string, b: string): number {
98 const parse = (v: string): [number, number, number] | null => {
99 const match = v.match(/(\d+)\.(\d+)\.(\d+)/);
100 return match ? [Number(match[1]), Number(match[2]), Number(match[3])] : null;
101 };
102 const left = parse(a);
103 const right = parse(b);
104 if (!left || !right) return 0;
105 for (let i = 0; i < 3; i += 1) {
106 if (left[i] < right[i]) return -1;
107 if (left[i] > right[i]) return 1;
108 }
109 return 0;
110}
111
112export function writePiSettingsPackage(
113 settingsPath: string,

Callers 1

runSetupFunction · 0.85

Calls 1

parseFunction · 0.70

Tested by

no test coverage detected