@foundrykit/cli 2.0.6 → 2.0.8

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/dist/index.js CHANGED
@@ -20,6 +20,30 @@ var CLI_VERSION = "1.0.16";
20
20
  var DEFAULT_REGISTRY_URL = "https://foundry.umiflow.com";
21
21
  var CACHE_TTL = 24 * 60 * 60 * 1e3;
22
22
  var CACHE_DIR = ".foundrykit";
23
+ var REGISTRY_CATEGORY_ORDER = [
24
+ "primitives",
25
+ "components",
26
+ "blocks",
27
+ "animations",
28
+ "maps",
29
+ "hooks",
30
+ "packages"
31
+ ];
32
+ var FOUNDRYKIT_PACKAGE_ALIASES = [
33
+ "animation",
34
+ "blocks",
35
+ "cli",
36
+ "components",
37
+ "eslint-config",
38
+ "hooks",
39
+ "maps",
40
+ "prettier-config",
41
+ "primitives",
42
+ "tailwind",
43
+ "typescript-config",
44
+ "types",
45
+ "utils"
46
+ ];
23
47
 
24
48
  // src/commands/init.ts
25
49
  function initCommand() {
@@ -204,6 +228,10 @@ async function getPathConfiguration(structure, skipPrompts) {
204
228
  structure.componentsPath || path.join(structure.baseDir, "components"),
205
229
  "blocks"
206
230
  ),
231
+ maps: path.join(
232
+ structure.componentsPath || path.join(structure.baseDir, "components"),
233
+ "maps"
234
+ ),
207
235
  animations: path.join(
208
236
  structure.componentsPath || path.join(structure.baseDir, "components"),
209
237
  "animations"
@@ -271,6 +299,12 @@ async function getPathConfiguration(structure, skipPrompts) {
271
299
  message: "Hooks directory:",
272
300
  default: defaults.hooks
273
301
  },
302
+ {
303
+ type: "input",
304
+ name: "maps",
305
+ message: "Maps directory:",
306
+ default: defaults.maps
307
+ },
274
308
  {
275
309
  type: "input",
276
310
  name: "animations",
@@ -564,6 +598,7 @@ async function createDirectories(pathConfig) {
564
598
  pathConfig.primitives,
565
599
  pathConfig.components,
566
600
  pathConfig.blocks,
601
+ pathConfig.maps,
567
602
  pathConfig.animations,
568
603
  pathConfig.hooks,
569
604
  pathConfig.lib
@@ -660,6 +695,7 @@ async function createConfigFile(options, structure, pathConfig) {
660
695
  components: normalizePath(pathConfig.components),
661
696
  blocks: normalizePath(pathConfig.blocks),
662
697
  hooks: normalizePath(pathConfig.hooks),
698
+ maps: normalizePath(pathConfig.maps),
663
699
  animations: normalizePath(pathConfig.animations)
664
700
  },
665
701
  packageManager: structure.packageManager,
@@ -739,12 +775,20 @@ var RegistryService = class {
739
775
  }
740
776
  const components = await response.json();
741
777
  await this.updateCache(components);
742
- return components;
778
+ return this.filterComponents(
779
+ this.withFoundryKitPackages(components),
780
+ category,
781
+ search
782
+ );
743
783
  } catch (error) {
744
784
  const cache = await this.loadCache();
745
785
  if (cache && this.isCacheValid(cache)) {
746
786
  console.log(chalk2.yellow("Using cached registry data"));
747
- return this.filterComponents(cache.components, category, search);
787
+ return this.filterComponents(
788
+ this.withFoundryKitPackages(cache.components),
789
+ category,
790
+ search
791
+ );
748
792
  }
749
793
  throw new Error(
750
794
  `Failed to connect to registry: ${error instanceof Error ? error.message : "Unknown error"}
@@ -760,6 +804,10 @@ Try again later or check your internet connection.`
760
804
  if (this.isSpecialDependency(id)) {
761
805
  return this.createSpecialDependency(id);
762
806
  }
807
+ const foundryKitPackage = this.resolveFoundryKitPackageName(id);
808
+ const isExplicitFoundryKitPackage = id.startsWith("@foundrykit/") || id.endsWith("-plugin") || FOUNDRYKIT_PACKAGE_ALIASES.includes(
809
+ id
810
+ );
763
811
  const cache = await this.loadCache();
764
812
  const cachedComponent = cache?.componentData?.[id];
765
813
  const hasValidCache = cache ? this.isCacheValid(cache) : false;
@@ -773,6 +821,9 @@ Try again later or check your internet connection.`
773
821
  const response = await fetch(url);
774
822
  if (!response.ok) {
775
823
  if (response.status === 404) {
824
+ if (foundryKitPackage && isExplicitFoundryKitPackage) {
825
+ return this.createFoundryKitPackageDependency(foundryKitPackage);
826
+ }
776
827
  throw new Error(`Component "${id}" not found in registry`);
777
828
  }
778
829
  throw new Error(
@@ -783,6 +834,9 @@ Try again later or check your internet connection.`
783
834
  await this.cacheComponent(component);
784
835
  return component;
785
836
  } catch (error) {
837
+ if (foundryKitPackage && isExplicitFoundryKitPackage) {
838
+ return this.createFoundryKitPackageDependency(foundryKitPackage);
839
+ }
786
840
  if (cachedComponent) {
787
841
  console.log(chalk2.yellow(`Using cached data for component: ${id}`));
788
842
  return cachedComponent;
@@ -805,8 +859,9 @@ Try again later or check your internet connection.`
805
859
  "cn",
806
860
  // Utils aliases
807
861
  "hooks",
808
- "types"
862
+ "types",
809
863
  // Package dependencies
864
+ "maps"
810
865
  ];
811
866
  return specialDependencies.includes(id);
812
867
  }
@@ -837,42 +892,13 @@ export function cn(...inputs: ClassValue[]) {
837
892
  };
838
893
  }
839
894
  if (id === "hooks") {
840
- const isInstalled = await this.isPackageInstalled("@foundrykit/hooks");
841
- if (isInstalled) {
842
- return {
843
- id: "hooks",
844
- name: "Hooks",
845
- description: "Custom React hooks package",
846
- category: "primitives",
847
- files: [],
848
- // No files to install, it's a package
849
- registryDependencies: [],
850
- packageDependencies: ["@foundrykit/hooks"]
851
- };
852
- } else {
853
- throw new Error(
854
- 'Package "@foundrykit/hooks" is not installed. Please install it first: pnpm add @foundrykit/hooks'
855
- );
856
- }
895
+ return this.createFoundryKitPackageDependency("@foundrykit/hooks");
857
896
  }
858
897
  if (id === "types") {
859
- const isInstalled = await this.isPackageInstalled("@foundrykit/types");
860
- if (isInstalled) {
861
- return {
862
- id: "types",
863
- name: "Types",
864
- description: "TypeScript type definitions",
865
- category: "primitives",
866
- files: [],
867
- // No files to install, it's a package
868
- registryDependencies: [],
869
- packageDependencies: ["@foundrykit/types"]
870
- };
871
- } else {
872
- throw new Error(
873
- 'Package "@foundrykit/types" is not installed. Please install it first: pnpm add @foundrykit/types'
874
- );
875
- }
898
+ return this.createFoundryKitPackageDependency("@foundrykit/types");
899
+ }
900
+ if (id === "maps") {
901
+ return this.createFoundryKitPackageDependency("@foundrykit/maps");
876
902
  }
877
903
  throw new Error(`Unknown special dependency: ${id}`);
878
904
  }
@@ -896,6 +922,47 @@ export function cn(...inputs: ClassValue[]) {
896
922
  return false;
897
923
  }
898
924
  }
925
+ resolveFoundryKitPackageName(id) {
926
+ if (/^@foundrykit\/[a-z0-9][a-z0-9-]*$/i.test(id)) {
927
+ return id;
928
+ }
929
+ if (FOUNDRYKIT_PACKAGE_ALIASES.includes(
930
+ id
931
+ ) || /^[a-z0-9][a-z0-9-]*-plugin$/i.test(id)) {
932
+ return `@foundrykit/${id}`;
933
+ }
934
+ return null;
935
+ }
936
+ createFoundryKitPackageDependency(packageName) {
937
+ const id = packageName.replace("@foundrykit/", "");
938
+ const category = id === "maps" ? "maps" : id === "hooks" ? "hooks" : "packages";
939
+ return {
940
+ id,
941
+ name: this.toDisplayName(id),
942
+ description: `${packageName} npm package`,
943
+ category,
944
+ files: [],
945
+ registryDependencies: [],
946
+ packageDependencies: [packageName]
947
+ };
948
+ }
949
+ withFoundryKitPackages(components) {
950
+ const packageEntries = FOUNDRYKIT_PACKAGE_ALIASES.map((packageId) => ({
951
+ id: packageId,
952
+ name: this.toDisplayName(packageId),
953
+ category: packageId === "maps" ? "maps" : packageId === "hooks" ? "hooks" : "packages",
954
+ description: `@foundrykit/${packageId} npm package`,
955
+ packageDependencies: [`@foundrykit/${packageId}`]
956
+ }));
957
+ const seenIds = new Set(components.map((component) => component.id));
958
+ return [
959
+ ...components,
960
+ ...packageEntries.filter((component) => !seenIds.has(component.id))
961
+ ];
962
+ }
963
+ toDisplayName(id) {
964
+ return id.split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
965
+ }
899
966
  /**
900
967
  * Update the local cache with new component list
901
968
  */
@@ -1028,12 +1095,7 @@ function listCommand() {
1028
1095
  console.log(chalk3.blue("\u{1F4E6} Available FoundryKit components:"));
1029
1096
  const registry = getRegistry();
1030
1097
  if (options.category) {
1031
- const validCategories = [
1032
- "primitives",
1033
- "components",
1034
- "blocks",
1035
- "animations"
1036
- ];
1098
+ const validCategories = REGISTRY_CATEGORY_ORDER;
1037
1099
  if (!validCategories.includes(options.category)) {
1038
1100
  console.error(chalk3.red(`Invalid category: ${options.category}`));
1039
1101
  console.log(
@@ -1088,11 +1150,14 @@ function displayComponents(components) {
1088
1150
  },
1089
1151
  {}
1090
1152
  );
1153
+ const knownCategories = new Set(
1154
+ REGISTRY_CATEGORY_ORDER
1155
+ );
1091
1156
  const categoryOrder = [
1092
- "primitives",
1093
- "components",
1094
- "blocks",
1095
- "animations"
1157
+ ...REGISTRY_CATEGORY_ORDER,
1158
+ ...Object.keys(grouped).filter(
1159
+ (category) => !knownCategories.has(category)
1160
+ )
1096
1161
  ];
1097
1162
  for (const category of categoryOrder) {
1098
1163
  const items = grouped[category];
@@ -1203,11 +1268,12 @@ async function selectComponentsInteractively() {
1203
1268
  }
1204
1269
  }
1205
1270
  function createGroupedChoices(components) {
1271
+ const knownCategories = new Set(
1272
+ REGISTRY_CATEGORY_ORDER
1273
+ );
1206
1274
  const categories = [
1207
- "primitives",
1208
- "components",
1209
- "blocks",
1210
- "animations"
1275
+ ...REGISTRY_CATEGORY_ORDER,
1276
+ ...components.map((component) => component.category).filter((category) => !knownCategories.has(category))
1211
1277
  ];
1212
1278
  const choices = [];
1213
1279
  for (const category of categories) {
@@ -1331,6 +1397,9 @@ async function hasConflictingFiles(componentData, options) {
1331
1397
  async function installComponentFiles(componentData, options) {
1332
1398
  const config = await loadConfig();
1333
1399
  const basePath = options.path || process.cwd();
1400
+ if (componentData.files.length === 0) {
1401
+ return;
1402
+ }
1334
1403
  console.log(chalk4.blue("\u{1F4DD} Installing component files..."));
1335
1404
  for (const file of componentData.files) {
1336
1405
  let resolvedPath;
@@ -1432,6 +1501,15 @@ async function detectPackageManager2() {
1432
1501
  async function showUsageExample(componentData) {
1433
1502
  const config = await loadConfig();
1434
1503
  console.log(chalk4.cyan("\n\u{1F4A1} Usage:"));
1504
+ if (componentData.files.length === 0) {
1505
+ const packageName = componentData.packageDependencies?.find(
1506
+ (dep) => dep.startsWith("@foundrykit/")
1507
+ );
1508
+ if (packageName) {
1509
+ console.log(chalk4.gray(`import { ... } from "${packageName}"`));
1510
+ }
1511
+ return;
1512
+ }
1435
1513
  const componentName = componentData.name.replace(/\s+/g, "");
1436
1514
  const importPath = getImportPath(componentData, config);
1437
1515
  console.log(chalk4.gray(`import { ${componentName} } from "${importPath}"`));
@@ -1480,6 +1558,20 @@ function transformImportsForConfig(content, config) {
1480
1558
  config,
1481
1559
  "animations"
1482
1560
  );
1561
+ transformed = transformRegistryBarrelImports(
1562
+ transformed,
1563
+ ["@foundrykit/maps", "@/components/maps"],
1564
+ importPaths.maps,
1565
+ config,
1566
+ "maps"
1567
+ );
1568
+ transformed = transformRegistryBarrelImports(
1569
+ transformed,
1570
+ ["@foundrykit/hooks", "@/hooks"],
1571
+ importPaths.hooks,
1572
+ config,
1573
+ "hooks"
1574
+ );
1483
1575
  transformed = transformed.replace(/@foundrykit\/utils/g, importPaths.utils).replace(/@\/lib\/utils/g, importPaths.utils);
1484
1576
  return transformed;
1485
1577
  }
@@ -1489,25 +1581,59 @@ function getConfiguredImportPaths(config) {
1489
1581
  components: "components",
1490
1582
  blocks: "components/blocks",
1491
1583
  animations: "components/animations",
1584
+ hooks: "hooks",
1585
+ maps: "components/maps",
1492
1586
  utils: "lib/utils"
1493
1587
  };
1494
1588
  return {
1495
- primitives: resolveImportBasePath(paths.primitives, config),
1496
- components: resolveImportBasePath(paths.components, config),
1497
- blocks: resolveImportBasePath(paths.blocks, config),
1498
- animations: resolveImportBasePath(paths.animations, config),
1589
+ primitives: resolveImportBasePath(paths.primitives, config, {
1590
+ preferRootAlias: true
1591
+ }),
1592
+ components: resolveImportBasePath(paths.components, config, {
1593
+ preferRootAlias: true
1594
+ }),
1595
+ blocks: resolveImportBasePath(paths.blocks, config, {
1596
+ preferRootAlias: true
1597
+ }),
1598
+ animations: resolveImportBasePath(paths.animations, config, {
1599
+ preferRootAlias: true
1600
+ }),
1601
+ maps: resolveImportBasePath(
1602
+ paths.maps ?? joinImportPath(paths.components, "maps"),
1603
+ config,
1604
+ {
1605
+ preferRootAlias: true
1606
+ }
1607
+ ),
1608
+ hooks: resolveImportBasePath(paths.hooks ?? "hooks", config, {
1609
+ preferRootAlias: true
1610
+ }),
1611
+ packages: resolveImportBasePath(paths.components, config, {
1612
+ preferRootAlias: true
1613
+ }),
1499
1614
  utils: resolveImportBasePath(paths.utils, config).replace(
1500
1615
  /\.(ts|js)x?$/,
1501
1616
  ""
1502
1617
  )
1503
1618
  };
1504
1619
  }
1505
- function resolveImportBasePath(filePath, config) {
1620
+ function resolveImportBasePath(filePath, config, options = {}) {
1621
+ if (isPackageImportSpecifier(filePath)) {
1622
+ return filePath.replace(/\/$/, "");
1623
+ }
1506
1624
  const normalizedPath = normalizeConfigPath(filePath).replace(
1507
1625
  /\.(ts|js)x?$/,
1508
1626
  ""
1509
1627
  );
1510
1628
  const aliases = config?.aliases ?? {};
1629
+ if (options.preferRootAlias && aliases["@"]) {
1630
+ const rootTarget = normalizeConfigPath(aliases["@"]);
1631
+ const matchesRoot = normalizedPath === rootTarget || rootTarget !== "" && normalizedPath.startsWith(`${rootTarget}/`) || rootTarget === "";
1632
+ if (matchesRoot) {
1633
+ const relativePath = rootTarget === "" ? normalizedPath : normalizedPath.slice(rootTarget.length).replace(/^\//, "");
1634
+ return joinImportPath("@", relativePath);
1635
+ }
1636
+ }
1511
1637
  const aliasMatches = Object.entries(aliases).map(([alias, target]) => ({
1512
1638
  alias,
1513
1639
  target: normalizeConfigPath(target)
@@ -1524,6 +1650,9 @@ function resolveImportBasePath(filePath, config) {
1524
1650
  function normalizeConfigPath(filePath) {
1525
1651
  return filePath.replace(/\\/g, "/").replace(/^\.\//, "").replace(/^\.\/?$/, "").replace(/\/$/, "");
1526
1652
  }
1653
+ function isPackageImportSpecifier(importPath) {
1654
+ return importPath.startsWith("@") && !importPath.startsWith("@/");
1655
+ }
1527
1656
  function joinImportPath(basePath, childPath) {
1528
1657
  const normalizedBase = basePath.replace(/\/$/, "");
1529
1658
  const normalizedChild = childPath.replace(/^\//, "").replace(/\/$/, "");
@@ -1538,7 +1667,10 @@ function transformRegistryBarrelImports(content, sources, destinationBasePath, c
1538
1667
  `import\\s+{([^}]+)}\\s+from\\s+["'](${sourcePattern})["'];?`,
1539
1668
  "g"
1540
1669
  );
1541
- return content.replace(importPattern, (match, imports) => {
1670
+ return content.replace(importPattern, (match, imports, source) => {
1671
+ if (isPackageImportSpecifier(destinationBasePath)) {
1672
+ return match.replace(source, destinationBasePath);
1673
+ }
1542
1674
  const groupedImports = groupImportsByComponent(imports, config, category);
1543
1675
  return Array.from(groupedImports.entries()).map(([componentPath, specifiers]) => {
1544
1676
  return `import { ${specifiers.join(", ")} } from "${destinationBasePath}/${componentPath}";`;
@@ -1583,7 +1715,7 @@ function getExportNameFromSpecifier(specifier) {
1583
1715
  }
1584
1716
  function getInstalledComponentExportMap(config, category) {
1585
1717
  const exportMap = /* @__PURE__ */ new Map();
1586
- const categoryPath = config.paths?.[category];
1718
+ const categoryPath = getConfiguredCategoryPath(config, category);
1587
1719
  if (!categoryPath) {
1588
1720
  return exportMap;
1589
1721
  }
@@ -1639,12 +1771,14 @@ function resolveComponentPath(originalPath, category, config) {
1639
1771
  components: "components",
1640
1772
  blocks: "components/blocks",
1641
1773
  animations: "components/animations",
1774
+ hooks: "hooks",
1775
+ maps: "components/maps",
1642
1776
  utils: "lib/utils"
1643
1777
  };
1644
1778
  if (originalPath === "lib/utils.ts") {
1645
1779
  return paths.utils || "lib/utils.ts";
1646
1780
  }
1647
- const categoryPath = paths[category] || paths.components;
1781
+ const categoryPath = getConfiguredCategoryPath(config, category) || paths.components;
1648
1782
  const fileName = path3.basename(originalPath);
1649
1783
  const componentName = path3.dirname(originalPath).split("/").pop() || "";
1650
1784
  if (category === "primitives") {
@@ -1663,28 +1797,81 @@ function resolveComponentPath(originalPath, category, config) {
1663
1797
  componentName,
1664
1798
  fileName
1665
1799
  );
1800
+ } else if (category === "maps") {
1801
+ return path3.join(
1802
+ paths.maps || path3.join(paths.components, "maps"),
1803
+ componentName,
1804
+ fileName
1805
+ );
1806
+ } else if (category === "hooks") {
1807
+ return path3.join(paths.hooks || "hooks", componentName, fileName);
1808
+ } else if (category === "packages") {
1809
+ return path3.join(paths.components, componentName, fileName);
1666
1810
  }
1667
1811
  return originalPath;
1668
1812
  }
1813
+ function getConfiguredCategoryPath(config, category) {
1814
+ const paths = config.paths;
1815
+ switch (category) {
1816
+ case "primitives":
1817
+ return paths.primitives;
1818
+ case "components":
1819
+ return paths.components;
1820
+ case "blocks":
1821
+ return paths.blocks;
1822
+ case "animations":
1823
+ return paths.animations;
1824
+ case "maps":
1825
+ return paths.maps ?? path3.join(paths.components, "maps");
1826
+ case "hooks":
1827
+ return paths.hooks ?? "hooks";
1828
+ case "packages":
1829
+ return paths.components;
1830
+ default:
1831
+ return void 0;
1832
+ }
1833
+ }
1669
1834
  function getImportPath(componentData, config) {
1670
1835
  const paths = config?.paths || {
1671
1836
  primitives: "components/primitives",
1672
1837
  components: "components",
1673
1838
  blocks: "components/blocks",
1674
1839
  animations: "components/animations",
1840
+ hooks: "hooks",
1841
+ maps: "components/maps",
1675
1842
  utils: "lib/utils"
1676
1843
  };
1677
1844
  const componentName = path3.basename(
1678
1845
  path3.dirname(componentData.files[0]?.path || "")
1679
1846
  );
1680
1847
  if (componentData.category === "primitives") {
1681
- return `${resolveImportBasePath(paths.primitives, config)}/${componentName}`;
1848
+ return `${resolveImportBasePath(paths.primitives, config, {
1849
+ preferRootAlias: true
1850
+ })}/${componentName}`;
1682
1851
  } else if (componentData.category === "components") {
1683
- return `${resolveImportBasePath(paths.components, config)}/${componentName}`;
1852
+ return `${resolveImportBasePath(paths.components, config, {
1853
+ preferRootAlias: true
1854
+ })}/${componentName}`;
1684
1855
  } else if (componentData.category === "blocks") {
1685
- return `${resolveImportBasePath(paths.blocks, config)}/${componentName}`;
1856
+ return `${resolveImportBasePath(paths.blocks, config, {
1857
+ preferRootAlias: true
1858
+ })}/${componentName}`;
1686
1859
  } else if (componentData.category === "animations") {
1687
- return `${resolveImportBasePath(paths.animations, config)}/${componentName}`;
1860
+ return `${resolveImportBasePath(paths.animations, config, {
1861
+ preferRootAlias: true
1862
+ })}/${componentName}`;
1863
+ } else if (componentData.category === "maps") {
1864
+ return `${resolveImportBasePath(
1865
+ paths.maps || path3.join(paths.components, "maps"),
1866
+ config,
1867
+ {
1868
+ preferRootAlias: true
1869
+ }
1870
+ )}/${componentName}`;
1871
+ } else if (componentData.category === "hooks") {
1872
+ return `${resolveImportBasePath(paths.hooks || "hooks", config, {
1873
+ preferRootAlias: true
1874
+ })}/${componentName}`;
1688
1875
  }
1689
1876
  return `@/components/${componentName}`;
1690
1877
  }