* 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)
| 95 | * a parse failure doesn't block the user with a phantom upgrade prompt). |
| 96 | */ |
| 97 | function 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 | |
| 112 | export function writePiSettingsPackage( |
| 113 | settingsPath: string, |