@foundrykit/cli 2.0.6 ā 2.0.7
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 +8 -0
- package/dist/cli.js +240 -62
- package/dist/cli.js.map +1 -1
- package/dist/index.js +240 -62
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/commands/add.ts +153 -16
- package/src/commands/init.ts +13 -0
- package/src/commands/list.ts +10 -13
- package/src/lib/constants.ts +26 -0
- package/src/lib/registry.ts +99 -39
- package/tests/dependency-resolution.test.ts +33 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@foundrykit/cli",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.7",
|
|
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": "2.0.
|
|
28
|
+
"@foundrykit/types": "2.0.3"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/node": "^20.19.9",
|
package/src/commands/add.ts
CHANGED
|
@@ -17,7 +17,7 @@ import type {
|
|
|
17
17
|
Config,
|
|
18
18
|
} from '@foundrykit/types';
|
|
19
19
|
import { getRegistry } from '../lib/registry.js';
|
|
20
|
-
import { CLI_VERSION } from '../lib/constants.js';
|
|
20
|
+
import { CLI_VERSION, REGISTRY_CATEGORY_ORDER } from '../lib/constants.js';
|
|
21
21
|
|
|
22
22
|
const execAsync = promisify(exec);
|
|
23
23
|
|
|
@@ -115,11 +115,14 @@ async function selectComponentsInteractively(): Promise<string[]> {
|
|
|
115
115
|
* Create grouped choices for the interactive selector
|
|
116
116
|
*/
|
|
117
117
|
function createGroupedChoices(components: ComponentMeta[]) {
|
|
118
|
+
const knownCategories = new Set<ComponentCategory>(
|
|
119
|
+
REGISTRY_CATEGORY_ORDER as readonly ComponentCategory[]
|
|
120
|
+
);
|
|
118
121
|
const categories: ComponentCategory[] = [
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
122
|
+
...(REGISTRY_CATEGORY_ORDER as readonly ComponentCategory[]),
|
|
123
|
+
...components
|
|
124
|
+
.map(component => component.category)
|
|
125
|
+
.filter(category => !knownCategories.has(category)),
|
|
123
126
|
];
|
|
124
127
|
|
|
125
128
|
const choices: any[] = [];
|
|
@@ -319,6 +322,10 @@ export async function installComponentFiles(
|
|
|
319
322
|
const config = await loadConfig();
|
|
320
323
|
const basePath = options.path || process.cwd();
|
|
321
324
|
|
|
325
|
+
if (componentData.files.length === 0) {
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
|
|
322
329
|
console.log(chalk.blue('š Installing component files...'));
|
|
323
330
|
|
|
324
331
|
for (const file of componentData.files) {
|
|
@@ -482,6 +489,16 @@ export async function showUsageExample(
|
|
|
482
489
|
const config = await loadConfig();
|
|
483
490
|
console.log(chalk.cyan('\nš” Usage:'));
|
|
484
491
|
|
|
492
|
+
if (componentData.files.length === 0) {
|
|
493
|
+
const packageName = componentData.packageDependencies?.find(dep =>
|
|
494
|
+
dep.startsWith('@foundrykit/')
|
|
495
|
+
);
|
|
496
|
+
if (packageName) {
|
|
497
|
+
console.log(chalk.gray(`import { ... } from "${packageName}"`));
|
|
498
|
+
}
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
|
|
485
502
|
const componentName = componentData.name.replace(/\s+/g, '');
|
|
486
503
|
const importPath = getImportPath(componentData, config);
|
|
487
504
|
|
|
@@ -549,6 +566,22 @@ export function transformImportsForConfig(
|
|
|
549
566
|
'animations'
|
|
550
567
|
);
|
|
551
568
|
|
|
569
|
+
transformed = transformRegistryBarrelImports(
|
|
570
|
+
transformed,
|
|
571
|
+
['@foundrykit/maps', '@/components/maps'],
|
|
572
|
+
importPaths.maps,
|
|
573
|
+
config,
|
|
574
|
+
'maps'
|
|
575
|
+
);
|
|
576
|
+
|
|
577
|
+
transformed = transformRegistryBarrelImports(
|
|
578
|
+
transformed,
|
|
579
|
+
['@foundrykit/hooks', '@/hooks'],
|
|
580
|
+
importPaths.hooks,
|
|
581
|
+
config,
|
|
582
|
+
'hooks'
|
|
583
|
+
);
|
|
584
|
+
|
|
552
585
|
// Handle utils imports
|
|
553
586
|
transformed = transformed
|
|
554
587
|
.replace(/@foundrykit\/utils/g, importPaths.utils)
|
|
@@ -565,14 +598,37 @@ function getConfiguredImportPaths(
|
|
|
565
598
|
components: 'components',
|
|
566
599
|
blocks: 'components/blocks',
|
|
567
600
|
animations: 'components/animations',
|
|
601
|
+
hooks: 'hooks',
|
|
602
|
+
maps: 'components/maps',
|
|
568
603
|
utils: 'lib/utils',
|
|
569
604
|
};
|
|
570
605
|
|
|
571
606
|
return {
|
|
572
|
-
primitives: resolveImportBasePath(paths.primitives, config
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
607
|
+
primitives: resolveImportBasePath(paths.primitives, config, {
|
|
608
|
+
preferRootAlias: true,
|
|
609
|
+
}),
|
|
610
|
+
components: resolveImportBasePath(paths.components, config, {
|
|
611
|
+
preferRootAlias: true,
|
|
612
|
+
}),
|
|
613
|
+
blocks: resolveImportBasePath(paths.blocks, config, {
|
|
614
|
+
preferRootAlias: true,
|
|
615
|
+
}),
|
|
616
|
+
animations: resolveImportBasePath(paths.animations, config, {
|
|
617
|
+
preferRootAlias: true,
|
|
618
|
+
}),
|
|
619
|
+
maps: resolveImportBasePath(
|
|
620
|
+
paths.maps ?? joinImportPath(paths.components, 'maps'),
|
|
621
|
+
config,
|
|
622
|
+
{
|
|
623
|
+
preferRootAlias: true,
|
|
624
|
+
}
|
|
625
|
+
),
|
|
626
|
+
hooks: resolveImportBasePath(paths.hooks ?? 'hooks', config, {
|
|
627
|
+
preferRootAlias: true,
|
|
628
|
+
}),
|
|
629
|
+
packages: resolveImportBasePath(paths.components, config, {
|
|
630
|
+
preferRootAlias: true,
|
|
631
|
+
}),
|
|
576
632
|
utils: resolveImportBasePath(paths.utils, config).replace(
|
|
577
633
|
/\.(ts|js)x?$/,
|
|
578
634
|
''
|
|
@@ -580,13 +636,33 @@ function getConfiguredImportPaths(
|
|
|
580
636
|
};
|
|
581
637
|
}
|
|
582
638
|
|
|
583
|
-
function resolveImportBasePath(
|
|
639
|
+
function resolveImportBasePath(
|
|
640
|
+
filePath: string,
|
|
641
|
+
config: Config,
|
|
642
|
+
options: { preferRootAlias?: boolean } = {}
|
|
643
|
+
): string {
|
|
584
644
|
const normalizedPath = normalizeConfigPath(filePath).replace(
|
|
585
645
|
/\.(ts|js)x?$/,
|
|
586
646
|
''
|
|
587
647
|
);
|
|
588
648
|
const aliases = config?.aliases ?? {};
|
|
589
649
|
|
|
650
|
+
if (options.preferRootAlias && aliases['@']) {
|
|
651
|
+
const rootTarget = normalizeConfigPath(aliases['@']);
|
|
652
|
+
const matchesRoot =
|
|
653
|
+
normalizedPath === rootTarget ||
|
|
654
|
+
(rootTarget !== '' && normalizedPath.startsWith(`${rootTarget}/`)) ||
|
|
655
|
+
rootTarget === '';
|
|
656
|
+
|
|
657
|
+
if (matchesRoot) {
|
|
658
|
+
const relativePath =
|
|
659
|
+
rootTarget === ''
|
|
660
|
+
? normalizedPath
|
|
661
|
+
: normalizedPath.slice(rootTarget.length).replace(/^\//, '');
|
|
662
|
+
return joinImportPath('@', relativePath);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
|
|
590
666
|
const aliasMatches = Object.entries(aliases)
|
|
591
667
|
.map(([alias, target]) => ({
|
|
592
668
|
alias,
|
|
@@ -728,7 +804,7 @@ function getInstalledComponentExportMap(
|
|
|
728
804
|
category: ComponentCategory
|
|
729
805
|
): Map<string, string> {
|
|
730
806
|
const exportMap = new Map<string, string>();
|
|
731
|
-
const categoryPath = config
|
|
807
|
+
const categoryPath = getConfiguredCategoryPath(config, category);
|
|
732
808
|
if (!categoryPath) {
|
|
733
809
|
return exportMap;
|
|
734
810
|
}
|
|
@@ -816,6 +892,8 @@ export function resolveComponentPath(
|
|
|
816
892
|
components: 'components',
|
|
817
893
|
blocks: 'components/blocks',
|
|
818
894
|
animations: 'components/animations',
|
|
895
|
+
hooks: 'hooks',
|
|
896
|
+
maps: 'components/maps',
|
|
819
897
|
utils: 'lib/utils',
|
|
820
898
|
};
|
|
821
899
|
|
|
@@ -825,7 +903,8 @@ export function resolveComponentPath(
|
|
|
825
903
|
}
|
|
826
904
|
|
|
827
905
|
// Get the base path for the category from config
|
|
828
|
-
const categoryPath =
|
|
906
|
+
const categoryPath =
|
|
907
|
+
getConfiguredCategoryPath(config, category) || paths.components;
|
|
829
908
|
|
|
830
909
|
// Extract just the filename from the original path
|
|
831
910
|
const fileName = path.basename(originalPath);
|
|
@@ -848,12 +927,48 @@ export function resolveComponentPath(
|
|
|
848
927
|
componentName,
|
|
849
928
|
fileName
|
|
850
929
|
);
|
|
930
|
+
} else if (category === 'maps') {
|
|
931
|
+
return path.join(
|
|
932
|
+
paths.maps || path.join(paths.components, 'maps'),
|
|
933
|
+
componentName,
|
|
934
|
+
fileName
|
|
935
|
+
);
|
|
936
|
+
} else if (category === 'hooks') {
|
|
937
|
+
return path.join(paths.hooks || 'hooks', componentName, fileName);
|
|
938
|
+
} else if (category === 'packages') {
|
|
939
|
+
return path.join(paths.components, componentName, fileName);
|
|
851
940
|
}
|
|
852
941
|
|
|
853
942
|
// Default to original path if category not recognized
|
|
854
943
|
return originalPath;
|
|
855
944
|
}
|
|
856
945
|
|
|
946
|
+
function getConfiguredCategoryPath(
|
|
947
|
+
config: Config,
|
|
948
|
+
category: ComponentCategory
|
|
949
|
+
): string | undefined {
|
|
950
|
+
const paths = config.paths;
|
|
951
|
+
|
|
952
|
+
switch (category) {
|
|
953
|
+
case 'primitives':
|
|
954
|
+
return paths.primitives;
|
|
955
|
+
case 'components':
|
|
956
|
+
return paths.components;
|
|
957
|
+
case 'blocks':
|
|
958
|
+
return paths.blocks;
|
|
959
|
+
case 'animations':
|
|
960
|
+
return paths.animations;
|
|
961
|
+
case 'maps':
|
|
962
|
+
return paths.maps ?? path.join(paths.components, 'maps');
|
|
963
|
+
case 'hooks':
|
|
964
|
+
return paths.hooks ?? 'hooks';
|
|
965
|
+
case 'packages':
|
|
966
|
+
return paths.components;
|
|
967
|
+
default:
|
|
968
|
+
return undefined;
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
|
|
857
972
|
/**
|
|
858
973
|
* Get import path for a component
|
|
859
974
|
*/
|
|
@@ -867,6 +982,8 @@ export function getImportPath(
|
|
|
867
982
|
components: 'components',
|
|
868
983
|
blocks: 'components/blocks',
|
|
869
984
|
animations: 'components/animations',
|
|
985
|
+
hooks: 'hooks',
|
|
986
|
+
maps: 'components/maps',
|
|
870
987
|
utils: 'lib/utils',
|
|
871
988
|
};
|
|
872
989
|
|
|
@@ -875,13 +992,33 @@ export function getImportPath(
|
|
|
875
992
|
);
|
|
876
993
|
|
|
877
994
|
if (componentData.category === 'primitives') {
|
|
878
|
-
return `${resolveImportBasePath(paths.primitives, config
|
|
995
|
+
return `${resolveImportBasePath(paths.primitives, config, {
|
|
996
|
+
preferRootAlias: true,
|
|
997
|
+
})}/${componentName}`;
|
|
879
998
|
} else if (componentData.category === 'components') {
|
|
880
|
-
return `${resolveImportBasePath(paths.components, config
|
|
999
|
+
return `${resolveImportBasePath(paths.components, config, {
|
|
1000
|
+
preferRootAlias: true,
|
|
1001
|
+
})}/${componentName}`;
|
|
881
1002
|
} else if (componentData.category === 'blocks') {
|
|
882
|
-
return `${resolveImportBasePath(paths.blocks, config
|
|
1003
|
+
return `${resolveImportBasePath(paths.blocks, config, {
|
|
1004
|
+
preferRootAlias: true,
|
|
1005
|
+
})}/${componentName}`;
|
|
883
1006
|
} else if (componentData.category === 'animations') {
|
|
884
|
-
return `${resolveImportBasePath(paths.animations, config
|
|
1007
|
+
return `${resolveImportBasePath(paths.animations, config, {
|
|
1008
|
+
preferRootAlias: true,
|
|
1009
|
+
})}/${componentName}`;
|
|
1010
|
+
} else if (componentData.category === 'maps') {
|
|
1011
|
+
return `${resolveImportBasePath(
|
|
1012
|
+
paths.maps || path.join(paths.components, 'maps'),
|
|
1013
|
+
config,
|
|
1014
|
+
{
|
|
1015
|
+
preferRootAlias: true,
|
|
1016
|
+
}
|
|
1017
|
+
)}/${componentName}`;
|
|
1018
|
+
} else if (componentData.category === 'hooks') {
|
|
1019
|
+
return `${resolveImportBasePath(paths.hooks || 'hooks', config, {
|
|
1020
|
+
preferRootAlias: true,
|
|
1021
|
+
})}/${componentName}`;
|
|
885
1022
|
}
|
|
886
1023
|
|
|
887
1024
|
return `@/components/${componentName}`;
|
package/src/commands/init.ts
CHANGED
|
@@ -37,6 +37,7 @@ interface PathConfig {
|
|
|
37
37
|
components: string;
|
|
38
38
|
blocks: string;
|
|
39
39
|
hooks: string;
|
|
40
|
+
maps: string;
|
|
40
41
|
animations: string;
|
|
41
42
|
styles: string;
|
|
42
43
|
lib: string;
|
|
@@ -285,6 +286,10 @@ async function getPathConfiguration(
|
|
|
285
286
|
structure.componentsPath || path.join(structure.baseDir, 'components'),
|
|
286
287
|
'blocks'
|
|
287
288
|
),
|
|
289
|
+
maps: path.join(
|
|
290
|
+
structure.componentsPath || path.join(structure.baseDir, 'components'),
|
|
291
|
+
'maps'
|
|
292
|
+
),
|
|
288
293
|
animations: path.join(
|
|
289
294
|
structure.componentsPath || path.join(structure.baseDir, 'components'),
|
|
290
295
|
'animations'
|
|
@@ -358,6 +363,12 @@ async function getPathConfiguration(
|
|
|
358
363
|
message: 'Hooks directory:',
|
|
359
364
|
default: defaults.hooks,
|
|
360
365
|
},
|
|
366
|
+
{
|
|
367
|
+
type: 'input',
|
|
368
|
+
name: 'maps',
|
|
369
|
+
message: 'Maps directory:',
|
|
370
|
+
default: defaults.maps,
|
|
371
|
+
},
|
|
361
372
|
{
|
|
362
373
|
type: 'input',
|
|
363
374
|
name: 'animations',
|
|
@@ -748,6 +759,7 @@ async function createDirectories(pathConfig: PathConfig): Promise<void> {
|
|
|
748
759
|
pathConfig.primitives,
|
|
749
760
|
pathConfig.components,
|
|
750
761
|
pathConfig.blocks,
|
|
762
|
+
pathConfig.maps,
|
|
751
763
|
pathConfig.animations,
|
|
752
764
|
pathConfig.hooks,
|
|
753
765
|
pathConfig.lib,
|
|
@@ -875,6 +887,7 @@ async function createConfigFile(
|
|
|
875
887
|
components: normalizePath(pathConfig.components),
|
|
876
888
|
blocks: normalizePath(pathConfig.blocks),
|
|
877
889
|
hooks: normalizePath(pathConfig.hooks),
|
|
890
|
+
maps: normalizePath(pathConfig.maps),
|
|
878
891
|
animations: normalizePath(pathConfig.animations),
|
|
879
892
|
},
|
|
880
893
|
packageManager: structure.packageManager,
|
package/src/commands/list.ts
CHANGED
|
@@ -10,6 +10,7 @@ import fs from 'fs-extra';
|
|
|
10
10
|
import path from 'path';
|
|
11
11
|
import type { ComponentMeta, ComponentCategory } from '@foundrykit/types';
|
|
12
12
|
import { getRegistry } from '../lib/registry.js';
|
|
13
|
+
import { REGISTRY_CATEGORY_ORDER } from '../lib/constants.js';
|
|
13
14
|
|
|
14
15
|
interface ListOptions {
|
|
15
16
|
category?: string;
|
|
@@ -32,15 +33,8 @@ export function listCommand() {
|
|
|
32
33
|
|
|
33
34
|
// Validate category if provided
|
|
34
35
|
if (options.category) {
|
|
35
|
-
const validCategories
|
|
36
|
-
|
|
37
|
-
'components',
|
|
38
|
-
'blocks',
|
|
39
|
-
'animations',
|
|
40
|
-
];
|
|
41
|
-
if (
|
|
42
|
-
!validCategories.includes(options.category as ComponentCategory)
|
|
43
|
-
) {
|
|
36
|
+
const validCategories = REGISTRY_CATEGORY_ORDER as readonly string[];
|
|
37
|
+
if (!validCategories.includes(options.category)) {
|
|
44
38
|
console.error(chalk.red(`Invalid category: ${options.category}`));
|
|
45
39
|
console.log(
|
|
46
40
|
chalk.gray(`Valid categories: ${validCategories.join(', ')}`)
|
|
@@ -108,11 +102,14 @@ function displayComponents(components: ComponentMeta[]): void {
|
|
|
108
102
|
);
|
|
109
103
|
|
|
110
104
|
// Display in category order
|
|
105
|
+
const knownCategories = new Set<ComponentCategory>(
|
|
106
|
+
REGISTRY_CATEGORY_ORDER as readonly ComponentCategory[]
|
|
107
|
+
);
|
|
111
108
|
const categoryOrder: ComponentCategory[] = [
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
109
|
+
...(REGISTRY_CATEGORY_ORDER as readonly ComponentCategory[]),
|
|
110
|
+
...(Object.keys(grouped).filter(
|
|
111
|
+
category => !knownCategories.has(category as ComponentCategory)
|
|
112
|
+
) as ComponentCategory[]),
|
|
116
113
|
];
|
|
117
114
|
|
|
118
115
|
for (const category of categoryOrder) {
|
package/src/lib/constants.ts
CHANGED
|
@@ -13,3 +13,29 @@ export const DEFAULT_REGISTRY_URL = 'https://foundry.umiflow.com';
|
|
|
13
13
|
export const CACHE_TTL = 24 * 60 * 60 * 1000; // 24 hours in milliseconds
|
|
14
14
|
export const CACHE_DIR = '.foundrykit';
|
|
15
15
|
export const CACHE_FILE = 'registry-cache.json';
|
|
16
|
+
|
|
17
|
+
export const REGISTRY_CATEGORY_ORDER = [
|
|
18
|
+
'primitives',
|
|
19
|
+
'components',
|
|
20
|
+
'blocks',
|
|
21
|
+
'animations',
|
|
22
|
+
'maps',
|
|
23
|
+
'hooks',
|
|
24
|
+
'packages',
|
|
25
|
+
] as const;
|
|
26
|
+
|
|
27
|
+
export const FOUNDRYKIT_PACKAGE_ALIASES = [
|
|
28
|
+
'animation',
|
|
29
|
+
'blocks',
|
|
30
|
+
'cli',
|
|
31
|
+
'components',
|
|
32
|
+
'eslint-config',
|
|
33
|
+
'hooks',
|
|
34
|
+
'maps',
|
|
35
|
+
'prettier-config',
|
|
36
|
+
'primitives',
|
|
37
|
+
'tailwind',
|
|
38
|
+
'typescript-config',
|
|
39
|
+
'types',
|
|
40
|
+
'utils',
|
|
41
|
+
] as const;
|
package/src/lib/registry.ts
CHANGED
|
@@ -7,7 +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 {
|
|
10
|
+
import {
|
|
11
|
+
DEFAULT_REGISTRY_URL,
|
|
12
|
+
CACHE_DIR,
|
|
13
|
+
CACHE_TTL,
|
|
14
|
+
FOUNDRYKIT_PACKAGE_ALIASES,
|
|
15
|
+
} from './constants.js';
|
|
11
16
|
import type {
|
|
12
17
|
ComponentMeta,
|
|
13
18
|
ComponentData,
|
|
@@ -69,13 +74,21 @@ export class RegistryService {
|
|
|
69
74
|
// Update cache
|
|
70
75
|
await this.updateCache(components);
|
|
71
76
|
|
|
72
|
-
return
|
|
77
|
+
return this.filterComponents(
|
|
78
|
+
this.withFoundryKitPackages(components),
|
|
79
|
+
category,
|
|
80
|
+
search
|
|
81
|
+
);
|
|
73
82
|
} catch (error) {
|
|
74
83
|
// Try to load from cache
|
|
75
84
|
const cache = await this.loadCache();
|
|
76
85
|
if (cache && this.isCacheValid(cache)) {
|
|
77
86
|
console.log(chalk.yellow('Using cached registry data'));
|
|
78
|
-
return this.filterComponents(
|
|
87
|
+
return this.filterComponents(
|
|
88
|
+
this.withFoundryKitPackages(cache.components),
|
|
89
|
+
category,
|
|
90
|
+
search
|
|
91
|
+
);
|
|
79
92
|
}
|
|
80
93
|
|
|
81
94
|
// No valid cache, throw error
|
|
@@ -96,6 +109,14 @@ export class RegistryService {
|
|
|
96
109
|
return this.createSpecialDependency(id);
|
|
97
110
|
}
|
|
98
111
|
|
|
112
|
+
const foundryKitPackage = this.resolveFoundryKitPackageName(id);
|
|
113
|
+
const isExplicitFoundryKitPackage =
|
|
114
|
+
id.startsWith('@foundrykit/') ||
|
|
115
|
+
id.endsWith('-plugin') ||
|
|
116
|
+
FOUNDRYKIT_PACKAGE_ALIASES.includes(
|
|
117
|
+
id as (typeof FOUNDRYKIT_PACKAGE_ALIASES)[number]
|
|
118
|
+
);
|
|
119
|
+
|
|
99
120
|
const cache = await this.loadCache();
|
|
100
121
|
const cachedComponent = cache?.componentData?.[id];
|
|
101
122
|
const hasValidCache = cache ? this.isCacheValid(cache) : false;
|
|
@@ -113,6 +134,9 @@ export class RegistryService {
|
|
|
113
134
|
|
|
114
135
|
if (!response.ok) {
|
|
115
136
|
if (response.status === 404) {
|
|
137
|
+
if (foundryKitPackage && isExplicitFoundryKitPackage) {
|
|
138
|
+
return this.createFoundryKitPackageDependency(foundryKitPackage);
|
|
139
|
+
}
|
|
116
140
|
throw new Error(`Component "${id}" not found in registry`);
|
|
117
141
|
}
|
|
118
142
|
throw new Error(
|
|
@@ -127,6 +151,10 @@ export class RegistryService {
|
|
|
127
151
|
|
|
128
152
|
return component;
|
|
129
153
|
} catch (error) {
|
|
154
|
+
if (foundryKitPackage && isExplicitFoundryKitPackage) {
|
|
155
|
+
return this.createFoundryKitPackageDependency(foundryKitPackage);
|
|
156
|
+
}
|
|
157
|
+
|
|
130
158
|
// Fall back to any cached component data, even if stale
|
|
131
159
|
if (cachedComponent) {
|
|
132
160
|
console.log(chalk.yellow(`Using cached data for component: ${id}`));
|
|
@@ -153,6 +181,7 @@ export class RegistryService {
|
|
|
153
181
|
'cn', // Utils aliases
|
|
154
182
|
'hooks',
|
|
155
183
|
'types', // Package dependencies
|
|
184
|
+
'maps',
|
|
156
185
|
];
|
|
157
186
|
return specialDependencies.includes(id);
|
|
158
187
|
}
|
|
@@ -185,46 +214,16 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
185
214
|
};
|
|
186
215
|
}
|
|
187
216
|
|
|
188
|
-
// Handle hooks package dependency
|
|
189
217
|
if (id === 'hooks') {
|
|
190
|
-
|
|
191
|
-
const isInstalled = await this.isPackageInstalled('@foundrykit/hooks');
|
|
192
|
-
if (isInstalled) {
|
|
193
|
-
return {
|
|
194
|
-
id: 'hooks',
|
|
195
|
-
name: 'Hooks',
|
|
196
|
-
description: 'Custom React hooks package',
|
|
197
|
-
category: 'primitives',
|
|
198
|
-
files: [], // No files to install, it's a package
|
|
199
|
-
registryDependencies: [],
|
|
200
|
-
packageDependencies: ['@foundrykit/hooks'],
|
|
201
|
-
};
|
|
202
|
-
} else {
|
|
203
|
-
throw new Error(
|
|
204
|
-
'Package "@foundrykit/hooks" is not installed. Please install it first: pnpm add @foundrykit/hooks'
|
|
205
|
-
);
|
|
206
|
-
}
|
|
218
|
+
return this.createFoundryKitPackageDependency('@foundrykit/hooks');
|
|
207
219
|
}
|
|
208
220
|
|
|
209
|
-
// Handle types package dependency
|
|
210
221
|
if (id === 'types') {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
name: 'Types',
|
|
217
|
-
description: 'TypeScript type definitions',
|
|
218
|
-
category: 'primitives',
|
|
219
|
-
files: [], // No files to install, it's a package
|
|
220
|
-
registryDependencies: [],
|
|
221
|
-
packageDependencies: ['@foundrykit/types'],
|
|
222
|
-
};
|
|
223
|
-
} else {
|
|
224
|
-
throw new Error(
|
|
225
|
-
'Package "@foundrykit/types" is not installed. Please install it first: pnpm add @foundrykit/types'
|
|
226
|
-
);
|
|
227
|
-
}
|
|
222
|
+
return this.createFoundryKitPackageDependency('@foundrykit/types');
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (id === 'maps') {
|
|
226
|
+
return this.createFoundryKitPackageDependency('@foundrykit/maps');
|
|
228
227
|
}
|
|
229
228
|
|
|
230
229
|
throw new Error(`Unknown special dependency: ${id}`);
|
|
@@ -253,6 +252,67 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
253
252
|
}
|
|
254
253
|
}
|
|
255
254
|
|
|
255
|
+
private resolveFoundryKitPackageName(id: string): string | null {
|
|
256
|
+
if (/^@foundrykit\/[a-z0-9][a-z0-9-]*$/i.test(id)) {
|
|
257
|
+
return id;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (
|
|
261
|
+
FOUNDRYKIT_PACKAGE_ALIASES.includes(
|
|
262
|
+
id as (typeof FOUNDRYKIT_PACKAGE_ALIASES)[number]
|
|
263
|
+
) ||
|
|
264
|
+
/^[a-z0-9][a-z0-9-]*-plugin$/i.test(id)
|
|
265
|
+
) {
|
|
266
|
+
return `@foundrykit/${id}`;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
private createFoundryKitPackageDependency(packageName: string): ComponentData {
|
|
273
|
+
const id = packageName.replace('@foundrykit/', '');
|
|
274
|
+
const category =
|
|
275
|
+
id === 'maps' ? 'maps' : id === 'hooks' ? 'hooks' : 'packages';
|
|
276
|
+
|
|
277
|
+
return {
|
|
278
|
+
id,
|
|
279
|
+
name: this.toDisplayName(id),
|
|
280
|
+
description: `${packageName} npm package`,
|
|
281
|
+
category,
|
|
282
|
+
files: [],
|
|
283
|
+
registryDependencies: [],
|
|
284
|
+
packageDependencies: [packageName],
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
private withFoundryKitPackages(components: ComponentMeta[]): ComponentMeta[] {
|
|
289
|
+
const packageEntries = FOUNDRYKIT_PACKAGE_ALIASES.map(packageId => ({
|
|
290
|
+
id: packageId,
|
|
291
|
+
name: this.toDisplayName(packageId),
|
|
292
|
+
category:
|
|
293
|
+
packageId === 'maps'
|
|
294
|
+
? ('maps' as const)
|
|
295
|
+
: packageId === 'hooks'
|
|
296
|
+
? ('hooks' as const)
|
|
297
|
+
: ('packages' as const),
|
|
298
|
+
description: `@foundrykit/${packageId} npm package`,
|
|
299
|
+
packageDependencies: [`@foundrykit/${packageId}`],
|
|
300
|
+
}));
|
|
301
|
+
|
|
302
|
+
const seenIds = new Set(components.map(component => component.id));
|
|
303
|
+
return [
|
|
304
|
+
...components,
|
|
305
|
+
...packageEntries.filter(component => !seenIds.has(component.id)),
|
|
306
|
+
];
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
private toDisplayName(id: string): string {
|
|
310
|
+
return id
|
|
311
|
+
.split('-')
|
|
312
|
+
.map(part => part.charAt(0).toUpperCase() + part.slice(1))
|
|
313
|
+
.join(' ');
|
|
314
|
+
}
|
|
315
|
+
|
|
256
316
|
/**
|
|
257
317
|
* Update the local cache with new component list
|
|
258
318
|
*/
|