@foundrykit/cli 1.0.9 → 1.0.11
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 +114 -40
- package/dist/cli.js.map +1 -1
- package/dist/index.js +114 -40
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/commands/add.ts +137 -41
- package/src/commands/init.ts +37 -16
- package/components.json +0 -20
package/src/commands/add.ts
CHANGED
|
@@ -14,6 +14,7 @@ import type {
|
|
|
14
14
|
ComponentMeta,
|
|
15
15
|
ComponentData,
|
|
16
16
|
ComponentCategory,
|
|
17
|
+
Config,
|
|
17
18
|
} from '@foundrykit/types';
|
|
18
19
|
import { getRegistry } from '../lib/registry.js';
|
|
19
20
|
import { CLI_VERSION } from '../lib/constants.js';
|
|
@@ -460,7 +461,7 @@ async function showUsageExample(componentData: ComponentData): Promise<void> {
|
|
|
460
461
|
/**
|
|
461
462
|
* Load FoundryKit configuration
|
|
462
463
|
*/
|
|
463
|
-
async function loadConfig(): Promise<
|
|
464
|
+
async function loadConfig(): Promise<Config> {
|
|
464
465
|
const configPath = path.join(process.cwd(), 'foundrykit.config.json');
|
|
465
466
|
if (!fs.existsSync(configPath)) {
|
|
466
467
|
throw new Error(
|
|
@@ -473,51 +474,128 @@ async function loadConfig(): Promise<any> {
|
|
|
473
474
|
/**
|
|
474
475
|
* Transform imports in file content based on config
|
|
475
476
|
*/
|
|
476
|
-
function transformImportsForConfig(content: string, config:
|
|
477
|
+
function transformImportsForConfig(content: string, config: Config): string {
|
|
477
478
|
let transformed = content;
|
|
478
479
|
|
|
479
|
-
//
|
|
480
|
-
const
|
|
481
|
-
|
|
482
|
-
|
|
480
|
+
// Ensure config.paths exists with fallbacks
|
|
481
|
+
const paths =
|
|
482
|
+
config?.paths && config?.aliases
|
|
483
|
+
? {
|
|
484
|
+
primitives: `${config.aliases['@/components']}/${config.paths.primitives.split('/').pop()}`,
|
|
485
|
+
components: `${config.aliases['@/components']}/${config.paths.components.split('/').pop()}`,
|
|
486
|
+
blocks: `${config.aliases['@/components']}/${config.paths.blocks.split('/').pop()}`,
|
|
487
|
+
animations: `${config.aliases['@/components']}/${config.paths.animations.split('/').pop()}`,
|
|
488
|
+
utils: `${config.aliases['@/lib']}/${config.paths.utils.split('/').pop()}`,
|
|
489
|
+
}
|
|
490
|
+
: {
|
|
491
|
+
primitives: 'components/primitives',
|
|
492
|
+
components: 'components',
|
|
493
|
+
blocks: 'components/blocks',
|
|
494
|
+
animations: 'components/animations',
|
|
495
|
+
utils: 'lib/utils',
|
|
496
|
+
};
|
|
497
|
+
|
|
498
|
+
// Transform imports using regex to capture component names and build proper paths
|
|
499
|
+
// Handle @/components/primitives imports
|
|
483
500
|
transformed = transformed.replace(
|
|
484
|
-
|
|
485
|
-
|
|
501
|
+
/import\s+{([^}]+)}\s+from\s+["']@\/components\/primitives["']/g,
|
|
502
|
+
(match, imports) => {
|
|
503
|
+
const componentNames = imports.split(',').map(
|
|
504
|
+
(imp: string) =>
|
|
505
|
+
imp
|
|
506
|
+
?.trim()
|
|
507
|
+
.split(/\s+as\s+/)[0]
|
|
508
|
+
?.trim() || ''
|
|
509
|
+
);
|
|
510
|
+
|
|
511
|
+
const primitivesPath = paths.primitives
|
|
512
|
+
.replace(/^\.\//, '')
|
|
513
|
+
.replace(/\/$/, '');
|
|
514
|
+
|
|
515
|
+
return `import {${imports}} from "@/${primitivesPath}/${componentNames[0].toLowerCase()}"`;
|
|
516
|
+
}
|
|
486
517
|
);
|
|
487
518
|
|
|
488
|
-
//
|
|
519
|
+
// Handle @/components/ui imports (legacy, maps to primitives)
|
|
489
520
|
transformed = transformed.replace(
|
|
490
|
-
|
|
491
|
-
|
|
521
|
+
/import\s+{([^}]+)}\s+from\s+["']@\/components\/ui["']/g,
|
|
522
|
+
(match, imports) => {
|
|
523
|
+
const componentNames = imports.split(',').map(
|
|
524
|
+
(imp: string) =>
|
|
525
|
+
imp
|
|
526
|
+
?.trim()
|
|
527
|
+
.split(/\s+as\s+/)[0]
|
|
528
|
+
?.trim() || ''
|
|
529
|
+
);
|
|
530
|
+
|
|
531
|
+
const primitivesPath = paths.primitives
|
|
532
|
+
.replace(/^\.\//, '')
|
|
533
|
+
.replace(/\/$/, '');
|
|
534
|
+
|
|
535
|
+
return `import {${imports}} from "@/${primitivesPath}/${componentNames[0].toLowerCase()}"`;
|
|
536
|
+
}
|
|
492
537
|
);
|
|
493
538
|
|
|
494
|
-
//
|
|
495
|
-
const componentsPath = config.paths.components
|
|
496
|
-
.replace(/^\.\//, '')
|
|
497
|
-
.replace(/\/$/, '');
|
|
539
|
+
// Handle @/components/components imports
|
|
498
540
|
transformed = transformed.replace(
|
|
499
|
-
|
|
500
|
-
|
|
541
|
+
/import\s+{([^}]+)}\s+from\s+["']@\/components\/components["']/g,
|
|
542
|
+
(match, imports) => {
|
|
543
|
+
const componentNames = imports.split(',').map(
|
|
544
|
+
(imp: string) =>
|
|
545
|
+
imp
|
|
546
|
+
?.trim()
|
|
547
|
+
.split(/\s+as\s+/)[0]
|
|
548
|
+
?.trim() || ''
|
|
549
|
+
);
|
|
550
|
+
|
|
551
|
+
const componentsPath = paths.components
|
|
552
|
+
.replace(/^\.\//, '')
|
|
553
|
+
.replace(/\/$/, '');
|
|
554
|
+
|
|
555
|
+
return `import {${imports}} from "@/${componentsPath}/${componentNames[0].toLowerCase()}"`;
|
|
556
|
+
}
|
|
501
557
|
);
|
|
502
558
|
|
|
503
|
-
|
|
504
|
-
.replace(/^\.\//, '')
|
|
505
|
-
.replace(/\/$/, '');
|
|
559
|
+
// Handle @/components/blocks imports
|
|
506
560
|
transformed = transformed.replace(
|
|
507
|
-
|
|
508
|
-
|
|
561
|
+
/import\s+{([^}]+)}\s+from\s+["']@\/components\/blocks["']/g,
|
|
562
|
+
(match, imports) => {
|
|
563
|
+
const componentNames = imports.split(',').map(
|
|
564
|
+
(imp: string) =>
|
|
565
|
+
imp
|
|
566
|
+
?.trim()
|
|
567
|
+
.split(/\s+as\s+/)[0]
|
|
568
|
+
?.trim() || ''
|
|
569
|
+
);
|
|
570
|
+
|
|
571
|
+
const blocksPath = paths.blocks.replace(/^\.\//, '').replace(/\/$/, '');
|
|
572
|
+
|
|
573
|
+
return `import {${imports}} from "@/${blocksPath}/${componentNames[0].toLowerCase()}"`;
|
|
574
|
+
}
|
|
509
575
|
);
|
|
510
576
|
|
|
511
|
-
|
|
512
|
-
.replace(/^\.\//, '')
|
|
513
|
-
.replace(/\/$/, '');
|
|
577
|
+
// Handle @/components/animations imports
|
|
514
578
|
transformed = transformed.replace(
|
|
515
|
-
|
|
516
|
-
|
|
579
|
+
/import\s+{([^}]+)}\s+from\s+["']@\/components\/animations["']/g,
|
|
580
|
+
(match, imports) => {
|
|
581
|
+
const componentNames = imports.split(',').map(
|
|
582
|
+
(imp: string) =>
|
|
583
|
+
imp
|
|
584
|
+
?.trim()
|
|
585
|
+
.split(/\s+as\s+/)[0]
|
|
586
|
+
?.trim() || ''
|
|
587
|
+
);
|
|
588
|
+
|
|
589
|
+
const animationsPath = paths.animations
|
|
590
|
+
.replace(/^\.\//, '')
|
|
591
|
+
.replace(/\/$/, '');
|
|
592
|
+
|
|
593
|
+
return `import {${imports}} from "@/${animationsPath}/${componentNames[0].toLowerCase()}"`;
|
|
594
|
+
}
|
|
517
595
|
);
|
|
518
596
|
|
|
519
597
|
// Handle utils imports
|
|
520
|
-
const utilsPath =
|
|
598
|
+
const utilsPath = paths.utils
|
|
521
599
|
.replace(/^\.\//, '')
|
|
522
600
|
.replace(/\/$/, '')
|
|
523
601
|
.replace(/\.(ts|js)$/, '');
|
|
@@ -534,13 +612,22 @@ function resolveComponentPath(
|
|
|
534
612
|
category: ComponentCategory,
|
|
535
613
|
config: any
|
|
536
614
|
): string {
|
|
615
|
+
// Ensure config.paths exists with fallbacks
|
|
616
|
+
const paths = config?.paths || {
|
|
617
|
+
primitives: 'components/primitives',
|
|
618
|
+
components: 'components',
|
|
619
|
+
blocks: 'components/blocks',
|
|
620
|
+
animations: 'components/animations',
|
|
621
|
+
utils: 'lib/utils',
|
|
622
|
+
};
|
|
623
|
+
|
|
537
624
|
// Special handling for utils files - they should go directly to lib/utils.ts
|
|
538
625
|
if (originalPath === 'lib/utils.ts') {
|
|
539
|
-
return
|
|
626
|
+
return paths.utils || 'lib/utils.ts';
|
|
540
627
|
}
|
|
541
628
|
|
|
542
629
|
// Get the base path for the category from config
|
|
543
|
-
const categoryPath =
|
|
630
|
+
const categoryPath = paths[category] || paths.components;
|
|
544
631
|
|
|
545
632
|
// Extract just the filename from the original path
|
|
546
633
|
const fileName = path.basename(originalPath);
|
|
@@ -550,17 +637,16 @@ function resolveComponentPath(
|
|
|
550
637
|
if (category === 'primitives') {
|
|
551
638
|
return path.join(categoryPath, componentName, fileName);
|
|
552
639
|
} else if (category === 'components') {
|
|
553
|
-
return path.join(
|
|
640
|
+
return path.join(paths.components, componentName, fileName);
|
|
554
641
|
} else if (category === 'blocks') {
|
|
555
642
|
return path.join(
|
|
556
|
-
|
|
643
|
+
paths.blocks || path.join(paths.components, 'blocks'),
|
|
557
644
|
componentName,
|
|
558
645
|
fileName
|
|
559
646
|
);
|
|
560
647
|
} else if (category === 'animations') {
|
|
561
648
|
return path.join(
|
|
562
|
-
|
|
563
|
-
path.join(config.paths.components, 'animations'),
|
|
649
|
+
paths.animations || path.join(paths.components, 'animations'),
|
|
564
650
|
componentName,
|
|
565
651
|
fileName
|
|
566
652
|
);
|
|
@@ -574,25 +660,35 @@ function resolveComponentPath(
|
|
|
574
660
|
* Get import path for a component
|
|
575
661
|
*/
|
|
576
662
|
function getImportPath(componentData: ComponentData, config: any): string {
|
|
577
|
-
|
|
663
|
+
// Ensure config.paths exists with fallbacks
|
|
664
|
+
const paths = config?.paths || {
|
|
665
|
+
primitives: 'components/primitives',
|
|
666
|
+
components: 'components',
|
|
667
|
+
blocks: 'components/blocks',
|
|
668
|
+
animations: 'components/animations',
|
|
669
|
+
utils: 'lib/utils',
|
|
670
|
+
};
|
|
671
|
+
|
|
672
|
+
const componentName = path.basename(
|
|
673
|
+
componentData.files[0]?.path || '',
|
|
674
|
+
'.tsx'
|
|
675
|
+
);
|
|
578
676
|
|
|
579
677
|
if (componentData.category === 'primitives') {
|
|
580
|
-
const primitivesPath =
|
|
678
|
+
const primitivesPath = paths.primitives
|
|
581
679
|
.replace(/^\.\//, '')
|
|
582
680
|
.replace(/\/$/, '');
|
|
583
681
|
return `@/${primitivesPath}/${componentName}`;
|
|
584
682
|
} else if (componentData.category === 'components') {
|
|
585
|
-
const componentsPath =
|
|
683
|
+
const componentsPath = paths.components
|
|
586
684
|
.replace(/^\.\//, '')
|
|
587
685
|
.replace(/\/$/, '');
|
|
588
686
|
return `@/${componentsPath}/${componentName}`;
|
|
589
687
|
} else if (componentData.category === 'blocks') {
|
|
590
|
-
const blocksPath =
|
|
591
|
-
.replace(/^\.\//, '')
|
|
592
|
-
.replace(/\/$/, '');
|
|
688
|
+
const blocksPath = paths.blocks.replace(/^\.\//, '').replace(/\/$/, '');
|
|
593
689
|
return `@/${blocksPath}/${componentName}`;
|
|
594
690
|
} else if (componentData.category === 'animations') {
|
|
595
|
-
const animationsPath =
|
|
691
|
+
const animationsPath = paths.animations
|
|
596
692
|
.replace(/^\.\//, '')
|
|
597
693
|
.replace(/\/$/, '');
|
|
598
694
|
return `@/${animationsPath}/${componentName}`;
|
package/src/commands/init.ts
CHANGED
|
@@ -3,7 +3,7 @@ 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
8
|
import { CLI_VERSION, DEFAULT_REGISTRY_URL } from '../lib/constants.js';
|
|
9
9
|
|
|
@@ -91,6 +91,8 @@ export function initCommand() {
|
|
|
91
91
|
await installDependencies();
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
console.log(pathConfig);
|
|
95
|
+
|
|
94
96
|
// Create configuration file with custom paths
|
|
95
97
|
await createConfigFile(options, projectStructure, pathConfig);
|
|
96
98
|
|
|
@@ -790,17 +792,26 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
790
792
|
`theme-provider${structure.isTypeScript ? '.tsx' : '.jsx'}`
|
|
791
793
|
);
|
|
792
794
|
|
|
793
|
-
const providersContent = `
|
|
795
|
+
const providersContent = `
|
|
796
|
+
'use client';
|
|
794
797
|
|
|
795
|
-
import
|
|
798
|
+
import type * as React from 'react';
|
|
799
|
+
import { ThemeProvider as NextThemesProvider } from 'next-themes';
|
|
796
800
|
|
|
797
801
|
export function ThemeProvider({ children }: { children: React.ReactNode }) {
|
|
798
802
|
return (
|
|
799
|
-
<
|
|
803
|
+
<NextThemesProvider
|
|
804
|
+
attribute='class'
|
|
805
|
+
defaultTheme='system'
|
|
806
|
+
enableSystem
|
|
807
|
+
disableTransitionOnChange
|
|
808
|
+
enableColorScheme
|
|
809
|
+
>
|
|
800
810
|
{children}
|
|
801
|
-
</
|
|
811
|
+
</NextThemesProvider>
|
|
802
812
|
);
|
|
803
813
|
}
|
|
814
|
+
|
|
804
815
|
`;
|
|
805
816
|
|
|
806
817
|
if (!fs.existsSync(providersPath)) {
|
|
@@ -847,28 +858,38 @@ async function createConfigFile(
|
|
|
847
858
|
}
|
|
848
859
|
|
|
849
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
|
+
|
|
850
869
|
const config = {
|
|
851
870
|
version: CLI_VERSION,
|
|
852
871
|
registry: DEFAULT_REGISTRY_URL,
|
|
853
872
|
paths: {
|
|
854
|
-
utils: pathConfig.utils,
|
|
855
|
-
primitives: pathConfig.primitives,
|
|
856
|
-
components: pathConfig.components,
|
|
857
|
-
blocks: pathConfig.blocks,
|
|
858
|
-
hooks: pathConfig.hooks,
|
|
859
|
-
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),
|
|
860
879
|
},
|
|
861
880
|
packageManager: structure.packageManager,
|
|
862
881
|
typescript: structure.isTypeScript,
|
|
863
882
|
framework: structure.framework,
|
|
864
883
|
tailwind: {
|
|
865
|
-
css: pathConfig.styles,
|
|
884
|
+
css: normalizePath(pathConfig.styles),
|
|
866
885
|
},
|
|
867
886
|
aliases: {
|
|
868
|
-
'@': structure.baseDir.replace(/\/$/, '') || '.',
|
|
869
|
-
'@/components':
|
|
870
|
-
|
|
871
|
-
|
|
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(/\/$/, '')),
|
|
872
893
|
},
|
|
873
894
|
};
|
|
874
895
|
|
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
|
-
}
|