@foundrykit/cli 1.0.3 → 1.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.
package/dist/index.js CHANGED
@@ -345,7 +345,14 @@ async function updateLayoutImport(globalCssPath) {
345
345
  }
346
346
  async function createDirectories() {
347
347
  console.log(chalk.blue("\u{1F4C1} Creating component directories..."));
348
- const dirs = ["components/ui", "components/blocks", "lib", "hooks"];
348
+ const dirs = [
349
+ "components/primitives",
350
+ "components/components",
351
+ "components/blocks",
352
+ "components/animations",
353
+ "lib",
354
+ "hooks"
355
+ ];
349
356
  for (const dir of dirs) {
350
357
  await fs.ensureDir(path.join(process.cwd(), dir));
351
358
  }
@@ -414,8 +421,8 @@ async function createConfigFile(options) {
414
421
  registry: "https://foundry.umiflow.com",
415
422
  paths: {
416
423
  utils: "./src/lib/utils.ts",
417
- primitives: "./src/components/ui",
418
- components: "./src/components",
424
+ primitives: "./src/components/primitives",
425
+ components: "./src/components/components",
419
426
  blocks: "./src/components/blocks",
420
427
  hooks: "./src/hooks",
421
428
  animations: "./src/components/animations"
@@ -439,8 +446,8 @@ async function createConfigFile(options) {
439
446
  if (hasAppDir && !fs.existsSync(path.join(process.cwd(), "src/app"))) {
440
447
  config.paths = {
441
448
  utils: "./lib/utils.ts",
442
- primitives: "./components/ui",
443
- components: "./components",
449
+ primitives: "./components/primitives",
450
+ components: "./components/components",
444
451
  blocks: "./components/blocks",
445
452
  hooks: "./hooks",
446
453
  animations: "./components/animations"
@@ -935,14 +942,6 @@ async function addSingleComponent(id, options) {
935
942
  console.log(chalk4.blue("\u{1F4E6} Installing required dependencies..."));
936
943
  for (const dep of componentData.registryDependencies) {
937
944
  try {
938
- if (dep === "primitives") {
939
- console.log(
940
- chalk4.gray(
941
- ` \u23ED Skipping "${dep}" - primitive dependencies will be handled separately`
942
- )
943
- );
944
- continue;
945
- }
946
945
  const depData = await registry.getComponent(dep);
947
946
  const hasExisting = await hasConflictingFiles(depData, options);
948
947
  if (!hasExisting) {
@@ -976,22 +975,26 @@ async function validateProject2() {
976
975
  "No package.json found. Please run this command in a project root."
977
976
  );
978
977
  }
979
- const packageJson2 = await fs3.readJson(packageJsonPath);
980
- const dependencies = {
981
- ...packageJson2.dependencies,
982
- ...packageJson2.devDependencies
983
- };
984
- const hasFoundryKit = Object.keys(dependencies).some(
985
- (dep) => dep.startsWith("@foundrykit/")
986
- );
987
- if (!hasFoundryKit && !dependencies.next) {
978
+ const configPath = path3.join(process.cwd(), "foundrykit.config.json");
979
+ if (!fs3.existsSync(configPath)) {
988
980
  throw new Error('FoundryKit not initialized. Run "foundrykit init" first.');
989
981
  }
990
982
  }
991
983
  async function hasConflictingFiles(componentData, options) {
984
+ const config = await loadConfig();
992
985
  const basePath = options.path || process.cwd();
993
986
  for (const file of componentData.files) {
994
- const filePath = path3.join(basePath, file.path);
987
+ let resolvedPath;
988
+ if (componentData.id === "utils" || file.path === "lib/utils.ts") {
989
+ resolvedPath = config.paths.utils || "lib/utils.ts";
990
+ } else {
991
+ resolvedPath = resolveComponentPath(
992
+ file.path,
993
+ componentData.category,
994
+ config
995
+ );
996
+ }
997
+ const filePath = path3.join(basePath, resolvedPath);
995
998
  if (fs3.existsSync(filePath)) {
996
999
  return true;
997
1000
  }
@@ -999,13 +1002,30 @@ async function hasConflictingFiles(componentData, options) {
999
1002
  return false;
1000
1003
  }
1001
1004
  async function installComponentFiles(componentData, options) {
1005
+ const config = await loadConfig();
1002
1006
  const basePath = options.path || process.cwd();
1003
1007
  console.log(chalk4.blue("\u{1F4DD} Installing component files..."));
1004
1008
  for (const file of componentData.files) {
1005
- const filePath = path3.join(basePath, file.path);
1009
+ let resolvedPath;
1010
+ if (componentData.id === "utils" || file.path === "lib/utils.ts") {
1011
+ resolvedPath = config.paths.utils || "lib/utils.ts";
1012
+ } else {
1013
+ resolvedPath = resolveComponentPath(
1014
+ file.path,
1015
+ componentData.category,
1016
+ config
1017
+ );
1018
+ }
1019
+ const filePath = path3.join(basePath, resolvedPath);
1006
1020
  await fs3.ensureDir(path3.dirname(filePath));
1021
+ if (!file.content || file.content.trim() === "") {
1022
+ console.log(
1023
+ chalk4.yellow(` \u26A0 Skipping ${resolvedPath} - no content available`)
1024
+ );
1025
+ continue;
1026
+ }
1007
1027
  await fs3.writeFile(filePath, file.content);
1008
- console.log(chalk4.green(` \u2713 ${file.path}`));
1028
+ console.log(chalk4.green(` \u2713 ${resolvedPath}`));
1009
1029
  }
1010
1030
  }
1011
1031
  async function handlePackageDependencies(componentData) {
@@ -1013,22 +1033,6 @@ async function handlePackageDependencies(componentData) {
1013
1033
  if (componentData.packageDependencies?.length) {
1014
1034
  componentData.packageDependencies.forEach((dep) => allDependencies.add(dep));
1015
1035
  }
1016
- if (componentData.registryDependencies?.includes("utils")) {
1017
- allDependencies.add("clsx");
1018
- allDependencies.add("tailwind-merge");
1019
- }
1020
- if (componentData.registryDependencies?.includes("primitives")) {
1021
- allDependencies.add("@radix-ui/react-slot");
1022
- allDependencies.add("class-variance-authority");
1023
- allDependencies.add("clsx");
1024
- allDependencies.add("tailwind-merge");
1025
- }
1026
- if (componentData.id === "button") {
1027
- allDependencies.add("class-variance-authority");
1028
- }
1029
- if (componentData.id === "search-bar") {
1030
- allDependencies.add("lucide-react");
1031
- }
1032
1036
  if (allDependencies.size === 0) {
1033
1037
  return;
1034
1038
  }
@@ -1084,47 +1088,70 @@ async function detectPackageManager2() {
1084
1088
  }
1085
1089
  return "pnpm";
1086
1090
  }
1087
- function showUsageExample(componentData) {
1091
+ async function showUsageExample(componentData) {
1092
+ const config = await loadConfig();
1088
1093
  console.log(chalk4.cyan("\n\u{1F4A1} Usage:"));
1089
1094
  const componentName = componentData.name.replace(/\s+/g, "");
1090
- if (componentData.category === "primitives" || componentData.category === "components") {
1091
- console.log(
1092
- chalk4.gray(
1093
- `import { ${componentName} } from "@/components/ui/${componentData.id}"`
1094
- )
1095
+ const importPath = getImportPath(componentData, config);
1096
+ console.log(chalk4.gray(`import { ${componentName} } from "${importPath}"`));
1097
+ if (componentData.usageExample) {
1098
+ console.log(chalk4.gray(`
1099
+ ${componentData.usageExample}`));
1100
+ }
1101
+ }
1102
+ async function loadConfig() {
1103
+ const configPath = path3.join(process.cwd(), "foundrykit.config.json");
1104
+ if (!fs3.existsSync(configPath)) {
1105
+ throw new Error(
1106
+ 'Configuration file not found. Run "foundrykit init" first.'
1095
1107
  );
1096
- } else if (componentData.category === "blocks") {
1097
- console.log(
1098
- chalk4.gray(
1099
- `import { ${componentName} } from "@/components/blocks/${componentData.id}"`
1100
- )
1108
+ }
1109
+ return fs3.readJson(configPath);
1110
+ }
1111
+ function resolveComponentPath(originalPath, category, config) {
1112
+ if (originalPath === "lib/utils.ts") {
1113
+ return config.paths.utils || "lib/utils.ts";
1114
+ }
1115
+ const categoryPath = config.paths[category] || config.paths.components;
1116
+ const fileName = path3.basename(originalPath);
1117
+ const componentName = path3.dirname(originalPath).split("/").pop() || "";
1118
+ if (category === "primitives") {
1119
+ return path3.join(categoryPath, componentName, fileName);
1120
+ } else if (category === "components") {
1121
+ return path3.join(
1122
+ config.paths.components,
1123
+ "components",
1124
+ componentName,
1125
+ fileName
1101
1126
  );
1102
- } else if (componentData.category === "animations") {
1103
- console.log(
1104
- chalk4.gray(
1105
- `import { ${componentName} } from "@/components/animations/${componentData.id}"`
1106
- )
1127
+ } else if (category === "blocks") {
1128
+ return path3.join(
1129
+ config.paths.blocks || path3.join(config.paths.components, "blocks"),
1130
+ componentName,
1131
+ fileName
1107
1132
  );
1108
- }
1109
- if (componentData.id === "button") {
1110
- console.log(chalk4.gray("\n<Button>Click me</Button>"));
1111
- console.log(chalk4.gray('<Button variant="outline">Outline</Button>'));
1112
- } else if (componentData.id === "input") {
1113
- console.log(chalk4.gray('\n<Input placeholder="Enter text..." />'));
1114
- } else if (componentData.id.includes("hero")) {
1115
- console.log(chalk4.gray(`
1116
- <${componentName} />`));
1117
- } else if (componentData.id === "card") {
1118
- console.log(chalk4.gray("\n<Card>"));
1119
- console.log(chalk4.gray(" <CardHeader>"));
1120
- console.log(chalk4.gray(" <CardTitle>Title</CardTitle>"));
1121
- console.log(
1122
- chalk4.gray(" <CardDescription>Description</CardDescription>")
1133
+ } else if (category === "animations") {
1134
+ return path3.join(
1135
+ config.paths.animations || path3.join(config.paths.components, "animations"),
1136
+ componentName,
1137
+ fileName
1123
1138
  );
1124
- console.log(chalk4.gray(" </CardHeader>"));
1125
- console.log(chalk4.gray(" <CardContent>Content</CardContent>"));
1126
- console.log(chalk4.gray("</Card>"));
1127
1139
  }
1140
+ return originalPath;
1141
+ }
1142
+ function getImportPath(componentData, config) {
1143
+ const aliases = config.aliases || {};
1144
+ const componentName = path3.basename(componentData.files[0].path, ".tsx");
1145
+ if (componentData.category === "primitives") {
1146
+ return `@/components/ui/${componentName}`;
1147
+ } else if (componentData.category === "components") {
1148
+ return `@/components/components/${componentName}`;
1149
+ } else if (componentData.category === "blocks") {
1150
+ return `@/components/blocks/${componentName}`;
1151
+ } else if (componentData.category === "animations") {
1152
+ return `@/components/animations/${componentName}`;
1153
+ }
1154
+ return `@/components/${componentName}`;
1128
1155
  }
1129
1156
 
1130
1157
  // src/commands/update.ts