-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault-version-parameter.ts
More file actions
43 lines (34 loc) · 1.24 KB
/
default-version-parameter.ts
File metadata and controls
43 lines (34 loc) · 1.24 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
import { getPty, ParameterSetting, SpawnStatus, StatefulParameter } from '@codifycli/plugin-core';
import { FnmConfig } from './fast-node-manager.js';
export class FnmDefaultVersionParameter extends StatefulParameter<FnmConfig, string> {
getSettings(): ParameterSetting {
return {
type: 'version',
};
}
override async refresh(): Promise<string | null> {
const $ = getPty();
const { data, status } = await $.spawnSafe('fnm list', { interactive: true });
if (status === SpawnStatus.ERROR) {
return null;
}
for (const line of data.split('\n')) {
if (line.includes('default')) {
const match = line.match(/v?(\d+\.\d+\.\d+)/);
if (match) return match[1];
}
}
return null;
}
override async add(valueToAdd: string): Promise<void> {
const $ = getPty();
await $.spawn(`fnm default ${valueToAdd}`, { interactive: true });
}
override async modify(newValue: string): Promise<void> {
const $ = getPty();
await $.spawn(`fnm default ${newValue}`, { interactive: true });
}
override async remove(valueToRemove: string): Promise<void> {
console.warn(`fnm does not support unsetting the default version. Node.js will remain at ${valueToRemove}. Skipping...`);
}
}