@foundrykit/cli 2.0.4 → 2.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.
@@ -1,6 +1,6 @@
1
1
 
2
2
  
3
- > @foundrykit/cli@1.0.16 build /Users/isj/Desktop/work/projects/foundry/packages/cli
3
+ > @foundrykit/cli@2.0.4 build /Users/isj/Desktop/work/projects/foundry/packages/cli
4
4
  > tsup
5
5
 
6
6
  CLI Building entry: {"index":"src/index.ts","cli":"src/index.ts"}
@@ -10,11 +10,11 @@
10
10
  CLI Target: es2022
11
11
  CLI Cleaning output folder
12
12
  ESM Build start
13
- ESM dist/cli.js 52.51 KB
14
- ESM dist/index.js 52.51 KB
15
- ESM dist/cli.js.map 100.57 KB
16
- ESM dist/index.js.map 100.57 KB
17
- ESM ⚡️ Build success in 447ms
13
+ ESM dist/cli.js 66.23 KB
14
+ ESM dist/cli.js.map 125.18 KB
15
+ ESM dist/index.js 66.23 KB
16
+ ESM dist/index.js.map 125.18 KB
17
+ ESM ⚡️ Build success in 24ms
18
18
  DTS Build start
19
- DTS ⚡️ Build success in 4955ms
19
+ DTS ⚡️ Build success in 1028ms
20
20
  DTS dist/index.d.ts 20.00 B
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @foundrykit/cli
2
2
 
3
+ ## 2.0.5
4
+
5
+ ### Patch Changes
6
+
7
+ - updates and adding in new component
8
+ - Updated dependencies
9
+ - @foundrykit/types@2.0.1
10
+
3
11
  ## 2.0.4
4
12
 
5
13
  ### Patch Changes
package/dist/cli.js CHANGED
@@ -1451,72 +1451,187 @@ async function loadConfig() {
1451
1451
  }
