@foundrykit/cli 2.0.2 ā 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/cli.js +93 -34
- package/dist/cli.js.map +1 -1
- package/dist/index.js +93 -34
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/commands/update.ts +106 -36
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@foundrykit/cli",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"tsup": "^8.0.0",
|
|
36
36
|
"typescript": "^5.9.2",
|
|
37
37
|
"vitest": "^1.2.0",
|
|
38
|
-
"@foundrykit/
|
|
39
|
-
"@foundrykit/
|
|
38
|
+
"@foundrykit/typescript-config": "1.0.5",
|
|
39
|
+
"@foundrykit/eslint-config": "1.0.5"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"build": "tsup",
|
package/src/commands/update.ts
CHANGED
|
@@ -3,7 +3,11 @@ import chalk from 'chalk';
|
|
|
3
3
|
import inquirer from 'inquirer';
|
|
4
4
|
import fs from 'fs-extra';
|
|
5
5
|
import path from 'path';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
addSingleComponent,
|
|
8
|
+
hasConflictingFiles,
|
|
9
|
+
type AddOptions,
|
|
10
|
+
} from './add.js';
|
|
7
11
|
import { getRegistry } from '../lib/registry.js';
|
|
8
12
|
import type { InstalledComponent } from '@foundrykit/types';
|
|
9
13
|
|
|
@@ -15,17 +19,27 @@ export function updateCommand() {
|
|
|
15
19
|
return new Command('update')
|
|
16
20
|
.description('Update installed components')
|
|
17
21
|
.argument('[id]', 'Component or block ID (omit to update all installed)')
|
|
18
|
-
.option(
|
|
22
|
+
.option(
|
|
23
|
+
'-o, --opt',
|
|
24
|
+
'interactively select which components to update, showing available upgrades'
|
|
25
|
+
)
|
|
26
|
+
.option('-f, --force', 'bypass cache and fetch fresh data from registry')
|
|
19
27
|
.option('-p, --path <path>', 'Custom installation path')
|
|
20
28
|
.action(async (id: string | undefined, options: UpdateOptions) => {
|
|
21
29
|
if (id) {
|
|
22
30
|
// Update single named component
|
|
23
31
|
try {
|
|
24
32
|
console.log(chalk.blue(`š Updating ${id}...`));
|
|
25
|
-
await addSingleComponent(id, {
|
|
33
|
+
await addSingleComponent(id, {
|
|
34
|
+
...options,
|
|
35
|
+
overwrite: true,
|
|
36
|
+
force: true,
|
|
37
|
+
});
|
|
26
38
|
} catch (error) {
|
|
27
39
|
console.error(chalk.red(`ā Failed to update ${id}:`));
|
|
28
|
-
console.error(
|
|
40
|
+
console.error(
|
|
41
|
+
chalk.red(error instanceof Error ? error.message : String(error))
|
|
42
|
+
);
|
|
29
43
|
process.exit(1);
|
|
30
44
|
}
|
|
31
45
|
return;
|
|
@@ -34,24 +48,35 @@ export function updateCommand() {
|
|
|
34
48
|
// Load installed components from config
|
|
35
49
|
const configPath = path.join(process.cwd(), 'foundrykit.config.json');
|
|
36
50
|
if (!fs.existsSync(configPath)) {
|
|
37
|
-
console.error(
|
|
51
|
+
console.error(
|
|
52
|
+
chalk.red(
|
|
53
|
+
'ā FoundryKit not initialized. Run "foundrykit init" first.'
|
|
54
|
+
)
|
|
55
|
+
);
|
|
38
56
|
process.exit(1);
|
|
39
57
|
}
|
|
40
58
|
|
|
41
59
|
const config = await fs.readJson(configPath);
|
|
42
|
-
let installed: Record<string, InstalledComponent> =
|
|
60
|
+
let installed: Record<string, InstalledComponent> =
|
|
61
|
+
config.installedComponents ?? {};
|
|
43
62
|
let installedIds = Object.keys(installed);
|
|
44
63
|
|
|
45
64
|
if (installedIds.length === 0) {
|
|
46
65
|
// No tracking data yet ā fall back to scanning the filesystem
|
|
47
|
-
console.log(
|
|
66
|
+
console.log(
|
|
67
|
+
chalk.gray(
|
|
68
|
+
'No install tracking found. Scanning filesystem for installed components...'
|
|
69
|
+
)
|
|
70
|
+
);
|
|
48
71
|
const registry = getRegistry();
|
|
49
72
|
let allComponents;
|
|
50
73
|
try {
|
|
51
74
|
allComponents = await registry.getComponents();
|
|
52
75
|
} catch (error) {
|
|
53
76
|
console.error(chalk.red('ā Failed to fetch registry:'));
|
|
54
|
-
console.error(
|
|
77
|
+
console.error(
|
|
78
|
+
chalk.red(error instanceof Error ? error.message : String(error))
|
|
79
|
+
);
|
|
55
80
|
process.exit(1);
|
|
56
81
|
}
|
|
57
82
|
|
|
@@ -73,19 +98,35 @@ export function updateCommand() {
|
|
|
73
98
|
installedIds = Object.keys(installed);
|
|
74
99
|
|
|
75
100
|
if (installedIds.length === 0) {
|
|
76
|
-
console.log(
|
|
101
|
+
console.log(
|
|
102
|
+
chalk.yellow(
|
|
103
|
+
'No installed components found. Use "foundrykit add" to install components.'
|
|
104
|
+
)
|
|
105
|
+
);
|
|
77
106
|
return;
|
|
78
107
|
}
|
|
79
108
|
|
|
80
|
-
console.log(
|
|
109
|
+
console.log(
|
|
110
|
+
chalk.gray(
|
|
111
|
+
`Found ${installedIds.length} installed component(s) via filesystem scan.`
|
|
112
|
+
)
|
|
113
|
+
);
|
|
81
114
|
}
|
|
82
115
|
|
|
83
116
|
if (options.opt) {
|
|
84
117
|
// --opt: fetch registry versions, show which have updates, let user pick
|
|
85
|
-
console.log(
|
|
118
|
+
console.log(
|
|
119
|
+
chalk.blue(
|
|
120
|
+
`š Checking for updates across ${installedIds.length} installed component(s)...`
|
|
121
|
+
)
|
|
122
|
+
);
|
|
86
123
|
|
|
87
124
|
const registry = getRegistry();
|
|
88
|
-
const withUpdates: Array<{
|
|
125
|
+
const withUpdates: Array<{
|
|
126
|
+
id: string;
|
|
127
|
+
installed: string | null;
|
|
128
|
+
latest: string | null;
|
|
129
|
+
}> = [];
|
|
89
130
|
const upToDate: string[] = [];
|
|
90
131
|
|
|
91
132
|
for (const compId of installedIds) {
|
|
@@ -99,21 +140,32 @@ export function updateCommand() {
|
|
|
99
140
|
installedVersion !== null &&
|
|
100
141
|
latestVersion !== installedVersion;
|
|
101
142
|
|
|
102
|
-
const unknownVersion =
|
|
143
|
+
const unknownVersion =
|
|
144
|
+
installedVersion === null || latestVersion === null;
|
|
103
145
|
|
|
104
146
|
if (hasUpdate || unknownVersion) {
|
|
105
|
-
withUpdates.push({
|
|
147
|
+
withUpdates.push({
|
|
148
|
+
id: compId,
|
|
149
|
+
installed: installedVersion,
|
|
150
|
+
latest: latestVersion,
|
|
151
|
+
});
|
|
106
152
|
} else {
|
|
107
153
|
upToDate.push(compId);
|
|
108
154
|
}
|
|
109
155
|
} catch {
|
|
110
156
|
// If we can't fetch, still offer the option to re-install
|
|
111
|
-
withUpdates.push({
|
|
157
|
+
withUpdates.push({
|
|
158
|
+
id: compId,
|
|
159
|
+
installed: installed[compId]?.version ?? null,
|
|
160
|
+
latest: null,
|
|
161
|
+
});
|
|
112
162
|
}
|
|
113
163
|
}
|
|
114
164
|
|
|
115
165
|
if (upToDate.length > 0) {
|
|
116
|
-
console.log(
|
|
166
|
+
console.log(
|
|
167
|
+
chalk.gray(`\nā Already up to date: ${upToDate.join(', ')}`)
|
|
168
|
+
);
|
|
117
169
|
}
|
|
118
170
|
|
|
119
171
|
if (withUpdates.length === 0) {
|
|
@@ -121,23 +173,29 @@ export function updateCommand() {
|
|
|
121
173
|
return;
|
|
122
174
|
}
|
|
123
175
|
|
|
124
|
-
const choices = withUpdates.map(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
176
|
+
const choices = withUpdates.map(
|
|
177
|
+
({ id: compId, installed: inst, latest }) => {
|
|
178
|
+
let versionLabel: string;
|
|
179
|
+
if (inst === null && latest === null) {
|
|
180
|
+
versionLabel = chalk.gray('(version unknown)');
|
|
181
|
+
} else if (latest === null) {
|
|
182
|
+
versionLabel = chalk.gray(
|
|
183
|
+
`(installed: ${inst} ā registry version unknown)`
|
|
184
|
+
);
|
|
185
|
+
} else if (inst === null) {
|
|
186
|
+
versionLabel = chalk.cyan(
|
|
187
|
+
`(latest: ${latest} ā install version not tracked)`
|
|
188
|
+
);
|
|
189
|
+
} else {
|
|
190
|
+
versionLabel = chalk.cyan(`(${inst} ā ${latest})`);
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
name: `${compId} ${versionLabel}`,
|
|
194
|
+
value: compId,
|
|
195
|
+
checked: true,
|
|
196
|
+
};
|
|
134
197
|
}
|
|
135
|
-
|
|
136
|
-
name: `${compId} ${versionLabel}`,
|
|
137
|
-
value: compId,
|
|
138
|
-
checked: true,
|
|
139
|
-
};
|
|
140
|
-
});
|
|
198
|
+
);
|
|
141
199
|
|
|
142
200
|
const { selectedIds } = await inquirer.prompt([
|
|
143
201
|
{
|
|
@@ -157,7 +215,11 @@ export function updateCommand() {
|
|
|
157
215
|
await runUpdates(selectedIds, options);
|
|
158
216
|
} else {
|
|
159
217
|
// No flag: update everything
|
|
160
|
-
console.log(
|
|
218
|
+
console.log(
|
|
219
|
+
chalk.blue(
|
|
220
|
+
`š Updating all ${installedIds.length} installed component(s)...`
|
|
221
|
+
)
|
|
222
|
+
);
|
|
161
223
|
await runUpdates(installedIds, options);
|
|
162
224
|
}
|
|
163
225
|
});
|
|
@@ -168,10 +230,16 @@ async function runUpdates(ids: string[], options: AddOptions): Promise<void> {
|
|
|
168
230
|
for (const compId of ids) {
|
|
169
231
|
try {
|
|
170
232
|
console.log(chalk.blue(`\nš Updating ${compId}...`));
|
|
171
|
-
await addSingleComponent(compId, {
|
|
233
|
+
await addSingleComponent(compId, {
|
|
234
|
+
...options,
|
|
235
|
+
overwrite: true,
|
|
236
|
+
force: true,
|
|
237
|
+
});
|
|
172
238
|
} catch (error) {
|
|
173
239
|
console.error(chalk.red(`ā Failed to update ${compId}:`));
|
|
174
|
-
console.error(
|
|
240
|
+
console.error(
|
|
241
|
+
chalk.red(error instanceof Error ? error.message : String(error))
|
|
242
|
+
);
|
|
175
243
|
failed++;
|
|
176
244
|
}
|
|
177
245
|
}
|
|
@@ -180,6 +248,8 @@ async function runUpdates(ids: string[], options: AddOptions): Promise<void> {
|
|
|
180
248
|
console.log(chalk.yellow(`\nā ${failed} component(s) failed to update.`));
|
|
181
249
|
process.exit(1);
|
|
182
250
|
} else {
|
|
183
|
-
console.log(
|
|
251
|
+
console.log(
|
|
252
|
+
chalk.green(`\nā
${ids.length} component(s) updated successfully!`)
|
|
253
|
+
);
|
|
184
254
|
}
|
|
185
255
|
}
|