@foundrykit/cli 1.0.1 → 1.0.2

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,11 @@
1
1
  # @foundrykit/cli
2
2
 
3
+ ## 1.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updating to use live data
8
+
3
9
  ## 1.0.1
4
10
 
5
11
  ### Patch Changes
package/dist/cli.js CHANGED
@@ -504,23 +504,11 @@ Try again later or check your internet connection.`
504
504
  */
505
505
  async getComponent(id) {
506
506
  try {
507
- if (id === "utils") {
508
- console.log(chalk2.gray(`Creating utils dependency...`));
509
- return this.createUtilsComponent();
510
- }
511
507
  const url = `${this.config.registryUrl}/registry/${id}`;
512
508
  console.log(chalk2.gray(`Fetching component: ${url}`));
513
509
  const response = await fetch(url);
514
510
  if (!response.ok) {
515
511
  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
512
  throw new Error(`Component "${id}" not found in registry`);
525
513
  }
526
514
  throw new Error(
@@ -536,10 +524,6 @@ Try again later or check your internet connection.`
536
524
  console.log(chalk2.yellow(`Using cached data for component: ${id}`));
537
525
  return cache.componentData[id];
538
526
  }
539
- if (this.isSpecialDependency(id)) {
540
- console.log(chalk2.yellow(`Creating local version of "${id}"`));
541
- return this.createSpecialDependency(id);
542
- }
543
527
  throw new Error(
544
528
  `Failed to fetch component "${id}": ${error instanceof Error ? error.message : "Unknown error"}
545
529
  Registry URL: ${this.config.registryUrl}
@@ -547,53 +531,6 @@ Try again later or check your internet connection.`
547
531
  );
548
532
  }
549
533
  }
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
534
  /**
598
535
  * Update the local cache with new component list
599
536
  */
@@ -834,6 +771,9 @@ import chalk4 from "chalk";
834
771
  import fs3 from "fs-extra";
835
772
  import path3 from "path";
836
773
  import inquirer2 from "inquirer";
774
+ import { exec } from "child_process";
775
+ import { promisify } from "util";
776
+ var execAsync = promisify(exec);
837
777
  function addCommand() {
838
778
  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
779
  try {
@@ -943,35 +883,13 @@ async function addSingleComponent(id, options) {
943
883
  console.log(chalk4.blue("\u{1F4E6} Installing required dependencies..."));
944
884
  for (const dep of componentData.registryDependencies) {
945
885
  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
- }
886
+ const depData = await registry.getComponent(dep);
887
+ const hasExisting = await hasConflictingFiles(depData, options);
888
+ if (!hasExisting) {
889
+ await installComponentFiles(depData, options);
890
+ console.log(chalk4.green(` \u2713 Installed ${dep}`));
967
891
  } 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
- }
892
+ console.log(chalk4.gray(` \u23ED ${dep} already exists`));
975
893
  }
976
894
  } catch (error) {
977
895
  console.log(
@@ -979,49 +897,13 @@ export function cn(...inputs: ClassValue[]) {
979
897
  ` \u26A0 Could not install dependency "${dep}": ${error instanceof Error ? error.message : "Unknown error"}`
980
898
  )
981
899
  );
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
900
  }
1003
901
  }
1004
902
  }
1005
903
  await installComponentFiles(componentData, options);
1006
904
  console.log(chalk4.green(`\u2705 ${componentData.name} added successfully!`));
1007
905
  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
- }
906
+ await handlePackageDependencies(componentData);
1025
907
  } catch (error) {
1026
908
  console.error(chalk4.red(`Failed to add ${id}:`));
1027
909
  throw error;
@@ -1066,6 +948,73 @@ async function installComponentFiles(componentData, options) {
1066
948
  console.log(chalk4.green(` \u2713 ${file.path}`));
1067
949
  }
1068
950
  }
951
+ async function handlePackageDependencies(componentData) {
952
+ const allDependencies = /* @__PURE__ */ new Set();
953
+ if (componentData.packageDependencies?.length) {
954
+ componentData.packageDependencies.forEach((dep) => allDependencies.add(dep));
955
+ }
956
+ if (componentData.registryDependencies?.includes("utils")) {
957
+ allDependencies.add("clsx");
958
+ allDependencies.add("tailwind-merge");
959
+ }
960
+ if (componentData.id === "button") {
961
+ allDependencies.add("class-variance-authority");
962
+ }
963
+ if (allDependencies.size === 0) {
964
+ return;
965
+ }
966
+ const missingPackages = await getMissingPackages(Array.from(allDependencies));
967
+ if (missingPackages.length === 0) {
968
+ console.log(chalk4.green("\u2705 All required packages are already installed"));
969
+ return;
970
+ }
971
+ console.log(chalk4.yellow("\n\u{1F4E6} Installing required packages..."));
972
+ console.log(chalk4.gray(` ${missingPackages.join(", ")}`));
973
+ const packageManager = await detectPackageManager2();
974
+ try {
975
+ const installCommand = `${packageManager} add ${missingPackages.join(" ")}`;
976
+ console.log(chalk4.blue(` Running: ${installCommand}`));
977
+ const { stdout, stderr } = await execAsync(installCommand);
978
+ if (stderr && !stderr.includes("warning")) {
979
+ console.error(chalk4.yellow(` Warning: ${stderr}`));
980
+ }
981
+ console.log(chalk4.green("\u2705 Packages installed successfully"));
982
+ } catch (error) {
983
+ console.log(chalk4.yellow("\n\u26A0\uFE0F Could not install packages automatically"));
984
+ console.log(chalk4.gray(" Please install them manually:"));
985
+ console.log(
986
+ chalk4.cyan(` ${packageManager} add ${missingPackages.join(" ")}`)
987
+ );
988
+ }
989
+ }
990
+ async function getMissingPackages(packages) {
991
+ const packageJsonPath = path3.join(process.cwd(), "package.json");
992
+ try {
993
+ const packageJson2 = await fs3.readJson(packageJsonPath);
994
+ const installedPackages = {
995
+ ...packageJson2.dependencies,
996
+ ...packageJson2.devDependencies
997
+ };
998
+ return packages.filter((pkg) => !installedPackages[pkg]);
999
+ } catch (error) {
1000
+ return packages;
1001
+ }
1002
+ }
1003
+ async function detectPackageManager2() {
1004
+ if (await fs3.pathExists(path3.join(process.cwd(), "pnpm-lock.yaml"))) {
1005
+ return "pnpm";
1006
+ }
1007
+ if (await fs3.pathExists(path3.join(process.cwd(), "yarn.lock"))) {
1008
+ return "yarn";
1009
+ }
1010
+ if (await fs3.pathExists(path3.join(process.cwd(), "package-lock.json"))) {
1011
+ return "npm";
1012
+ }
1013
+ if (await fs3.pathExists(path3.join(process.cwd(), "bun.lockb"))) {
1014
+ return "bun";
1015
+ }
1016
+ return "pnpm";
1017
+ }
1069
1018
  function showUsageExample(componentData) {
1070
1019
  console.log(chalk4.cyan("\n\u{1F4A1} Usage:"));
1071
1020
  const componentName = componentData.name.replace(/\s+/g, "");