@foundrykit/cli 1.1.0 ā 2.0.0
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 +11 -0
- package/dist/cli.js +131 -19
- package/dist/cli.js.map +1 -1
- package/dist/index.js +131 -19
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/commands/add.ts +22 -0
- package/src/commands/update.ts +138 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@foundrykit/cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"glob": "^10.3.10",
|
|
26
26
|
"inquirer": "^9.2.15",
|
|
27
27
|
"node-fetch": "^3.3.0",
|
|
28
|
-
"@foundrykit/types": "1.0
|
|
28
|
+
"@foundrykit/types": "1.1.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/node": "^20.19.9",
|
|
@@ -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/eslint-config": "1.0.5",
|
|
39
|
+
"@foundrykit/typescript-config": "1.0.5"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"build": "tsup",
|
package/src/commands/add.ts
CHANGED
|
@@ -225,6 +225,9 @@ export async function addSingleComponent(
|
|
|
225
225
|
// Install the component files
|
|
226
226
|
await installComponentFiles(componentData, options);
|
|
227
227
|
|
|
228
|
+
// Track the installed component in config
|
|
229
|
+
await trackInstalledComponent(componentData);
|
|
230
|
+
|
|
228
231
|
console.log(chalk.green(`ā
${componentData.name} added successfully!`));
|
|
229
232
|
|
|
230
233
|
// Show usage example
|
|
@@ -355,6 +358,25 @@ export async function installComponentFiles(
|
|
|
355
358
|
await updateConfigVersion();
|
|
356
359
|
}
|
|
357
360
|
|
|
361
|
+
/**
|
|
362
|
+
* Record an installed component in foundrykit.config.json
|
|
363
|
+
*/
|
|
364
|
+
export async function trackInstalledComponent(
|
|
365
|
+
componentData: ComponentData
|
|
366
|
+
): Promise<void> {
|
|
367
|
+
const configPath = path.join(process.cwd(), 'foundrykit.config.json');
|
|
368
|
+
if (!fs.existsSync(configPath)) return;
|
|
369
|
+
|
|
370
|
+
const config = await fs.readJson(configPath);
|
|
371
|
+
config.installedComponents = config.installedComponents ?? {};
|
|
372
|
+
config.installedComponents[componentData.id] = {
|
|
373
|
+
id: componentData.id,
|
|
374
|
+
version: componentData.version ?? null,
|
|
375
|
+
installedAt: new Date().toISOString(),
|
|
376
|
+
};
|
|
377
|
+
await fs.writeJson(configPath, config, { spaces: 2 });
|
|
378
|
+
}
|
|
379
|
+
|
|
358
380
|
/**
|
|
359
381
|
* Handle package dependencies - check and auto-install if needed
|
|
360
382
|
*/
|
package/src/commands/update.ts
CHANGED
|
@@ -1,29 +1,152 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
|
+
import inquirer from 'inquirer';
|
|
4
|
+
import fs from 'fs-extra';
|
|
5
|
+
import path from 'path';
|
|
3
6
|
import { addSingleComponent, type AddOptions } from './add.js';
|
|
7
|
+
import { getRegistry } from '../lib/registry.js';
|
|
8
|
+
import type { InstalledComponent } from '@foundrykit/types';
|
|
4
9
|
|
|
5
10
|
interface UpdateOptions extends AddOptions {
|
|
6
|
-
|
|
11
|
+
opt?: boolean;
|
|
7
12
|
}
|
|
8
13
|
|
|
9
14
|
export function updateCommand() {
|
|
10
15
|
return new Command('update')
|
|
11
|
-
.description('Update
|
|
12
|
-
.argument('
|
|
16
|
+
.description('Update installed components')
|
|
17
|
+
.argument('[id]', 'Component or block ID (omit to update all installed)')
|
|
18
|
+
.option('--opt', 'interactively select which components to update, showing available upgrades')
|
|
13
19
|
.option('-p, --path <path>', 'Custom installation path')
|
|
14
|
-
.action(async (id: string, options: UpdateOptions) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
overwrite: true
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
.action(async (id: string | undefined, options: UpdateOptions) => {
|
|
21
|
+
if (id) {
|
|
22
|
+
// Update single named component
|
|
23
|
+
try {
|
|
24
|
+
console.log(chalk.blue(`š Updating ${id}...`));
|
|
25
|
+
await addSingleComponent(id, { ...options, overwrite: true });
|
|
26
|
+
} catch (error) {
|
|
27
|
+
console.error(chalk.red(`ā Failed to update ${id}:`));
|
|
28
|
+
console.error(chalk.red(error instanceof Error ? error.message : String(error)));
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Load installed components from config
|
|
35
|
+
const configPath = path.join(process.cwd(), 'foundrykit.config.json');
|
|
36
|
+
if (!fs.existsSync(configPath)) {
|
|
37
|
+
console.error(chalk.red('ā FoundryKit not initialized. Run "foundrykit init" first.'));
|
|
26
38
|
process.exit(1);
|
|
27
39
|
}
|
|
40
|
+
|
|
41
|
+
const config = await fs.readJson(configPath);
|
|
42
|
+
const installed: Record<string, InstalledComponent> = config.installedComponents ?? {};
|
|
43
|
+
const installedIds = Object.keys(installed);
|
|
44
|
+
|
|
45
|
+
if (installedIds.length === 0) {
|
|
46
|
+
console.log(chalk.yellow('No installed components found. Use "foundrykit add" to install components.'));
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (options.opt) {
|
|
51
|
+
// --opt: fetch registry versions, show which have updates, let user pick
|
|
52
|
+
console.log(chalk.blue(`š Checking for updates across ${installedIds.length} installed component(s)...`));
|
|
53
|
+
|
|
54
|
+
const registry = getRegistry();
|
|
55
|
+
const withUpdates: Array<{ id: string; installed: string | null; latest: string | null }> = [];
|
|
56
|
+
const upToDate: string[] = [];
|
|
57
|
+
|
|
58
|
+
for (const compId of installedIds) {
|
|
59
|
+
try {
|
|
60
|
+
const data = await registry.getComponent(compId);
|
|
61
|
+
const installedVersion = installed[compId]?.version ?? null;
|
|
62
|
+
const latestVersion = data.version ?? null;
|
|
63
|
+
|
|
64
|
+
const hasUpdate =
|
|
65
|
+
latestVersion !== null &&
|
|
66
|
+
installedVersion !== null &&
|
|
67
|
+
latestVersion !== installedVersion;
|
|
68
|
+
|
|
69
|
+
const unknownVersion = installedVersion === null || latestVersion === null;
|
|
70
|
+
|
|
71
|
+
if (hasUpdate || unknownVersion) {
|
|
72
|
+
withUpdates.push({ id: compId, installed: installedVersion, latest: latestVersion });
|
|
73
|
+
} else {
|
|
74
|
+
upToDate.push(compId);
|
|
75
|
+
}
|
|
76
|
+
} catch {
|
|
77
|
+
// If we can't fetch, still offer the option to re-install
|
|
78
|
+
withUpdates.push({ id: compId, installed: installed[compId]?.version ?? null, latest: null });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (upToDate.length > 0) {
|
|
83
|
+
console.log(chalk.gray(`\nā Already up to date: ${upToDate.join(', ')}`));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (withUpdates.length === 0) {
|
|
87
|
+
console.log(chalk.green('\nā
All components are up to date.'));
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const choices = withUpdates.map(({ id: compId, installed: inst, latest }) => {
|
|
92
|
+
let versionLabel: string;
|
|
93
|
+
if (inst === null && latest === null) {
|
|
94
|
+
versionLabel = chalk.gray('(version unknown)');
|
|
95
|
+
} else if (latest === null) {
|
|
96
|
+
versionLabel = chalk.gray(`(installed: ${inst} ā registry version unknown)`);
|
|
97
|
+
} else if (inst === null) {
|
|
98
|
+
versionLabel = chalk.cyan(`(latest: ${latest} ā install version not tracked)`);
|
|
99
|
+
} else {
|
|
100
|
+
versionLabel = chalk.cyan(`(${inst} ā ${latest})`);
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
name: `${compId} ${versionLabel}`,
|
|
104
|
+
value: compId,
|
|
105
|
+
checked: true,
|
|
106
|
+
};
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const { selectedIds } = await inquirer.prompt([
|
|
110
|
+
{
|
|
111
|
+
type: 'checkbox',
|
|
112
|
+
name: 'selectedIds',
|
|
113
|
+
message: 'Select components to update:',
|
|
114
|
+
choices,
|
|
115
|
+
pageSize: 20,
|
|
116
|
+
},
|
|
117
|
+
]);
|
|
118
|
+
|
|
119
|
+
if (selectedIds.length === 0) {
|
|
120
|
+
console.log(chalk.yellow('No components selected.'));
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
await runUpdates(selectedIds, options);
|
|
125
|
+
} else {
|
|
126
|
+
// No flag: update everything
|
|
127
|
+
console.log(chalk.blue(`š Updating all ${installedIds.length} installed component(s)...`));
|
|
128
|
+
await runUpdates(installedIds, options);
|
|
129
|
+
}
|
|
28
130
|
});
|
|
29
131
|
}
|
|
132
|
+
|
|
133
|
+
async function runUpdates(ids: string[], options: AddOptions): Promise<void> {
|
|
134
|
+
let failed = 0;
|
|
135
|
+
for (const compId of ids) {
|
|
136
|
+
try {
|
|
137
|
+
console.log(chalk.blue(`\nš Updating ${compId}...`));
|
|
138
|
+
await addSingleComponent(compId, { ...options, overwrite: true });
|
|
139
|
+
} catch (error) {
|
|
140
|
+
console.error(chalk.red(`ā Failed to update ${compId}:`));
|
|
141
|
+
console.error(chalk.red(error instanceof Error ? error.message : String(error)));
|
|
142
|
+
failed++;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (failed > 0) {
|
|
147
|
+
console.log(chalk.yellow(`\nā ${failed} component(s) failed to update.`));
|
|
148
|
+
process.exit(1);
|
|
149
|
+
} else {
|
|
150
|
+
console.log(chalk.green(`\nā
${ids.length} component(s) updated successfully!`));
|
|
151
|
+
}
|
|
152
|
+
}
|