@foundrykit/cli 1.0.9 → 1.0.10

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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # @foundrykit/cli
2
2
 
3
+ ## 1.0.10
4
+
5
+ ### Patch Changes
6
+
7
+ - Update to add command, import transformations and configs for many files
8
+ - Updated dependencies
9
+ - @foundrykit/types@1.0.6
10
+
3
11
  ## 1.0.9
4
12
 
5
13
  ### Patch Changes
package/dist/cli.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,94 @@ 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 || {
1322
+ primitives: "components/primitives",
1323
+ components: "components",
1324
+ blocks: "components/blocks",
1325
+ animations: "components/animations",
1326
+ utils: "lib/utils"
1327
+ };
1304
1328
  transformed = transformed.replace(
1305
- /@\/components\/primitives/g,
1306
- `@/${primitivesPath}`
1329
+ /import\s+{([^}]+)}\s+from\s+["']@\/components\/primitives["']/g,
1330
+ (match, imports) => {
1331
+ const componentNames = imports.split(",").map(
1332
+ (imp) => imp?.trim().split(/\s+as\s+/)[0]?.trim() || ""
1333
+ );
1334
+ const primitivesPath = paths.primitives.replace(/^\.\//, "").replace(/\/$/, "");
1335
+ return `import {${imports}} from "@/${primitivesPath}/${componentNames[0].toLowerCase()}"`;
1336
+ }
1307
1337
  );
1308
1338
  transformed = transformed.replace(
1309
- /@\/components\/ui/g,
1310
- `@/${primitivesPath}`
1339
+ /import\s+{([^}]+)}\s+from\s+["']@\/components\/ui["']/g,
1340
+ (match, imports) => {
1341
+ const componentNames = imports.split(",").map(
1342
+ (imp) => imp?.trim().split(/\s+as\s+/)[0]?.trim() || ""
1343
+ );
1344
+ const primitivesPath = paths.primitives.replace(/^\.\//, "").replace(/\/$/, "");
1345
+ return `import {${imports}} from "@/${primitivesPath}/${componentNames[0].toLowerCase()}"`;
1346
+ }
1311
1347
  );
1312
- const componentsPath = config.paths.components.replace(/^\.\//, "").replace(/\/$/, "");
1313
1348
  transformed = transformed.replace(
1314
- /@\/components\/components/g,
1315
- `@/${componentsPath}`
1349
+ /import\s+{([^}]+)}\s+from\s+["']@\/components\/components["']/g,
1350
+ (match, imports) => {
1351
+ const componentNames = imports.split(",").map(
1352
+ (imp) => imp?.trim().split(/\s+as\s+/)[0]?.trim() || ""
1353
+ );
1354
+ const componentsPath = paths.components.replace(/^\.\//, "").replace(/\/$/, "");
1355
+ return `import {${imports}} from "@/${componentsPath}/${componentNames[0].toLowerCase()}"`;
1356
+ }
1316
1357
  );
1317
- const blocksPath = config.paths.blocks.replace(/^\.\//, "").replace(/\/$/, "");
1318
1358
  transformed = transformed.replace(
1319
- /@\/components\/blocks/g,
1320
- `@/${blocksPath}`
1359
+ /import\s+{([^}]+)}\s+from\s+["']@\/components\/blocks["']/g,
1360
+ (match, imports) => {
1361
+ const componentNames = imports.split(",").map(
1362
+ (imp) => imp?.trim().split(/\s+as\s+/)[0]?.trim() || ""
1363
+ );
1364
+ const blocksPath = paths.blocks.replace(/^\.\//, "").replace(/\/$/, "");
1365
+ return `import {${imports}} from "@/${blocksPath}/${componentNames[0].toLowerCase()}"`;
1366
+ }
1321
1367
  );
1322
- const animationsPath = config.paths.animations.replace(/^\.\//, "").replace(/\/$/, "");
1323
1368
  transformed = transformed.replace(
1324
- /@\/components\/animations/g,
1325
- `@/${animationsPath}`
1369
+ /import\s+{([^}]+)}\s+from\s+["']@\/components\/animations["']/g,
1370
+ (match, imports) => {
1371
+ const componentNames = imports.split(",").map(
1372
+ (imp) => imp?.trim().split(/\s+as\s+/)[0]?.trim() || ""
1373
+ );
1374
+ const animationsPath = paths.animations.replace(/^\.\//, "").replace(/\/$/, "");
1375
+ return `import {${imports}} from "@/${animationsPath}/${componentNames[0].toLowerCase()}"`;
1376
+ }
1326
1377
  );
1327
- const utilsPath = config.paths.utils.replace(/^\.\//, "").replace(/\/$/, "").replace(/\.(ts|js)$/, "");
1378
+ const utilsPath = paths.utils.replace(/^\.\//, "").replace(/\/$/, "").replace(/\.(ts|js)$/, "");
1328
1379
  transformed = transformed.replace(/@\/lib\/utils/g, `@/${utilsPath}`);
1329
1380
  return transformed;
1330
1381
  }
1331
1382
  function resolveComponentPath(originalPath, category, config) {
1383
+ const paths = config?.paths || {
1384
+ primitives: "components/primitives",
1385
+ components: "components",
1386
+ blocks: "components/blocks",
1387
+ animations: "components/animations",
1388
+ utils: "lib/utils"
1389
+ };
1332
1390
  if (originalPath === "lib/utils.ts") {
1333
- return config.paths.utils || "lib/utils.ts";
1391
+ return paths.utils || "lib/utils.ts";
1334
1392
  }
1335
- const categoryPath = config.paths[category] || config.paths.components;
1393
+ const categoryPath = paths[category] || paths.components;
1336
1394
  const fileName = path3.basename(originalPath);
1337
1395
  const componentName = path3.dirname(originalPath).split("/").pop() || "";
1338
1396
  if (category === "primitives") {
1339
1397
  return path3.join(categoryPath, componentName, fileName);
1340
1398
  } else if (category === "components") {
1341
- return path3.join(config.paths.components, componentName, fileName);
1399
+ return path3.join(paths.components, componentName, fileName);
1342
1400
  } else if (category === "blocks") {
1343
1401
  return path3.join(
1344
- config.paths.blocks || path3.join(config.paths.components, "blocks"),
1402
+ paths.blocks || path3.join(paths.components, "blocks"),
1345
1403
  componentName,
1346
1404
  fileName
1347
1405
  );
1348
1406
  } else if (category === "animations") {
1349
1407
  return path3.join(
1350
- config.paths.animations || path3.join(config.paths.components, "animations"),
1408
+ paths.animations || path3.join(paths.components, "animations"),
1351
1409
  componentName,
1352
1410
  fileName
1353
1411
  );
@@ -1355,18 +1413,28 @@ function resolveComponentPath(originalPath, category, config) {
1355
1413
  return originalPath;
1356
1414
  }
1357
1415
  function getImportPath(componentData, config) {
1358
- const componentName = path3.basename(componentData.files[0].path, ".tsx");
1416
+ const paths = config?.paths || {
1417
+ primitives: "components/primitives",
1418
+ components: "components",
1419
+ blocks: "components/blocks",
1420
+ animations: "components/animations",
1421
+ utils: "lib/utils"
1422
+ };
1423
+ const componentName = path3.basename(
1424
+ componentData.files[0]?.path || "",
1425
+ ".tsx"
1426
+ );
1359
1427
  if (componentData.category === "primitives") {
1360
- const primitivesPath = config.paths.primitives.replace(/^\.\//, "").replace(/\/$/, "");
1428
+ const primitivesPath = paths.primitives.replace(/^\.\//, "").replace(/\/$/, "");
1361
1429
  return `@/${primitivesPath}/${componentName}`;
1362
1430
  } else if (componentData.category === "components") {
1363
- const componentsPath = config.paths.components.replace(/^\.\//, "").replace(/\/$/, "");
1431
+ const componentsPath = paths.components.replace(/^\.\//, "").replace(/\/$/, "");
1364
1432
  return `@/${componentsPath}/${componentName}`;
1365
1433
  } else if (componentData.category === "blocks") {
1366
- const blocksPath = config.paths.blocks.replace(/^\.\//, "").replace(/\/$/, "");
1434
+ const blocksPath = paths.blocks.replace(/^\.\//, "").replace(/\/$/, "");
1367
1435
  return `@/${blocksPath}/${componentName}`;
1368
1436
  } else if (componentData.category === "animations") {
1369
- const animationsPath = config.paths.animations.replace(/^\.\//, "").replace(/\/$/, "");
1437
+ const animationsPath = paths.animations.replace(/^\.\//, "").replace(/\/$/, "");
1370
1438
  return `@/${animationsPath}/${componentName}`;
1371
1439
  }
1372
1440
  return `@/components/${componentName}`;