@foundrykit/cli 1.0.3 → 1.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.
@@ -187,16 +187,6 @@ async function addSingleComponent(
187
187
  console.log(chalk.blue('📦 Installing required dependencies...'));
188
188
  for (const dep of componentData.registryDependencies) {
189
189
  try {
190
- // Skip 'primitives' as it's not a single component but a category
191
- if (dep === 'primitives') {
192
- console.log(
193
- chalk.gray(
194
- ` ⏭ Skipping "${dep}" - primitive dependencies will be handled separately`
195
- )
196
- );
197
- continue;
198
- }
199
-
200
190
  // Fetch dependency from registry
201
191
  const depData = await registry.getComponent(dep);
202
192
 
@@ -250,18 +240,9 @@ async function validateProject(): Promise<void> {
250
240
  );
251
241
  }
252
242
 
253
- const packageJson = await fs.readJson(packageJsonPath);
254
- const dependencies = {
255
- ...packageJson.dependencies,
256
- ...packageJson.devDependencies,
257
- };
258
-
259
- // Check for Next.js or FoundryKit packages
260
- const hasFoundryKit = Object.keys(dependencies).some(dep =>
261
- dep.startsWith('@foundrykit/')
262
- );
263
-
264
- if (!hasFoundryKit && !dependencies.next) {
243
+ // Check for configuration file
244
+ const configPath = path.join(process.cwd(), 'foundrykit.config.json');
245
+ if (!fs.existsSync(configPath)) {
265
246
  throw new Error('FoundryKit not initialized. Run "foundrykit init" first.');
266
247
  }
267
248
  }
@@ -273,10 +254,16 @@ async function hasConflictingFiles(
273
254
  componentData: ComponentData,
274
255
  options: AddOptions
275
256
  ): Promise<boolean> {
257
+ const config = await loadConfig();
276
258
  const basePath = options.path || process.cwd();
277
259
 
278
260
  for (const file of componentData.files) {
279
- const filePath = path.join(basePath, file.path);
261
+ const resolvedPath = resolveComponentPath(
262
+ file.path,
263
+ componentData.category,
264
+ config
265
+ );
266
+ const filePath = path.join(basePath, resolvedPath);
280
267
  if (fs.existsSync(filePath)) {
281
268
  return true;
282
269
  }
@@ -292,12 +279,18 @@ async function installComponentFiles(
292
279
  componentData: ComponentData,
293
280
  options: AddOptions
294
281
  ): Promise<void> {
282
+ const config = await loadConfig();
295
283
  const basePath = options.path || process.cwd();
296
284
 
297
285
  console.log(chalk.blue('📝 Installing component files...'));
298
286
 
299
287
  for (const file of componentData.files) {
300
- const filePath = path.join(basePath, file.path);
288
+ const resolvedPath = resolveComponentPath(
289
+ file.path,
290
+ componentData.category,
291
+ config
292
+ );
293
+ const filePath = path.join(basePath, resolvedPath);
301
294
 
302
295
  // Ensure directory exists
303
296
  await fs.ensureDir(path.dirname(filePath));
@@ -305,7 +298,7 @@ async function installComponentFiles(
305
298
  // Write file
306
299
  await fs.writeFile(filePath, file.content);
307
300
 
308
- console.log(chalk.green(` ✓ ${file.path}`));
301
+ console.log(chalk.green(` ✓ ${resolvedPath}`));
309
302
  }
310
303
  }
311
304
 
@@ -315,38 +308,13 @@ async function installComponentFiles(
315
308
  async function handlePackageDependencies(
316
309
  componentData: ComponentData
317
310
  ): Promise<void> {
311
+ // Only use the package dependencies specified by the component
318
312
  const allDependencies = new Set<string>();
319
313
 
320
- // Add component's package dependencies
321
314
  if (componentData.packageDependencies?.length) {
322
315
  componentData.packageDependencies.forEach(dep => allDependencies.add(dep));
323
316
  }
324
317
 
325
- // Add utils dependencies if utils is a dependency
326
- if (componentData.registryDependencies?.includes('utils')) {
327
- allDependencies.add('clsx');
328
- allDependencies.add('tailwind-merge');
329
- }
330
-
331
- // Add primitives dependencies if primitives is a dependency
332
- if (componentData.registryDependencies?.includes('primitives')) {
333
- // Common primitives dependencies
334
- allDependencies.add('@radix-ui/react-slot');
335
- allDependencies.add('class-variance-authority');
336
- allDependencies.add('clsx');
337
- allDependencies.add('tailwind-merge');
338
- }
339
-
340
- // Add class-variance-authority for button
341
- if (componentData.id === 'button') {
342
- allDependencies.add('class-variance-authority');
343
- }
344
-
345
- // Add lucide-react for components that use icons
346
- if (componentData.id === 'search-bar') {
347
- allDependencies.add('lucide-react');
348
- }
349
-
350
318
  if (allDependencies.size === 0) {
351
319
  return;
352
320
  }
@@ -430,51 +398,94 @@ async function detectPackageManager(): Promise<string> {
430
398
  /**
431
399
  * Show usage example for the installed component
432
400
  */
433
- function showUsageExample(componentData: ComponentData): void {
401
+ async function showUsageExample(componentData: ComponentData): Promise<void> {
402
+ const config = await loadConfig();
434
403
  console.log(chalk.cyan('\n💡 Usage:'));
435
404
 
436
405
  const componentName = componentData.name.replace(/\s+/g, '');
406
+ const importPath = getImportPath(componentData, config);
437
407
 
438
- if (
439
- componentData.category === 'primitives' ||
440
- componentData.category === 'components'
441
- ) {
442
- console.log(
443
- chalk.gray(
444
- `import { ${componentName} } from "@/components/ui/${componentData.id}"`
445
- )
408
+ console.log(chalk.gray(`import { ${componentName} } from "${importPath}"`));
409
+
410
+ // Show usage example if provided in component data
411
+ if (componentData.usageExample) {
412
+ console.log(chalk.gray(`\n${componentData.usageExample}`));
413
+ }
414
+ }
415
+
416
+ /**
417
+ * Load FoundryKit configuration
418
+ */
419
+ async function loadConfig(): Promise<any> {
420
+ const configPath = path.join(process.cwd(), 'foundrykit.config.json');
421
+ if (!fs.existsSync(configPath)) {
422
+ throw new Error(
423
+ 'Configuration file not found. Run "foundrykit init" first.'
446
424
  );
447
- } else if (componentData.category === 'blocks') {
448
- console.log(
449
- chalk.gray(
450
- `import { ${componentName} } from "@/components/blocks/${componentData.id}"`
451
- )
425
+ }
426
+ return fs.readJson(configPath);
427
+ }
428
+
429
+ /**
430
+ * Resolve component path based on category and configuration
431
+ */
432
+ function resolveComponentPath(
433
+ originalPath: string,
434
+ category: ComponentCategory,
435
+ config: any
436
+ ): string {
437
+ // Get the base path for the category from config
438
+ const categoryPath = config.paths[category] || config.paths.components;
439
+
440
+ // Extract just the filename from the original path
441
+ const fileName = path.basename(originalPath);
442
+ const componentName = path.dirname(originalPath).split('/').pop() || '';
443
+
444
+ // Build the resolved path based on category
445
+ if (category === 'primitives') {
446
+ return path.join(categoryPath, componentName, fileName);
447
+ } else if (category === 'components') {
448
+ return path.join(
449
+ config.paths.components,
450
+ 'components',
451
+ componentName,
452
+ fileName
452
453
  );
453
- } else if (componentData.category === 'animations') {
454
- console.log(
455
- chalk.gray(
456
- `import { ${componentName} } from "@/components/animations/${componentData.id}"`
457
- )
454
+ } else if (category === 'blocks') {
455
+ return path.join(
456
+ config.paths.blocks || path.join(config.paths.components, 'blocks'),
457
+ componentName,
458
+ fileName
459
+ );
460
+ } else if (category === 'animations') {
461
+ return path.join(
462
+ config.paths.animations ||
463
+ path.join(config.paths.components, 'animations'),
464
+ componentName,
465
+ fileName
458
466
  );
459
467
  }
460
468
 
461
- // Show basic usage examples based on component type
462
- if (componentData.id === 'button') {
463
- console.log(chalk.gray('\n<Button>Click me</Button>'));
464
- console.log(chalk.gray('<Button variant="outline">Outline</Button>'));
465
- } else if (componentData.id === 'input') {
466
- console.log(chalk.gray('\n<Input placeholder="Enter text..." />'));
467
- } else if (componentData.id.includes('hero')) {
468
- console.log(chalk.gray(`\n<${componentName} />`));
469
- } else if (componentData.id === 'card') {
470
- console.log(chalk.gray('\n<Card>'));
471
- console.log(chalk.gray(' <CardHeader>'));
472
- console.log(chalk.gray(' <CardTitle>Title</CardTitle>'));
473
- console.log(
474
- chalk.gray(' <CardDescription>Description</CardDescription>')
475
- );
476
- console.log(chalk.gray(' </CardHeader>'));
477
- console.log(chalk.gray(' <CardContent>Content</CardContent>'));
478
- console.log(chalk.gray('</Card>'));
469
+ // Default to original path if category not recognized
470
+ return originalPath;
471
+ }
472
+
473
+ /**
474
+ * Get import path for a component
475
+ */
476
+ function getImportPath(componentData: ComponentData, config: any): string {
477
+ const aliases = config.aliases || {};
478
+ const componentName = path.basename(componentData.files[0].path, '.tsx');
479
+
480
+ if (componentData.category === 'primitives') {
481
+ return `@/components/ui/${componentName}`;
482
+ } else if (componentData.category === 'components') {
483
+ return `@/components/components/${componentName}`;
484
+ } else if (componentData.category === 'blocks') {
485
+ return `@/components/blocks/${componentName}`;
486
+ } else if (componentData.category === 'animations') {
487
+ return `@/components/animations/${componentName}`;
479
488
  }
489
+
490
+ return `@/components/${componentName}`;
480
491
  }
@@ -526,7 +526,14 @@ async function updateLayoutImport(globalCssPath: string): Promise<void> {
526
526
  async function createDirectories(): Promise<void> {
527
527
  console.log(chalk.blue('📁 Creating component directories...'));
528
528
 
529
- const dirs = ['components/ui', 'components/blocks', 'lib', 'hooks'];
529
+ const dirs = [
530
+ 'components/primitives',
531
+ 'components/components',
532
+ 'components/blocks',
533
+ 'components/animations',
534
+ 'lib',
535
+ 'hooks',
536
+ ];
530
537
 
531
538
  for (const dir of dirs) {
532
539
  await fs.ensureDir(path.join(process.cwd(), dir));
@@ -621,8 +628,8 @@ async function createConfigFile(options: InitOptions): Promise<void> {
621
628
  registry: 'https://foundry.umiflow.com',
622
629
  paths: {
623
630
  utils: './src/lib/utils.ts',
624
- primitives: './src/components/ui',
625
- components: './src/components',
631
+ primitives: './src/components/primitives',
632
+ components: './src/components/components',
626
633
  blocks: './src/components/blocks',
627
634
  hooks: './src/hooks',
628
635
  animations: './src/components/animations',
@@ -649,8 +656,8 @@ async function createConfigFile(options: InitOptions): Promise<void> {
649
656
  // Using app directory without src
650
657
  config.paths = {
651
658
  utils: './lib/utils.ts',
652
- primitives: './components/ui',
653
- components: './components',
659
+ primitives: './components/primitives',
660
+ components: './components/components',
654
661
  blocks: './components/blocks',
655
662
  hooks: './hooks',
656
663
  animations: './components/animations',