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