@foundrykit/cli 1.0.8 → 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,21 @@
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
+
11
+ ## 1.0.9
12
+
13
+ ### Patch Changes
14
+
15
+ - Update to config version management and config paths
16
+ - Updated dependencies
17
+ - @foundrykit/types@1.0.5
18
+
3
19
  ## 1.0.8
4
20
 
5
21
  ### Patch Changes
package/dist/cli.js CHANGED
@@ -14,6 +14,14 @@ import path from "path";
14
14
  import inquirer from "inquirer";
15
15
  import { exec } from "child_process";
16
16
  import { promisify } from "util";
17
+
18
+ // src/lib/constants.ts
19
+ var CLI_VERSION = "1.0.8";
20
+ var DEFAULT_REGISTRY_URL = "https://foundry.umiflow.com";
21
+ var CACHE_TTL = 24 * 60 * 60 * 1e3;
22
+ var CACHE_DIR = ".foundrykit";
23
+
24
+ // src/commands/init.ts
17
25
  function initCommand() {
18
26
  return new Command("init").description("Initialize FoundryKit in your project").option("-f, --force", "overwrite existing files").option("--skip-install", "skip installing dependencies").option("--skip-prompts", "use default paths without prompting").action(async (options) => {
19
27
  try {
@@ -46,6 +54,7 @@ function initCommand() {
46
54
  if (!options.skipInstall) {
47
55
  await installDependencies();
48
56
  }
57
+ console.log(pathConfig);
49
58
  await createConfigFile(options, projectStructure, pathConfig);
50
59
  await installUtils(pathConfig);
51
60
  await setupTailwindV4(
@@ -586,17 +595,26 @@ export function cn(...inputs: ClassValue[]) {
586
595
  path.dirname(pathConfig.components),
587
596
  `theme-provider${structure.isTypeScript ? ".tsx" : ".jsx"}`
588
597
  );
589
- const providersContent = `'use client';
598
+ const providersContent = `
599
+ 'use client';
590
600
 
591
- import { ThemeProvider } from 'next-themes';
601
+ import type * as React from 'react';
602
+ import { ThemeProvider as NextThemesProvider } from 'next-themes';
592
603
 
593
604
  export function ThemeProvider({ children }: { children: React.ReactNode }) {
594
605
  return (
595
- <ThemeProvider attribute="class" defaultTheme="system" enableSystem>
606
+ <NextThemesProvider
607
+ attribute='class'
608
+ defaultTheme='system'
609
+ enableSystem
610
+ disableTransitionOnChange
611
+ enableColorScheme
612
+ >
596
613
  {children}
597
- </ThemeProvider>
614
+ </NextThemesProvider>
598
615
  );
599
616
  }
617
+
600
618
  `;
601
619
  if (!fs.existsSync(providersPath)) {
602
620
  await fs.writeFile(providersPath, providersContent);
@@ -627,28 +645,36 @@ async function createConfigFile(options, structure, pathConfig) {
627
645
  console.log(chalk.yellow("\u26A0\uFE0F Configuration file already exists"));
628
646
  return;
629
647
  }
648
+ const normalizePath = (p) => {
649
+ if (p.startsWith("./") || p.startsWith("../") || path.isAbsolute(p)) {
650
+ return p;
651
+ }
652
+ return `./${p}`;
653
+ };
630
654
  const config = {
631
- version: "1.0.0",
632
- registry: "https://foundry.umiflow.com",
655
+ version: CLI_VERSION,
656
+ registry: DEFAULT_REGISTRY_URL,
633
657
  paths: {
634
- utils: pathConfig.utils,
635
- primitives: pathConfig.primitives,
636
- components: pathConfig.components,
637
- blocks: pathConfig.blocks,
638
- hooks: pathConfig.hooks,
639
- 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)
640
664
  },
641
665
  packageManager: structure.packageManager,
642
666
  typescript: structure.isTypeScript,
643
667
  framework: structure.framework,
644
668
  tailwind: {
645
- css: pathConfig.styles
669
+ css: normalizePath(pathConfig.styles)
646
670
  },
647
671
  aliases: {
648
- "@": structure.baseDir.replace(/\/$/, "") || ".",
649
- "@/components": path.dirname(pathConfig.components).replace(/\/$/, ""),
650
- "@/lib": pathConfig.lib.replace(/\/$/, ""),
651
- "@/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(/\/$/, ""))
652
678
  }
653
679
  };
654
680
  await fs.writeJson(configPath, config, { spaces: 2 });
@@ -684,10 +710,9 @@ import path2 from "path";
684
710
  import os from "os";
685
711
  import chalk2 from "chalk";
686
712
  var DEFAULT_CONFIG = {
687
- registryUrl: process.env.FOUNDRYKIT_REGISTRY_URL || "https://foundry.umiflow.com",
688
- cacheDir: path2.join(os.homedir(), ".foundrykit", "cache"),
689
- cacheMaxAge: 1e3 * 60 * 60 * 24
690
- // 24 hours
713
+ registryUrl: process.env.FOUNDRYKIT_REGISTRY_URL || DEFAULT_REGISTRY_URL,
714
+ cacheDir: path2.join(os.homedir(), CACHE_DIR, "cache"),
715
+ cacheMaxAge: CACHE_TTL
691
716
  };
692
717
  var RegistryService = class {
693
718
  config;
@@ -1138,6 +1163,16 @@ async function addSingleComponent(id, options) {
1138
1163
  throw error;
1139
1164
  }
1140
1165
  }
1166
+ async function updateConfigVersion() {
1167
+ const configPath = path3.join(process.cwd(), "foundrykit.config.json");
1168
+ if (fs3.existsSync(configPath)) {
1169
+ const config = await fs3.readJson(configPath);
1170
+ if (config.version !== CLI_VERSION) {
1171
+ config.version = CLI_VERSION;
1172
+ await fs3.writeJson(configPath, config, { spaces: 2 });
1173
+ }
1174
+ }
1175
+ }
1141
1176
  async function validateProject2() {
1142
1177
  const packageJsonPath = path3.join(process.cwd(), "package.json");
1143
1178
  if (!fs3.existsSync(packageJsonPath)) {
@@ -1149,6 +1184,7 @@ async function validateProject2() {
1149
1184
  if (!fs3.existsSync(configPath)) {
1150
1185
  throw new Error('FoundryKit not initialized. Run "foundrykit init" first.');
1151
1186
  }
1187
+ await updateConfigVersion();
1152
1188
  }
1153
1189
  async function hasConflictingFiles(componentData, options) {
1154
1190
  const config = await loadConfig();
@@ -1194,9 +1230,11 @@ async function installComponentFiles(componentData, options) {
1194
1230
  );
1195
1231
  continue;
1196
1232
  }
1197
- await fs3.writeFile(filePath, file.content);
1198
- console.log(chalk4.green(` \u2713 ${resolvedPath}`));
1233
+ const transformedContent = transformImportsForConfig(file.content, config);
1234
+ await fs3.writeFile(filePath, transformedContent);
1235
+ console.log(chalk4.gray(` \u2713 Created ${resolvedPath}`));
1199
1236
  }
1237
+ await updateConfigVersion();
1200
1238
  }
1201
1239
  async function handlePackageDependencies(componentData) {
1202
1240
  const allDependencies = /* @__PURE__ */ new Set();
@@ -1278,31 +1316,96 @@ async function loadConfig() {
1278
1316
  }
1279
1317
  return fs3.readJson(configPath);
1280
1318
  }
1319
+ function transformImportsForConfig(content, config) {
1320
+ let transformed = content;
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
+ };
1328
+ transformed = transformed.replace(
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
+ }
1337
+ );
1338
+ transformed = transformed.replace(
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
+ }
1347
+ );
1348
+ transformed = transformed.replace(
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
+ }
1357
+ );
1358
+ transformed = transformed.replace(
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
+ }
1367
+ );
1368
+ transformed = transformed.replace(
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
+ }
1377
+ );
1378
+ const utilsPath = paths.utils.replace(/^\.\//, "").replace(/\/$/, "").replace(/\.(ts|js)$/, "");
1379
+ transformed = transformed.replace(/@\/lib\/utils/g, `@/${utilsPath}`);
1380
+ return transformed;
1381
+ }
1281
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
+ };
1282
1390
  if (originalPath === "lib/utils.ts") {
1283
- return config.paths.utils || "lib/utils.ts";
1391
+ return paths.utils || "lib/utils.ts";
1284
1392
  }
1285
- const categoryPath = config.paths[category] || config.paths.components;
1393
+ const categoryPath = paths[category] || paths.components;
1286
1394
  const fileName = path3.basename(originalPath);
1287
1395
  const componentName = path3.dirname(originalPath).split("/").pop() || "";
1288
1396
  if (category === "primitives") {
1289
1397
  return path3.join(categoryPath, componentName, fileName);
1290
1398
  } else if (category === "components") {
1291
- return path3.join(
1292
- config.paths.components,
1293
- "components",
1294
- componentName,
1295
- fileName
1296
- );
1399
+ return path3.join(paths.components, componentName, fileName);
1297
1400
  } else if (category === "blocks") {
1298
1401
  return path3.join(
1299
- config.paths.blocks || path3.join(config.paths.components, "blocks"),
1402
+ paths.blocks || path3.join(paths.components, "blocks"),
1300
1403
  componentName,
1301
1404
  fileName
1302
1405
  );
1303
1406
  } else if (category === "animations") {
1304
1407
  return path3.join(
1305
- config.paths.animations || path3.join(config.paths.components, "animations"),
1408
+ paths.animations || path3.join(paths.components, "animations"),
1306
1409
  componentName,
1307
1410
  fileName
1308
1411
  );
@@ -1310,16 +1413,29 @@ function resolveComponentPath(originalPath, category, config) {
1310
1413
  return originalPath;
1311
1414
  }
1312
1415
  function getImportPath(componentData, config) {
1313
- const aliases = config.aliases || {};
1314
- 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
+ );
1315
1427
  if (componentData.category === "primitives") {
1316
- return `@/components/ui/${componentName}`;
1428
+ const primitivesPath = paths.primitives.replace(/^\.\//, "").replace(/\/$/, "");
1429
+ return `@/${primitivesPath}/${componentName}`;
1317
1430
  } else if (componentData.category === "components") {
1318
- return `@/components/components/${componentName}`;
1431
+ const componentsPath = paths.components.replace(/^\.\//, "").replace(/\/$/, "");
1432
+ return `@/${componentsPath}/${componentName}`;
1319
1433
  } else if (componentData.category === "blocks") {
1320
- return `@/components/blocks/${componentName}`;
1434
+ const blocksPath = paths.blocks.replace(/^\.\//, "").replace(/\/$/, "");
1435
+ return `@/${blocksPath}/${componentName}`;
1321
1436
  } else if (componentData.category === "animations") {
1322
- return `@/components/animations/${componentName}`;
1437
+ const animationsPath = paths.animations.replace(/^\.\//, "").replace(/\/$/, "");
1438
+ return `@/${animationsPath}/${componentName}`;
1323
1439
  }
1324
1440
  return `@/components/${componentName}`;
1325
1441
  }