@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/dist/index.js CHANGED
@@ -54,6 +54,7 @@ function initCommand() {
54
54
  if (!options.skipInstall) {
55
55
  await installDependencies();
56
56
  }
57
+ console.log(pathConfig);
57
58
  await createConfigFile(options, projectStructure, pathConfig);
58
59
  await installUtils(pathConfig);
59
60
  await setupTailwindV4(
@@ -594,17 +595,26 @@ export function cn(...inputs: ClassValue[]) {
594
595
  path.dirname(pathConfig.components),
595
596
  `theme-provider${structure.isTypeScript ? ".tsx" : ".jsx"}`
596
597
  );
597
- const providersContent = `'use client';
598
+ const providersContent = `
599
+ 'use client';
598
600
 
599
- import { ThemeProvider } from 'next-themes';
601
+ import type * as React from 'react';
602
+ import { ThemeProvider as NextThemesProvider } from 'next-themes';
600
603
 
601
604
  export function ThemeProvider({ children }: { children: React.ReactNode }) {
602
605
  return (
603
- <ThemeProvider attribute="class" defaultTheme="system" enableSystem>
606
+ <NextThemesProvider
607
+ attribute='class'
608
+ defaultTheme='system'
609
+ enableSystem
610
+ disableTransitionOnChange
611
+ enableColorScheme
612
+ >
604
613
  {children}
605
- </ThemeProvider>
614
+ </NextThemesProvider>
606
615
  );
607
616
  }
617
+
608
618
  `;
609
619
  if (!fs.existsSync(providersPath)) {
610
620
  await fs.writeFile(providersPath, providersContent);
@@ -635,28 +645,36 @@ async function createConfigFile(options, structure, pathConfig) {
635
645
  console.log(chalk.yellow("\u26A0\uFE0F Configuration file already exists"));
636
646
  return;
637
647
  }
648
+ const normalizePath = (p) => {
649
+ if (p.startsWith("./") || p.startsWith("../") || path.isAbsolute(p)) {
650
+ return p;
651
+ }
652
+ return `./${p}`;
653
+ };
638
654
  const config = {
639
655
  version: CLI_VERSION,
640
656
  registry: DEFAULT_REGISTRY_URL,
641
657
  paths: {
642
- utils: pathConfig.utils,
643
- primitives: pathConfig.primitives,
644
- components: pathConfig.components,
645
- blocks: pathConfig.blocks,
646
- hooks: pathConfig.hooks,
647
- animations: pathConfig.animations
658
+ utils: normalizePath(pathConfig.utils),
659
+ primitives: normalizePath(pathConfig.primitives),
660
+ components: normalizePath(pathConfig.components),
661
+ blocks: normalizePath(pathConfig.blocks),
662
+ hooks: normalizePath(pathConfig.hooks),
663
+ animations: normalizePath(pathConfig.animations)
648
664
  },
649
665
  packageManager: structure.packageManager,
650
666
  typescript: structure.isTypeScript,
651
667
  framework: structure.framework,
652
668
  tailwind: {
653
- css: pathConfig.styles
669
+ css: normalizePath(pathConfig.styles)
654
670
  },
655
671
  aliases: {
656
- "@": structure.baseDir.replace(/\/$/, "") || ".",
657
- "@/components": path.dirname(pathConfig.components).replace(/\/$/, ""),
658
- "@/lib": pathConfig.lib.replace(/\/$/, ""),
659
- "@/hooks": pathConfig.hooks.replace(/\/$/, "")
672
+ "@": normalizePath(structure.baseDir.replace(/\/$/, "") || "."),
673
+ "@/components": normalizePath(
674
+ path.dirname(pathConfig.components).replace(/\/$/, "")
675
+ ),
676
+ "@/lib": normalizePath(pathConfig.lib.replace(/\/$/, "")),
677
+ "@/hooks": normalizePath(pathConfig.hooks.replace(/\/$/, ""))
660
678
  }
661
679
  };
662
680
  await fs.writeJson(configPath, config, { spaces: 2 });
@@ -1300,54 +1318,100 @@ async function loadConfig() {
1300
1318
  }
1301
1319
  function transformImportsForConfig(content, config) {
1302
1320
  let transformed = content;
1303
- const primitivesPath = config.paths.primitives.replace(/^\.\//, "").replace(/\/$/, "");
1321
+ const paths = config?.paths && config?.aliases ? {
1322
+ primitives: `${config.aliases["@/components"]}/${config.paths.primitives.split("/").pop()}`,
1323
+ components: `${config.aliases["@/components"]}/${config.paths.components.split("/").pop()}`,
1324
+ blocks: `${config.aliases["@/components"]}/${config.paths.blocks.split("/").pop()}`,
1325
+ animations: `${config.aliases["@/components"]}/${config.paths.animations.split("/").pop()}`,
1326
+ utils: `${config.aliases["@/lib"]}/${config.paths.utils.split("/").pop()}`
1327
+ } : {
1328
+ primitives: "components/primitives",
1329
+ components: "components",
1330
+ blocks: "components/blocks",
1331
+ animations: "components/animations",
1332
+ utils: "lib/utils"
1333
+ };
1304
1334
  transformed = transformed.replace(
1305
- /@\/components\/primitives/g,
1306
- `@/${primitivesPath}`
1335
+ /import\s+{([^}]+)}\s+from\s+["']@\/components\/primitives["']/g,
1336
+ (match, imports) => {
1337
+ const componentNames = imports.split(",").map(
1338
+ (imp) => imp?.trim().split(/\s+as\s+/)[0]?.trim() || ""
1339
+ );
1340
+ const primitivesPath = paths.primitives.replace(/^\.\//, "").replace(/\/$/, "");
1341
+ return `import {${imports}} from "@/${primitivesPath}/${componentNames[0].toLowerCase()}"`;
1342
+ }
1307
1343
  );
1308
1344
  transformed = transformed.replace(
1309
- /@\/components\/ui/g,
1310
- `@/${primitivesPath}`
1345
+ /import\s+{([^}]+)}\s+from\s+["']@\/components\/ui["']/g,
1346
+ (match, imports) => {
1347
+ const componentNames = imports.split(",").map(
1348
+ (imp) => imp?.trim().split(/\s+as\s+/)[0]?.trim() || ""
1349
+ );
1350
+ const primitivesPath = paths.primitives.replace(/^\.\//, "").replace(/\/$/, "");
1351
+ return `import {${imports}} from "@/${primitivesPath}/${componentNames[0].toLowerCase()}"`;
1352
+ }
1311
1353
  );
1312
- const componentsPath = config.paths.components.replace(/^\.\//, "").replace(/\/$/, "");
1313
1354
  transformed = transformed.replace(
1314
- /@\/components\/components/g,
1315
- `@/${componentsPath}`
1355
+ /import\s+{([^}]+)}\s+from\s+["']@\/components\/components["']/g,
1356
+ (match, imports) => {
1357
+ const componentNames = imports.split(",").map(
1358
+ (imp) => imp?.trim().split(/\s+as\s+/)[0]?.trim() || ""
1359
+ );
1360
+ const componentsPath = paths.components.replace(/^\.\//, "").replace(/\/$/, "");
1361
+ return `import {${imports}} from "@/${componentsPath}/${componentNames[0].toLowerCase()}"`;
1362
+ }
1316
1363
  );
1317
- const blocksPath = config.paths.blocks.replace(/^\.\//, "").replace(/\/$/, "");
1318
1364
  transformed = transformed.replace(
1319
- /@\/components\/blocks/g,
1320
- `@/${blocksPath}`
1365
+ /import\s+{([^}]+)}\s+from\s+["']@\/components\/blocks["']/g,
1366
+ (match, imports) => {
1367
+ const componentNames = imports.split(",").map(
1368
+ (imp) => imp?.trim().split(/\s+as\s+/)[0]?.trim() || ""
1369
+ );
1370
+ const blocksPath = paths.blocks.replace(/^\.\//, "").replace(/\/$/, "");
1371
+ return `import {${imports}} from "@/${blocksPath}/${componentNames[0].toLowerCase()}"`;
1372
+ }
1321
1373
  );
1322
- const animationsPath = config.paths.animations.replace(/^\.\//, "").replace(/\/$/, "");
1323
1374
  transformed = transformed.replace(
1324
- /@\/components\/animations/g,
1325
- `@/${animationsPath}`
1375
+ /import\s+{([^}]+)}\s+from\s+["']@\/components\/animations["']/g,
1376
+ (match, imports) => {
1377
+ const componentNames = imports.split(",").map(
1378
+ (imp) => imp?.trim().split(/\s+as\s+/)[0]?.trim() || ""
1379
+ );
1380
+ const animationsPath = paths.animations.replace(/^\.\//, "").replace(/\/$/, "");
1381
+ return `import {${imports}} from "@/${animationsPath}/${componentNames[0].toLowerCase()}"`;
1382
+ }
1326
1383
  );
1327
- const utilsPath = config.paths.utils.replace(/^\.\//, "").replace(/\/$/, "").replace(/\.(ts|js)$/, "");
1384
+ const utilsPath = paths.utils.replace(/^\.\//, "").replace(/\/$/, "").replace(/\.(ts|js)$/, "");
1328
1385
  transformed = transformed.replace(/@\/lib\/utils/g, `@/${utilsPath}`);
1329
1386
  return transformed;
1330
1387
  }
1331
1388
  function resolveComponentPath(originalPath, category, config) {
1389
+ const paths = config?.paths || {
1390
+ primitives: "components/primitives",
1391
+ components: "components",
1392
+ blocks: "components/blocks",
1393
+ animations: "components/animations",
1394
+ utils: "lib/utils"
1395
+ };
1332
1396
  if (originalPath === "lib/utils.ts") {
1333
- return config.paths.utils || "lib/utils.ts";
1397
+ return paths.utils || "lib/utils.ts";
1334
1398
  }
1335
- const categoryPath = config.paths[category] || config.paths.components;
1399
+ const categoryPath = paths[category] || paths.components;
1336
1400
  const fileName = path3.basename(originalPath);
1337
1401
  const componentName = path3.dirname(originalPath).split("/").pop() || "";
1338
1402
  if (category === "primitives") {
1339
1403
  return path3.join(categoryPath, componentName, fileName);
1340
1404
  } else if (category === "components") {
1341
- return path3.join(config.paths.components, componentName, fileName);
1405
+ return path3.join(paths.components, componentName, fileName);
1342
1406
  } else if (category === "blocks") {
1343
1407
  return path3.join(
1344
- config.paths.blocks || path3.join(config.paths.components, "blocks"),
1408
+ paths.blocks || path3.join(paths.components, "blocks"),
1345
1409
  componentName,
1346
1410
  fileName
1347
1411
  );
1348
1412
  } else if (category === "animations") {
1349
1413
  return path3.join(
1350
- config.paths.animations || path3.join(config.paths.components, "animations"),
1414
+ paths.animations || path3.join(paths.components, "animations"),
1351
1415
  componentName,
1352
1416
  fileName
1353
1417
  );
@@ -1355,18 +1419,28 @@ function resolveComponentPath(originalPath, category, config) {
1355
1419
  return originalPath;
1356
1420
  }
1357
1421
  function getImportPath(componentData, config) {
1358
- const componentName = path3.basename(componentData.files[0].path, ".tsx");
1422
+ const paths = config?.paths || {
1423
+ primitives: "components/primitives",
1424
+ components: "components",
1425
+ blocks: "components/blocks",
1426
+ animations: "components/animations",
1427
+ utils: "lib/utils"
1428
+ };
1429
+ const componentName = path3.basename(
1430
+ componentData.files[0]?.path || "",
1431
+ ".tsx"
1432
+ );
1359
1433
  if (componentData.category === "primitives") {
1360
- const primitivesPath = config.paths.primitives.replace(/^\.\//, "").replace(/\/$/, "");
1434
+ const primitivesPath = paths.primitives.replace(/^\.\//, "").replace(/\/$/, "");
1361
1435
  return `@/${primitivesPath}/${componentName}`;
1362
1436
  } else if (componentData.category === "components") {
1363
- const componentsPath = config.paths.components.replace(/^\.\//, "").replace(/\/$/, "");
1437
+ const componentsPath = paths.components.replace(/^\.\//, "").replace(/\/$/, "");
1364
1438
  return `@/${componentsPath}/${componentName}`;
1365
1439
  } else if (componentData.category === "blocks") {
1366
- const blocksPath = config.paths.blocks.replace(/^\.\//, "").replace(/\/$/, "");
1440
+ const blocksPath = paths.blocks.replace(/^\.\//, "").replace(/\/$/, "");
1367
1441
  return `@/${blocksPath}/${componentName}`;
1368
1442
  } else if (componentData.category === "animations") {
1369
- const animationsPath = config.paths.animations.replace(/^\.\//, "").replace(/\/$/, "");
1443
+ const animationsPath = paths.animations.replace(/^\.\//, "").replace(/\/$/, "");
1370
1444
  return `@/${animationsPath}/${componentName}`;
1371
1445
  }
1372
1446
  return `@/components/${componentName}`;