1452
1452
  function transformImportsForConfig(content, config) {
1453
1453
  let transformed = content;
1454
- const paths = config?.paths && config?.aliases ? {
1455
- primitives: `components/${config.paths.primitives.split("/").pop()}`,
1456
- components: `components/${config.paths.components.split("/").pop()}`,
1457
- blocks: `components/${config.paths.blocks.split("/").pop()}`,
1458
- animations: `components/${config.paths.animations.split("/").pop()}`,
1459
- utils: `lib/${config.paths.utils.split("/").pop()}`
1460
- } : {
1454
+ const importPaths = getConfiguredImportPaths(config);
1455
+ transformed = transformRegistryBarrelImports(
1456
+ transformed,
1457
+ ["@foundrykit/primitives", "@/components/primitives", "@/components/ui"],
1458
+ importPaths.primitives,
1459
+ config,
1460
+ "primitives"
1461
+ );
1462
+ transformed = transformRegistryBarrelImports(
1463
+ transformed,
1464
+ ["@foundrykit/components", "@/components/components"],
1465
+ importPaths.components,
1466
+ config,
1467
+ "components"
1468
+ );
1469
+ transformed = transformRegistryBarrelImports(
1470
+ transformed,
1471
+ ["@foundrykit/blocks", "@/components/blocks"],
1472
+ importPaths.blocks,
1473
+ config,
1474
+ "blocks"
1475
+ );
1476
+ transformed = transformRegistryBarrelImports(
1477
+ transformed,
1478
+ ["@foundrykit/animation", "@/components/animations"],
1479
+ importPaths.animations,
1480
+ config,
1481
+ "animations"
1482
+ );
1483
+ transformed = transformed.replace(/@foundrykit\/utils/g, importPaths.utils).replace(/@\/lib\/utils/g, importPaths.utils);
1484
+ return transformed;
1485
+ }
1486
+ function getConfiguredImportPaths(config) {
1487
+ const paths = config?.paths || {
1461
1488
  primitives: "components/primitives",
1462
1489
  components: "components",
1463
1490
  blocks: "components/blocks",
1464
1491
  animations: "components/animations",
1465
1492
  utils: "lib/utils"
1466
1493
  };
1467
- transformed = transformed.replace(
1468
- /import\s+{([^}]+)}\s+from\s+["']@\/components\/primitives["']/g,
1469
- (match, imports) => {
1470
- const componentNames = imports.split(",").map(
1471
- (imp) => imp?.trim().split(/\s+as\s+/)[0]?.trim() || ""
1472
- );
1473
- const primitivesPath = paths.primitives.replace(/^\.\//, "").replace(/\/$/, "");
1474
- return `import {${imports}} from "@/${primitivesPath}/${componentNames[0].toLowerCase()}"`;
1475
- }
1494
+ 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),
1499
+ utils: resolveImportBasePath(paths.utils, config).replace(
1500
+ /\.(ts|js)x?$/,
1501
+ ""
1502
+ )
1503
+ };
1504
+ }
1505
+ function resolveImportBasePath(filePath, config) {
1506
+ const normalizedPath = normalizeConfigPath(filePath).replace(
1507
+ /\.(ts|js)x?$/,
1508
+ ""
1476
1509
  );
1477
- transformed = transformed.replace(
1478
- /import\s+{([^}]+)}\s+from\s+["']@\/components\/ui["']/g,
1479
- (match, imports) => {
1480
- const componentNames = imports.split(",").map(
1481
- (imp) => imp?.trim().split(/\s+as\s+/)[0]?.trim() || ""
1482
- );
1483
- const primitivesPath = paths.primitives.replace(/^\.\//, "").replace(/\/$/, "");
1484
- return `import {${imports}} from "@/${primitivesPath}/${componentNames[0].toLowerCase()}"`;
1485
- }
1510
+ const aliases = config?.aliases ?? {};
1511
+ const aliasMatches = Object.entries(aliases).map(([alias, target]) => ({
1512
+ alias,
1513
+ target: normalizeConfigPath(target)
1514
+ })).filter(({ target }) => {
1515
+ return normalizedPath === target || target !== "" && normalizedPath.startsWith(`${target}/`) || target === "";
1516
+ }).sort((a, b) => b.target.length - a.target.length);
1517
+ const bestMatch = aliasMatches[0];
1518
+ if (bestMatch) {
1519
+ const relativePath = bestMatch.target === "" ? normalizedPath : normalizedPath.slice(bestMatch.target.length).replace(/^\//, "");
1520
+ return joinImportPath(bestMatch.alias, relativePath);
1521
+ }
1522
+ return joinImportPath("@", normalizedPath);
1523
+ }
1524
+ function normalizeConfigPath(filePath) {
1525
+ return filePath.replace(/\\/g, "/").replace(/^\.\//, "").replace(/^\.\/?$/, "").replace(/\/$/, "");
1526
+ }
1527
+ function joinImportPath(basePath, childPath) {
1528
+ const normalizedBase = basePath.replace(/\/$/, "");
1529
+ const normalizedChild = childPath.replace(/^\//, "").replace(/\/$/, "");
1530
+ if (!normalizedChild) {
1531
+ return normalizedBase;
1532
+ }
1533
+ return `${normalizedBase}/${normalizedChild}`;
1534
+ }
1535
+ function transformRegistryBarrelImports(content, sources, destinationBasePath, config, category) {
1536
+ const sourcePattern = sources.map((source) => source.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|");
1537
+ const importPattern = new RegExp(
1538
+ `import\\s+{([^}]+)}\\s+from\\s+["'](${sourcePattern})["'];?`,
1539
+ "g"
1486
1540
  );
1487
- transformed = transformed.replace(
1488
- /import\s+{([^}]+)}\s+from\s+["']@\/components\/components["']/g,
1489
- (match, imports) => {
1490
- const componentNames = imports.split(",").map(
1491
- (imp) => imp?.trim().split(/\s+as\s+/)[0]?.trim() || ""
1492
- );
1493
- const componentsPath = paths.components.replace(/^\.\//, "").replace(/\/$/, "");
1494
- return `import {${imports}} from "@/${componentsPath}/${componentNames[0].toLowerCase()}"`;
1495
- }
1541
+ return content.replace(importPattern, (match, imports) => {
1542
+ const groupedImports = groupImportsByComponent(imports, config, category);
1543
+ return Array.from(groupedImports.entries()).map(([componentPath, specifiers]) => {
1544
+ return `import { ${specifiers.join(", ")} } from "${destinationBasePath}/${componentPath}";`;
1545
+ }).join("\n");
1546
+ });
1547
+ }
1548
+ function groupImportsByComponent(imports, config, category) {
1549
+ const groupedImports = /* @__PURE__ */ new Map();
1550
+ const exportMap = getInstalledComponentExportMap(config, category);
1551
+ const specifiers = imports.split(",").map((specifier) => specifier.trim()).filter(Boolean);
1552
+ const exportNames = specifiers.map(getExportNameFromSpecifier);
1553
+ for (const specifier of specifiers) {
1554
+ const componentPath = getComponentPathForSpecifier(
1555
+ specifier,
1556
+ exportNames,
1557
+ exportMap
1558
+ );
1559
+ const existing = groupedImports.get(componentPath) ?? [];
1560
+ existing.push(specifier);
1561
+ groupedImports.set(componentPath, existing);
1562
+ }
1563
+ return groupedImports;
1564
+ }
1565
+ function getComponentPathForSpecifier(specifier, importExportNames, exportMap) {
1566
+ const exportName = getExportNameFromSpecifier(specifier);
1567
+ const mappedPath = exportMap.get(exportName);
1568
+ if (mappedPath) {
1569
+ return mappedPath;
1570
+ }
1571
+ const siblingOwnerName = importExportNames.filter((name) => name !== exportName).sort((a, b) => a.length - b.length).find((name) => exportName.toLowerCase().startsWith(name.toLowerCase()));
1572
+ if (siblingOwnerName) {
1573
+ return exportMap.get(siblingOwnerName) ?? toKebabCase(siblingOwnerName);
1574
+ }
1575
+ const variantsOwnerName = exportName.replace(/Variants$/, "");
1576
+ if (variantsOwnerName !== exportName) {
1577
+ return exportMap.get(variantsOwnerName) ?? toKebabCase(variantsOwnerName);
1578
+ }
1579
+ return toKebabCase(exportName);
1580
+ }
1581
+ function getExportNameFromSpecifier(specifier) {
1582
+ return specifier.replace(/^type\s+/, "").split(/\s+as\s+/)[0]?.trim() || specifier;
1583
+ }
1584
+ function getInstalledComponentExportMap(config, category) {
1585
+ const exportMap = /* @__PURE__ */ new Map();
1586
+ const categoryPath = config.paths?.[category];
1587
+ if (!categoryPath) {
1588
+ return exportMap;
1589
+ }
1590
+ const absoluteCategoryPath = path3.resolve(
1591
+ process.cwd(),
1592
+ normalizeConfigPath(categoryPath)
1496
1593
  );
1497
- transformed = transformed.replace(
1498
- /import\s+{([^}]+)}\s+from\s+["']@\/components\/blocks["']/g,
1499
- (match, imports) => {
1500
- const componentNames = imports.split(",").map(
1501
- (imp) => imp?.trim().split(/\s+as\s+/)[0]?.trim() || ""
1502
- );
1503
- const blocksPath = paths.blocks.replace(/^\.\//, "").replace(/\/$/, "");
1504
- return `import {${imports}} from "@/${blocksPath}/${componentNames[0].toLowerCase()}"`;
1594
+ if (!fs3.existsSync(absoluteCategoryPath)) {
1595
+ return exportMap;
1596
+ }
1597
+ for (const entry of fs3.readdirSync(absoluteCategoryPath, {
1598
+ withFileTypes: true
1599
+ })) {
1600
+ if (!entry.isDirectory()) continue;
1601
+ const componentPath = entry.name;
1602
+ const componentDir = path3.join(absoluteCategoryPath, componentPath);
1603
+ const entryFiles = ["index.tsx", "index.ts", "index.jsx", "index.js"].map((fileName) => path3.join(componentDir, fileName)).filter((filePath) => fs3.existsSync(filePath));
1604
+ for (const filePath of entryFiles) {
1605
+ const content = fs3.readFileSync(filePath, "utf-8");
1606
+ for (const exportName of parseExportNames(content)) {
1607
+ exportMap.set(exportName, componentPath);
1608
+ }
1505
1609
  }
1506
- );
1507
- transformed = transformed.replace(
1508
- /import\s+{([^}]+)}\s+from\s+["']@\/components\/animations["']/g,
1509
- (match, imports) => {
1510
- const componentNames = imports.split(",").map(
1511
- (imp) => imp?.trim().split(/\s+as\s+/)[0]?.trim() || ""
1512
- );
1513
- const animationsPath = paths.animations.replace(/^\.\//, "").replace(/\/$/, "");
1514
- return `import {${imports}} from "@/${animationsPath}/${componentNames[0].toLowerCase()}"`;
1610
+ }
1611
+ return exportMap;
1612
+ }
1613
+ function parseExportNames(content) {
1614
+ const exportNames = /* @__PURE__ */ new Set();
1615
+ const namedExportPattern = /export\s*{\s*([^}]+)\s*}/g;
1616
+ const declarationExportPattern = /export\s+(?:declare\s+)?(?:const|let|var|function|class|interface|type|enum)\s+([A-Za-z_$][\w$]*)/g;
1617
+ for (const match of content.matchAll(namedExportPattern)) {
1618
+ const exports = match[1] ?? "";
1619
+ for (const rawExport of exports.split(",")) {
1620
+ const exportName = rawExport.trim().replace(/^type\s+/, "").split(/\s+as\s+/).pop()?.trim();
1621
+ if (exportName) {
1622
+ exportNames.add(exportName);
1623
+ }
1515
1624
  }
1516
- );
1517
- const utilsPath = paths.utils.replace(/^\.\//, "").replace(/\/$/, "").replace(/\.(ts|js)$/, "");
1518
- transformed = transformed.replace(/@\/lib\/utils/g, `@/${utilsPath}`);
1519
- return transformed;
1625
+ }
1626
+ for (const match of content.matchAll(declarationExportPattern)) {
1627
+ if (match[1]) {
1628
+ exportNames.add(match[1]);
1629
+ }
1630
+ }
1631
+ return Array.from(exportNames);
1632
+ }
1633
+ function toKebabCase(value) {
1634
+ return value.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1-$2").toLowerCase();
1520
1635
  }
1521
1636
  function resolveComponentPath(originalPath, category, config) {
1522
1637
  const paths = config?.paths || {
@@ -1560,21 +1675,16 @@ function getImportPath(componentData, config) {
1560
1675
  utils: "lib/utils"
1561
1676
  };
1562
1677
  const componentName = path3.basename(
1563
- componentData.files[0]?.path || "",
1564
- ".tsx"
1678
+ path3.dirname(componentData.files[0]?.path || "")
1565
1679
  );
1566
1680
  if (componentData.category === "primitives") {
1567
- const primitivesPath = paths.primitives.replace(/^\.\//, "").replace(/\/$/, "");
1568
- return `@/${primitivesPath}/${componentName}`;
1681
+ return `${resolveImportBasePath(paths.primitives, config)}/${componentName}`;
1569
1682
  } else if (componentData.category === "components") {
1570
- const componentsPath = paths.components.replace(/^\.\//, "").replace(/\/$/, "");
1571
- return `@/${componentsPath}/${componentName}`;
1683
+ return `${resolveImportBasePath(paths.components, config)}/${componentName}`;
1572
1684
  } else if (componentData.category === "blocks") {
1573
- const blocksPath = paths.blocks.replace(/^\.\//, "").replace(/\/$/, "");
1574
- return `@/${blocksPath}/${componentName}`;
1685
+ return `${resolveImportBasePath(paths.blocks, config)}/${componentName}`;
1575
1686
  } else if (componentData.category === "animations") {
1576
- const animationsPath = paths.animations.replace(/^\.\//, "").replace(/\/$/, "");
1577
- return `@/${animationsPath}/${componentName}`;
1687
+ return `${resolveImportBasePath(paths.animations, config)}/${componentName}`;
1578
1688
  }
1579
1689
  return `@/components/${componentName}`;
1580
1690
  }