@foundrykit/cli 1.0.15 → 1.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foundrykit/cli",
3
- "version": "1.0.15",
3
+ "version": "1.1.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.8"
28
+ "@foundrykit/types": "1.0.9"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/node": "^20.19.9",
@@ -35,15 +35,15 @@
35
35
  "tsup": "^8.0.0",
36
36
  "typescript": "^5.9.2",
37
37
  "vitest": "^1.2.0",
38
- "@foundrykit/eslint-config": "1.0.4",
39
- "@foundrykit/typescript-config": "1.0.4"
38
+ "@foundrykit/typescript-config": "1.0.5",
39
+ "@foundrykit/eslint-config": "1.0.5"
40
40
  },
41
41
  "scripts": {
42
42
  "build": "tsup",
43
43
  "dev": "tsup --watch",
44
44
  "lint": "eslint . --max-warnings 0",
45
45
  "type-check": "tsc --noEmit",
46
- "test": "vitest",
46
+ "test": "vitest run",
47
47
  "test:watch": "vitest --watch"
48
48
  }
49
49
  }
@@ -27,6 +27,8 @@ interface AddOptions {
27
27
  overwrite?: boolean;
28
28
  }
29
29
 
30
+ export type { AddOptions };
31
+
30
32
  export function addCommand() {
31
33
  return new Command('add')
32
34
  .description('Add a component or block to your project')
@@ -149,7 +151,7 @@ function createGroupedChoices(components: ComponentMeta[]) {
149
151
  /**
150
152
  * Add a single component to the project
151
153
  */
152
- async function addSingleComponent(
154
+ export async function addSingleComponent(
153
155
  id: string,
154
156
  options: AddOptions
155
157
  ): Promise<void> {
@@ -239,7 +241,7 @@ async function addSingleComponent(
239
241
  /**
240
242
  * Update config version to match CLI version
241
243
  */
242
- async function updateConfigVersion(): Promise<void> {
244
+ export async function updateConfigVersion(): Promise<void> {
243
245
  const configPath = path.join(process.cwd(), 'foundrykit.config.json');
244
246
  if (fs.existsSync(configPath)) {
245
247
  const config = await fs.readJson(configPath);
@@ -253,7 +255,7 @@ async function updateConfigVersion(): Promise<void> {
253
255
  /**
254
256
  * Validate that the project is properly initialized
255
257
  */
256
- async function validateProject(): Promise<void> {
258
+ export async function validateProject(): Promise<void> {
257
259
  const packageJsonPath = path.join(process.cwd(), 'package.json');
258
260
 
259
261
  if (!fs.existsSync(packageJsonPath)) {
@@ -275,7 +277,7 @@ async function validateProject(): Promise<void> {
275
277
  /**
276
278
  * Check if component files already exist
277
279
  */
278
- async function hasConflictingFiles(
280
+ export async function hasConflictingFiles(
279
281
  componentData: ComponentData,
280
282
  options: AddOptions
281
283
  ): Promise<boolean> {
@@ -306,7 +308,7 @@ async function hasConflictingFiles(
306
308
  /**
307
309
  * Install component files to the project
308
310
  */
309
- async function installComponentFiles(
311
+ export async function installComponentFiles(
310
312
  componentData: ComponentData,
311
313
  options: AddOptions
312
314
  ): Promise<void> {
@@ -356,7 +358,7 @@ async function installComponentFiles(
356
358
  /**
357
359
  * Handle package dependencies - check and auto-install if needed
358
360
  */
359
- async function handlePackageDependencies(
361
+ export async function handlePackageDependencies(
360
362
  componentData: ComponentData
361
363
  ): Promise<void> {
362
364
  // Only use the package dependencies specified by the component
@@ -407,7 +409,7 @@ async function handlePackageDependencies(
407
409
  /**
408
410
  * Check which packages are missing from the project
409
411
  */
410
- async function getMissingPackages(packages: string[]): Promise<string[]> {
412
+ export async function getMissingPackages(packages: string[]): Promise<string[]> {
411
413
  const packageJsonPath = path.join(process.cwd(), 'package.json');
412
414
 
413
415
  try {
@@ -427,7 +429,7 @@ async function getMissingPackages(packages: string[]): Promise<string[]> {
427
429
  /**
428
430
  * Detect which package manager is being used
429
431
  */
430
- async function detectPackageManager(): Promise<string> {
432
+ export async function detectPackageManager(): Promise<string> {
431
433
  // Check for lock files
432
434
  if (await fs.pathExists(path.join(process.cwd(), 'pnpm-lock.yaml'))) {
433
435
  return 'pnpm';
@@ -449,7 +451,9 @@ async function detectPackageManager(): Promise<string> {
449
451
  /**
450
452
  * Show usage example for the installed component
451
453
  */
452
- async function showUsageExample(componentData: ComponentData): Promise<void> {
454
+ export async function showUsageExample(
455
+ componentData: ComponentData
456
+ ): Promise<void> {
453
457
  const config = await loadConfig();
454
458
  console.log(chalk.cyan('\n💡 Usage:'));
455
459
 
@@ -467,7 +471,7 @@ async function showUsageExample(componentData: ComponentData): Promise<void> {
467
471
  /**
468
472
  * Load FoundryKit configuration
469
473
  */
470
- async function loadConfig(): Promise<Config> {
474
+ export async function loadConfig(): Promise<Config> {
471
475
  const configPath = path.join(process.cwd(), 'foundrykit.config.json');
472
476
  if (!fs.existsSync(configPath)) {
473
477
  throw new Error(
@@ -480,7 +484,7 @@ async function loadConfig(): Promise<Config> {
480
484
  /**
481
485
  * Transform imports in file content based on config
482
486
  */
483
- function transformImportsForConfig(content: string, config: Config): string {
487
+ export function transformImportsForConfig(content: string, config: Config): string {
484
488
  let transformed = content;
485
489
 
486
490
  // Ensure config.paths exists with fallbacks
@@ -613,7 +617,7 @@ function transformImportsForConfig(content: string, config: Config): string {
613
617
  /**
614
618
  * Resolve component path based on category and configuration
615
619
  */
616
- function resolveComponentPath(
620
+ export function resolveComponentPath(
617
621
  originalPath: string,
618
622
  category: ComponentCategory,
619
623
  config: any
@@ -665,7 +669,7 @@ function resolveComponentPath(
665
669
  /**
666
670
  * Get import path for a component
667
671
  */
668
- function getImportPath(componentData: ComponentData, config: any): string {
672
+ export function getImportPath(componentData: ComponentData, config: any): string {
669
673
  // Ensure config.paths exists with fallbacks
670
674
  const paths = config?.paths || {
671
675
  primitives: 'components/primitives',
@@ -1,11 +1,127 @@
1
1
  import { Command } from 'commander';
2
2
  import chalk from 'chalk';
3
+ import fs from 'fs-extra';
4
+ import path from 'path';
5
+ import { DEFAULT_REGISTRY_URL } from '../lib/constants.js';
6
+ import { loadConfig } from './add.js';
7
+
8
+ interface CheckResult {
9
+ label: string;
10
+ ok: boolean;
11
+ detail: string;
12
+ }
3
13
 
4
14
  export function doctorCommand() {
5
15
  return new Command('doctor')
6
16
  .description('Check project health and configuration')
7
17
  .action(async () => {
8
18
  console.log(chalk.blue('🔍 Checking project health...'));
9
- console.log(chalk.green('✅ All checks passed!'));
19
+
20
+ const results: CheckResult[] = [];
21
+
22
+ const packageJsonPath = path.join(process.cwd(), 'package.json');
23
+ const hasPackageJson = await fs.pathExists(packageJsonPath);
24
+ results.push({
25
+ label: 'package.json',
26
+ ok: hasPackageJson,
27
+ detail: hasPackageJson
28
+ ? 'Project manifest found'
29
+ : 'Run this command in a project root',
30
+ });
31
+
32
+ let packageJson: Record<string, any> | null = null;
33
+ if (hasPackageJson) {
34
+ packageJson = await fs.readJson(packageJsonPath);
35
+ }
36
+
37
+ const hasNext =
38
+ !!packageJson &&
39
+ !!(packageJson.dependencies?.next || packageJson.devDependencies?.next);
40
+ results.push({
41
+ label: 'Framework',
42
+ ok: hasNext,
43
+ detail: hasNext
44
+ ? 'Next.js dependency detected'
45
+ : 'FoundryKit currently expects a Next.js project',
46
+ });
47
+
48
+ const configPath = path.join(process.cwd(), 'foundrykit.config.json');
49
+ const hasConfig = await fs.pathExists(configPath);
50
+ results.push({
51
+ label: 'FoundryKit config',
52
+ ok: hasConfig,
53
+ detail: hasConfig
54
+ ? 'foundrykit.config.json found'
55
+ : 'Run "foundrykit init" to create the configuration file',
56
+ });
57
+
58
+ let config:
59
+ | Awaited<ReturnType<typeof loadConfig>>
60
+ | null = null;
61
+ if (hasConfig) {
62
+ try {
63
+ config = await loadConfig();
64
+ const hasRequiredPaths =
65
+ !!config.paths?.utils &&
66
+ !!config.paths?.primitives &&
67
+ !!config.paths?.components &&
68
+ !!config.paths?.blocks &&
69
+ !!config.paths?.animations;
70
+
71
+ results.push({
72
+ label: 'Config shape',
73
+ ok: hasRequiredPaths,
74
+ detail: hasRequiredPaths
75
+ ? 'Required install paths are configured'
76
+ : 'Configuration is missing one or more required install paths',
77
+ });
78
+
79
+ const registryUrl = config.registry || DEFAULT_REGISTRY_URL;
80
+ try {
81
+ const response = await fetch(`${registryUrl}/registry`, {
82
+ headers: { Accept: 'application/json' },
83
+ });
84
+
85
+ results.push({
86
+ label: 'Registry',
87
+ ok: response.ok,
88
+ detail: response.ok
89
+ ? `Registry reachable at ${registryUrl}`
90
+ : `Registry returned ${response.status} ${response.statusText}`,
91
+ });
92
+ } catch (error) {
93
+ results.push({
94
+ label: 'Registry',
95
+ ok: false,
96
+ detail: `Unable to reach ${registryUrl}: ${
97
+ error instanceof Error ? error.message : 'Unknown error'
98
+ }`,
99
+ });
100
+ }
101
+ } catch (error) {
102
+ results.push({
103
+ label: 'Config shape',
104
+ ok: false,
105
+ detail: `Failed to read foundrykit.config.json: ${
106
+ error instanceof Error ? error.message : 'Unknown error'
107
+ }`,
108
+ });
109
+ }
110
+ }
111
+
112
+ for (const result of results) {
113
+ const icon = result.ok ? chalk.green('✅') : chalk.red('❌');
114
+ console.log(`${icon} ${result.label}: ${result.detail}`);
115
+ }
116
+
117
+ const hasFailures = results.some(result => !result.ok);
118
+ if (hasFailures) {
119
+ console.log(
120
+ chalk.yellow('\n⚠️ Found issues that should be resolved before continuing.')
121
+ );
122
+ process.exit(1);
123
+ }
124
+
125
+ console.log(chalk.green('\n✅ All checks passed!'));
10
126
  });
11
127
  }
@@ -1,12 +1,29 @@
1
1
  import { Command } from 'commander';
2
2
  import chalk from 'chalk';
3
+ import { addSingleComponent, type AddOptions } from './add.js';
4
+
5
+ interface UpdateOptions extends AddOptions {
6
+ path?: string;
7
+ }
3
8
 
4
9
  export function updateCommand() {
5
10
  return new Command('update')
6
11
  .description('Update an existing component or block')
7
12
  .argument('<id>', 'Component or block ID')
8
- .action(async id => {
9
- console.log(chalk.blue(`🔄 Updating ${id}...`));
10
- console.log(chalk.green(`✅ ${id} updated successfully!`));
13
+ .option('-p, --path <path>', 'Custom installation path')
14
+ .action(async (id: string, options: UpdateOptions) => {
15
+ try {
16
+ console.log(chalk.blue(`🔄 Updating ${id}...`));
17
+ await addSingleComponent(id, {
18
+ ...options,
19
+ overwrite: true,
20
+ });
21
+ } catch (error) {
22
+ console.error(chalk.red(`❌ Failed to update ${id}:`));
23
+ console.error(
24
+ chalk.red(error instanceof Error ? error.message : String(error))
25
+ );
26
+ process.exit(1);
27
+ }
11
28
  });
12
29
  }
@@ -4,7 +4,7 @@
4
4
 
5
5
  // CLI version - update this when publishing new versions
6
6
  // This should match the version in package.json
7
- export const CLI_VERSION = '1.0.8';
7
+ export const CLI_VERSION = '1.0.16';
8
8
 
9
9
  // Default registry URL
10
10
  export const DEFAULT_REGISTRY_URL = 'https://foundry.umiflow.com';
@@ -96,6 +96,15 @@ export class RegistryService {
96
96
  return this.createSpecialDependency(id);
97
97
  }
98
98
 
99
+ const cache = await this.loadCache();
100
+ const cachedComponent = cache?.componentData?.[id];
101
+ const hasValidCache = cache ? this.isCacheValid(cache) : false;
102
+
103
+ if (cachedComponent && hasValidCache) {
104
+ console.log(chalk.gray(`Using cached data for component: ${id}`));
105
+ return cachedComponent;
106
+ }
107
+
99
108
  try {
100
109
  const url = `${this.config.registryUrl}/registry/${id}`;
101
110
  console.log(chalk.gray(`Fetching component: ${url}`));
@@ -118,11 +127,10 @@ export class RegistryService {
118
127
 
119
128
  return component;
120
129
  } catch (error) {
121
- // Try to load from cache
122
- const cache = await this.loadCache();
123
- if (cache?.componentData?.[id]) {
130
+ // Fall back to any cached component data, even if stale
131
+ if (cachedComponent) {
124
132
  console.log(chalk.yellow(`Using cached data for component: ${id}`));
125
- return cache.componentData[id];
133
+ return cachedComponent;
126
134
  }
127
135
 
128
136
  // No cached data, throw error
@@ -271,12 +279,17 @@ export function cn(...inputs: ClassValue[]) {
271
279
  */
272
280
  private async cacheComponent(component: ComponentData): Promise<void> {
273
281
  try {
274
- const cache = await this.loadCache();
275
- if (!cache) return;
282
+ const cache = (await this.loadCache()) ?? {
283
+ version: '1.0.0',
284
+ lastUpdated: new Date().toISOString(),
285
+ components: [],
286
+ componentData: {},
287
+ };
276
288
 
277
289
  cache.componentData[component.id] = component;
278
290
  cache.lastUpdated = new Date().toISOString();
279
291
 
292
+ await fs.ensureDir(this.config.cacheDir);
280
293
  await fs.writeJson(this.cacheFile, cache, { spaces: 2 });
281
294
  } catch (error) {
282
295
  // Cache update failed, but don't throw
@@ -6,7 +6,7 @@ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
6
6
  import fs from 'fs-extra';
7
7
  import path from 'path';
8
8
  import os from 'os';
9
- import { RegistryService } from '../src/lib/registry';
9
+ import { RegistryService } from '../src/lib/registry.js';
10
10
  import type { ComponentData } from '@foundrykit/types';
11
11
 
12
12
  describe('Dependency Resolution', () => {
@@ -44,10 +44,10 @@ describe('Dependency Resolution', () => {
44
44
  expect(component).toBeDefined();
45
45
  expect(component.id).toBe('utils');
46
46
  expect(component.files).toHaveLength(1);
47
- expect(component.files[0].path).toBe('lib/utils.ts');
48
- expect(component.files[0].content).toContain('cn');
49
- expect(component.files[0].content).toContain('clsx');
50
- expect(component.files[0].content).toContain('twMerge');
47
+ expect(component.files[0]!.path).toBe('lib/utils.ts');
48
+ expect(component.files[0]!.content).toContain('cn');
49
+ expect(component.files[0]!.content).toContain('clsx');
50
+ expect(component.files[0]!.content).toContain('twMerge');
51
51
  });
52
52
 
53
53
  it('should handle lib alias for utils', async () => {
@@ -55,7 +55,7 @@ describe('Dependency Resolution', () => {
55
55
 
56
56
  expect(component).toBeDefined();
57
57
  expect(component.id).toBe('utils');
58
- expect(component.files[0].path).toBe('lib/utils.ts');
58
+ expect(component.files[0]!.path).toBe('lib/utils.ts');
59
59
  });
60
60
 
61
61
  it('should handle helpers alias for utils', async () => {
@@ -63,7 +63,7 @@ describe('Dependency Resolution', () => {
63
63
 
64
64
  expect(component).toBeDefined();
65
65
  expect(component.id).toBe('utils');
66
- expect(component.files[0].path).toBe('lib/utils.ts');
66
+ expect(component.files[0]!.path).toBe('lib/utils.ts');
67
67
  });
68
68
 
69
69
  it('should handle cn alias for utils', async () => {
@@ -71,7 +71,7 @@ describe('Dependency Resolution', () => {
71
71
 
72
72
  expect(component).toBeDefined();
73
73
  expect(component.id).toBe('utils');
74
- expect(component.files[0].path).toBe('lib/utils.ts');
74
+ expect(component.files[0]!.path).toBe('lib/utils.ts');
75
75
  });
76
76
  });
77
77
 
@@ -205,7 +205,7 @@ describe('Dependency Resolution', () => {
205
205
 
206
206
  // Simulate installation
207
207
  await fs.ensureDir(path.dirname(utilsPath));
208
- await fs.writeFile(utilsPath, utils.files[0].content);
208
+ await fs.writeFile(utilsPath, utils.files[0]!.content);
209
209
 
210
210
  expect(await fs.pathExists(utilsPath)).toBe(true);
211
211