@foundrykit/cli 0.1.2 → 1.0.1

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,25 @@
1
1
  # @foundrykit/cli
2
2
 
3
+ ## 1.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updating the way the add commands installs and added external files and
8
+ dependencies
9
+ - Updated dependencies
10
+ - @foundrykit/types@1.0.1
11
+
12
+ ## 1.0.0
13
+
14
+ ### Major Changes
15
+
16
+ - Version alignment push
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies
21
+ - @foundrykit/types@1.0.0
22
+
3
23
  ## 0.1.2
4
24
 
5
25
  ### Patch Changes
package/dist/cli.js CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  // src/index.ts
4
4
  import { Command as Command6 } from "commander";
5
+ import { readFileSync } from "fs";
6
+ import { fileURLToPath } from "url";
7
+ import { dirname, join } from "path";
5
8
 
6
9
  // src/commands/init.ts
7
10
  import { Command } from "commander";
@@ -65,10 +68,10 @@ async function validateNextJsProject() {
65
68
  "No package.json found. Please run this command in a Next.js project root."
66
69
  );
67
70
  }
68
- const packageJson = await fs.readJson(packageJsonPath);
71
+ const packageJson2 = await fs.readJson(packageJsonPath);
69
72
  const dependencies = {
70
- ...packageJson.dependencies,
71
- ...packageJson.devDependencies
73
+ ...packageJson2.dependencies,
74
+ ...packageJson2.devDependencies
72
75
  };
