@foundrykit/cli 1.0.13 → 1.0.15

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
@@ -757,6 +757,9 @@ Try again later or check your internet connection.`
757
757
  * Fetch a specific component by ID
758
758
  */
759
759
  async getComponent(id) {
760
+ if (this.isSpecialDependency(id)) {
761
+ return this.createSpecialDependency(id);
762
+ }
760
763
  try {
761
764
  const url = `${this.config.registryUrl}/registry/${id}`;
762
765
  console.log(chalk2.gray(`Fetching component: ${url}`));
@@ -785,6 +788,108 @@ Try again later or check your internet connection.`
785
788
  );
786
789
  }
787
790
  }
791
+ /**
792
+ * Check if a dependency ID is a special dependency that should be handled locally
793
+ */
794
+ isSpecialDependency(id) {
795
+ const specialDependencies = [
796
+ "utils",
797
+ "lib",
798
+ "helpers",
799
+ "cn",
800
+ // Utils aliases
801
+ "hooks",
802
+ "types"
803
+ // Package dependencies
804
+ ];
805
+ return specialDependencies.includes(id);
806
+ }
807
+ /**
808
+ * Create a special dependency component data
809
+ */
810
+ async createSpecialDependency(id) {
811
+ if (["utils", "lib", "helpers", "cn"].includes(id)) {
812
+ return {
813
+ id: "utils",
814
+ name: "Utils",
815
+ description: "Utility functions for className merging",
816
+ category: "primitives",
817
+ files: [
818
+ {
819
+ path: "lib/utils.ts",
820
+ content: `import { type ClassValue, clsx } from 'clsx';
821
+ import { twMerge } from 'tailwind-merge';
822
+
823
+ export function cn(...inputs: ClassValue[]) {
824
+ return twMerge(clsx(inputs));
825
+ }`,
826
+ type: "util"
827
+ }
828
+ ],
829
+ registryDependencies: [],
830
+ packageDependencies: ["clsx", "tailwind-merge"]
831
+ };
832
+ }
833
+ if (id === "hooks") {
834
+ const isInstalled = await this.isPackageInstalled("@foundrykit/hooks");
835
+ if (isInstalled) {
836
+ return {
837
+ id: "hooks",
838
+ name: "Hooks",
839
+ description: "Custom React hooks package",
840
+ category: "primitives",
841
+ files: [],
842
+ // No files to install, it's a package
843
+ registryDependencies: [],
844
+ packageDependencies: ["@foundrykit/hooks"]
845
+ };
846
+ } else {
847
+ throw new Error(
848
+ 'Package "@foundrykit/hooks" is not installed. Please install it first: pnpm add @foundrykit/hooks'
849
+ );
850
+ }
851
+ }
852
+ if (id === "types") {
853
+ const isInstalled = await this.isPackageInstalled("@foundrykit/types");
854
+ if (isInstalled) {
855
+ return {
856
+ id: "types",
857
+ name: "Types",
858
+ description: "TypeScript type definitions",
859
+ category: "primitives",
860
+ files: [],
861
+ // No files to install, it's a package
862
+ registryDependencies: [],
863
+ packageDependencies: ["@foundrykit/types"]
864
+ };
865
+ } else {
866
+ throw new Error(
867
+ 'Package "@foundrykit/types" is not installed. Please install it first: pnpm add @foundrykit/types'
868
+ );
869
+ }
870
+ }
871
+ throw new Error(`Unknown special dependency: ${id}`);
872
+ }
873
+ /**
874
+ * Check if a package is installed in the current project
875
+ */
876
+ async isPackageInstalled(packageName) {
877
+ try {
878
+ const packageJsonPath = path2.join(process.cwd(), "package.json");
879
+ if (!await fs2.pathExists(packageJsonPath)) {
880
+ return false;
881
+ }
882
+ const packageJson2 = await fs2.readJson(packageJsonPath);
883
+ const allDeps = {
884
+ ...packageJson2.dependencies,
885
+ ...packageJson2.devDependencies,
886
+ ...packageJson2.peerDependencies
887
+ };
888
+ return packageName in allDeps;
889
+ } catch (error) {
890
+ return false;
891
+ }
892
+ }
788
893
  /**
789
894
  * Update the local cache with new component list
790
895
  */
@@ -1138,6 +1243,10 @@ async function addSingleComponent(id, options) {
1138
1243
  for (const dep of componentData.registryDependencies) {
1139
1244
  try {
1140
1245
  const depData = await registry.getComponent(dep);
1246
+ if (["hooks", "types"].includes(dep)) {
1247
+ console.log(chalk4.green(` \u2713 ${dep} package is available`));
1248
+ continue;
1249
+ }
1141
1250
  const hasExisting = await hasConflictingFiles(depData, options);
1142
1251
  if (!hasExisting) {
1143
1252
  await installComponentFiles(depData, options);