@foundrykit/cli 1.0.1 → 1.0.3

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,17 @@
1
1
  # @foundrykit/cli
2
2
 
3
+ ## 1.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Add GitHub production registry fetching support
8
+
9
+ ## 1.0.2
10
+
11
+ ### Patch Changes
12
+
13
+ - Updating to use live data
14
+
3
15
  ## 1.0.1
4
16
 
5
17
  ### Patch Changes
package/dist/cli.js CHANGED
@@ -14,10 +14,10 @@ import path from "path";
14
14
  import { execSync } from "child_process";
15
15
  import inquirer from "inquirer";
16
16
  function initCommand() {
17
- return new Command("init").description("Initialize FoundryKit in your Next.js project").option("-f, --force", "overwrite existing files").option("--skip-install", "skip installing dependencies").action(async (options) => {
17
+ return new Command("init").description("Initialize FoundryKit in your project").option("-f, --force", "overwrite existing files").option("--skip-install", "skip installing dependencies").action(async (options) => {
18
18
  try {
19
19
  console.log(chalk.blue("\u{1F680} Initializing FoundryKit..."));
20
- await validateNextJsProject();
20
+ await validateProject();
21
21
  if (!options.force && await isFoundryKitInitialized()) {
22
22
  const { shouldContinue } = await inquirer.prompt([
23
23
  {
@@ -35,6 +35,8 @@ function initCommand() {
35
35
  if (!options.skipInstall) {
36
36
  await installDependencies();
37
37
  }
38
+ await createConfigFile(options);
39
+ await installUtils();
38
40
  await setupTailwindV4();
39
41
  await createDirectories();
40
42
  await createExampleFiles();
@@ -43,14 +45,18 @@ function initCommand() {
43
45
  console.log(chalk.cyan("\n\u{1F4E6} Next steps:"));
44
46
  console.log(
45
47
  chalk.gray(
46
- " 1. Add a component: npx @foundrykit/cli add hero-minimal"
48
+ " 1. Add a component: pnpm dlx @foundrykit/cli add hero-minimal"
47
49
  )
48
50
  );
49
51
  console.log(
50
- chalk.gray(" 2. List available components: npx @foundrykit/cli list")
52
+ chalk.gray(
53
+ " 2. List available components: pnpm dlx @foundrykit/cli list"
54
+ )
51
55
  );
52
56
  console.log(
53
- chalk.gray(" 3. Check out the docs: https://foundrykit.dev")
57
+ chalk.gray(
58
+ " 3. Check out the docs: https://foundry-docs.umiflow.com"
59
+ )
54
60
  );
55
61
  } catch (error) {
56
62
  console.error(chalk.red("\u274C Failed to initialize FoundryKit:"));
@@ -61,7 +67,7 @@ function initCommand() {
61
67
  }
62
68
  });
63
69
  }
64
- async function validateNextJsProject() {
70
+ async function validateProject() {
65
71
  const packageJsonPath = path.join(process.cwd(), "package.json");
66
72
  if (!fs.existsSync(packageJsonPath)) {
67
73
  throw new Error(
@@ -81,82 +87,32 @@ async function validateNextJsProject() {
81
87
  console.log(chalk.green("\u2705 Next.js project detected"));
82
88
  }
83
89
  async function isFoundryKitInitialized() {
84
- const packageJsonPath = path.join(process.cwd(), "package.json");
85
- if (fs.existsSync(packageJsonPath)) {
86
- const packageJson2 = await fs.readJson(packageJsonPath);
87
- const dependencies = {
88
- ...packageJson2.dependencies,
89
- ...packageJson2.devDependencies
90
- };
91
- return Object.keys(dependencies).some(
92
- (dep) => dep.startsWith("@foundrykit/")
93
- );
94
- }
95
- return false;
90
+ const configPath = path.join(process.cwd(), "foundrykit.config.json");
91
+ return fs.existsSync(configPath);
96
92
  }
97
93
  async function installDependencies() {
98
- console.log(chalk.blue("\u{1F4E6} Installing FoundryKit dependencies..."));
99
- const isWorkspace = await checkIfWorkspace();
100
- if (isWorkspace) {
101
- console.log(
102
- chalk.yellow("\u26A0\uFE0F Workspace detected - skipping dependency installation")
103
- );
104
- console.log(chalk.gray("Dependencies are already available via workspace"));
105
- return;
106
- }
107
- const dependencies = [
108
- "@foundrykit/primitives",
109
- "@foundrykit/components",
110
- "@foundrykit/blocks",
111
- "@foundrykit/hooks",
112
- "@foundrykit/animation",
113
- "@foundrykit/tailwind"
114
- ];
94
+ console.log(chalk.blue("\u{1F4E6} Installing base dependencies..."));
95
+ const dependencies = ["clsx", "tailwind-merge"];
115
96
  try {
116
97
  const packageManager = detectPackageManager();
117
98
  console.log(chalk.gray(`Using ${packageManager}...`));
118
- const installCmd = packageManager === "npm" ? `npm install ${dependencies.join(" ")}` : packageManager === "yarn" ? `yarn add ${dependencies.join(" ")}` : `pnpm add ${dependencies.join(" ")}`;
99
+ const installCmd = packageManager === "npm" ? `npm install ${dependencies.join(" ")}` : packageManager === "yarn" ? `yarn add ${dependencies.join(" ")}` : packageManager === "bun" ? `bun add ${dependencies.join(" ")}` : `pnpm add ${dependencies.join(" ")}`;
119
100
  execSync(installCmd, { stdio: "inherit" });
120
101
  console.log(chalk.green("\u2705 Dependencies installed"));
121
102
  } catch (error) {
122
- throw new Error(
123
- "Failed to install dependencies. Please install them manually."
103
+ console.log(
104
+ chalk.yellow("\u26A0\uFE0F Could not install dependencies automatically")
124
105
  );
125
- }
126
- }
127
- async function checkIfWorkspace() {
128
- try {
129
- const pnpmWorkspacePath = path.join(
130
- process.cwd(),
131
- "../../pnpm-workspace.yaml"
106
+ console.log(chalk.gray("Please install them manually:"));
107
+ console.log(
108
+ chalk.cyan(` ${detectPackageManager()} add ${dependencies.join(" ")}`)
132
109
  );
133
- if (fs.existsSync(pnpmWorkspacePath)) {
134
- return true;
135
- }
136
- const packageJsonPath = path.join(process.cwd(), "package.json");
137
- if (fs.existsSync(packageJsonPath)) {
138
- const packageJson2 = await fs.readJson(packageJsonPath);
139
- const allDeps = {
140
- ...packageJson2.dependencies,
141
- ...packageJson2.devDependencies
142
- };
143
- const foundryKitPackages = Object.keys(allDeps).filter(
144
- (key) => key.startsWith("@foundrykit/")
145
- );
146
- for (const pkg of foundryKitPackages) {
147
- if (allDeps[pkg]?.includes("workspace:")) {
148
- return true;
149
- }
150
- }
151
- }
152
- return false;
153
- } catch {
154
- return false;
155
110
  }
156
111
  }
157
112
  function detectPackageManager() {
158
113
  if (fs.existsSync("pnpm-lock.yaml")) return "pnpm";
159
114
  if (fs.existsSync("yarn.lock")) return "yarn";
115
+ if (fs.existsSync("bun.lockb")) return "bun";
160
116
  return "npm";
161
117
  }
162
118
  async function setupTailwindV4() {
@@ -444,6 +400,102 @@ async function updatePackageScripts() {
444
400
  await fs.writeJson(packageJsonPath, packageJson2, { spaces: 2 });
445
401
  console.log(chalk.green("\u2705 Package scripts updated"));
446
402
  }
403
+ async function createConfigFile(options) {
404
+ console.log(chalk.blue("\u{1F4DD} Creating configuration file..."));
405
+ const configPath = path.join(process.cwd(), "foundrykit.config.json");
406
+ if (fs.existsSync(configPath) && !options.force) {
407
+ console.log(chalk.yellow("\u26A0\uFE0F Configuration file already exists"));
408
+ return;
409
+ }
410
+ const framework = await detectFramework();
411
+ const isTypeScript = fs.existsSync(path.join(process.cwd(), "tsconfig.json"));
412
+ const config = {
413
+ version: "1.0.0",
414
+ registry: "https://foundry.umiflow.com",
415
+ paths: {
416
+ utils: "./src/lib/utils.ts",
417
+ primitives: "./src/components/ui",
418
+ components: "./src/components",
419
+ blocks: "./src/components/blocks",
420
+ hooks: "./src/hooks",
421
+ animations: "./src/components/animations"
422
+ },
423
+ packageManager: detectPackageManager(),
424
+ typescript: isTypeScript,
425
+ framework,
426
+ tailwind: {
427
+ config: "./tailwind.config.js",
428
+ css: "./src/styles/globals.css"
429
+ },
430
+ aliases: {
431
+ "@": "./src",
432
+ "@/components": "./src/components",
433
+ "@/lib": "./src/lib",
434
+ "@/hooks": "./src/hooks"
435
+ }
436
+ };
437
+ if (framework === "next") {
438
+ const hasAppDir = fs.existsSync(path.join(process.cwd(), "app"));
439
+ if (hasAppDir && !fs.existsSync(path.join(process.cwd(), "src/app"))) {
440
+ config.paths = {
441
+ utils: "./lib/utils.ts",
442
+ primitives: "./components/ui",
443
+ components: "./components",
444
+ blocks: "./components/blocks",
445
+ hooks: "./hooks",
446
+ animations: "./components/animations"
447
+ };
448
+ config.tailwind.css = "./app/globals.css";
449
+ config.aliases = {
450
+ "@": "./",
451
+ "@/components": "./components",
452
+ "@/lib": "./lib",
453
+ "@/hooks": "./hooks"
454
+ };
455
+ }
456
+ }
457
+ await fs.writeJson(configPath, config, { spaces: 2 });
458
+ console.log(chalk.green("\u2705 Created foundrykit.config.json"));
459
+ }
460
+ async function installUtils() {
461
+ console.log(chalk.blue("\u{1F4E6} Installing utils..."));
462
+ const configPath = path.join(process.cwd(), "foundrykit.config.json");
463
+ if (!fs.existsSync(configPath)) {
464
+ console.log(chalk.yellow("\u26A0\uFE0F Configuration file not found"));
465
+ return;
466
+ }
467
+ const config = await fs.readJson(configPath);
468
+ const utilsPath = path.join(process.cwd(), config.paths.utils);
469
+ if (fs.existsSync(utilsPath)) {
470
+ console.log(chalk.yellow("\u26A0\uFE0F Utils file already exists"));
471
+ return;
472
+ }
473
+ await fs.ensureDir(path.dirname(utilsPath));
474
+ const utilsContent = `import { type ClassValue, clsx } from 'clsx';
475
+ import { twMerge } from 'tailwind-merge';
476
+
477
+ export function cn(...inputs: ClassValue[]) {
478
+ return twMerge(clsx(inputs));
479
+ }
480
+ `;
481
+ await fs.writeFile(utilsPath, utilsContent);
482
+ console.log(chalk.green("\u2705 Created utils file"));
483
+ }
484
+ async function detectFramework() {
485
+ const packageJsonPath = path.join(process.cwd(), "package.json");
486
+ if (fs.existsSync(packageJsonPath)) {
487
+ const packageJson2 = await fs.readJson(packageJsonPath);
488
+ const deps = {
489
+ ...packageJson2.dependencies,
490
+ ...packageJson2.devDependencies
491
+ };
492
+ if (deps.next) return "next";
493
+ if (deps.remix) return "remix";
494
+ if (deps.vite) return "vite";
495
+ if (deps.react) return "react";
496
+ }
497
+ return "react";
498
+ }
447
499
 
448
500
  // src/commands/list.ts
449
501
  import { Command as Command2 } from "commander";
@@ -504,23 +556,11 @@ Try again later or check your internet connection.`
504
556
  */
505
557
  async getComponent(id) {
506
558
  try {
507
- if (id === "utils") {
508
- console.log(chalk2.gray(`Creating utils dependency...`));
509
- return this.createUtilsComponent();
510
- }
511
559
  const url = `${this.config.registryUrl}/registry/${id}`;
512
560
  console.log(chalk2.gray(`Fetching component: ${url}`));
513
561
  const response = await fetch(url);
514
562
  if (!response.ok) {
515
563
  if (response.status === 404) {
516
- if (this.isSpecialDependency(id)) {
517
- console.log(
518
- chalk2.yellow(
519
- `Special dependency "${id}" will be handled separately`
520
- )
521
- );
522
- return this.createSpecialDependency(id);
523
- }
524
564
  throw new Error(`Component "${id}" not found in registry`);
525
565
  }
526
566
  throw new Error(
@@ -536,10 +576,6 @@ Try again later or check your internet connection.`
536
576
  console.log(chalk2.yellow(`Using cached data for component: ${id}`));
537
577
  return cache.componentData[id];
538
578
  }
539
- if (this.isSpecialDependency(id)) {
540
- console.log(chalk2.yellow(`Creating local version of "${id}"`));
541
- return this.createSpecialDependency(id);
542
- }
543
579
  throw new Error(
544
580
  `Failed to fetch component "${id}": ${error instanceof Error ? error.message : "Unknown error"}
545
581
  Registry URL: ${this.config.registryUrl}
@@ -547,53 +583,6 @@ Try again later or check your internet connection.`
547
583
  );
548
584
  }
549
585
  }
550
- /**
551
- * Check if a dependency is a special/utility dependency
552
- */
553
- isSpecialDependency(id) {
554
- const specialDeps = ["utils", "lib", "helpers", "cn"];
555
- return specialDeps.includes(id);
556
- }
557
- /**
558
- * Create a special dependency component
559
- */
560
- createSpecialDependency(id) {
561
- switch (id) {
562
- case "utils":
563
- case "lib":
564
- case "helpers":
565
- case "cn":
566
- return this.createUtilsComponent();
567
- default:
568
- throw new Error(`Unknown special dependency: ${id}`);
569
- }
570
- }
571
- /**
572
- * Create a utils component with the cn function
573
- */
574
- createUtilsComponent() {
575
- return {
576
- id: "utils",
577
- name: "Utils",
578
- category: "primitives",
579
- description: "Utility functions for className merging",
580
- tags: ["utility", "helper"],
581
- packageDependencies: ["clsx", "tailwind-merge"],
582
- files: [
583
- {
584
- path: "lib/utils.ts",
585
- type: "util",
586
- content: `import { type ClassValue, clsx } from 'clsx';
587
- import { twMerge } from 'tailwind-merge';
588
-
589
- export function cn(...inputs: ClassValue[]) {
590
- return twMerge(clsx(inputs));
591
- }
592
- `
593
- }
594
- ]
595
- };
596
- }
597
586
  /**
598
587
  * Update the local cache with new component list
599
588
  */
@@ -834,6 +823,9 @@ import chalk4 from "chalk";
834
823
  import fs3 from "fs-extra";
835
824
  import path3 from "path";
836
825
  import inquirer2 from "inquirer";
826
+ import { exec } from "child_process";
827
+ import { promisify } from "util";
828
+ var execAsync = promisify(exec);
837
829
  function addCommand() {
838
830
  return new Command3("add").description("Add a component or block to your project").argument("[id]", "Component or block ID (optional for interactive mode)").option("--with-animation", "Include animation variants").option("-p, --path <path>", "Custom installation path").option("-o, --overwrite", "Overwrite existing files").action(async (id, options) => {
839
831
  try {
@@ -921,7 +913,7 @@ function createGroupedChoices(components) {
921
913
  async function addSingleComponent(id, options) {
922
914
  console.log(chalk4.blue(`
923
915
  \u{1F4E6} Adding ${id} to your project...`));
924
- await validateProject();
916
+ await validateProject2();
925
917
  const registry = getRegistry();
926
918
  try {
927
919
  const componentData = await registry.getComponent(id);
@@ -943,35 +935,21 @@ async function addSingleComponent(id, options) {
943
935
  console.log(chalk4.blue("\u{1F4E6} Installing required dependencies..."));
944
936
  for (const dep of componentData.registryDependencies) {
945
937
  try {
946
- if (dep === "utils") {
947
- const utilsPath = path3.join(
948
- options.path || process.cwd(),
949
- "lib/utils.ts"
938
+ if (dep === "primitives") {
939
+ console.log(
940
+ chalk4.gray(
941
+ ` \u23ED Skipping "${dep}" - primitive dependencies will be handled separately`
942
+ )
950
943
  );
951
- if (!fs3.existsSync(utilsPath)) {
952
- await fs3.ensureDir(path3.dirname(utilsPath));
953
- await fs3.writeFile(
954
- utilsPath,
955
- `import { type ClassValue, clsx } from "clsx"
956
- import { twMerge } from "tailwind-merge"
957
-
958
- export function cn(...inputs: ClassValue[]) {
959
- return twMerge(clsx(inputs))
960
- }
961
- `
962
- );
963
- console.log(chalk4.green(` \u2713 Created ${dep} file`));
964
- } else {
965
- console.log(chalk4.gray(` \u23ED ${dep} already exists`));
966
- }
944
+ continue;
945
+ }
946
+ const depData = await registry.getComponent(dep);
947
+ const hasExisting = await hasConflictingFiles(depData, options);
948
+ if (!hasExisting) {
949
+ await installComponentFiles(depData, options);
950
+ console.log(chalk4.green(` \u2713 Installed ${dep}`));
967
951
  } else {
968
- const depData = await registry.getComponent(dep);
969
- if (!await hasConflictingFiles(depData, options)) {
970
- await installComponentFiles(depData, options);
971
- console.log(chalk4.green(` \u2713 Installed ${dep}`));
972
- } else {
973
- console.log(chalk4.gray(` \u23ED ${dep} already exists`));
974
- }
952
+ console.log(chalk4.gray(` \u23ED ${dep} already exists`));
975
953
  }
976
954
  } catch (error) {
977
955
  console.log(
@@ -979,55 +957,19 @@ export function cn(...inputs: ClassValue[]) {
979
957
  ` \u26A0 Could not install dependency "${dep}": ${error instanceof Error ? error.message : "Unknown error"}`
980
958
  )
981
959
  );
982
- if (dep === "utils" && error instanceof Error && error.message.includes("not found")) {
983
- const utilsPath = path3.join(
984
- options.path || process.cwd(),
985
- "lib/utils.ts"
986
- );
987
- if (!fs3.existsSync(utilsPath)) {
988
- await fs3.ensureDir(path3.dirname(utilsPath));
989
- await fs3.writeFile(
990
- utilsPath,
991
- `import { type ClassValue, clsx } from "clsx"
992
- import { twMerge } from "tailwind-merge"
993
-
994
- export function cn(...inputs: ClassValue[]) {
995
- return twMerge(clsx(inputs))
996
- }
997
- `
998
- );
999
- console.log(chalk4.green(` \u2713 Created ${dep} file`));
1000
- }
1001
- }
1002
960
  }
1003
961
  }
1004
962
  }
1005
963
  await installComponentFiles(componentData, options);
1006
964
  console.log(chalk4.green(`\u2705 ${componentData.name} added successfully!`));
1007
965
  showUsageExample(componentData);
1008
- if (componentData.packageDependencies?.length) {
1009
- console.log(chalk4.yellow("\n\u{1F4E6} Required npm packages:"));
1010
- console.log(
1011
- chalk4.gray(` ${componentData.packageDependencies.join(", ")}`)
1012
- );
1013
- console.log(chalk4.gray(" Install them with:"));
1014
- console.log(
1015
- chalk4.cyan(` pnpm add ${componentData.packageDependencies.join(" ")}`)
1016
- );
1017
- }
1018
- if (componentData.registryDependencies?.includes("utils")) {
1019
- const utilsDeps = ["clsx", "tailwind-merge"];
1020
- console.log(chalk4.yellow("\n\u{1F4E6} Required packages for utils:"));
1021
- console.log(chalk4.gray(` ${utilsDeps.join(", ")}`));
1022
- console.log(chalk4.gray(" Install them with:"));
1023
- console.log(chalk4.cyan(` pnpm add ${utilsDeps.join(" ")}`));
1024
- }
966
+ await handlePackageDependencies(componentData);
1025
967
  } catch (error) {
1026
968
  console.error(chalk4.red(`Failed to add ${id}:`));
1027
969
  throw error;
1028
970
  }
1029
971
  }
1030
- async function validateProject() {
972
+ async function validateProject2() {
1031
973
  const packageJsonPath = path3.join(process.cwd(), "package.json");
1032
974
  if (!fs3.existsSync(packageJsonPath)) {
1033
975
  throw new Error(
@@ -1066,6 +1008,82 @@ async function installComponentFiles(componentData, options) {
1066
1008
  console.log(chalk4.green(` \u2713 ${file.path}`));
1067
1009
  }
1068
1010
  }
1011
+ async function handlePackageDependencies(componentData) {
1012
+ const allDependencies = /* @__PURE__ */ new Set();
1013
+ if (componentData.packageDependencies?.length) {
1014
+ componentData.packageDependencies.forEach((dep) => allDependencies.add(dep));
1015
+ }
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
+ if (allDependencies.size === 0) {
1033
+ return;
1034
+ }
1035
+ const missingPackages = await getMissingPackages(Array.from(allDependencies));
1036
+ if (missingPackages.length === 0) {
1037
+ console.log(chalk4.green("\u2705 All required packages are already installed"));
1038
+ return;
1039
+ }
1040
+ console.log(chalk4.yellow("\n\u{1F4E6} Installing required packages..."));
1041
+ console.log(chalk4.gray(` ${missingPackages.join(", ")}`));
1042
+ const packageManager = await detectPackageManager2();
1043
+ try {
1044
+ const installCommand = `${packageManager} add ${missingPackages.join(" ")}`;
1045
+ console.log(chalk4.blue(` Running: ${installCommand}`));
1046
+ const { stdout, stderr } = await execAsync(installCommand);
1047
+ if (stderr && !stderr.includes("warning")) {
1048
+ console.error(chalk4.yellow(` Warning: ${stderr}`));
1049
+ }
1050
+ console.log(chalk4.green("\u2705 Packages installed successfully"));
1051
+ } catch (error) {
1052
+ console.log(chalk4.yellow("\n\u26A0\uFE0F Could not install packages automatically"));
1053
+ console.log(chalk4.gray(" Please install them manually:"));
1054
+ console.log(
1055
+ chalk4.cyan(` ${packageManager} add ${missingPackages.join(" ")}`)
1056
+ );
1057
+ }
1058
+ }
1059
+ async function getMissingPackages(packages) {
1060
+ const packageJsonPath = path3.join(process.cwd(), "package.json");
1061
+ try {
1062
+ const packageJson2 = await fs3.readJson(packageJsonPath);
1063
+ const installedPackages = {
1064
+ ...packageJson2.dependencies,
1065
+ ...packageJson2.devDependencies
1066
+ };
1067
+ return packages.filter((pkg) => !installedPackages[pkg]);
1068
+ } catch (error) {
1069
+ return packages;
1070
+ }
1071
+ }
1072
+ async function detectPackageManager2() {
1073
+ if (await fs3.pathExists(path3.join(process.cwd(), "pnpm-lock.yaml"))) {
1074
+ return "pnpm";
1075
+ }
1076
+ if (await fs3.pathExists(path3.join(process.cwd(), "yarn.lock"))) {
1077
+ return "yarn";
1078
+ }
1079
+ if (await fs3.pathExists(path3.join(process.cwd(), "package-lock.json"))) {
1080
+ return "npm";
1081
+ }
1082
+ if (await fs3.pathExists(path3.join(process.cwd(), "bun.lockb"))) {
1083
+ return "bun";
1084
+ }
1085
+ return "pnpm";
1086
+ }
1069
1087
  function showUsageExample(componentData) {
1070
1088
  console.log(chalk4.cyan("\n\u{1F4A1} Usage:"));
1071
1089
  const componentName = componentData.name.replace(/\s+/g, "");