73
76
  if (!dependencies.next) {
74
77
  throw new Error(
@@ -80,10 +83,10 @@ async function validateNextJsProject() {
80
83
  async function isFoundryKitInitialized() {
81
84
  const packageJsonPath = path.join(process.cwd(), "package.json");
82
85
  if (fs.existsSync(packageJsonPath)) {
83
- const packageJson = await fs.readJson(packageJsonPath);
86
+ const packageJson2 = await fs.readJson(packageJsonPath);
84
87
  const dependencies = {
85
- ...packageJson.dependencies,
86
- ...packageJson.devDependencies
88
+ ...packageJson2.dependencies,
89
+ ...packageJson2.devDependencies
87
90
  };
88
91
  return Object.keys(dependencies).some(
89
92
  (dep) => dep.startsWith("@foundrykit/")
@@ -132,10 +135,10 @@ async function checkIfWorkspace() {
132
135
  }
133
136
  const packageJsonPath = path.join(process.cwd(), "package.json");
134
137
  if (fs.existsSync(packageJsonPath)) {
135
- const packageJson = await fs.readJson(packageJsonPath);
138
+ const packageJson2 = await fs.readJson(packageJsonPath);
136
139
  const allDeps = {
137
- ...packageJson.dependencies,
138
- ...packageJson.devDependencies
140
+ ...packageJson2.dependencies,
141
+ ...packageJson2.devDependencies
139
142
  };
140
143
  const foundryKitPackages = Object.keys(allDeps).filter(
141
144
  (key) => key.startsWith("@foundrykit/")
@@ -428,17 +431,17 @@ export function Providers({ children }: { children: React.ReactNode }) {
428
431
  async function updatePackageScripts() {
429
432
  console.log(chalk.blue("\u{1F4CB} Updating package.json scripts..."));
430
433
  const packageJsonPath = path.join(process.cwd(), "package.json");
431
- const packageJson = await fs.readJson(packageJsonPath);
432
- if (!packageJson.scripts) {
433
- packageJson.scripts = {};
434
+ const packageJson2 = await fs.readJson(packageJsonPath);
435
+ if (!packageJson2.scripts) {
436
+ packageJson2.scripts = {};
434
437
  }
435
- if (!packageJson.scripts["foundrykit"]) {
436
- packageJson.scripts["foundrykit"] = "foundrykit";
438
+ if (!packageJson2.scripts["foundrykit"]) {
439
+ packageJson2.scripts["foundrykit"] = "foundrykit";
437
440
  }
438
- if (!packageJson.scripts["fk"]) {
439
- packageJson.scripts["fk"] = "foundrykit";
441
+ if (!packageJson2.scripts["fk"]) {
442
+ packageJson2.scripts["fk"] = "foundrykit";
440
443
  }
441
- await fs.writeJson(packageJsonPath, packageJson, { spaces: 2 });
444
+ await fs.writeJson(packageJsonPath, packageJson2, { spaces: 2 });
442
445
  console.log(chalk.green("\u2705 Package scripts updated"));
443
446
  }
444
447
 
@@ -501,11 +504,23 @@ Try again later or check your internet connection.`
501
504
  */
502
505
  async getComponent(id) {
503
506
  try {
507
+ if (id === "utils") {
508
+ console.log(chalk2.gray(`Creating utils dependency...`));
509
+ return this.createUtilsComponent();
510
+ }
504
511
  const url = `${this.config.registryUrl}/registry/${id}`;
505
512
  console.log(chalk2.gray(`Fetching component: ${url}`));
506
513
  const response = await fetch(url);
507
514
  if (!response.ok) {
508
515
  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
+ }
509
524
  throw new Error(`Component "${id}" not found in registry`);
510
525
  }
511
526
  throw new Error(
@@ -521,6 +536,10 @@ Try again later or check your internet connection.`
521
536
  console.log(chalk2.yellow(`Using cached data for component: ${id}`));
522
537
  return cache.componentData[id];
523
538
  }
539
+ if (this.isSpecialDependency(id)) {
540
+ console.log(chalk2.yellow(`Creating local version of "${id}"`));
541
+ return this.createSpecialDependency(id);
542
+ }
524
543
  throw new Error(
525
544
  `Failed to fetch component "${id}": ${error instanceof Error ? error.message : "Unknown error"}
526
545
  Registry URL: ${this.config.registryUrl}
@@ -528,6 +547,53 @@ Try again later or check your internet connection.`
528
547
  );
529
548
  }
530
549
  }
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
+ }
531
597
  /**
532
598
  * Update the local cache with new component list
533
599
  */
@@ -876,10 +942,63 @@ async function addSingleComponent(id, options) {
876
942
  if (componentData.registryDependencies?.length) {
877
943
  console.log(chalk4.blue("\u{1F4E6} Installing required dependencies..."));
878
944
  for (const dep of componentData.registryDependencies) {
879
- const depData = await registry.getComponent(dep);
880
- if (!await hasConflictingFiles(depData, options)) {
881
- await installComponentFiles(depData, options);
882
- console.log(chalk4.green(` \u2713 Installed ${dep}`));
945
+ try {
946
+ if (dep === "utils") {
947
+ const utilsPath = path3.join(
948
+ options.path || process.cwd(),
949
+ "lib/utils.ts"
950
+ );
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
+ }
967
+ } 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
+ }
975
+ }
976
+ } catch (error) {
977
+ console.log(
978
+ chalk4.yellow(
979
+ ` \u26A0 Could not install dependency "${dep}": ${error instanceof Error ? error.message : "Unknown error"}`
980
+ )
981
+ );
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
+ }
883
1002
  }
884
1003
  }
885
1004
  }
@@ -896,6 +1015,13 @@ async function addSingleComponent(id, options) {
896
1015
  chalk4.cyan(` pnpm add ${componentData.packageDependencies.join(" ")}`)
897
1016
  );
898
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
+ }
899
1025
  } catch (error) {
900
1026
  console.error(chalk4.red(`Failed to add ${id}:`));
901
1027
  throw error;
@@ -908,10 +1034,10 @@ async function validateProject() {
908
1034
  "No package.json found. Please run this command in a project root."
909
1035
  );
910
1036
  }
911
- const packageJson = await fs3.readJson(packageJsonPath);
1037
+ const packageJson2 = await fs3.readJson(packageJsonPath);
912
1038
  const dependencies = {
913
- ...packageJson.dependencies,
914
- ...packageJson.devDependencies
1039
+ ...packageJson2.dependencies,
1040
+ ...packageJson2.devDependencies
915
1041
  };
916
1042
  const hasFoundryKit = Object.keys(dependencies).some(
917
1043
  (dep) => dep.startsWith("@foundrykit/")
@@ -1004,8 +1130,13 @@ function doctorCommand() {
1004
1130
  }
1005
1131
 
1006
1132
  // src/index.ts
1133
+ var __filename = fileURLToPath(import.meta.url);
1134
+ var __dirname = dirname(__filename);
1135
+ var packageJson = JSON.parse(
1136
+ readFileSync(join(__dirname, "..", "package.json"), "utf-8")
1137
+ );
1007
1138
  var program = new Command6();
1008
- program.name("foundrykit").description("FoundryKit CLI - Component library management tool").version("0.1.0");
1139
+ program.name("foundrykit").description("FoundryKit CLI - Component library management tool").version(packageJson.version);
1009
1140
  program.addCommand(initCommand());
1010
1141
  program.addCommand(listCommand());
1011
1142
  program.addCommand(addCommand());