@foundrykit/cli 1.0.8 → 1.0.10
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 +155 -39
- package/dist/cli.js.map +1 -1
- package/dist/index.js +155 -39
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/commands/add.ts +191 -20
- package/src/commands/init.ts +40 -18
- package/src/commands/list.ts +3 -0
- package/src/lib/constants.ts +15 -0
- package/src/lib/registry.ts +9 -4
- package/components.json +0 -20
package/src/commands/add.ts
CHANGED
|
@@ -16,6 +16,7 @@ import type {
|
|
|
16
16
|
ComponentCategory,
|
|
17
17
|
} from '@foundrykit/types';
|
|
18
18
|
import { getRegistry } from '../lib/registry.js';
|
|
19
|
+
import { CLI_VERSION } from '../lib/constants.js';
|
|
19
20
|
|
|
20
21
|
const execAsync = promisify(exec);
|
|
21
22
|
|
|
@@ -228,6 +229,20 @@ async function addSingleComponent(
|
|
|
228
229
|
}
|
|
229
230
|
}
|
|
230
231
|
|
|
232
|
+
/**
|
|
233
|
+
* Update config version to match CLI version
|
|
234
|
+
*/
|
|
235
|
+
async function updateConfigVersion(): Promise<void> {
|
|
236
|
+
const configPath = path.join(process.cwd(), 'foundrykit.config.json');
|
|
237
|
+
if (fs.existsSync(configPath)) {
|
|
238
|
+
const config = await fs.readJson(configPath);
|
|
239
|
+
if (config.version !== CLI_VERSION) {
|
|
240
|
+
config.version = CLI_VERSION;
|
|
241
|
+
await fs.writeJson(configPath, config, { spaces: 2 });
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
231
246
|
/**
|
|
232
247
|
* Validate that the project is properly initialized
|
|
233
248
|
*/
|
|
@@ -245,6 +260,9 @@ async function validateProject(): Promise<void> {
|
|
|
245
260
|
if (!fs.existsSync(configPath)) {
|
|
246
261
|
throw new Error('FoundryKit not initialized. Run "foundrykit init" first.');
|
|
247
262
|
}
|
|
263
|
+
|
|
264
|
+
// Update config version if needed
|
|
265
|
+
await updateConfigVersion();
|
|
248
266
|
}
|
|
249
267
|
|
|
250
268
|
/**
|
|
@@ -316,11 +334,16 @@ async function installComponentFiles(
|
|
|
316
334
|
continue;
|
|
317
335
|
}
|
|
318
336
|
|
|
319
|
-
//
|
|
320
|
-
|
|
337
|
+
// Transform imports based on config
|
|
338
|
+
const transformedContent = transformImportsForConfig(file.content, config);
|
|
321
339
|
|
|
322
|
-
|
|
340
|
+
// Write the file
|
|
341
|
+
await fs.writeFile(filePath, transformedContent);
|
|
342
|
+
console.log(chalk.gray(` ✓ Created ${resolvedPath}`));
|
|
323
343
|
}
|
|
344
|
+
|
|
345
|
+
// Update config version after successful installation
|
|
346
|
+
await updateConfigVersion();
|
|
324
347
|
}
|
|
325
348
|
|
|
326
349
|
/**
|
|
@@ -447,6 +470,130 @@ async function loadConfig(): Promise<any> {
|
|
|
447
470
|
return fs.readJson(configPath);
|
|
448
471
|
}
|
|
449
472
|
|
|
473
|
+
/**
|
|
474
|
+
* Transform imports in file content based on config
|
|
475
|
+
*/
|
|
476
|
+
function transformImportsForConfig(content: string, config: any): string {
|
|
477
|
+
let transformed = content;
|
|
478
|
+
|
|
479
|
+
// Ensure config.paths exists with fallbacks
|
|
480
|
+
const paths = config?.paths || {
|
|
481
|
+
primitives: 'components/primitives',
|
|
482
|
+
components: 'components',
|
|
483
|
+
blocks: 'components/blocks',
|
|
484
|
+
animations: 'components/animations',
|
|
485
|
+
utils: 'lib/utils',
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
// Transform imports using regex to capture component names and build proper paths
|
|
489
|
+
// Handle @/components/primitives imports
|
|
490
|
+
transformed = transformed.replace(
|
|
491
|
+
/import\s+{([^}]+)}\s+from\s+["']@\/components\/primitives["']/g,
|
|
492
|
+
(match, imports) => {
|
|
493
|
+
const componentNames = imports.split(',').map(
|
|
494
|
+
(imp: string) =>
|
|
495
|
+
imp
|
|
496
|
+
?.trim()
|
|
497
|
+
.split(/\s+as\s+/)[0]
|
|
498
|
+
?.trim() || ''
|
|
499
|
+
);
|
|
500
|
+
|
|
501
|
+
const primitivesPath = paths.primitives
|
|
502
|
+
.replace(/^\.\//, '')
|
|
503
|
+
.replace(/\/$/, '');
|
|
504
|
+
|
|
505
|
+
return `import {${imports}} from "@/${primitivesPath}/${componentNames[0].toLowerCase()}"`;
|
|
506
|
+
}
|
|
507
|
+
);
|
|
508
|
+
|
|
509
|
+
// Handle @/components/ui imports (legacy, maps to primitives)
|
|
510
|
+
transformed = transformed.replace(
|
|
511
|
+
/import\s+{([^}]+)}\s+from\s+["']@\/components\/ui["']/g,
|
|
512
|
+
(match, imports) => {
|
|
513
|
+
const componentNames = imports.split(',').map(
|
|
514
|
+
(imp: string) =>
|
|
515
|
+
imp
|
|
516
|
+
?.trim()
|
|
517
|
+
.split(/\s+as\s+/)[0]
|
|
518
|
+
?.trim() || ''
|
|
519
|
+
);
|
|
520
|
+
|
|
521
|
+
const primitivesPath = paths.primitives
|
|
522
|
+
.replace(/^\.\//, '')
|
|
523
|
+
.replace(/\/$/, '');
|
|
524
|
+
|
|
525
|
+
return `import {${imports}} from "@/${primitivesPath}/${componentNames[0].toLowerCase()}"`;
|
|
526
|
+
}
|
|
527
|
+
);
|
|
528
|
+
|
|
529
|
+
// Handle @/components/components imports
|
|
530
|
+
transformed = transformed.replace(
|
|
531
|
+
/import\s+{([^}]+)}\s+from\s+["']@\/components\/components["']/g,
|
|
532
|
+
(match, imports) => {
|
|
533
|
+
const componentNames = imports.split(',').map(
|
|
534
|
+
(imp: string) =>
|
|
535
|
+
imp
|
|
536
|
+
?.trim()
|
|
537
|
+
.split(/\s+as\s+/)[0]
|
|
538
|
+
?.trim() || ''
|
|
539
|
+
);
|
|
540
|
+
|
|
541
|
+
const componentsPath = paths.components
|
|
542
|
+
.replace(/^\.\//, '')
|
|
543
|
+
.replace(/\/$/, '');
|
|
544
|
+
|
|
545
|
+
return `import {${imports}} from "@/${componentsPath}/${componentNames[0].toLowerCase()}"`;
|
|
546
|
+
}
|
|
547
|
+
);
|
|
548
|
+
|
|
549
|
+
// Handle @/components/blocks imports
|
|
550
|
+
transformed = transformed.replace(
|
|
551
|
+
/import\s+{([^}]+)}\s+from\s+["']@\/components\/blocks["']/g,
|
|
552
|
+
(match, imports) => {
|
|
553
|
+
const componentNames = imports.split(',').map(
|
|
554
|
+
(imp: string) =>
|
|
555
|
+
imp
|
|
556
|
+
?.trim()
|
|
557
|
+
.split(/\s+as\s+/)[0]
|
|
558
|
+
?.trim() || ''
|
|
559
|
+
);
|
|
560
|
+
|
|
561
|
+
const blocksPath = paths.blocks.replace(/^\.\//, '').replace(/\/$/, '');
|
|
562
|
+
|
|
563
|
+
return `import {${imports}} from "@/${blocksPath}/${componentNames[0].toLowerCase()}"`;
|
|
564
|
+
}
|
|
565
|
+
);
|
|
566
|
+
|
|
567
|
+
// Handle @/components/animations imports
|
|
568
|
+
transformed = transformed.replace(
|
|
569
|
+
/import\s+{([^}]+)}\s+from\s+["']@\/components\/animations["']/g,
|
|
570
|
+
(match, imports) => {
|
|
571
|
+
const componentNames = imports.split(',').map(
|
|
572
|
+
(imp: string) =>
|
|
573
|
+
imp
|
|
574
|
+
?.trim()
|
|
575
|
+
.split(/\s+as\s+/)[0]
|
|
576
|
+
?.trim() || ''
|
|
577
|
+
);
|
|
578
|
+
|
|
579
|
+
const animationsPath = paths.animations
|
|
580
|
+
.replace(/^\.\//, '')
|
|
581
|
+
.replace(/\/$/, '');
|
|
582
|
+
|
|
583
|
+
return `import {${imports}} from "@/${animationsPath}/${componentNames[0].toLowerCase()}"`;
|
|
584
|
+
}
|
|
585
|
+
);
|
|
586
|
+
|
|
587
|
+
// Handle utils imports
|
|
588
|
+
const utilsPath = paths.utils
|
|
589
|
+
.replace(/^\.\//, '')
|
|
590
|
+
.replace(/\/$/, '')
|
|
591
|
+
.replace(/\.(ts|js)$/, '');
|
|
592
|
+
transformed = transformed.replace(/@\/lib\/utils/g, `@/${utilsPath}`);
|
|
593
|
+
|
|
594
|
+
return transformed;
|
|
595
|
+
}
|
|
596
|
+
|
|
450
597
|
/**
|
|
451
598
|
* Resolve component path based on category and configuration
|
|
452
599
|
*/
|
|
@@ -455,13 +602,22 @@ function resolveComponentPath(
|
|
|
455
602
|
category: ComponentCategory,
|
|
456
603
|
config: any
|
|
457
604
|
): string {
|
|
605
|
+
// Ensure config.paths exists with fallbacks
|
|
606
|
+
const paths = config?.paths || {
|
|
607
|
+
primitives: 'components/primitives',
|
|
608
|
+
components: 'components',
|
|
609
|
+
blocks: 'components/blocks',
|
|
610
|
+
animations: 'components/animations',
|
|
611
|
+
utils: 'lib/utils',
|
|
612
|
+
};
|
|
613
|
+
|
|
458
614
|
// Special handling for utils files - they should go directly to lib/utils.ts
|
|
459
615
|
if (originalPath === 'lib/utils.ts') {
|
|
460
|
-
return
|
|
616
|
+
return paths.utils || 'lib/utils.ts';
|
|
461
617
|
}
|
|
462
618
|
|
|
463
619
|
// Get the base path for the category from config
|
|
464
|
-
const categoryPath =
|
|
620
|
+
const categoryPath = paths[category] || paths.components;
|
|
465
621
|
|
|
466
622
|
// Extract just the filename from the original path
|
|
467
623
|
const fileName = path.basename(originalPath);
|
|
@@ -471,22 +627,16 @@ function resolveComponentPath(
|
|
|
471
627
|
if (category === 'primitives') {
|
|
472
628
|
return path.join(categoryPath, componentName, fileName);
|
|
473
629
|
} else if (category === 'components') {
|
|
474
|
-
return path.join(
|
|
475
|
-
config.paths.components,
|
|
476
|
-
'components',
|
|
477
|
-
componentName,
|
|
478
|
-
fileName
|
|
479
|
-
);
|
|
630
|
+
return path.join(paths.components, componentName, fileName);
|
|
480
631
|
} else if (category === 'blocks') {
|
|
481
632
|
return path.join(
|
|
482
|
-
|
|
633
|
+
paths.blocks || path.join(paths.components, 'blocks'),
|
|
483
634
|
componentName,
|
|
484
635
|
fileName
|
|
485
636
|
);
|
|
486
637
|
} else if (category === 'animations') {
|
|
487
638
|
return path.join(
|
|
488
|
-
|
|
489
|
-
path.join(config.paths.components, 'animations'),
|
|
639
|
+
paths.animations || path.join(paths.components, 'animations'),
|
|
490
640
|
componentName,
|
|
491
641
|
fileName
|
|
492
642
|
);
|
|
@@ -500,17 +650,38 @@ function resolveComponentPath(
|
|
|
500
650
|
* Get import path for a component
|
|
501
651
|
*/
|
|
502
652
|
function getImportPath(componentData: ComponentData, config: any): string {
|
|
503
|
-
|
|
504
|
-
const
|
|
653
|
+
// Ensure config.paths exists with fallbacks
|
|
654
|
+
const paths = config?.paths || {
|
|
655
|
+
primitives: 'components/primitives',
|
|
656
|
+
components: 'components',
|
|
657
|
+
blocks: 'components/blocks',
|
|
658
|
+
animations: 'components/animations',
|
|
659
|
+
utils: 'lib/utils',
|
|
660
|
+
};
|
|
661
|
+
|
|
662
|
+
const componentName = path.basename(
|
|
663
|
+
componentData.files[0]?.path || '',
|
|
664
|
+
'.tsx'
|
|
665
|
+
);
|
|
505
666
|
|
|
506
667
|
if (componentData.category === 'primitives') {
|
|
507
|
-
|
|
668
|
+
const primitivesPath = paths.primitives
|
|
669
|
+
.replace(/^\.\//, '')
|
|
670
|
+
.replace(/\/$/, '');
|
|
671
|
+
return `@/${primitivesPath}/${componentName}`;
|
|
508
672
|
} else if (componentData.category === 'components') {
|
|
509
|
-
|
|
673
|
+
const componentsPath = paths.components
|
|
674
|
+
.replace(/^\.\//, '')
|
|
675
|
+
.replace(/\/$/, '');
|
|
676
|
+
return `@/${componentsPath}/${componentName}`;
|
|
510
677
|
} else if (componentData.category === 'blocks') {
|
|
511
|
-
|
|
678
|
+
const blocksPath = paths.blocks.replace(/^\.\//, '').replace(/\/$/, '');
|
|
679
|
+
return `@/${blocksPath}/${componentName}`;
|
|
512
680
|
} else if (componentData.category === 'animations') {
|
|
513
|
-
|
|
681
|
+
const animationsPath = paths.animations
|
|
682
|
+
.replace(/^\.\//, '')
|
|
683
|
+
.replace(/\/$/, '');
|
|
684
|
+
return `@/${animationsPath}/${componentName}`;
|
|
514
685
|
}
|
|
515
686
|
|
|
516
687
|
return `@/components/${componentName}`;
|
package/src/commands/init.ts
CHANGED
|
@@ -3,8 +3,9 @@ import chalk from 'chalk';
|
|
|
3
3
|
import fs from 'fs-extra';
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import inquirer from 'inquirer';
|
|
6
|
-
import { exec
|
|
6
|
+
import { exec } from 'child_process';
|
|
7
7
|
import { promisify } from 'util';
|
|
8
|
+
import { CLI_VERSION, DEFAULT_REGISTRY_URL } from '../lib/constants.js';
|
|
8
9
|
|
|
9
10
|
interface InitOptions {
|
|
10
11
|
force?: boolean;
|
|
@@ -90,6 +91,8 @@ export function initCommand() {
|
|
|
90
91
|
await installDependencies();
|
|
91
92
|
}
|
|
92
93
|
|
|
94
|
+
console.log(pathConfig);
|
|
95
|
+
|
|
93
96
|
// Create configuration file with custom paths
|
|
94
97
|
await createConfigFile(options, projectStructure, pathConfig);
|
|
95
98
|
|
|
@@ -789,17 +792,26 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
789
792
|
`theme-provider${structure.isTypeScript ? '.tsx' : '.jsx'}`
|
|
790
793
|
);
|
|
791
794
|
|
|
792
|
-
const providersContent = `
|
|
795
|
+
const providersContent = `
|
|
796
|
+
'use client';
|
|
793
797
|
|
|
794
|
-
import
|
|
798
|
+
import type * as React from 'react';
|
|
799
|
+
import { ThemeProvider as NextThemesProvider } from 'next-themes';
|
|
795
800
|
|
|
796
801
|
export function ThemeProvider({ children }: { children: React.ReactNode }) {
|
|
797
802
|
return (
|
|
798
|
-
<
|
|
803
|
+
<NextThemesProvider
|
|
804
|
+
attribute='class'
|
|
805
|
+
defaultTheme='system'
|
|
806
|
+
enableSystem
|
|
807
|
+
disableTransitionOnChange
|
|
808
|
+
enableColorScheme
|
|
809
|
+
>
|
|
799
810
|
{children}
|
|
800
|
-
</
|
|
811
|
+
</NextThemesProvider>
|
|
801
812
|
);
|
|
802
813
|
}
|
|
814
|
+
|
|
803
815
|
`;
|
|
804
816
|
|
|
805
817
|
if (!fs.existsSync(providersPath)) {
|
|
@@ -846,28 +858,38 @@ async function createConfigFile(
|
|
|
846
858
|
}
|
|
847
859
|
|
|
848
860
|
// Create configuration with custom paths
|
|
861
|
+
// Normalize paths - ensure they start with ./ if they're relative
|
|
862
|
+
const normalizePath = (p: string) => {
|
|
863
|
+
if (p.startsWith('./') || p.startsWith('../') || path.isAbsolute(p)) {
|
|
864
|
+
return p;
|
|
865
|
+
}
|
|
866
|
+
return `./${p}`;
|
|
867
|
+
};
|
|
868
|
+
|
|
849
869
|
const config = {
|
|
850
|
-
version:
|
|
851
|
-
registry:
|
|
870
|
+
version: CLI_VERSION,
|
|
871
|
+
registry: DEFAULT_REGISTRY_URL,
|
|
852
872
|
paths: {
|
|
853
|
-
utils: pathConfig.utils,
|
|
854
|
-
primitives: pathConfig.primitives,
|
|
855
|
-
components: pathConfig.components,
|
|
856
|
-
blocks: pathConfig.blocks,
|
|
857
|
-
hooks: pathConfig.hooks,
|
|
858
|
-
animations: pathConfig.animations,
|
|
873
|
+
utils: normalizePath(pathConfig.utils),
|
|
874
|
+
primitives: normalizePath(pathConfig.primitives),
|
|
875
|
+
components: normalizePath(pathConfig.components),
|
|
876
|
+
blocks: normalizePath(pathConfig.blocks),
|
|
877
|
+
hooks: normalizePath(pathConfig.hooks),
|
|
878
|
+
animations: normalizePath(pathConfig.animations),
|
|
859
879
|
},
|
|
860
880
|
packageManager: structure.packageManager,
|
|
861
881
|
typescript: structure.isTypeScript,
|
|
862
882
|
framework: structure.framework,
|
|
863
883
|
tailwind: {
|
|
864
|
-
css: pathConfig.styles,
|
|
884
|
+
css: normalizePath(pathConfig.styles),
|
|
865
885
|
},
|
|
866
886
|
aliases: {
|
|
867
|
-
'@': structure.baseDir.replace(/\/$/, '') || '.',
|
|
868
|
-
'@/components':
|
|
869
|
-
|
|
870
|
-
|
|
887
|
+
'@': normalizePath(structure.baseDir.replace(/\/$/, '') || '.'),
|
|
888
|
+
'@/components': normalizePath(
|
|
889
|
+
path.dirname(pathConfig.components).replace(/\/$/, '')
|
|
890
|
+
),
|
|
891
|
+
'@/lib': normalizePath(pathConfig.lib.replace(/\/$/, '')),
|
|
892
|
+
'@/hooks': normalizePath(pathConfig.hooks.replace(/\/$/, '')),
|
|
871
893
|
},
|
|
872
894
|
};
|
|
873
895
|
|
package/src/commands/list.ts
CHANGED
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
|
|
6
6
|
import { Command } from 'commander';
|
|
7
7
|
import chalk from 'chalk';
|
|
8
|
+
import inquirer from 'inquirer';
|
|
9
|
+
import fs from 'fs-extra';
|
|
10
|
+
import path from 'path';
|
|
8
11
|
import type { ComponentMeta, ComponentCategory } from '@foundrykit/types';
|
|
9
12
|
import { getRegistry } from '../lib/registry.js';
|
|
10
13
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared constants for FoundryKit CLI
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// CLI version - update this when publishing new versions
|
|
6
|
+
// This should match the version in package.json
|
|
7
|
+
export const CLI_VERSION = '1.0.8';
|
|
8
|
+
|
|
9
|
+
// Default registry URL
|
|
10
|
+
export const DEFAULT_REGISTRY_URL = 'https://foundry.umiflow.com';
|
|
11
|
+
|
|
12
|
+
// Cache settings
|
|
13
|
+
export const CACHE_TTL = 24 * 60 * 60 * 1000; // 24 hours in milliseconds
|
|
14
|
+
export const CACHE_DIR = '.foundrykit';
|
|
15
|
+
export const CACHE_FILE = 'registry-cache.json';
|
package/src/lib/registry.ts
CHANGED
|
@@ -7,6 +7,12 @@ import fs from 'fs-extra';
|
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import os from 'os';
|
|
9
9
|
import chalk from 'chalk';
|
|
10
|
+
import {
|
|
11
|
+
DEFAULT_REGISTRY_URL,
|
|
12
|
+
CACHE_DIR,
|
|
13
|
+
CACHE_FILE,
|
|
14
|
+
CACHE_TTL,
|
|
15
|
+
} from './constants.js';
|
|
10
16
|
import type {
|
|
11
17
|
ComponentMeta,
|
|
12
18
|
ComponentData,
|
|
@@ -21,10 +27,9 @@ import type {
|
|
|
21
27
|
* Default configuration
|
|
22
28
|
*/
|
|
23
29
|
const DEFAULT_CONFIG: CLIConfig = {
|
|
24
|
-
registryUrl:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
cacheMaxAge: 1000 * 60 * 60 * 24, // 24 hours
|
|
30
|
+
registryUrl: process.env.FOUNDRYKIT_REGISTRY_URL || DEFAULT_REGISTRY_URL,
|
|
31
|
+
cacheDir: path.join(os.homedir(), CACHE_DIR, 'cache'),
|
|
32
|
+
cacheMaxAge: CACHE_TTL,
|
|
28
33
|
};
|
|
29
34
|
|
|
30
35
|
/**
|
package/components.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://ui.shadcn.com/schema.json",
|
|
3
|
-
"style": "new-york",
|
|
4
|
-
"rsc": true,
|
|
5
|
-
"tsx": true,
|
|
6
|
-
"tailwind": {
|
|
7
|
-
"config": "",
|
|
8
|
-
"css": "src/styles/globals.css",
|
|
9
|
-
"baseColor": "neutral",
|
|
10
|
-
"cssVariables": true
|
|
11
|
-
},
|
|
12
|
-
"iconLibrary": "lucide",
|
|
13
|
-
"aliases": {
|
|
14
|
-
"components": "@workspace/ui/components",
|
|
15
|
-
"utils": "@workspace/ui/lib/utils",
|
|
16
|
-
"hooks": "@workspace/ui/hooks",
|
|
17
|
-
"lib": "@workspace/ui/lib",
|
|
18
|
-
"ui": "@workspace/ui/components"
|
|
19
|
-
}
|
|
20
|
-
}
|