@foundrykit/cli 1.0.3 → 1.0.5
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 +16 -0
- package/dist/cli.js +102 -75
- package/dist/cli.js.map +1 -1
- package/dist/index.js +102 -75
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/commands/add.ts +125 -88
- package/src/commands/init.ts +12 -5
package/src/commands/add.ts
CHANGED
|
@@ -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
|
-
|
|
254
|
-
const
|
|
255
|
-
|
|
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,22 @@ 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
|
-
|
|
261
|
+
// Special handling for utils to ensure it always goes to the right place
|
|
262
|
+
let resolvedPath: string;
|
|
263
|
+
if (componentData.id === 'utils' || file.path === 'lib/utils.ts') {
|
|
264
|
+
resolvedPath = config.paths.utils || 'lib/utils.ts';
|
|
265
|
+
} else {
|
|
266
|
+
resolvedPath = resolveComponentPath(
|
|
267
|
+
file.path,
|
|
268
|
+
componentData.category,
|
|
269
|
+
config
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
const filePath = path.join(basePath, resolvedPath);
|
|
280
273
|
if (fs.existsSync(filePath)) {
|
|
281
274
|
return true;
|
|
282
275
|
}
|
|
@@ -292,20 +285,41 @@ async function installComponentFiles(
|
|
|
292
285
|
componentData: ComponentData,
|
|
293
286
|
options: AddOptions
|
|
294
287
|
): Promise<void> {
|
|
288
|
+
const config = await loadConfig();
|
|
295
289
|
const basePath = options.path || process.cwd();
|
|
296
290
|
|
|
297
291
|
console.log(chalk.blue('📝 Installing component files...'));
|
|
298
292
|
|
|
299
293
|
for (const file of componentData.files) {
|
|
300
|
-
|
|
294
|
+
// Special handling for utils to ensure it always goes to the right place
|
|
295
|
+
let resolvedPath: string;
|
|
296
|
+
if (componentData.id === 'utils' || file.path === 'lib/utils.ts') {
|
|
297
|
+
resolvedPath = config.paths.utils || 'lib/utils.ts';
|
|
298
|
+
} else {
|
|
299
|
+
resolvedPath = resolveComponentPath(
|
|
300
|
+
file.path,
|
|
301
|
+
componentData.category,
|
|
302
|
+
config
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const filePath = path.join(basePath, resolvedPath);
|
|
301
307
|
|
|
302
308
|
// Ensure directory exists
|
|
303
309
|
await fs.ensureDir(path.dirname(filePath));
|
|
304
310
|
|
|
311
|
+
// Check if file has content before writing
|
|
312
|
+
if (!file.content || file.content.trim() === '') {
|
|
313
|
+
console.log(
|
|
314
|
+
chalk.yellow(` ⚠ Skipping ${resolvedPath} - no content available`)
|
|
315
|
+
);
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
|
|
305
319
|
// Write file
|
|
306
320
|
await fs.writeFile(filePath, file.content);
|
|
307
321
|
|
|
308
|
-
console.log(chalk.green(` ✓ ${
|
|
322
|
+
console.log(chalk.green(` ✓ ${resolvedPath}`));
|
|
309
323
|
}
|
|
310
324
|
}
|
|
311
325
|
|
|
@@ -315,38 +329,13 @@ async function installComponentFiles(
|
|
|
315
329
|
async function handlePackageDependencies(
|
|
316
330
|
componentData: ComponentData
|
|
317
331
|
): Promise<void> {
|
|
332
|
+
// Only use the package dependencies specified by the component
|
|
318
333
|
const allDependencies = new Set<string>();
|
|
319
334
|
|
|
320
|
-
// Add component's package dependencies
|
|
321
335
|
if (componentData.packageDependencies?.length) {
|
|
322
336
|
componentData.packageDependencies.forEach(dep => allDependencies.add(dep));
|
|
323
337
|
}
|
|
324
338
|
|
|
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
339
|
if (allDependencies.size === 0) {
|
|
351
340
|
return;
|
|
352
341
|
}
|
|
@@ -430,51 +419,99 @@ async function detectPackageManager(): Promise<string> {
|
|
|
430
419
|
/**
|
|
431
420
|
* Show usage example for the installed component
|
|
432
421
|
*/
|
|
433
|
-
function showUsageExample(componentData: ComponentData): void {
|
|
422
|
+
async function showUsageExample(componentData: ComponentData): Promise<void> {
|
|
423
|
+
const config = await loadConfig();
|
|
434
424
|
console.log(chalk.cyan('\n💡 Usage:'));
|
|
435
425
|
|
|
436
426
|
const componentName = componentData.name.replace(/\s+/g, '');
|
|
427
|
+
const importPath = getImportPath(componentData, config);
|
|
437
428
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
) {
|
|
442
|
-
console.log(
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
429
|
+
console.log(chalk.gray(`import { ${componentName} } from "${importPath}"`));
|
|
430
|
+
|
|
431
|
+
// Show usage example if provided in component data
|
|
432
|
+
if (componentData.usageExample) {
|
|
433
|
+
console.log(chalk.gray(`\n${componentData.usageExample}`));
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Load FoundryKit configuration
|
|
439
|
+
*/
|
|
440
|
+
async function loadConfig(): Promise<any> {
|
|
441
|
+
const configPath = path.join(process.cwd(), 'foundrykit.config.json');
|
|
442
|
+
if (!fs.existsSync(configPath)) {
|
|
443
|
+
throw new Error(
|
|
444
|
+
'Configuration file not found. Run "foundrykit init" first.'
|
|
446
445
|
);
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
446
|
+
}
|
|
447
|
+
return fs.readJson(configPath);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Resolve component path based on category and configuration
|
|
452
|
+
*/
|
|
453
|
+
function resolveComponentPath(
|
|
454
|
+
originalPath: string,
|
|
455
|
+
category: ComponentCategory,
|
|
456
|
+
config: any
|
|
457
|
+
): string {
|
|
458
|
+
// Special handling for utils files - they should go directly to lib/utils.ts
|
|
459
|
+
if (originalPath === 'lib/utils.ts') {
|
|
460
|
+
return config.paths.utils || 'lib/utils.ts';
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// Get the base path for the category from config
|
|
464
|
+
const categoryPath = config.paths[category] || config.paths.components;
|
|
465
|
+
|
|
466
|
+
// Extract just the filename from the original path
|
|
467
|
+
const fileName = path.basename(originalPath);
|
|
468
|
+
const componentName = path.dirname(originalPath).split('/').pop() || '';
|
|
469
|
+
|
|
470
|
+
// Build the resolved path based on category
|
|
471
|
+
if (category === 'primitives') {
|
|
472
|
+
return path.join(categoryPath, componentName, fileName);
|
|
473
|
+
} else if (category === 'components') {
|
|
474
|
+
return path.join(
|
|
475
|
+
config.paths.components,
|
|
476
|
+
'components',
|
|
477
|
+
componentName,
|
|
478
|
+
fileName
|
|
452
479
|
);
|
|
453
|
-
} else if (
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
480
|
+
} else if (category === 'blocks') {
|
|
481
|
+
return path.join(
|
|
482
|
+
config.paths.blocks || path.join(config.paths.components, 'blocks'),
|
|
483
|
+
componentName,
|
|
484
|
+
fileName
|
|
485
|
+
);
|
|
486
|
+
} else if (category === 'animations') {
|
|
487
|
+
return path.join(
|
|
488
|
+
config.paths.animations ||
|
|
489
|
+
path.join(config.paths.components, 'animations'),
|
|
490
|
+
componentName,
|
|
491
|
+
fileName
|
|
458
492
|
);
|
|
459
493
|
}
|
|
460
494
|
|
|
461
|
-
//
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
495
|
+
// Default to original path if category not recognized
|
|
496
|
+
return originalPath;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Get import path for a component
|
|
501
|
+
*/
|
|
502
|
+
function getImportPath(componentData: ComponentData, config: any): string {
|
|
503
|
+
const aliases = config.aliases || {};
|
|
504
|
+
const componentName = path.basename(componentData.files[0].path, '.tsx');
|
|
505
|
+
|
|
506
|
+
if (componentData.category === 'primitives') {
|
|
507
|
+
return `@/components/ui/${componentName}`;
|
|
508
|
+
} else if (componentData.category === 'components') {
|
|
509
|
+
return `@/components/components/${componentName}`;
|
|
510
|
+
} else if (componentData.category === 'blocks') {
|
|
511
|
+
return `@/components/blocks/${componentName}`;
|
|
512
|
+
} else if (componentData.category === 'animations') {
|
|
513
|
+
return `@/components/animations/${componentName}`;
|
|
479
514
|
}
|
|
515
|
+
|
|
516
|
+
return `@/components/${componentName}`;
|
|
480
517
|
}
|
package/src/commands/init.ts
CHANGED
|
@@ -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 = [
|
|
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/
|
|
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/
|
|
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',
|