@foundrykit/cli 2.0.10 → 2.0.12
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/.turbo/turbo-type-check.log +1 -1
- package/CHANGELOG.md +18 -0
- package/README.md +37 -35
- package/dist/cli.js +1896 -1894
- package/dist/cli.js.map +1 -1
- package/dist/index.js +1896 -1894
- package/dist/index.js.map +1 -1
- package/package.json +8 -6
- package/postcss.config.mjs +1 -1
- package/src/commands/add.ts +22 -18
- package/src/commands/doctor.ts +10 -7
- package/src/commands/init.ts +13 -20
- package/src/commands/list.ts +3 -6
- package/src/commands/update.ts +8 -8
- package/src/index.ts +5 -5
- package/src/lib/registry.ts +36 -33
- package/tests/dependency-resolution.test.ts +31 -22
- package/.turbo/turbo-build.log +0 -20
- package/.turbo/turbo-test.log +0 -42
- package/eslint.config.js +0 -4
package/dist/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
|
-
import { Command as Command6 } from "commander";
|
|
5
4
|
import { readFileSync } from "fs";
|
|
6
|
-
import { fileURLToPath } from "url";
|
|
7
5
|
import { dirname, join } from "path";
|
|
6
|
+
import { fileURLToPath } from "url";
|
|
7
|
+
import { Command as Command6 } from "commander";
|
|
8
8
|
|
|
9
|
-
// src/commands/
|
|
10
|
-
import { Command } from "commander";
|
|
11
|
-
import chalk from "chalk";
|
|
12
|
-
import fs from "fs-extra";
|
|
13
|
-
import path from "path";
|
|
14
|
-
import inquirer from "inquirer";
|
|
9
|
+
// src/commands/add.ts
|
|
15
10
|
import { exec } from "child_process";
|
|
11
|
+
import path2 from "path";
|
|
16
12
|
import { promisify } from "util";
|
|
13
|
+
import chalk2 from "chalk";
|
|
14
|
+
import { Command } from "commander";
|
|
15
|
+
import fs2 from "fs-extra";
|
|
16
|
+
import inquirer from "inquirer";
|
|
17
17
|
|
|
18
18
|
// src/lib/constants.ts
|
|
19
19
|
var CLI_VERSION = "1.0.16";
|
|
@@ -46,1981 +46,2066 @@ var FOUNDRYKIT_PACKAGE_ALIASES = [
|
|
|
46
46
|
"utils"
|
|
47
47
|
];
|
|
48
48
|
|
|
49
|
-
// src/
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
// src/lib/registry.ts
|
|
50
|
+
import os from "os";
|
|
51
|
+
import path from "path";
|
|
52
|
+
import chalk from "chalk";
|
|
53
|
+
import fs from "fs-extra";
|
|
54
|
+
var DEFAULT_CONFIG = {
|
|
55
|
+
registryUrl: process.env.FOUNDRYKIT_REGISTRY_URL || DEFAULT_REGISTRY_URL,
|
|
56
|
+
cacheDir: path.join(os.homedir(), CACHE_DIR, "cache"),
|
|
57
|
+
cacheMaxAge: CACHE_TTL
|
|
58
|
+
};
|
|
59
|
+
var RegistryService = class {
|
|
60
|
+
config;
|
|
61
|
+
cacheFile;
|
|
62
|
+
foundryKitPackagesPromise = null;
|
|
63
|
+
constructor(config) {
|
|
64
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
65
|
+
this.cacheFile = path.join(this.config.cacheDir, "registry.json");
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Fetch all components from the registry
|
|
69
|
+
*/
|
|
70
|
+
async getComponents(category, search) {
|
|
52
71
|
try {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
]);
|
|
64
|
-
if (!shouldContinue) {
|
|
65
|
-
console.log(chalk.yellow("\u274C Initialization cancelled."));
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
const projectStructure = await detectProjectStructure();
|
|
70
|
-
console.log(
|
|
71
|
-
chalk.gray(
|
|
72
|
-
`Detected project structure: ${projectStructure.hasSrc ? "src/" : "root"} based`
|
|
73
|
-
)
|
|
74
|
-
);
|
|
75
|
-
const pathConfig = await getPathConfiguration(
|
|
76
|
-
projectStructure,
|
|
77
|
-
options.skipPrompts
|
|
78
|
-
);
|
|
79
|
-
if (!options.skipInstall) {
|
|
80
|
-
await installDependencies();
|
|
72
|
+
const params = new URLSearchParams();
|
|
73
|
+
if (category) params.append("category", category);
|
|
74
|
+
if (search) params.append("search", search);
|
|
75
|
+
const url = `${this.config.registryUrl}/registry${params.toString() ? `?${params.toString()}` : ""}`;
|
|
76
|
+
console.log(chalk.gray(`Fetching from: ${url}`));
|
|
77
|
+
const response = await fetch(url);
|
|
78
|
+
if (!response.ok) {
|
|
79
|
+
throw new Error(
|
|
80
|
+
`Registry returned ${response.status}: ${response.statusText}`
|
|
81
|
+
);
|
|
81
82
|
}
|
|
82
|
-
|
|
83
|
-
await
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
options.skipPrompts
|
|
89
|
-
);
|
|
90
|
-
await createDirectories(pathConfig);
|
|
91
|
-
await createExampleFiles(pathConfig, projectStructure);
|
|
92
|
-
await updatePackageScripts();
|
|
93
|
-
console.log(chalk.green("\n\u2705 FoundryKit initialized successfully!"));
|
|
94
|
-
console.log(chalk.cyan("\n\u{1F4E6} Next steps:"));
|
|
95
|
-
console.log(
|
|
96
|
-
chalk.gray(
|
|
97
|
-
" 1. Add a component: pnpm dlx @foundrykit/cli add hero-minimal"
|
|
98
|
-
)
|
|
99
|
-
);
|
|
100
|
-
console.log(
|
|
101
|
-
chalk.gray(
|
|
102
|
-
" 2. List available components: pnpm dlx @foundrykit/cli list"
|
|
103
|
-
)
|
|
104
|
-
);
|
|
105
|
-
console.log(
|
|
106
|
-
chalk.gray(
|
|
107
|
-
" 3. Check out the docs: https://foundry-docs.umiflow.com"
|
|
108
|
-
)
|
|
83
|
+
const components = await response.json();
|
|
84
|
+
await this.updateCache(components);
|
|
85
|
+
return this.filterComponents(
|
|
86
|
+
await this.withFoundryKitPackages(components),
|
|
87
|
+
category,
|
|
88
|
+
search
|
|
109
89
|
);
|
|
110
90
|
} catch (error) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
chalk.
|
|
91
|
+
const cache = await this.loadCache();
|
|
92
|
+
if (cache && this.isCacheValid(cache)) {
|
|
93
|
+
console.log(chalk.yellow("Using cached registry data"));
|
|
94
|
+
return this.filterComponents(
|
|
95
|
+
await this.withFoundryKitPackages(cache.components),
|
|
96
|
+
category,
|
|
97
|
+
search
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
const npmPackages = await this.fetchFoundryKitPackages();
|
|
101
|
+
if (npmPackages.length > 0) {
|
|
102
|
+
console.log(chalk.yellow("Using npm package data"));
|
|
103
|
+
return this.filterComponents(npmPackages, category, search);
|
|
104
|
+
}
|
|
105
|
+
throw new Error(
|
|
106
|
+
`Failed to connect to registry: ${error instanceof Error ? error.message : "Unknown error"}
|
|
107
|
+
Registry URL: ${this.config.registryUrl}
|
|
108
|
+
Try again later or check your internet connection.`
|
|
114
109
|
);
|
|
115
|
-
process.exit(1);
|
|
116
110
|
}
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
async function validateProject() {
|
|
120
|
-
const packageJsonPath = path.join(process.cwd(), "package.json");
|
|
121
|
-
if (!fs.existsSync(packageJsonPath)) {
|
|
122
|
-
throw new Error(
|
|
123
|
-
"No package.json found. Please run this command in a project directory."
|
|
124
|
-
);
|
|
125
111
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
112
|
+
/**
|
|
113
|
+
* Fetch a specific component by ID
|
|
114
|
+
*/
|
|
115
|
+
async getComponent(id, force = false) {
|
|
116
|
+
if (this.isSpecialDependency(id)) {
|
|
117
|
+
return this.createSpecialDependency(id);
|
|
118
|
+
}
|
|
119
|
+
const foundryKitPackage = this.resolveFoundryKitPackageName(id);
|
|
120
|
+
const isKnownFoundryKitPackage = id.startsWith("@foundrykit/") || id.endsWith("-plugin") || FOUNDRYKIT_PACKAGE_ALIASES.includes(
|
|
121
|
+
id
|
|
134
122
|
);
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
123
|
+
const cache = await this.loadCache();
|
|
124
|
+
const cachedComponent = cache?.componentData?.[id];
|
|
125
|
+
const hasValidCache = cache ? this.isCacheValid(cache) : false;
|
|
126
|
+
if (!force && cachedComponent && hasValidCache) {
|
|
127
|
+
console.log(chalk.gray(`Using cached data for component: ${id}`));
|
|
128
|
+
return cachedComponent;
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
const url = `${this.config.registryUrl}/registry/${id}`;
|
|
132
|
+
console.log(chalk.gray(`Fetching component: ${url}`));
|
|
133
|
+
const response = await fetch(url);
|
|
134
|
+
if (!response.ok) {
|
|
135
|
+
if (response.status === 404) {
|
|
136
|
+
if (foundryKitPackage) {
|
|
137
|
+
const npmPackage = await this.createFoundryKitPackageDependency(
|
|
138
|
+
foundryKitPackage,
|
|
139
|
+
!isKnownFoundryKitPackage
|
|
140
|
+
);
|
|
141
|
+
if (npmPackage) return npmPackage;
|
|
142
|
+
}
|
|
143
|
+
throw new Error(`Component "${id}" not found in registry`);
|
|
144
|
+
}
|
|
145
|
+
throw new Error(
|
|
146
|
+
`Registry returned ${response.status}: ${response.statusText}`
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
const component = await response.json();
|
|
150
|
+
await this.cacheComponent(component);
|
|
151
|
+
return component;
|
|
152
|
+
} catch (error) {
|
|
153
|
+
if (foundryKitPackage) {
|
|
154
|
+
const npmPackage = await this.createFoundryKitPackageDependency(
|
|
155
|
+
foundryKitPackage,
|
|
156
|
+
!isKnownFoundryKitPackage
|
|
157
|
+
);
|
|
158
|
+
if (npmPackage) return npmPackage;
|
|
160
159
|
}
|
|
160
|
+
if (cachedComponent) {
|
|
161
|
+
console.log(chalk.yellow(`Using cached data for component: ${id}`));
|
|
162
|
+
return cachedComponent;
|
|
163
|
+
}
|
|
164
|
+
throw new Error(
|
|
165
|
+
`Failed to fetch component "${id}": ${error instanceof Error ? error.message : "Unknown error"}
|
|
166
|
+
Registry URL: ${this.config.registryUrl}
|
|
167
|
+
Try again later or check your internet connection.`
|
|
168
|
+
);
|
|
161
169
|
}
|
|
162
|
-
|
|
163
|
-
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Check if a dependency ID is a special dependency that should be handled locally
|
|
173
|
+
*/
|
|
174
|
+
isSpecialDependency(id) {
|
|
175
|
+
const specialDependencies = [
|
|
176
|
+
"utils",
|
|
177
|
+
"lib",
|
|
178
|
+
"helpers",
|
|
179
|
+
"cn",
|
|
180
|
+
// Utils aliases
|
|
181
|
+
"hooks",
|
|
182
|
+
"types",
|
|
183
|
+
// Package dependencies
|
|
184
|
+
"maps"
|
|
185
|
+
];
|
|
186
|
+
return specialDependencies.includes(id);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Create a special dependency component data
|
|
190
|
+
*/
|
|
191
|
+
async createSpecialDependency(id) {
|
|
192
|
+
if (["utils", "lib", "helpers", "cn"].includes(id)) {
|
|
193
|
+
return {
|
|
194
|
+
id: "utils",
|
|
195
|
+
name: "Utils",
|
|
196
|
+
description: "Utility functions for className merging",
|
|
197
|
+
category: "primitives",
|
|
198
|
+
files: [
|
|
199
|
+
{
|
|
200
|
+
path: "lib/utils.ts",
|
|
201
|
+
content: `import { type ClassValue, clsx } from 'clsx';
|
|
202
|
+
import { twMerge } from 'tailwind-merge';
|
|
203
|
+
|
|
204
|
+
export function cn(...inputs: ClassValue[]) {
|
|
205
|
+
return twMerge(clsx(inputs));
|
|
206
|
+
}`,
|
|
207
|
+
type: "util"
|
|
208
|
+
}
|
|
209
|
+
],
|
|
210
|
+
registryDependencies: [],
|
|
211
|
+
packageDependencies: ["clsx", "tailwind-merge"]
|
|
212
|
+
};
|
|
164
213
|
}
|
|
165
|
-
if (
|
|
166
|
-
|
|
214
|
+
if (id === "hooks") {
|
|
215
|
+
const component = await this.createFoundryKitPackageDependency("@foundrykit/hooks");
|
|
216
|
+
if (component) return component;
|
|
167
217
|
}
|
|
168
|
-
if (
|
|
169
|
-
|
|
218
|
+
if (id === "types") {
|
|
219
|
+
const component = await this.createFoundryKitPackageDependency("@foundrykit/types");
|
|
220
|
+
if (component) return component;
|
|
170
221
|
}
|
|
171
|
-
if (
|
|
172
|
-
|
|
222
|
+
if (id === "maps") {
|
|
223
|
+
const component = await this.createFoundryKitPackageDependency("@foundrykit/maps");
|
|
224
|
+
if (component) return component;
|
|
173
225
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
226
|
+
throw new Error(`Unknown special dependency: ${id}`);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Check if a package is installed in the current project
|
|
230
|
+
*/
|
|
231
|
+
async isPackageInstalled(packageName) {
|
|
232
|
+
try {
|
|
233
|
+
const packageJsonPath = path.join(process.cwd(), "package.json");
|
|
234
|
+
if (!await fs.pathExists(packageJsonPath)) {
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
const packageJson2 = await fs.readJson(packageJsonPath);
|
|
238
|
+
const allDeps = {
|
|
239
|
+
...packageJson2.dependencies,
|
|
240
|
+
...packageJson2.devDependencies,
|
|
241
|
+
...packageJson2.peerDependencies
|
|
242
|
+
};
|
|
243
|
+
return packageName in allDeps;
|
|
244
|
+
} catch {
|
|
245
|
+
return false;
|
|
181
246
|
}
|
|
182
|
-
|
|
183
|
-
|
|
247
|
+
}
|
|
248
|
+
resolveFoundryKitPackageName(id) {
|
|
249
|
+
if (/^@foundrykit\/[a-z0-9][a-z0-9-]*$/i.test(id)) {
|
|
250
|
+
return id;
|
|
184
251
|
}
|
|
185
|
-
if (
|
|
186
|
-
|
|
252
|
+
if (/^[a-z0-9][a-z0-9-]*$/i.test(id)) {
|
|
253
|
+
return `@foundrykit/${id}`;
|
|
187
254
|
}
|
|
188
|
-
|
|
189
|
-
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
async createFoundryKitPackageDependency(packageName, requirePublishedPackage = false) {
|
|
258
|
+
const id = packageName.replace("@foundrykit/", "");
|
|
259
|
+
const category = id === "maps" ? "maps" : id === "hooks" ? "hooks" : "packages";
|
|
260
|
+
const metadata = await this.fetchPackageMetadata(packageName);
|
|
261
|
+
if (requirePublishedPackage && !metadata) {
|
|
262
|
+
return null;
|
|
190
263
|
}
|
|
264
|
+
return {
|
|
265
|
+
id,
|
|
266
|
+
name: this.toDisplayName(id),
|
|
267
|
+
version: metadata?.version,
|
|
268
|
+
description: metadata?.description ?? `${packageName} npm package`,
|
|
269
|
+
category,
|
|
270
|
+
files: [],
|
|
271
|
+
registryDependencies: [],
|
|
272
|
+
packageDependencies: [packageName]
|
|
273
|
+
};
|
|
191
274
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
hasLib: !!libPath,
|
|
199
|
-
hasHooks: !!hooksPath,
|
|
200
|
-
hasStyles: !!stylesPath,
|
|
201
|
-
baseDir,
|
|
202
|
-
framework: "next",
|
|
203
|
-
isTypeScript,
|
|
204
|
-
packageManager,
|
|
205
|
-
appPath,
|
|
206
|
-
componentsPath,
|
|
207
|
-
libPath,
|
|
208
|
-
hooksPath,
|
|
209
|
-
stylesPath
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
async function getPathConfiguration(structure, skipPrompts) {
|
|
213
|
-
const ext = structure.isTypeScript ? ".ts" : ".js";
|
|
214
|
-
const jsxExt = structure.isTypeScript ? ".tsx" : ".jsx";
|
|
215
|
-
const defaults = {
|
|
216
|
-
utils: path.join(
|
|
217
|
-
structure.libPath || path.join(structure.baseDir, "lib"),
|
|
218
|
-
`utils${ext}`
|
|
219
|
-
),
|
|
220
|
-
primitives: path.join(
|
|
221
|
-
structure.componentsPath || path.join(structure.baseDir, "components"),
|
|
222
|
-
"primitives"
|
|
223
|
-
),
|
|
224
|
-
components: path.join(
|
|
225
|
-
structure.componentsPath || path.join(structure.baseDir, "components"),
|
|
226
|
-
"ui"
|
|
227
|
-
),
|
|
228
|
-
blocks: path.join(
|
|
229
|
-
structure.componentsPath || path.join(structure.baseDir, "components"),
|
|
230
|
-
"blocks"
|
|
231
|
-
),
|
|
232
|
-
maps: path.join(
|
|
233
|
-
structure.componentsPath || path.join(structure.baseDir, "components"),
|
|
234
|
-
"maps"
|
|
235
|
-
),
|
|
236
|
-
animations: path.join(
|
|
237
|
-
structure.componentsPath || path.join(structure.baseDir, "components"),
|
|
238
|
-
"animations"
|
|
239
|
-
),
|
|
240
|
-
hooks: structure.hooksPath || path.join(structure.baseDir, "hooks"),
|
|
241
|
-
lib: structure.libPath || path.join(structure.baseDir, "lib"),
|
|
242
|
-
styles: path.join(structure.appPath || structure.baseDir, "globals.css")
|
|
243
|
-
};
|
|
244
|
-
if (structure.appPath) {
|
|
245
|
-
const possibleStylePaths = [
|
|
246
|
-
path.join(structure.appPath, "globals.css"),
|
|
247
|
-
path.join(structure.appPath, "global.css"),
|
|
248
|
-
path.join(structure.stylesPath || "", "globals.css"),
|
|
249
|
-
path.join(structure.stylesPath || "", "global.css")
|
|
275
|
+
async withFoundryKitPackages(components) {
|
|
276
|
+
const packageEntries = await this.fetchFoundryKitPackages();
|
|
277
|
+
const seenIds = new Set(components.map((component) => component.id));
|
|
278
|
+
return [
|
|
279
|
+
...components,
|
|
280
|
+
...packageEntries.filter((component) => !seenIds.has(component.id))
|
|
250
281
|
];
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
282
|
+
}
|
|
283
|
+
toDisplayName(id) {
|
|
284
|
+
return id.split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
|
|
285
|
+
}
|
|
286
|
+
async fetchFoundryKitPackages() {
|
|
287
|
+
if (!this.foundryKitPackagesPromise) {
|
|
288
|
+
this.foundryKitPackagesPromise = this.fetchFoundryKitPackagesFromNpm();
|
|
289
|
+
}
|
|
290
|
+
try {
|
|
291
|
+
return await this.foundryKitPackagesPromise;
|
|
292
|
+
} catch {
|
|
293
|
+
return this.getFallbackFoundryKitPackages();
|
|
256
294
|
}
|
|
257
295
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
);
|
|
262
|
-
|
|
296
|
+
async fetchFoundryKitPackagesFromNpm() {
|
|
297
|
+
const url = `${NPM_REGISTRY_URL}/-/v1/search?text=scope:foundrykit&size=250`;
|
|
298
|
+
console.log(chalk.gray(`Fetching FoundryKit packages from npm: ${url}`));
|
|
299
|
+
const response = await fetch(url);
|
|
300
|
+
if (!response.ok) {
|
|
301
|
+
throw new Error(
|
|
302
|
+
`npm returned ${response.status}: ${response.statusText}`
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
const data = await response.json();
|
|
306
|
+
return (data.objects ?? []).map((item) => item.package).filter((pkg) => {
|
|
307
|
+
return Boolean(pkg?.name?.startsWith("@foundrykit/"));
|
|
308
|
+
}).map(
|
|
309
|
+
(pkg) => this.toPackageComponentMeta(pkg.name, {
|
|
310
|
+
version: pkg.version,
|
|
311
|
+
description: pkg.description,
|
|
312
|
+
keywords: pkg.keywords
|
|
313
|
+
})
|
|
314
|
+
).sort((a, b) => a.id.localeCompare(b.id));
|
|
263
315
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}
|
|
278
|
-
},
|
|
279
|
-
{
|
|
280
|
-
type: "input",
|
|
281
|
-
name: "components",
|
|
282
|
-
message: "Components directory:",
|
|
283
|
-
default: defaults.components
|
|
284
|
-
},
|
|
285
|
-
{
|
|
286
|
-
type: "input",
|
|
287
|
-
name: "primitives",
|
|
288
|
-
message: "Primitives directory:",
|
|
289
|
-
default: defaults.primitives
|
|
290
|
-
},
|
|
291
|
-
{
|
|
292
|
-
type: "input",
|
|
293
|
-
name: "blocks",
|
|
294
|
-
message: "Blocks directory:",
|
|
295
|
-
default: defaults.blocks
|
|
296
|
-
},
|
|
297
|
-
{
|
|
298
|
-
type: "input",
|
|
299
|
-
name: "hooks",
|
|
300
|
-
message: "Hooks directory:",
|
|
301
|
-
default: defaults.hooks
|
|
302
|
-
},
|
|
303
|
-
{
|
|
304
|
-
type: "input",
|
|
305
|
-
name: "maps",
|
|
306
|
-
message: "Maps directory:",
|
|
307
|
-
default: defaults.maps
|
|
308
|
-
},
|
|
309
|
-
{
|
|
310
|
-
type: "input",
|
|
311
|
-
name: "animations",
|
|
312
|
-
message: "Animations directory:",
|
|
313
|
-
default: defaults.animations
|
|
314
|
-
},
|
|
315
|
-
{
|
|
316
|
-
type: "input",
|
|
317
|
-
name: "styles",
|
|
318
|
-
message: "Global styles file:",
|
|
319
|
-
default: defaults.styles
|
|
320
|
-
},
|
|
321
|
-
{
|
|
322
|
-
type: "input",
|
|
323
|
-
name: "lib",
|
|
324
|
-
message: "Lib directory:",
|
|
325
|
-
default: defaults.lib
|
|
316
|
+
async fetchPackageMetadata(packageName) {
|
|
317
|
+
try {
|
|
318
|
+
const encodedName = packageName.replace("/", "%2F");
|
|
319
|
+
const response = await fetch(`${NPM_REGISTRY_URL}/${encodedName}`);
|
|
320
|
+
if (!response.ok) return null;
|
|
321
|
+
const data = await response.json();
|
|
322
|
+
return {
|
|
323
|
+
version: data["dist-tags"]?.latest ?? Object.keys(data.versions ?? {}).sort(compareVersions).at(-1),
|
|
324
|
+
description: data.description,
|
|
325
|
+
keywords: data.keywords
|
|
326
|
+
};
|
|
327
|
+
} catch {
|
|
328
|
+
return null;
|
|
326
329
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
console.log(chalk.blue("\u{1F4E6} Installing dependencies..."));
|
|
332
|
-
const packageManager = detectPackageManager();
|
|
333
|
-
const execAsync2 = promisify(exec);
|
|
334
|
-
const dependencies = [
|
|
335
|
-
"clsx",
|
|
336
|
-
"tailwind-merge",
|
|
337
|
-
"framer-motion",
|
|
338
|
-
"lucide-react",
|
|
339
|
-
"next-themes",
|
|
340
|
-
"cmdk",
|
|
341
|
-
"@foundrykit/tailwind",
|
|
342
|
-
"@radix-ui/react-dialog",
|
|
343
|
-
"@radix-ui/react-dropdown-menu",
|
|
344
|
-
"@radix-ui/react-label",
|
|
345
|
-
"@radix-ui/react-popover",
|
|
346
|
-
"@radix-ui/react-select",
|
|
347
|
-
"@radix-ui/react-separator",
|
|
348
|
-
"@radix-ui/react-slot",
|
|
349
|
-
"@radix-ui/react-switch",
|
|
350
|
-
"@radix-ui/react-tabs",
|
|
351
|
-
"@radix-ui/react-tooltip"
|
|
352
|
-
];
|
|
353
|
-
const devDependencies = ["tailwindcss", "autoprefixer", "postcss"];
|
|
354
|
-
try {
|
|
355
|
-
const installCmd = packageManager === "npm" ? "install" : "add";
|
|
356
|
-
await execAsync2(
|
|
357
|
-
`${packageManager} ${installCmd} ${dependencies.join(" ")}`
|
|
358
|
-
);
|
|
359
|
-
const devFlag = packageManager === "npm" ? "--save-dev" : "-D";
|
|
360
|
-
await execAsync2(
|
|
361
|
-
`${packageManager} ${installCmd} ${devFlag} ${devDependencies.join(" ")}`
|
|
330
|
+
}
|
|
331
|
+
getFallbackFoundryKitPackages() {
|
|
332
|
+
return FOUNDRYKIT_PACKAGE_ALIASES.map(
|
|
333
|
+
(packageId) => this.toPackageComponentMeta(`@foundrykit/${packageId}`)
|
|
362
334
|
);
|
|
363
|
-
console.log(chalk.green("\u2705 Dependencies installed"));
|
|
364
|
-
} catch (error) {
|
|
365
|
-
console.error(chalk.yellow("\u26A0\uFE0F Failed to install some dependencies"));
|
|
366
|
-
console.error(chalk.gray("You may need to install them manually"));
|
|
367
335
|
}
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
{
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
name: "Keep direct import from @foundrykit/tailwind/globals.css",
|
|
397
|
-
value: "direct"
|
|
398
|
-
},
|
|
399
|
-
{
|
|
400
|
-
name: "Switch to local globals.css file (recommended for customization)",
|
|
401
|
-
value: "local"
|
|
402
|
-
}
|
|
403
|
-
],
|
|
404
|
-
default: "direct"
|
|
405
|
-
}
|
|
406
|
-
]);
|
|
407
|
-
if (importPreference === "direct") {
|
|
408
|
-
console.log(
|
|
409
|
-
chalk.green(
|
|
410
|
-
"\u2705 Keeping direct import from @foundrykit/tailwind/globals.css"
|
|
411
|
-
)
|
|
412
|
-
);
|
|
413
|
-
return;
|
|
414
|
-
}
|
|
415
|
-
await createOrUpdateGlobalsCss(pathConfig, projectStructure);
|
|
416
|
-
await updateLayoutImport(layoutPath, pathConfig);
|
|
417
|
-
return;
|
|
336
|
+
toPackageComponentMeta(packageName, metadata = {}) {
|
|
337
|
+
const id = packageName.replace("@foundrykit/", "");
|
|
338
|
+
return {
|
|
339
|
+
id,
|
|
340
|
+
name: this.toDisplayName(id),
|
|
341
|
+
version: metadata.version,
|
|
342
|
+
category: id === "maps" ? "maps" : id === "hooks" ? "hooks" : "packages",
|
|
343
|
+
description: metadata.description ?? `${packageName} npm package`,
|
|
344
|
+
tags: metadata.keywords,
|
|
345
|
+
packageDependencies: [packageName]
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Update the local cache with new component list
|
|
350
|
+
*/
|
|
351
|
+
async updateCache(components) {
|
|
352
|
+
try {
|
|
353
|
+
const cache = await this.loadCache();
|
|
354
|
+
const newCache = {
|
|
355
|
+
version: "1.0.0",
|
|
356
|
+
lastUpdated: (/* @__PURE__ */ new Date()).toISOString(),
|
|
357
|
+
components,
|
|
358
|
+
componentData: cache?.componentData || {}
|
|
359
|
+
};
|
|
360
|
+
await fs.ensureDir(this.config.cacheDir);
|
|
361
|
+
await fs.writeJson(this.cacheFile, newCache, { spaces: 2 });
|
|
362
|
+
} catch {
|
|
363
|
+
console.log(chalk.gray("Failed to update cache"));
|
|
418
364
|
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Cache a specific component
|
|
368
|
+
*/
|
|
369
|
+
async cacheComponent(component) {
|
|
370
|
+
try {
|
|
371
|
+
const cache = await this.loadCache() ?? {
|
|
372
|
+
version: "1.0.0",
|
|
373
|
+
lastUpdated: (/* @__PURE__ */ new Date()).toISOString(),
|
|
374
|
+
components: [],
|
|
375
|
+
componentData: {}
|
|
376
|
+
};
|
|
377
|
+
cache.componentData[component.id] = component;
|
|
378
|
+
cache.lastUpdated = (/* @__PURE__ */ new Date()).toISOString();
|
|
379
|
+
await fs.ensureDir(this.config.cacheDir);
|
|
380
|
+
await fs.writeJson(this.cacheFile, cache, { spaces: 2 });
|
|
381
|
+
} catch {
|
|
382
|
+
console.log(chalk.gray("Failed to cache component"));
|
|
432
383
|
}
|
|
433
384
|
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
choices: [
|
|
442
|
-
{
|
|
443
|
-
name: "Create/update a local globals.css file (recommended for customization)",
|
|
444
|
-
value: "local"
|
|
445
|
-
},
|
|
446
|
-
{
|
|
447
|
-
name: "Import directly from @foundrykit/tailwind/globals.css",
|
|
448
|
-
value: "direct"
|
|
449
|
-
}
|
|
450
|
-
],
|
|
451
|
-
default: "local"
|
|
385
|
+
/**
|
|
386
|
+
* Load the local cache
|
|
387
|
+
*/
|
|
388
|
+
async loadCache() {
|
|
389
|
+
try {
|
|
390
|
+
if (await fs.pathExists(this.cacheFile)) {
|
|
391
|
+
return await fs.readJson(this.cacheFile);
|
|
452
392
|
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
}
|
|
456
|
-
if (setupPreference === "direct") {
|
|
457
|
-
await addDirectImportToLayout(layoutPath, pathConfig);
|
|
458
|
-
} else {
|
|
459
|
-
await createOrUpdateGlobalsCss(pathConfig, projectStructure);
|
|
460
|
-
if (layoutPath) {
|
|
461
|
-
await updateLayoutImport(layoutPath, pathConfig);
|
|
393
|
+
} catch {
|
|
394
|
+
console.log(chalk.gray("Failed to load cache"));
|
|
462
395
|
}
|
|
396
|
+
return null;
|
|
463
397
|
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
const cssContent = `/* Import FoundryKit's Tailwind CSS v4 styles */
|
|
472
|
-
@import "@foundrykit/tailwind/globals.css";
|
|
473
|
-
|
|
474
|
-
/* Your custom styles below */
|
|
475
|
-
`;
|
|
476
|
-
await fs.ensureDir(path.dirname(globalsCssPath));
|
|
477
|
-
await fs.writeFile(globalsCssPath, cssContent);
|
|
478
|
-
console.log(chalk.green(`\u2705 Created ${pathConfig.styles}`));
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
async function updateExistingGlobalsCss(globalsCssPath) {
|
|
482
|
-
const content = await fs.readFile(globalsCssPath, "utf-8");
|
|
483
|
-
if (content.includes("@foundrykit/tailwind/globals.css")) {
|
|
484
|
-
console.log(chalk.gray("globals.css already imports FoundryKit styles"));
|
|
485
|
-
return;
|
|
486
|
-
}
|
|
487
|
-
if (content.includes('@import "tailwindcss"')) {
|
|
488
|
-
const updatedContent = content.replace(
|
|
489
|
-
'@import "tailwindcss"',
|
|
490
|
-
`/* Import FoundryKit's Tailwind CSS v4 styles */
|
|
491
|
-
@import "@foundrykit/tailwind/globals.css"`
|
|
492
|
-
);
|
|
493
|
-
await fs.writeFile(globalsCssPath, updatedContent);
|
|
494
|
-
console.log(chalk.green("\u2705 Updated globals.css with FoundryKit styles"));
|
|
495
|
-
} else {
|
|
496
|
-
const updatedContent = `/* Import FoundryKit's Tailwind CSS v4 styles */
|
|
497
|
-
@import "@foundrykit/tailwind/globals.css";
|
|
498
|
-
|
|
499
|
-
/* Your custom styles below */
|
|
500
|
-
${content}`;
|
|
501
|
-
await fs.writeFile(globalsCssPath, updatedContent);
|
|
502
|
-
console.log(chalk.green("\u2705 Updated globals.css with FoundryKit styles"));
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
async function findLayoutFile(projectStructure) {
|
|
506
|
-
const possiblePaths = [];
|
|
507
|
-
if (projectStructure.appPath) {
|
|
508
|
-
const ext = projectStructure.isTypeScript ? ".tsx" : ".jsx";
|
|
509
|
-
possiblePaths.push(
|
|
510
|
-
path.join(projectStructure.appPath, `layout${ext}`),
|
|
511
|
-
path.join(projectStructure.appPath, `layout.js`)
|
|
512
|
-
);
|
|
398
|
+
/**
|
|
399
|
+
* Check if cache is still valid
|
|
400
|
+
*/
|
|
401
|
+
isCacheValid(cache) {
|
|
402
|
+
const lastUpdated = new Date(cache.lastUpdated).getTime();
|
|
403
|
+
const now = Date.now();
|
|
404
|
+
return now - lastUpdated < this.config.cacheMaxAge;
|
|
513
405
|
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
406
|
+
/**
|
|
407
|
+
* Filter components by category and search
|
|
408
|
+
*/
|
|
409
|
+
filterComponents(components, category, search) {
|
|
410
|
+
let filtered = components;
|
|
411
|
+
if (category) {
|
|
412
|
+
filtered = filtered.filter((c) => c.category === category);
|
|
413
|
+
}
|
|
414
|
+
if (search) {
|
|
415
|
+
const searchLower = search.toLowerCase();
|
|
416
|
+
filtered = filtered.filter(
|
|
417
|
+
(c) => c.name.toLowerCase().includes(searchLower) || c.description.toLowerCase().includes(searchLower) || c.id.toLowerCase().includes(searchLower) || c.tags?.some((tag) => tag.toLowerCase().includes(searchLower))
|
|
418
|
+
);
|
|
526
419
|
}
|
|
420
|
+
return filtered;
|
|
527
421
|
}
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
const importPath = relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
537
|
-
const globalImportRegex = /import\s+['"]([^'"]*globals?\.css)['"]/;
|
|
538
|
-
const match = content.match(globalImportRegex);
|
|
539
|
-
if (match) {
|
|
540
|
-
content = content.replace(globalImportRegex, `import '${importPath}'`);
|
|
541
|
-
} else if (!content.includes(importPath)) {
|
|
542
|
-
const importStatement = `import '${importPath}';
|
|
543
|
-
`;
|
|
544
|
-
const importRegex = /^(import\s+.*?;\s*)+/m;
|
|
545
|
-
const importMatch = content.match(importRegex);
|
|
546
|
-
if (importMatch) {
|
|
547
|
-
const lastImportIndex = importMatch.index + importMatch[0].length;
|
|
548
|
-
content = content.slice(0, lastImportIndex) + importStatement + content.slice(lastImportIndex);
|
|
549
|
-
} else {
|
|
550
|
-
content = importStatement + content;
|
|
422
|
+
/**
|
|
423
|
+
* Clear the local cache
|
|
424
|
+
*/
|
|
425
|
+
async clearCache() {
|
|
426
|
+
try {
|
|
427
|
+
if (await fs.pathExists(this.cacheFile)) {
|
|
428
|
+
await fs.remove(this.cacheFile);
|
|
429
|
+
console.log(chalk.green("Cache cleared successfully"));
|
|
551
430
|
}
|
|
431
|
+
} catch (error) {
|
|
432
|
+
throw new Error(
|
|
433
|
+
`Failed to clear cache: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
434
|
+
);
|
|
552
435
|
}
|
|
553
|
-
await fs.writeFile(layoutPath, content);
|
|
554
|
-
console.log(
|
|
555
|
-
chalk.gray(
|
|
556
|
-
`Updated ${path.relative(process.cwd(), layoutPath)} with CSS import`
|
|
557
|
-
)
|
|
558
|
-
);
|
|
559
|
-
} catch (error) {
|
|
560
|
-
console.error(chalk.yellow("\u26A0\uFE0F Failed to update layout with CSS import"));
|
|
561
436
|
}
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
437
|
+
/**
|
|
438
|
+
* Get cache statistics
|
|
439
|
+
*/
|
|
440
|
+
async getCacheStats() {
|
|
441
|
+
try {
|
|
442
|
+
if (await fs.pathExists(this.cacheFile)) {
|
|
443
|
+
const cache = await this.loadCache();
|
|
444
|
+
const stats = await fs.stat(this.cacheFile);
|
|
445
|
+
return {
|
|
446
|
+
exists: true,
|
|
447
|
+
size: stats.size,
|
|
448
|
+
lastUpdated: cache?.lastUpdated || null,
|
|
449
|
+
componentCount: cache?.components.length || 0
|
|
450
|
+
};
|
|
576
451
|
}
|
|
577
|
-
|
|
578
|
-
console.log(
|
|
579
|
-
chalk.green("\u2705 Added direct import of FoundryKit styles to layout")
|
|
580
|
-
);
|
|
452
|
+
} catch {
|
|
581
453
|
}
|
|
582
|
-
|
|
583
|
-
|
|
454
|
+
return {
|
|
455
|
+
exists: false,
|
|
456
|
+
size: 0,
|
|
457
|
+
lastUpdated: null,
|
|
458
|
+
componentCount: 0
|
|
459
|
+
};
|
|
584
460
|
}
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
return path.join(process.cwd(), importPath.replace("@/", "src/"));
|
|
591
|
-
} else if (importPath.startsWith("/")) {
|
|
592
|
-
return path.join(process.cwd(), importPath);
|
|
461
|
+
};
|
|
462
|
+
var registryInstance = null;
|
|
463
|
+
function getRegistry(config) {
|
|
464
|
+
if (!registryInstance) {
|
|
465
|
+
registryInstance = new RegistryService(config);
|
|
593
466
|
}
|
|
594
|
-
return
|
|
467
|
+
return registryInstance;
|
|
595
468
|
}
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
const
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
pathConfig.animations,
|
|
604
|
-
pathConfig.hooks,
|
|
605
|
-
pathConfig.lib
|
|
606
|
-
];
|
|
607
|
-
for (const dir of dirs) {
|
|
608
|
-
const fullPath = path.join(process.cwd(), dir);
|
|
609
|
-
await fs.ensureDir(fullPath);
|
|
610
|
-
console.log(chalk.gray(`Created ${dir}`));
|
|
469
|
+
function compareVersions(a, b) {
|
|
470
|
+
const aParts = normalizeVersion(a).split(".").map(Number);
|
|
471
|
+
const bParts = normalizeVersion(b).split(".").map(Number);
|
|
472
|
+
const length = Math.max(aParts.length, bParts.length);
|
|
473
|
+
for (let index = 0; index < length; index++) {
|
|
474
|
+
const diff = (aParts[index] ?? 0) - (bParts[index] ?? 0);
|
|
475
|
+
if (diff !== 0) return diff;
|
|
611
476
|
}
|
|
612
|
-
|
|
477
|
+
return 0;
|
|
478
|
+
}
|
|
479
|
+
function normalizeVersion(version) {
|
|
480
|
+
return version.replace(/^[^\d]*/, "").split("-")[0]?.replace(/[^\d.]/g, "") || "0";
|
|
613
481
|
}
|
|
614
|
-
async function createExampleFiles(pathConfig, structure) {
|
|
615
|
-
console.log(chalk.blue("\u{1F4DD} Creating example files..."));
|
|
616
|
-
const utilsPath = path.join(process.cwd(), pathConfig.utils);
|
|
617
|
-
const utilsContent = `import { type ClassValue, clsx } from 'clsx';
|
|
618
|
-
import { twMerge } from 'tailwind-merge';
|
|
619
482
|
|
|
620
|
-
|
|
621
|
-
|
|
483
|
+
// src/commands/add.ts
|
|
484
|
+
var execAsync = promisify(exec);
|
|
485
|
+
function addCommand() {
|
|
486
|
+
return new Command("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) => {
|
|
487
|
+
try {
|
|
488
|
+
if (!id) {
|
|
489
|
+
const selectedIds = await selectComponentsInteractively();
|
|
490
|
+
if (selectedIds.length === 0) {
|
|
491
|
+
console.log(chalk2.yellow("No components selected."));
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
for (const componentId of selectedIds) {
|
|
495
|
+
await addSingleComponent(componentId, options);
|
|
496
|
+
}
|
|
497
|
+
} else {
|
|
498
|
+
await addSingleComponent(id, options);
|
|
499
|
+
}
|
|
500
|
+
} catch (error) {
|
|
501
|
+
console.error(chalk2.red("\u274C Failed to add component:"));
|
|
502
|
+
console.error(
|
|
503
|
+
chalk2.red(error instanceof Error ? error.message : String(error))
|
|
504
|
+
);
|
|
505
|
+
process.exit(1);
|
|
506
|
+
}
|
|
507
|
+
});
|
|
622
508
|
}
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
console.log(chalk.gray(`Created ${pathConfig.utils}`));
|
|
628
|
-
}
|
|
629
|
-
const providersPath = path.join(
|
|
630
|
-
process.cwd(),
|
|
631
|
-
path.dirname(pathConfig.components),
|
|
632
|
-
`theme-provider${structure.isTypeScript ? ".tsx" : ".jsx"}`
|
|
509
|
+
async function selectComponentsInteractively() {
|
|
510
|
+
console.log(chalk2.blue("\u{1F4E6} Select components to add:"));
|
|
511
|
+
console.log(
|
|
512
|
+
chalk2.gray(" Use arrow keys to navigate, space to select, a to toggle all")
|
|
633
513
|
);
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
514
|
+
console.log(chalk2.gray(" Press enter when done\n"));
|
|
515
|
+
const registry = getRegistry();
|
|
516
|
+
try {
|
|
517
|
+
console.log(chalk2.gray("Fetching components from registry..."));
|
|
518
|
+
const allComponents = await registry.getComponents();
|
|
519
|
+
if (allComponents.length === 0) {
|
|
520
|
+
console.log(chalk2.yellow("No components available in the registry."));
|
|
521
|
+
return [];
|
|
522
|
+
}
|
|
523
|
+
const groupedChoices = createGroupedChoices(allComponents);
|
|
524
|
+
const { selectedComponents } = await inquirer.prompt([
|
|
525
|
+
{
|
|
526
|
+
type: "checkbox",
|
|
527
|
+
name: "selectedComponents",
|
|
528
|
+
message: "Which components would you like to add?",
|
|
529
|
+
choices: groupedChoices,
|
|
530
|
+
pageSize: 20,
|
|
531
|
+
loop: false
|
|
532
|
+
}
|
|
533
|
+
]);
|
|
534
|
+
return selectedComponents;
|
|
535
|
+
} catch (error) {
|
|
536
|
+
console.error(chalk2.red("Failed to fetch components from registry:"));
|
|
537
|
+
console.error(
|
|
538
|
+
chalk2.red(error instanceof Error ? error.message : String(error))
|
|
539
|
+
);
|
|
540
|
+
throw error;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
function createGroupedChoices(components) {
|
|
544
|
+
const knownCategories = new Set(
|
|
545
|
+
REGISTRY_CATEGORY_ORDER
|
|
651
546
|
);
|
|
547
|
+
const categories = [
|
|
548
|
+
...REGISTRY_CATEGORY_ORDER,
|
|
549
|
+
...components.map((component) => component.category).filter((category) => !knownCategories.has(category))
|
|
550
|
+
];
|
|
551
|
+
const choices = [];
|
|
552
|
+
for (const category of categories) {
|
|
553
|
+
const categoryComponents = components.filter((c) => c.category === category);
|
|
554
|
+
if (categoryComponents.length === 0) continue;
|
|
555
|
+
choices.push({
|
|
556
|
+
name: chalk2.bold.cyan(`\u2500\u2500\u2500 ${category.toUpperCase()} \u2500\u2500\u2500`),
|
|
557
|
+
disabled: true,
|
|
558
|
+
value: `separator-${category}`
|
|
559
|
+
});
|
|
560
|
+
for (const component of categoryComponents) {
|
|
561
|
+
choices.push({
|
|
562
|
+
name: `${component.name} - ${chalk2.gray(component.description)}`,
|
|
563
|
+
value: component.id,
|
|
564
|
+
short: component.name
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
return choices;
|
|
652
569
|
}
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
570
|
+
async function addSingleComponent(id, options) {
|
|
571
|
+
console.log(chalk2.blue(`
|
|
572
|
+
\u{1F4E6} Adding ${id} to your project...`));
|
|
573
|
+
await validateProject();
|
|
574
|
+
const registry = getRegistry();
|
|
575
|
+
try {
|
|
576
|
+
const componentData = await registry.getComponent(id, options.force);
|
|
577
|
+
if (!options.overwrite && await hasConflictingFiles(componentData, options)) {
|
|
578
|
+
const { shouldContinue } = await inquirer.prompt([
|
|
579
|
+
{
|
|
580
|
+
type: "confirm",
|
|
581
|
+
name: "shouldContinue",
|
|
582
|
+
message: `Some files for ${componentData.name} already exist. Overwrite?`,
|
|
583
|
+
default: false
|
|
584
|
+
}
|
|
585
|
+
]);
|
|
586
|
+
if (!shouldContinue) {
|
|
587
|
+
console.log(chalk2.yellow(`\u23ED\uFE0F Skipping ${componentData.name}.`));
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
if (componentData.registryDependencies?.length) {
|
|
592
|
+
console.log(chalk2.blue("\u{1F4E6} Installing required dependencies..."));
|
|
593
|
+
for (const dep of componentData.registryDependencies) {
|
|
594
|
+
try {
|
|
595
|
+
const depData = await registry.getComponent(dep);
|
|
596
|
+
if (["hooks", "types"].includes(dep)) {
|
|
597
|
+
console.log(chalk2.green(` \u2713 ${dep} package is available`));
|
|
598
|
+
continue;
|
|
599
|
+
}
|
|
600
|
+
const hasExisting = await hasConflictingFiles(depData, options);
|
|
601
|
+
if (!hasExisting) {
|
|
602
|
+
await installComponentFiles(depData, options);
|
|
603
|
+
console.log(chalk2.green(` \u2713 Installed ${dep}`));
|
|
604
|
+
} else {
|
|
605
|
+
console.log(chalk2.gray(` \u23ED ${dep} already exists`));
|
|
606
|
+
}
|
|
607
|
+
} catch (error) {
|
|
608
|
+
console.log(
|
|
609
|
+
chalk2.yellow(
|
|
610
|
+
` \u26A0 Could not install dependency "${dep}": ${error instanceof Error ? error.message : "Unknown error"}`
|
|
611
|
+
)
|
|
612
|
+
);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
await installComponentFiles(componentData, options);
|
|
617
|
+
await trackInstalledComponent(componentData);
|
|
618
|
+
console.log(chalk2.green(`\u2705 ${componentData.name} added successfully!`));
|
|
619
|
+
showUsageExample(componentData);
|
|
620
|
+
await handlePackageDependencies(componentData, options);
|
|
621
|
+
} catch (error) {
|
|
622
|
+
console.error(chalk2.red(`Failed to add ${id}:`));
|
|
623
|
+
throw error;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
async function updateConfigVersion() {
|
|
627
|
+
const configPath = path2.join(process.cwd(), "foundrykit.config.json");
|
|
628
|
+
if (fs2.existsSync(configPath)) {
|
|
629
|
+
const config = await fs2.readJson(configPath);
|
|
630
|
+
if (config.version !== CLI_VERSION) {
|
|
631
|
+
config.version = CLI_VERSION;
|
|
632
|
+
await fs2.writeJson(configPath, config, { spaces: 2 });
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
async function validateProject() {
|
|
637
|
+
const packageJsonPath = path2.join(process.cwd(), "package.json");
|
|
638
|
+
if (!fs2.existsSync(packageJsonPath)) {
|
|
639
|
+
throw new Error(
|
|
640
|
+
"No package.json found. Please run this command in a project root."
|
|
661
641
|
);
|
|
662
642
|
}
|
|
663
|
-
|
|
643
|
+
const configPath = path2.join(process.cwd(), "foundrykit.config.json");
|
|
644
|
+
if (!fs2.existsSync(configPath)) {
|
|
645
|
+
throw new Error('FoundryKit not initialized. Run "foundrykit init" first.');
|
|
646
|
+
}
|
|
647
|
+
await updateConfigVersion();
|
|
664
648
|
}
|
|
665
|
-
async function
|
|
666
|
-
|
|
667
|
-
const
|
|
668
|
-
const
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
649
|
+
async function hasConflictingFiles(componentData, options) {
|
|
650
|
+
const config = await loadConfig();
|
|
651
|
+
const basePath = options.path || process.cwd();
|
|
652
|
+
for (const file of componentData.files) {
|
|
653
|
+
let resolvedPath;
|
|
654
|
+
if (componentData.id === "utils" || file.path === "lib/utils.ts") {
|
|
655
|
+
resolvedPath = config.paths.utils || "lib/utils.ts";
|
|
656
|
+
} else {
|
|
657
|
+
resolvedPath = resolveComponentPath(
|
|
658
|
+
file.path,
|
|
659
|
+
componentData.category,
|
|
660
|
+
config
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
const filePath = path2.join(basePath, resolvedPath);
|
|
664
|
+
if (fs2.existsSync(filePath)) {
|
|
665
|
+
return true;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
return false;
|
|
676
669
|
}
|
|
677
|
-
async function
|
|
678
|
-
|
|
679
|
-
const
|
|
680
|
-
if (
|
|
681
|
-
console.log(chalk.yellow("\u26A0\uFE0F Configuration file already exists"));
|
|
670
|
+
async function installComponentFiles(componentData, options) {
|
|
671
|
+
const config = await loadConfig();
|
|
672
|
+
const basePath = options.path || process.cwd();
|
|
673
|
+
if (componentData.files.length === 0) {
|
|
682
674
|
return;
|
|
683
675
|
}
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
676
|
+
console.log(chalk2.blue("\u{1F4DD} Installing component files..."));
|
|
677
|
+
for (const file of componentData.files) {
|
|
678
|
+
let resolvedPath;
|
|
679
|
+
if (componentData.id === "utils" || file.path === "lib/utils.ts") {
|
|
680
|
+
resolvedPath = config.paths.utils || "lib/utils.ts";
|
|
681
|
+
} else {
|
|
682
|
+
resolvedPath = resolveComponentPath(
|
|
683
|
+
file.path,
|
|
684
|
+
componentData.category,
|
|
685
|
+
config
|
|
686
|
+
);
|
|
687
687
|
}
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
primitives: normalizePath(pathConfig.primitives),
|
|
696
|
-
components: normalizePath(pathConfig.components),
|
|
697
|
-
blocks: normalizePath(pathConfig.blocks),
|
|
698
|
-
hooks: normalizePath(pathConfig.hooks),
|
|
699
|
-
maps: normalizePath(pathConfig.maps),
|
|
700
|
-
animations: normalizePath(pathConfig.animations)
|
|
701
|
-
},
|
|
702
|
-
packageManager: structure.packageManager,
|
|
703
|
-
typescript: structure.isTypeScript,
|
|
704
|
-
framework: structure.framework,
|
|
705
|
-
tailwind: {
|
|
706
|
-
css: normalizePath(pathConfig.styles)
|
|
707
|
-
},
|
|
708
|
-
aliases: {
|
|
709
|
-
"@": normalizePath(structure.baseDir.replace(/\/$/, "") || "."),
|
|
710
|
-
"@/components": normalizePath(
|
|
711
|
-
path.dirname(pathConfig.components).replace(/\/$/, "")
|
|
712
|
-
),
|
|
713
|
-
"@/lib": normalizePath(pathConfig.lib.replace(/\/$/, "")),
|
|
714
|
-
"@/hooks": normalizePath(pathConfig.hooks.replace(/\/$/, ""))
|
|
688
|
+
const filePath = path2.join(basePath, resolvedPath);
|
|
689
|
+
await fs2.ensureDir(path2.dirname(filePath));
|
|
690
|
+
if (!file.content || file.content.trim() === "") {
|
|
691
|
+
console.log(
|
|
692
|
+
chalk2.yellow(` \u26A0 Skipping ${resolvedPath} - no content available`)
|
|
693
|
+
);
|
|
694
|
+
continue;
|
|
715
695
|
}
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
696
|
+
const transformedContent = transformImportsForConfig(file.content, config);
|
|
697
|
+
await fs2.writeFile(filePath, transformedContent);
|
|
698
|
+
console.log(chalk2.gray(` \u2713 Created ${resolvedPath}`));
|
|
699
|
+
}
|
|
700
|
+
await updateConfigVersion();
|
|
719
701
|
}
|
|
720
|
-
async function
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
const
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
702
|
+
async function trackInstalledComponent(componentData) {
|
|
703
|
+
const configPath = path2.join(process.cwd(), "foundrykit.config.json");
|
|
704
|
+
if (!fs2.existsSync(configPath)) return;
|
|
705
|
+
const config = await fs2.readJson(configPath);
|
|
706
|
+
config.installedComponents = config.installedComponents ?? {};
|
|
707
|
+
config.installedComponents[componentData.id] = {
|
|
708
|
+
id: componentData.id,
|
|
709
|
+
version: componentData.version ?? null,
|
|
710
|
+
installedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
711
|
+
};
|
|
712
|
+
await fs2.writeJson(configPath, config, { spaces: 2 });
|
|
728
713
|
}
|
|
729
|
-
|
|
730
|
-
const
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
console.log(chalk.green("\u2705 Utility functions installed"));
|
|
735
|
-
} else {
|
|
736
|
-
console.log(chalk.gray("Utils file already exists, skipping..."));
|
|
714
|
+
async function handlePackageDependencies(componentData, options = {}) {
|
|
715
|
+
const allDependencies = /* @__PURE__ */ new Set();
|
|
716
|
+
if (componentData.packageDependencies?.length) {
|
|
717
|
+
for (const dep of componentData.packageDependencies)
|
|
718
|
+
allDependencies.add(dep);
|
|
737
719
|
}
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
// src/commands/list.ts
|
|
741
|
-
import { Command as Command2 } from "commander";
|
|
742
|
-
import chalk3 from "chalk";
|
|
743
|
-
|
|
744
|
-
// src/lib/registry.ts
|
|
745
|
-
import fs2 from "fs-extra";
|
|
746
|
-
import path2 from "path";
|
|
747
|
-
import os from "os";
|
|
748
|
-
import chalk2 from "chalk";
|
|
749
|
-
var DEFAULT_CONFIG = {
|
|
750
|
-
registryUrl: process.env.FOUNDRYKIT_REGISTRY_URL || DEFAULT_REGISTRY_URL,
|
|
751
|
-
cacheDir: path2.join(os.homedir(), CACHE_DIR, "cache"),
|
|
752
|
-
cacheMaxAge: CACHE_TTL
|
|
753
|
-
};
|
|
754
|
-
var RegistryService = class {
|
|
755
|
-
config;
|
|
756
|
-
cacheFile;
|
|
757
|
-
foundryKitPackagesPromise = null;
|
|
758
|
-
constructor(config) {
|
|
759
|
-
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
760
|
-
this.cacheFile = path2.join(this.config.cacheDir, "registry.json");
|
|
720
|
+
if (allDependencies.size === 0) {
|
|
721
|
+
return;
|
|
761
722
|
}
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
if (category) params.append("category", category);
|
|
769
|
-
if (search) params.append("search", search);
|
|
770
|
-
const url = `${this.config.registryUrl}/registry${params.toString() ? "?" + params.toString() : ""}`;
|
|
771
|
-
console.log(chalk2.gray(`Fetching from: ${url}`));
|
|
772
|
-
const response = await fetch(url);
|
|
773
|
-
if (!response.ok) {
|
|
774
|
-
throw new Error(
|
|
775
|
-
`Registry returned ${response.status}: ${response.statusText}`
|
|
776
|
-
);
|
|
777
|
-
}
|
|
778
|
-
const components = await response.json();
|
|
779
|
-
await this.updateCache(components);
|
|
780
|
-
return this.filterComponents(
|
|
781
|
-
await this.withFoundryKitPackages(components),
|
|
782
|
-
category,
|
|
783
|
-
search
|
|
784
|
-
);
|
|
785
|
-
} catch (error) {
|
|
786
|
-
const cache = await this.loadCache();
|
|
787
|
-
if (cache && this.isCacheValid(cache)) {
|
|
788
|
-
console.log(chalk2.yellow("Using cached registry data"));
|
|
789
|
-
return this.filterComponents(
|
|
790
|
-
await this.withFoundryKitPackages(cache.components),
|
|
791
|
-
category,
|
|
792
|
-
search
|
|
793
|
-
);
|
|
794
|
-
}
|
|
795
|
-
const npmPackages = await this.fetchFoundryKitPackages();
|
|
796
|
-
if (npmPackages.length > 0) {
|
|
797
|
-
console.log(chalk2.yellow("Using npm package data"));
|
|
798
|
-
return this.filterComponents(npmPackages, category, search);
|
|
799
|
-
}
|
|
800
|
-
throw new Error(
|
|
801
|
-
`Failed to connect to registry: ${error instanceof Error ? error.message : "Unknown error"}
|
|
802
|
-
Registry URL: ${this.config.registryUrl}
|
|
803
|
-
Try again later or check your internet connection.`
|
|
804
|
-
);
|
|
805
|
-
}
|
|
723
|
+
const dependencies = Array.from(allDependencies);
|
|
724
|
+
const forcePackageUpdate = componentData.files.length === 0 && (options.force || options.overwrite);
|
|
725
|
+
const missingPackages = forcePackageUpdate ? dependencies : await getMissingPackages(dependencies);
|
|
726
|
+
if (missingPackages.length === 0) {
|
|
727
|
+
console.log(chalk2.green("\u2705 All required packages are already installed"));
|
|
728
|
+
return;
|
|
806
729
|
}
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
730
|
+
const packagesToInstall = missingPackages.map(
|
|
731
|
+
(pkg) => forcePackageUpdate ? getPackageInstallSpec(pkg, componentData.version) : pkg
|
|
732
|
+
);
|
|
733
|
+
console.log(
|
|
734
|
+
chalk2.yellow(
|
|
735
|
+
forcePackageUpdate ? "\n\u{1F4E6} Updating required packages..." : "\n\u{1F4E6} Installing required packages..."
|
|
736
|
+
)
|
|
737
|
+
);
|
|
738
|
+
console.log(chalk2.gray(` ${packagesToInstall.join(", ")}`));
|
|
739
|
+
const packageManager = await detectPackageManager();
|
|
740
|
+
try {
|
|
741
|
+
const installCommand = `${packageManager} add ${packagesToInstall.join(" ")}`;
|
|
742
|
+
console.log(chalk2.blue(` Running: ${installCommand}`));
|
|
743
|
+
const { stderr } = await execAsync(installCommand);
|
|
744
|
+
if (stderr && !stderr.includes("warning")) {
|
|
745
|
+
console.error(chalk2.yellow(` Warning: ${stderr}`));
|
|
813
746
|
}
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
747
|
+
console.log(chalk2.green("\u2705 Packages installed successfully"));
|
|
748
|
+
} catch {
|
|
749
|
+
console.log(chalk2.yellow("\n\u26A0\uFE0F Could not install packages automatically"));
|
|
750
|
+
console.log(chalk2.gray(" Please install them manually:"));
|
|
751
|
+
console.log(
|
|
752
|
+
chalk2.cyan(` ${packageManager} add ${packagesToInstall.join(" ")}`)
|
|
817
753
|
);
|
|
818
|
-
const cache = await this.loadCache();
|
|
819
|
-
const cachedComponent = cache?.componentData?.[id];
|
|
820
|
-
const hasValidCache = cache ? this.isCacheValid(cache) : false;
|
|
821
|
-
if (!force && cachedComponent && hasValidCache) {
|
|
822
|
-
console.log(chalk2.gray(`Using cached data for component: ${id}`));
|
|
823
|
-
return cachedComponent;
|
|
824
|
-
}
|
|
825
|
-
try {
|
|
826
|
-
const url = `${this.config.registryUrl}/registry/${id}`;
|
|
827
|
-
console.log(chalk2.gray(`Fetching component: ${url}`));
|
|
828
|
-
const response = await fetch(url);
|
|
829
|
-
if (!response.ok) {
|
|
830
|
-
if (response.status === 404) {
|
|
831
|
-
if (foundryKitPackage) {
|
|
832
|
-
const npmPackage = await this.createFoundryKitPackageDependency(
|
|
833
|
-
foundryKitPackage,
|
|
834
|
-
!isKnownFoundryKitPackage
|
|
835
|
-
);
|
|
836
|
-
if (npmPackage) return npmPackage;
|
|
837
|
-
}
|
|
838
|
-
throw new Error(`Component "${id}" not found in registry`);
|
|
839
|
-
}
|
|
840
|
-
throw new Error(
|
|
841
|
-
`Registry returned ${response.status}: ${response.statusText}`
|
|
842
|
-
);
|
|
843
|
-
}
|
|
844
|
-
const component = await response.json();
|
|
845
|
-
await this.cacheComponent(component);
|
|
846
|
-
return component;
|
|
847
|
-
} catch (error) {
|
|
848
|
-
if (foundryKitPackage) {
|
|
849
|
-
const npmPackage = await this.createFoundryKitPackageDependency(
|
|
850
|
-
foundryKitPackage,
|
|
851
|
-
!isKnownFoundryKitPackage
|
|
852
|
-
);
|
|
853
|
-
if (npmPackage) return npmPackage;
|
|
854
|
-
}
|
|
855
|
-
if (cachedComponent) {
|
|
856
|
-
console.log(chalk2.yellow(`Using cached data for component: ${id}`));
|
|
857
|
-
return cachedComponent;
|
|
858
|
-
}
|
|
859
|
-
throw new Error(
|
|
860
|
-
`Failed to fetch component "${id}": ${error instanceof Error ? error.message : "Unknown error"}
|
|
861
|
-
Registry URL: ${this.config.registryUrl}
|
|
862
|
-
Try again later or check your internet connection.`
|
|
863
|
-
);
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
/**
|
|
867
|
-
* Check if a dependency ID is a special dependency that should be handled locally
|
|
868
|
-
*/
|
|
869
|
-
isSpecialDependency(id) {
|
|
870
|
-
const specialDependencies = [
|
|
871
|
-
"utils",
|
|
872
|
-
"lib",
|
|
873
|
-
"helpers",
|
|
874
|
-
"cn",
|
|
875
|
-
// Utils aliases
|
|
876
|
-
"hooks",
|
|
877
|
-
"types",
|
|
878
|
-
// Package dependencies
|
|
879
|
-
"maps"
|
|
880
|
-
];
|
|
881
|
-
return specialDependencies.includes(id);
|
|
882
754
|
}
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
if (["utils", "lib", "helpers", "cn"].includes(id)) {
|
|
888
|
-
return {
|
|
889
|
-
id: "utils",
|
|
890
|
-
name: "Utils",
|
|
891
|
-
description: "Utility functions for className merging",
|
|
892
|
-
category: "primitives",
|
|
893
|
-
files: [
|
|
894
|
-
{
|
|
895
|
-
path: "lib/utils.ts",
|
|
896
|
-
content: `import { type ClassValue, clsx } from 'clsx';
|
|
897
|
-
import { twMerge } from 'tailwind-merge';
|
|
898
|
-
|
|
899
|
-
export function cn(...inputs: ClassValue[]) {
|
|
900
|
-
return twMerge(clsx(inputs));
|
|
901
|
-
}`,
|
|
902
|
-
type: "util"
|
|
903
|
-
}
|
|
904
|
-
],
|
|
905
|
-
registryDependencies: [],
|
|
906
|
-
packageDependencies: ["clsx", "tailwind-merge"]
|
|
907
|
-
};
|
|
908
|
-
}
|
|
909
|
-
if (id === "hooks") {
|
|
910
|
-
const component = await this.createFoundryKitPackageDependency("@foundrykit/hooks");
|
|
911
|
-
if (component) return component;
|
|
912
|
-
}
|
|
913
|
-
if (id === "types") {
|
|
914
|
-
const component = await this.createFoundryKitPackageDependency("@foundrykit/types");
|
|
915
|
-
if (component) return component;
|
|
916
|
-
}
|
|
917
|
-
if (id === "maps") {
|
|
918
|
-
const component = await this.createFoundryKitPackageDependency("@foundrykit/maps");
|
|
919
|
-
if (component) return component;
|
|
920
|
-
}
|
|
921
|
-
throw new Error(`Unknown special dependency: ${id}`);
|
|
755
|
+
}
|
|
756
|
+
function getPackageInstallSpec(packageName, version) {
|
|
757
|
+
if (!packageName.startsWith("@foundrykit/")) {
|
|
758
|
+
return packageName;
|
|
922
759
|
}
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
...packageJson2.peerDependencies
|
|
937
|
-
};
|
|
938
|
-
return packageName in allDeps;
|
|
939
|
-
} catch (error) {
|
|
940
|
-
return false;
|
|
941
|
-
}
|
|
760
|
+
return `${packageName}@${version ?? "latest"}`;
|
|
761
|
+
}
|
|
762
|
+
async function getMissingPackages(packages) {
|
|
763
|
+
const packageJsonPath = path2.join(process.cwd(), "package.json");
|
|
764
|
+
try {
|
|
765
|
+
const packageJson2 = await fs2.readJson(packageJsonPath);
|
|
766
|
+
const installedPackages = {
|
|
767
|
+
...packageJson2.dependencies,
|
|
768
|
+
...packageJson2.devDependencies
|
|
769
|
+
};
|
|
770
|
+
return packages.filter((pkg) => !installedPackages[pkg]);
|
|
771
|
+
} catch {
|
|
772
|
+
return packages;
|
|
942
773
|
}
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
if (/^[a-z0-9][a-z0-9-]*$/i.test(id)) {
|
|
948
|
-
return `@foundrykit/${id}`;
|
|
949
|
-
}
|
|
950
|
-
return null;
|
|
774
|
+
}
|
|
775
|
+
async function detectPackageManager() {
|
|
776
|
+
if (await fs2.pathExists(path2.join(process.cwd(), "pnpm-lock.yaml"))) {
|
|
777
|
+
return "pnpm";
|
|
951
778
|
}
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
const category = id === "maps" ? "maps" : id === "hooks" ? "hooks" : "packages";
|
|
955
|
-
const metadata = await this.fetchPackageMetadata(packageName);
|
|
956
|
-
if (requirePublishedPackage && !metadata) {
|
|
957
|
-
return null;
|
|
958
|
-
}
|
|
959
|
-
return {
|
|
960
|
-
id,
|
|
961
|
-
name: this.toDisplayName(id),
|
|
962
|
-
version: metadata?.version,
|
|
963
|
-
description: metadata?.description ?? `${packageName} npm package`,
|
|
964
|
-
category,
|
|
965
|
-
files: [],
|
|
966
|
-
registryDependencies: [],
|
|
967
|
-
packageDependencies: [packageName]
|
|
968
|
-
};
|
|
779
|
+
if (await fs2.pathExists(path2.join(process.cwd(), "yarn.lock"))) {
|
|
780
|
+
return "yarn";
|
|
969
781
|
}
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
const seenIds = new Set(components.map((component) => component.id));
|
|
973
|
-
return [
|
|
974
|
-
...components,
|
|
975
|
-
...packageEntries.filter((component) => !seenIds.has(component.id))
|
|
976
|
-
];
|
|
782
|
+
if (await fs2.pathExists(path2.join(process.cwd(), "package-lock.json"))) {
|
|
783
|
+
return "npm";
|
|
977
784
|
}
|
|
978
|
-
|
|
979
|
-
return
|
|
785
|
+
if (await fs2.pathExists(path2.join(process.cwd(), "bun.lockb"))) {
|
|
786
|
+
return "bun";
|
|
980
787
|
}
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
const url = `${NPM_REGISTRY_URL}/-/v1/search?text=scope:foundrykit&size=250`;
|
|
993
|
-
console.log(chalk2.gray(`Fetching FoundryKit packages from npm: ${url}`));
|
|
994
|
-
const response = await fetch(url);
|
|
995
|
-
if (!response.ok) {
|
|
996
|
-
throw new Error(
|
|
997
|
-
`npm returned ${response.status}: ${response.statusText}`
|
|
998
|
-
);
|
|
788
|
+
return "pnpm";
|
|
789
|
+
}
|
|
790
|
+
async function showUsageExample(componentData) {
|
|
791
|
+
const config = await loadConfig();
|
|
792
|
+
console.log(chalk2.cyan("\n\u{1F4A1} Usage:"));
|
|
793
|
+
if (componentData.files.length === 0) {
|
|
794
|
+
const packageName = componentData.packageDependencies?.find(
|
|
795
|
+
(dep) => dep.startsWith("@foundrykit/")
|
|
796
|
+
);
|
|
797
|
+
if (packageName) {
|
|
798
|
+
console.log(chalk2.gray(`import { ... } from "${packageName}"`));
|
|
999
799
|
}
|
|
1000
|
-
|
|
1001
|
-
return (data.objects ?? []).map((item) => item.package).filter((pkg) => {
|
|
1002
|
-
return Boolean(pkg?.name?.startsWith("@foundrykit/"));
|
|
1003
|
-
}).map((pkg) => this.toPackageComponentMeta(pkg.name, {
|
|
1004
|
-
version: pkg.version,
|
|
1005
|
-
description: pkg.description,
|
|
1006
|
-
keywords: pkg.keywords
|
|
1007
|
-
})).sort((a, b) => a.id.localeCompare(b.id));
|
|
800
|
+
return;
|
|
1008
801
|
}
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
return {
|
|
1016
|
-
version: data["dist-tags"]?.latest ?? Object.keys(data.versions ?? {}).sort(compareVersions).at(-1),
|
|
1017
|
-
description: data.description,
|
|
1018
|
-
keywords: data.keywords
|
|
1019
|
-
};
|
|
1020
|
-
} catch {
|
|
1021
|
-
return null;
|
|
1022
|
-
}
|
|
802
|
+
const componentName = componentData.name.replace(/\s+/g, "");
|
|
803
|
+
const importPath = getImportPath(componentData, config);
|
|
804
|
+
console.log(chalk2.gray(`import { ${componentName} } from "${importPath}"`));
|
|
805
|
+
if (componentData.usageExample) {
|
|
806
|
+
console.log(chalk2.gray(`
|
|
807
|
+
${componentData.usageExample}`));
|
|
1023
808
|
}
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
809
|
+
}
|
|
810
|
+
async function loadConfig() {
|
|
811
|
+
const configPath = path2.join(process.cwd(), "foundrykit.config.json");
|
|
812
|
+
if (!fs2.existsSync(configPath)) {
|
|
813
|
+
throw new Error(
|
|
814
|
+
'Configuration file not found. Run "foundrykit init" first.'
|
|
1027
815
|
);
|
|
1028
816
|
}
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
817
|
+
return fs2.readJson(configPath);
|
|
818
|
+
}
|
|
819
|
+
function transformImportsForConfig(content, config) {
|
|
820
|
+
let transformed = content;
|
|
821
|
+
const importPaths = getConfiguredImportPaths(config);
|
|
822
|
+
transformed = transformRegistryBarrelImports(
|
|
823
|
+
transformed,
|
|
824
|
+
["@foundrykit/primitives", "@/components/primitives", "@/components/ui"],
|
|
825
|
+
importPaths.primitives,
|
|
826
|
+
config,
|
|
827
|
+
"primitives"
|
|
828
|
+
);
|
|
829
|
+
transformed = transformRegistryBarrelImports(
|
|
830
|
+
transformed,
|
|
831
|
+
["@foundrykit/components", "@/components/components"],
|
|
832
|
+
importPaths.components,
|
|
833
|
+
config,
|
|
834
|
+
"components"
|
|
835
|
+
);
|
|
836
|
+
transformed = transformRegistryBarrelImports(
|
|
837
|
+
transformed,
|
|
838
|
+
["@foundrykit/blocks", "@/components/blocks"],
|
|
839
|
+
importPaths.blocks,
|
|
840
|
+
config,
|
|
841
|
+
"blocks"
|
|
842
|
+
);
|
|
843
|
+
transformed = transformRegistryBarrelImports(
|
|
844
|
+
transformed,
|
|
845
|
+
["@foundrykit/animation", "@/components/animations"],
|
|
846
|
+
importPaths.animations,
|
|
847
|
+
config,
|
|
848
|
+
"animations"
|
|
849
|
+
);
|
|
850
|
+
transformed = transformRegistryBarrelImports(
|
|
851
|
+
transformed,
|
|
852
|
+
["@foundrykit/maps", "@/components/maps"],
|
|
853
|
+
importPaths.maps,
|
|
854
|
+
config,
|
|
855
|
+
"maps"
|
|
856
|
+
);
|
|
857
|
+
transformed = transformRegistryBarrelImports(
|
|
858
|
+
transformed,
|
|
859
|
+
["@foundrykit/hooks", "@/hooks"],
|
|
860
|
+
importPaths.hooks,
|
|
861
|
+
config,
|
|
862
|
+
"hooks"
|
|
863
|
+
);
|
|
864
|
+
transformed = transformed.replace(/@foundrykit\/utils/g, importPaths.utils).replace(/@\/lib\/utils/g, importPaths.utils);
|
|
865
|
+
return transformed;
|
|
866
|
+
}
|
|
867
|
+
function getConfiguredImportPaths(config) {
|
|
868
|
+
const paths = config?.paths || {
|
|
869
|
+
primitives: "components/primitives",
|
|
870
|
+
components: "components",
|
|
871
|
+
blocks: "components/blocks",
|
|
872
|
+
animations: "components/animations",
|
|
873
|
+
hooks: "hooks",
|
|
874
|
+
maps: "components/maps",
|
|
875
|
+
utils: "lib/utils"
|
|
876
|
+
};
|
|
877
|
+
return {
|
|
878
|
+
primitives: resolveImportBasePath(paths.primitives, config, {
|
|
879
|
+
preferRootAlias: true
|
|
880
|
+
}),
|
|
881
|
+
components: resolveImportBasePath(paths.components, config, {
|
|
882
|
+
preferRootAlias: true
|
|
883
|
+
}),
|
|
884
|
+
blocks: resolveImportBasePath(paths.blocks, config, {
|
|
885
|
+
preferRootAlias: true
|
|
886
|
+
}),
|
|
887
|
+
animations: resolveImportBasePath(paths.animations, config, {
|
|
888
|
+
preferRootAlias: true
|
|
889
|
+
}),
|
|
890
|
+
maps: resolveImportBasePath(
|
|
891
|
+
paths.maps ?? joinImportPath(paths.components, "maps"),
|
|
892
|
+
config,
|
|
893
|
+
{
|
|
894
|
+
preferRootAlias: true
|
|
895
|
+
}
|
|
896
|
+
),
|
|
897
|
+
hooks: resolveImportBasePath(paths.hooks ?? "hooks", config, {
|
|
898
|
+
preferRootAlias: true
|
|
899
|
+
}),
|
|
900
|
+
packages: resolveImportBasePath(paths.components, config, {
|
|
901
|
+
preferRootAlias: true
|
|
902
|
+
}),
|
|
903
|
+
utils: resolveImportBasePath(paths.utils, config).replace(
|
|
904
|
+
/\.(ts|js)x?$/,
|
|
905
|
+
""
|
|
906
|
+
)
|
|
907
|
+
};
|
|
908
|
+
}
|
|
909
|
+
function resolveImportBasePath(filePath, config, options = {}) {
|
|
910
|
+
if (isPackageImportSpecifier(filePath)) {
|
|
911
|
+
return filePath.replace(/\/$/, "");
|
|
1040
912
|
}
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
};
|
|
1053
|
-
await fs2.ensureDir(this.config.cacheDir);
|
|
1054
|
-
await fs2.writeJson(this.cacheFile, newCache, { spaces: 2 });
|
|
1055
|
-
} catch (error) {
|
|
1056
|
-
console.log(chalk2.gray("Failed to update cache"));
|
|
913
|
+
const normalizedPath = normalizeConfigPath(filePath).replace(
|
|
914
|
+
/\.(ts|js)x?$/,
|
|
915
|
+
""
|
|
916
|
+
);
|
|
917
|
+
const aliases = config?.aliases ?? {};
|
|
918
|
+
if (options.preferRootAlias && aliases["@"]) {
|
|
919
|
+
const rootTarget = normalizeConfigPath(aliases["@"]);
|
|
920
|
+
const matchesRoot = normalizedPath === rootTarget || rootTarget !== "" && normalizedPath.startsWith(`${rootTarget}/`) || rootTarget === "";
|
|
921
|
+
if (matchesRoot) {
|
|
922
|
+
const relativePath = rootTarget === "" ? normalizedPath : normalizedPath.slice(rootTarget.length).replace(/^\//, "");
|
|
923
|
+
return joinImportPath("@", relativePath);
|
|
1057
924
|
}
|
|
1058
925
|
}
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
};
|
|
1070
|
-
cache.componentData[component.id] = component;
|
|
1071
|
-
cache.lastUpdated = (/* @__PURE__ */ new Date()).toISOString();
|
|
1072
|
-
await fs2.ensureDir(this.config.cacheDir);
|
|
1073
|
-
await fs2.writeJson(this.cacheFile, cache, { spaces: 2 });
|
|
1074
|
-
} catch (error) {
|
|
1075
|
-
console.log(chalk2.gray("Failed to cache component"));
|
|
1076
|
-
}
|
|
926
|
+
const aliasMatches = Object.entries(aliases).map(([alias, target]) => ({
|
|
927
|
+
alias,
|
|
928
|
+
target: normalizeConfigPath(target)
|
|
929
|
+
})).filter(({ target }) => {
|
|
930
|
+
return normalizedPath === target || target !== "" && normalizedPath.startsWith(`${target}/`) || target === "";
|
|
931
|
+
}).sort((a, b) => b.target.length - a.target.length);
|
|
932
|
+
const bestMatch = aliasMatches[0];
|
|
933
|
+
if (bestMatch) {
|
|
934
|
+
const relativePath = bestMatch.target === "" ? normalizedPath : normalizedPath.slice(bestMatch.target.length).replace(/^\//, "");
|
|
935
|
+
return joinImportPath(bestMatch.alias, relativePath);
|
|
1077
936
|
}
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
937
|
+
return joinImportPath("@", normalizedPath);
|
|
938
|
+
}
|
|
939
|
+
function normalizeConfigPath(filePath) {
|
|
940
|
+
return filePath.replace(/\\/g, "/").replace(/^\.\//, "").replace(/^\.\/?$/, "").replace(/\/$/, "");
|
|
941
|
+
}
|
|
942
|
+
function isPackageImportSpecifier(importPath) {
|
|
943
|
+
return importPath.startsWith("@") && !importPath.startsWith("@/");
|
|
944
|
+
}
|
|
945
|
+
function joinImportPath(basePath, childPath) {
|
|
946
|
+
const normalizedBase = basePath.replace(/\/$/, "");
|
|
947
|
+
const normalizedChild = childPath.replace(/^\//, "").replace(/\/$/, "");
|
|
948
|
+
if (!normalizedChild) {
|
|
949
|
+
return normalizedBase;
|
|
950
|
+
}
|
|
951
|
+
return `${normalizedBase}/${normalizedChild}`;
|
|
952
|
+
}
|
|
953
|
+
function transformRegistryBarrelImports(content, sources, destinationBasePath, config, category) {
|
|
954
|
+
const sourcePattern = sources.map((source) => source.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|");
|
|
955
|
+
const importPattern = new RegExp(
|
|
956
|
+
`import\\s+{([^}]+)}\\s+from\\s+["'](${sourcePattern})["'];?`,
|
|
957
|
+
"g"
|
|
958
|
+
);
|
|
959
|
+
return content.replace(
|
|
960
|
+
importPattern,
|
|
961
|
+
(match, imports, source) => {
|
|
962
|
+
if (isPackageImportSpecifier(destinationBasePath)) {
|
|
963
|
+
return match.replace(source, destinationBasePath);
|
|
1085
964
|
}
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
}
|
|
1091
|
-
/**
|
|
1092
|
-
* Check if cache is still valid
|
|
1093
|
-
*/
|
|
1094
|
-
isCacheValid(cache) {
|
|
1095
|
-
const lastUpdated = new Date(cache.lastUpdated).getTime();
|
|
1096
|
-
const now = Date.now();
|
|
1097
|
-
return now - lastUpdated < this.config.cacheMaxAge;
|
|
1098
|
-
}
|
|
1099
|
-
/**
|
|
1100
|
-
* Filter components by category and search
|
|
1101
|
-
*/
|
|
1102
|
-
filterComponents(components, category, search) {
|
|
1103
|
-
let filtered = components;
|
|
1104
|
-
if (category) {
|
|
1105
|
-
filtered = filtered.filter((c) => c.category === category);
|
|
1106
|
-
}
|
|
1107
|
-
if (search) {
|
|
1108
|
-
const searchLower = search.toLowerCase();
|
|
1109
|
-
filtered = filtered.filter(
|
|
1110
|
-
(c) => c.name.toLowerCase().includes(searchLower) || c.description.toLowerCase().includes(searchLower) || c.id.toLowerCase().includes(searchLower) || c.tags?.some((tag) => tag.toLowerCase().includes(searchLower))
|
|
1111
|
-
);
|
|
1112
|
-
}
|
|
1113
|
-
return filtered;
|
|
1114
|
-
}
|
|
1115
|
-
/**
|
|
1116
|
-
* Clear the local cache
|
|
1117
|
-
*/
|
|
1118
|
-
async clearCache() {
|
|
1119
|
-
try {
|
|
1120
|
-
if (await fs2.pathExists(this.cacheFile)) {
|
|
1121
|
-
await fs2.remove(this.cacheFile);
|
|
1122
|
-
console.log(chalk2.green("Cache cleared successfully"));
|
|
1123
|
-
}
|
|
1124
|
-
} catch (error) {
|
|
1125
|
-
throw new Error(
|
|
1126
|
-
`Failed to clear cache: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
1127
|
-
);
|
|
965
|
+
const groupedImports = groupImportsByComponent(imports, config, category);
|
|
966
|
+
return Array.from(groupedImports.entries()).map(([componentPath, specifiers]) => {
|
|
967
|
+
return `import { ${specifiers.join(", ")} } from "${destinationBasePath}/${componentPath}";`;
|
|
968
|
+
}).join("\n");
|
|
1128
969
|
}
|
|
970
|
+
);
|
|
971
|
+
}
|
|
972
|
+
function groupImportsByComponent(imports, config, category) {
|
|
973
|
+
const groupedImports = /* @__PURE__ */ new Map();
|
|
974
|
+
const exportMap = getInstalledComponentExportMap(config, category);
|
|
975
|
+
const specifiers = imports.split(",").map((specifier) => specifier.trim()).filter(Boolean);
|
|
976
|
+
const exportNames = specifiers.map(getExportNameFromSpecifier);
|
|
977
|
+
for (const specifier of specifiers) {
|
|
978
|
+
const componentPath = getComponentPathForSpecifier(
|
|
979
|
+
specifier,
|
|
980
|
+
exportNames,
|
|
981
|
+
exportMap
|
|
982
|
+
);
|
|
983
|
+
const existing = groupedImports.get(componentPath) ?? [];
|
|
984
|
+
existing.push(specifier);
|
|
985
|
+
groupedImports.set(componentPath, existing);
|
|
1129
986
|
}
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
const stats = await fs2.stat(this.cacheFile);
|
|
1138
|
-
return {
|
|
1139
|
-
exists: true,
|
|
1140
|
-
size: stats.size,
|
|
1141
|
-
lastUpdated: cache?.lastUpdated || null,
|
|
1142
|
-
componentCount: cache?.components.length || 0
|
|
1143
|
-
};
|
|
1144
|
-
}
|
|
1145
|
-
} catch (error) {
|
|
1146
|
-
}
|
|
1147
|
-
return {
|
|
1148
|
-
exists: false,
|
|
1149
|
-
size: 0,
|
|
1150
|
-
lastUpdated: null,
|
|
1151
|
-
componentCount: 0
|
|
1152
|
-
};
|
|
987
|
+
return groupedImports;
|
|
988
|
+
}
|
|
989
|
+
function getComponentPathForSpecifier(specifier, importExportNames, exportMap) {
|
|
990
|
+
const exportName = getExportNameFromSpecifier(specifier);
|
|
991
|
+
const mappedPath = exportMap.get(exportName);
|
|
992
|
+
if (mappedPath) {
|
|
993
|
+
return mappedPath;
|
|
1153
994
|
}
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
if (!registryInstance) {
|
|
1158
|
-
registryInstance = new RegistryService(config);
|
|
995
|
+
const siblingOwnerName = importExportNames.filter((name) => name !== exportName).sort((a, b) => a.length - b.length).find((name) => exportName.toLowerCase().startsWith(name.toLowerCase()));
|
|
996
|
+
if (siblingOwnerName) {
|
|
997
|
+
return exportMap.get(siblingOwnerName) ?? toKebabCase(siblingOwnerName);
|
|
1159
998
|
}
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
const aParts = normalizeVersion(a).split(".").map(Number);
|
|
1164
|
-
const bParts = normalizeVersion(b).split(".").map(Number);
|
|
1165
|
-
const length = Math.max(aParts.length, bParts.length);
|
|
1166
|
-
for (let index = 0; index < length; index++) {
|
|
1167
|
-
const diff = (aParts[index] ?? 0) - (bParts[index] ?? 0);
|
|
1168
|
-
if (diff !== 0) return diff;
|
|
999
|
+
const variantsOwnerName = exportName.replace(/Variants$/, "");
|
|
1000
|
+
if (variantsOwnerName !== exportName) {
|
|
1001
|
+
return exportMap.get(variantsOwnerName) ?? toKebabCase(variantsOwnerName);
|
|
1169
1002
|
}
|
|
1170
|
-
return
|
|
1171
|
-
}
|
|
1172
|
-
function normalizeVersion(version) {
|
|
1173
|
-
return version.replace(/^[^\d]*/, "").split("-")[0]?.replace(/[^\d.]/g, "") || "0";
|
|
1003
|
+
return toKebabCase(exportName);
|
|
1174
1004
|
}
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
function listCommand() {
|
|
1178
|
-
return new Command2("list").description("List all available FoundryKit components and blocks").option(
|
|
1179
|
-
"-c, --category <category>",
|
|
1180
|
-
"filter by category (primitives, components, blocks, animations)"
|
|
1181
|
-
).option("-s, --search <term>", "search components by name or description").action(async (options) => {
|
|
1182
|
-
try {
|
|
1183
|
-
console.log(chalk3.blue("\u{1F4E6} Available FoundryKit components:"));
|
|
1184
|
-
const registry = getRegistry();
|
|
1185
|
-
if (options.category) {
|
|
1186
|
-
const validCategories = REGISTRY_CATEGORY_ORDER;
|
|
1187
|
-
if (!validCategories.includes(options.category)) {
|
|
1188
|
-
console.error(chalk3.red(`Invalid category: ${options.category}`));
|
|
1189
|
-
console.log(
|
|
1190
|
-
chalk3.gray(`Valid categories: ${validCategories.join(", ")}`)
|
|
1191
|
-
);
|
|
1192
|
-
process.exit(1);
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
console.log(chalk3.gray("Fetching from registry..."));
|
|
1196
|
-
const components = await registry.getComponents(
|
|
1197
|
-
options.category,
|
|
1198
|
-
options.search
|
|
1199
|
-
);
|
|
1200
|
-
if (components.length === 0) {
|
|
1201
|
-
console.log(
|
|
1202
|
-
chalk3.yellow("\nNo components found matching your criteria.")
|
|
1203
|
-
);
|
|
1204
|
-
if (options.search) {
|
|
1205
|
-
console.log(chalk3.gray(`Search term: "${options.search}"`));
|
|
1206
|
-
}
|
|
1207
|
-
if (options.category) {
|
|
1208
|
-
console.log(chalk3.gray(`Category: ${options.category}`));
|
|
1209
|
-
}
|
|
1210
|
-
return;
|
|
1211
|
-
}
|
|
1212
|
-
displayComponents(components);
|
|
1213
|
-
console.log(chalk3.cyan("\n\u{1F4A1} Usage:"));
|
|
1214
|
-
console.log(
|
|
1215
|
-
chalk3.gray(" foundrykit add # Interactive mode")
|
|
1216
|
-
);
|
|
1217
|
-
console.log(
|
|
1218
|
-
chalk3.gray(" foundrykit add <id> # Add specific component")
|
|
1219
|
-
);
|
|
1220
|
-
console.log(chalk3.gray(" foundrykit add button # Example"));
|
|
1221
|
-
} catch (error) {
|
|
1222
|
-
console.error(chalk3.red("\u274C Failed to fetch component registry:"));
|
|
1223
|
-
console.error(
|
|
1224
|
-
chalk3.red(error instanceof Error ? error.message : String(error))
|
|
1225
|
-
);
|
|
1226
|
-
process.exit(1);
|
|
1227
|
-
}
|
|
1228
|
-
});
|
|
1005
|
+
function getExportNameFromSpecifier(specifier) {
|
|
1006
|
+
return specifier.replace(/^type\s+/, "").split(/\s+as\s+/)[0]?.trim() || specifier;
|
|
1229
1007
|
}
|
|
1230
|
-
function
|
|
1231
|
-
const
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
{}
|
|
1240
|
-
);
|
|
1241
|
-
const knownCategories = new Set(
|
|
1242
|
-
REGISTRY_CATEGORY_ORDER
|
|
1008
|
+
function getInstalledComponentExportMap(config, category) {
|
|
1009
|
+
const exportMap = /* @__PURE__ */ new Map();
|
|
1010
|
+
const categoryPath = getConfiguredCategoryPath(config, category);
|
|
1011
|
+
if (!categoryPath) {
|
|
1012
|
+
return exportMap;
|
|
1013
|
+
}
|
|
1014
|
+
const absoluteCategoryPath = path2.resolve(
|
|
1015
|
+
process.cwd(),
|
|
1016
|
+
normalizeConfigPath(categoryPath)
|
|
1243
1017
|
);
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
const
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
`${chalk3.green("\u25CF")} ${chalk3.bold(item.name)} ${chalk3.gray(
|
|
1259
|
-
`(${item.id})`
|
|
1260
|
-
)}`
|
|
1261
|
-
);
|
|
1262
|
-
console.log(` ${chalk3.gray(item.description)}`);
|
|
1263
|
-
if (item.tags && item.tags.length > 0) {
|
|
1264
|
-
console.log(
|
|
1265
|
-
` ${chalk3.blue(item.tags.map((tag) => `#${tag}`).join(" "))}`
|
|
1266
|
-
);
|
|
1267
|
-
}
|
|
1268
|
-
if (item.registryDependencies && item.registryDependencies.length > 0) {
|
|
1269
|
-
console.log(
|
|
1270
|
-
` ${chalk3.yellow("Requires:")} ${item.registryDependencies.join(
|
|
1271
|
-
", "
|
|
1272
|
-
)}`
|
|
1273
|
-
);
|
|
1274
|
-
}
|
|
1275
|
-
if (item.packageDependencies && item.packageDependencies.length > 0) {
|
|
1276
|
-
console.log(
|
|
1277
|
-
` ${chalk3.magenta("NPM packages:")} ${item.packageDependencies.join(
|
|
1278
|
-
", "
|
|
1279
|
-
)}`
|
|
1280
|
-
);
|
|
1018
|
+
if (!fs2.existsSync(absoluteCategoryPath)) {
|
|
1019
|
+
return exportMap;
|
|
1020
|
+
}
|
|
1021
|
+
for (const entry of fs2.readdirSync(absoluteCategoryPath, {
|
|
1022
|
+
withFileTypes: true
|
|
1023
|
+
})) {
|
|
1024
|
+
if (!entry.isDirectory()) continue;
|
|
1025
|
+
const componentPath = entry.name;
|
|
1026
|
+
const componentDir = path2.join(absoluteCategoryPath, componentPath);
|
|
1027
|
+
const entryFiles = ["index.tsx", "index.ts", "index.jsx", "index.js"].map((fileName) => path2.join(componentDir, fileName)).filter((filePath) => fs2.existsSync(filePath));
|
|
1028
|
+
for (const filePath of entryFiles) {
|
|
1029
|
+
const content = fs2.readFileSync(filePath, "utf-8");
|
|
1030
|
+
for (const exportName of parseExportNames(content)) {
|
|
1031
|
+
exportMap.set(exportName, componentPath);
|
|
1281
1032
|
}
|
|
1282
|
-
console.log();
|
|
1283
1033
|
}
|
|
1284
1034
|
}
|
|
1285
|
-
|
|
1286
|
-
const byCategory = Object.entries(grouped).map(([cat, items]) => `${items.length} ${cat}`).join(", ");
|
|
1287
|
-
console.log(chalk3.gray("\u2500".repeat(40)));
|
|
1288
|
-
console.log(chalk3.gray(`Total: ${total} components (${byCategory})`));
|
|
1035
|
+
return exportMap;
|
|
1289
1036
|
}
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
function addCommand() {
|
|
1301
|
-
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) => {
|
|
1302
|
-
try {
|
|
1303
|
-
if (!id) {
|
|
1304
|
-
const selectedIds = await selectComponentsInteractively();
|
|
1305
|
-
if (selectedIds.length === 0) {
|
|
1306
|
-
console.log(chalk4.yellow("No components selected."));
|
|
1307
|
-
return;
|
|
1308
|
-
}
|
|
1309
|
-
for (const componentId of selectedIds) {
|
|
1310
|
-
await addSingleComponent(componentId, options);
|
|
1311
|
-
}
|
|
1312
|
-
} else {
|
|
1313
|
-
await addSingleComponent(id, options);
|
|
1037
|
+
function parseExportNames(content) {
|
|
1038
|
+
const exportNames = /* @__PURE__ */ new Set();
|
|
1039
|
+
const namedExportPattern = /export\s*{\s*([^}]+)\s*}/g;
|
|
1040
|
+
const declarationExportPattern = /export\s+(?:declare\s+)?(?:const|let|var|function|class|interface|type|enum)\s+([A-Za-z_$][\w$]*)/g;
|
|
1041
|
+
for (const match of content.matchAll(namedExportPattern)) {
|
|
1042
|
+
const exports = match[1] ?? "";
|
|
1043
|
+
for (const rawExport of exports.split(",")) {
|
|
1044
|
+
const exportName = rawExport.trim().replace(/^type\s+/, "").split(/\s+as\s+/).pop()?.trim();
|
|
1045
|
+
if (exportName) {
|
|
1046
|
+
exportNames.add(exportName);
|
|
1314
1047
|
}
|
|
1315
|
-
} catch (error) {
|
|
1316
|
-
console.error(chalk4.red("\u274C Failed to add component:"));
|
|
1317
|
-
console.error(
|
|
1318
|
-
chalk4.red(error instanceof Error ? error.message : String(error))
|
|
1319
|
-
);
|
|
1320
|
-
process.exit(1);
|
|
1321
1048
|
}
|
|
1322
|
-
}
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
console.log(
|
|
1327
|
-
chalk4.gray(" Use arrow keys to navigate, space to select, a to toggle all")
|
|
1328
|
-
);
|
|
1329
|
-
console.log(chalk4.gray(" Press enter when done\n"));
|
|
1330
|
-
const registry = getRegistry();
|
|
1331
|
-
try {
|
|
1332
|
-
console.log(chalk4.gray("Fetching components from registry..."));
|
|
1333
|
-
const allComponents = await registry.getComponents();
|
|
1334
|
-
if (allComponents.length === 0) {
|
|
1335
|
-
console.log(chalk4.yellow("No components available in the registry."));
|
|
1336
|
-
return [];
|
|
1049
|
+
}
|
|
1050
|
+
for (const match of content.matchAll(declarationExportPattern)) {
|
|
1051
|
+
if (match[1]) {
|
|
1052
|
+
exportNames.add(match[1]);
|
|
1337
1053
|
}
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1054
|
+
}
|
|
1055
|
+
return Array.from(exportNames);
|
|
1056
|
+
}
|
|
1057
|
+
function toKebabCase(value) {
|
|
1058
|
+
return value.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1-$2").toLowerCase();
|
|
1059
|
+
}
|
|
1060
|
+
function resolveComponentPath(originalPath, category, config) {
|
|
1061
|
+
const paths = config?.paths || {
|
|
1062
|
+
primitives: "components/primitives",
|
|
1063
|
+
components: "components",
|
|
1064
|
+
blocks: "components/blocks",
|
|
1065
|
+
animations: "components/animations",
|
|
1066
|
+
hooks: "hooks",
|
|
1067
|
+
maps: "components/maps",
|
|
1068
|
+
utils: "lib/utils"
|
|
1069
|
+
};
|
|
1070
|
+
if (originalPath === "lib/utils.ts") {
|
|
1071
|
+
return paths.utils || "lib/utils.ts";
|
|
1072
|
+
}
|
|
1073
|
+
const categoryPath = getConfiguredCategoryPath(config, category) || paths.components;
|
|
1074
|
+
const fileName = path2.basename(originalPath);
|
|
1075
|
+
const componentName = path2.dirname(originalPath).split("/").pop() || "";
|
|
1076
|
+
if (category === "primitives") {
|
|
1077
|
+
return path2.join(categoryPath, componentName, fileName);
|
|
1078
|
+
} else if (category === "components") {
|
|
1079
|
+
return path2.join(paths.components, componentName, fileName);
|
|
1080
|
+
} else if (category === "blocks") {
|
|
1081
|
+
return path2.join(
|
|
1082
|
+
paths.blocks || path2.join(paths.components, "blocks"),
|
|
1083
|
+
componentName,
|
|
1084
|
+
fileName
|
|
1354
1085
|
);
|
|
1355
|
-
|
|
1086
|
+
} else if (category === "animations") {
|
|
1087
|
+
return path2.join(
|
|
1088
|
+
paths.animations || path2.join(paths.components, "animations"),
|
|
1089
|
+
componentName,
|
|
1090
|
+
fileName
|
|
1091
|
+
);
|
|
1092
|
+
} else if (category === "maps") {
|
|
1093
|
+
return path2.join(
|
|
1094
|
+
paths.maps || path2.join(paths.components, "maps"),
|
|
1095
|
+
componentName,
|
|
1096
|
+
fileName
|
|
1097
|
+
);
|
|
1098
|
+
} else if (category === "hooks") {
|
|
1099
|
+
return path2.join(paths.hooks || "hooks", componentName, fileName);
|
|
1100
|
+
} else if (category === "packages") {
|
|
1101
|
+
return path2.join(paths.components, componentName, fileName);
|
|
1356
1102
|
}
|
|
1103
|
+
return originalPath;
|
|
1357
1104
|
}
|
|
1358
|
-
function
|
|
1359
|
-
const
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
name: `${component.name} - ${chalk4.gray(component.description)}`,
|
|
1378
|
-
value: component.id,
|
|
1379
|
-
short: component.name
|
|
1380
|
-
});
|
|
1381
|
-
}
|
|
1105
|
+
function getConfiguredCategoryPath(config, category) {
|
|
1106
|
+
const paths = config.paths;
|
|
1107
|
+
switch (category) {
|
|
1108
|
+
case "primitives":
|
|
1109
|
+
return paths.primitives;
|
|
1110
|
+
case "components":
|
|
1111
|
+
return paths.components;
|
|
1112
|
+
case "blocks":
|
|
1113
|
+
return paths.blocks;
|
|
1114
|
+
case "animations":
|
|
1115
|
+
return paths.animations;
|
|
1116
|
+
case "maps":
|
|
1117
|
+
return paths.maps ?? path2.join(paths.components, "maps");
|
|
1118
|
+
case "hooks":
|
|
1119
|
+
return paths.hooks ?? "hooks";
|
|
1120
|
+
case "packages":
|
|
1121
|
+
return paths.components;
|
|
1122
|
+
default:
|
|
1123
|
+
return void 0;
|
|
1382
1124
|
}
|
|
1383
|
-
return choices;
|
|
1384
1125
|
}
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1126
|
+
function getImportPath(componentData, config) {
|
|
1127
|
+
const paths = config?.paths || {
|
|
1128
|
+
primitives: "components/primitives",
|
|
1129
|
+
components: "components",
|
|
1130
|
+
blocks: "components/blocks",
|
|
1131
|
+
animations: "components/animations",
|
|
1132
|
+
hooks: "hooks",
|
|
1133
|
+
maps: "components/maps",
|
|
1134
|
+
utils: "lib/utils"
|
|
1135
|
+
};
|
|
1136
|
+
const componentName = path2.basename(
|
|
1137
|
+
path2.dirname(componentData.files[0]?.path || "")
|
|
1138
|
+
);
|
|
1139
|
+
if (componentData.category === "primitives") {
|
|
1140
|
+
return `${resolveImportBasePath(paths.primitives, config, {
|
|
1141
|
+
preferRootAlias: true
|
|
1142
|
+
})}/${componentName}`;
|
|
1143
|
+
} else if (componentData.category === "components") {
|
|
1144
|
+
return `${resolveImportBasePath(paths.components, config, {
|
|
1145
|
+
preferRootAlias: true
|
|
1146
|
+
})}/${componentName}`;
|
|
1147
|
+
} else if (componentData.category === "blocks") {
|
|
1148
|
+
return `${resolveImportBasePath(paths.blocks, config, {
|
|
1149
|
+
preferRootAlias: true
|
|
1150
|
+
})}/${componentName}`;
|
|
1151
|
+
} else if (componentData.category === "animations") {
|
|
1152
|
+
return `${resolveImportBasePath(paths.animations, config, {
|
|
1153
|
+
preferRootAlias: true
|
|
1154
|
+
})}/${componentName}`;
|
|
1155
|
+
} else if (componentData.category === "maps") {
|
|
1156
|
+
return `${resolveImportBasePath(
|
|
1157
|
+
paths.maps || path2.join(paths.components, "maps"),
|
|
1158
|
+
config,
|
|
1159
|
+
{
|
|
1160
|
+
preferRootAlias: true
|
|
1404
1161
|
}
|
|
1162
|
+
)}/${componentName}`;
|
|
1163
|
+
} else if (componentData.category === "hooks") {
|
|
1164
|
+
return `${resolveImportBasePath(paths.hooks || "hooks", config, {
|
|
1165
|
+
preferRootAlias: true
|
|
1166
|
+
})}/${componentName}`;
|
|
1167
|
+
}
|
|
1168
|
+
return `@/components/${componentName}`;
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
// src/commands/doctor.ts
|
|
1172
|
+
import path3 from "path";
|
|
1173
|
+
import chalk3 from "chalk";
|
|
1174
|
+
import { Command as Command2 } from "commander";
|
|
1175
|
+
import fs3 from "fs-extra";
|
|
1176
|
+
function doctorCommand() {
|
|
1177
|
+
return new Command2("doctor").description("Check project health and configuration").action(async () => {
|
|
1178
|
+
console.log(chalk3.blue("\u{1F50D} Checking project health..."));
|
|
1179
|
+
const results = [];
|
|
1180
|
+
const packageJsonPath = path3.join(process.cwd(), "package.json");
|
|
1181
|
+
const hasPackageJson = await fs3.pathExists(packageJsonPath);
|
|
1182
|
+
results.push({
|
|
1183
|
+
label: "package.json",
|
|
1184
|
+
ok: hasPackageJson,
|
|
1185
|
+
detail: hasPackageJson ? "Project manifest found" : "Run this command in a project root"
|
|
1186
|
+
});
|
|
1187
|
+
let packageJson2 = null;
|
|
1188
|
+
if (hasPackageJson) {
|
|
1189
|
+
packageJson2 = await fs3.readJson(packageJsonPath);
|
|
1405
1190
|
}
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1191
|
+
const hasNext = !!packageJson2 && !!(packageJson2.dependencies?.next || packageJson2.devDependencies?.next);
|
|
1192
|
+
results.push({
|
|
1193
|
+
label: "Framework",
|
|
1194
|
+
ok: hasNext,
|
|
1195
|
+
detail: hasNext ? "Next.js dependency detected" : "FoundryKit currently expects a Next.js project"
|
|
1196
|
+
});
|
|
1197
|
+
const configPath = path3.join(process.cwd(), "foundrykit.config.json");
|
|
1198
|
+
const hasConfig = await fs3.pathExists(configPath);
|
|
1199
|
+
results.push({
|
|
1200
|
+
label: "FoundryKit config",
|
|
1201
|
+
ok: hasConfig,
|
|
1202
|
+
detail: hasConfig ? "foundrykit.config.json found" : 'Run "foundrykit init" to create the configuration file'
|
|
1203
|
+
});
|
|
1204
|
+
let config = null;
|
|
1205
|
+
if (hasConfig) {
|
|
1206
|
+
try {
|
|
1207
|
+
config = await loadConfig();
|
|
1208
|
+
const hasRequiredPaths = !!config.paths?.utils && !!config.paths?.primitives && !!config.paths?.components && !!config.paths?.blocks && !!config.paths?.animations;
|
|
1209
|
+
results.push({
|
|
1210
|
+
label: "Config shape",
|
|
1211
|
+
ok: hasRequiredPaths,
|
|
1212
|
+
detail: hasRequiredPaths ? "Required install paths are configured" : "Configuration is missing one or more required install paths"
|
|
1213
|
+
});
|
|
1214
|
+
const registryUrl = config.registry || DEFAULT_REGISTRY_URL;
|
|
1409
1215
|
try {
|
|
1410
|
-
const
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
console.log(chalk4.green(` \u2713 Installed ${dep}`));
|
|
1419
|
-
} else {
|
|
1420
|
-
console.log(chalk4.gray(` \u23ED ${dep} already exists`));
|
|
1421
|
-
}
|
|
1216
|
+
const response = await fetch(`${registryUrl}/registry`, {
|
|
1217
|
+
headers: { Accept: "application/json" }
|
|
1218
|
+
});
|
|
1219
|
+
results.push({
|
|
1220
|
+
label: "Registry",
|
|
1221
|
+
ok: response.ok,
|
|
1222
|
+
detail: response.ok ? `Registry reachable at ${registryUrl}` : `Registry returned ${response.status} ${response.statusText}`
|
|
1223
|
+
});
|
|
1422
1224
|
} catch (error) {
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
);
|
|
1225
|
+
results.push({
|
|
1226
|
+
label: "Registry",
|
|
1227
|
+
ok: false,
|
|
1228
|
+
detail: `Unable to reach ${registryUrl}: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
1229
|
+
});
|
|
1428
1230
|
}
|
|
1231
|
+
} catch (error) {
|
|
1232
|
+
results.push({
|
|
1233
|
+
label: "Config shape",
|
|
1234
|
+
ok: false,
|
|
1235
|
+
detail: `Failed to read foundrykit.config.json: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
1236
|
+
});
|
|
1429
1237
|
}
|
|
1430
1238
|
}
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
showUsageExample(componentData);
|
|
1435
|
-
await handlePackageDependencies(componentData, options);
|
|
1436
|
-
} catch (error) {
|
|
1437
|
-
console.error(chalk4.red(`Failed to add ${id}:`));
|
|
1438
|
-
throw error;
|
|
1439
|
-
}
|
|
1440
|
-
}
|
|
1441
|
-
async function updateConfigVersion() {
|
|
1442
|
-
const configPath = path3.join(process.cwd(), "foundrykit.config.json");
|
|
1443
|
-
if (fs3.existsSync(configPath)) {
|
|
1444
|
-
const config = await fs3.readJson(configPath);
|
|
1445
|
-
if (config.version !== CLI_VERSION) {
|
|
1446
|
-
config.version = CLI_VERSION;
|
|
1447
|
-
await fs3.writeJson(configPath, config, { spaces: 2 });
|
|
1239
|
+
for (const result of results) {
|
|
1240
|
+
const icon = result.ok ? chalk3.green("\u2705") : chalk3.red("\u274C");
|
|
1241
|
+
console.log(`${icon} ${result.label}: ${result.detail}`);
|
|
1448
1242
|
}
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
"No package.json found. Please run this command in a project root."
|
|
1456
|
-
);
|
|
1457
|
-
}
|
|
1458
|
-
const configPath = path3.join(process.cwd(), "foundrykit.config.json");
|
|
1459
|
-
if (!fs3.existsSync(configPath)) {
|
|
1460
|
-
throw new Error('FoundryKit not initialized. Run "foundrykit init" first.');
|
|
1461
|
-
}
|
|
1462
|
-
await updateConfigVersion();
|
|
1463
|
-
}
|
|
1464
|
-
async function hasConflictingFiles(componentData, options) {
|
|
1465
|
-
const config = await loadConfig();
|
|
1466
|
-
const basePath = options.path || process.cwd();
|
|
1467
|
-
for (const file of componentData.files) {
|
|
1468
|
-
let resolvedPath;
|
|
1469
|
-
if (componentData.id === "utils" || file.path === "lib/utils.ts") {
|
|
1470
|
-
resolvedPath = config.paths.utils || "lib/utils.ts";
|
|
1471
|
-
} else {
|
|
1472
|
-
resolvedPath = resolveComponentPath(
|
|
1473
|
-
file.path,
|
|
1474
|
-
componentData.category,
|
|
1475
|
-
config
|
|
1243
|
+
const hasFailures = results.some((result) => !result.ok);
|
|
1244
|
+
if (hasFailures) {
|
|
1245
|
+
console.log(
|
|
1246
|
+
chalk3.yellow(
|
|
1247
|
+
"\n\u26A0\uFE0F Found issues that should be resolved before continuing."
|
|
1248
|
+
)
|
|
1476
1249
|
);
|
|
1250
|
+
process.exit(1);
|
|
1477
1251
|
}
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
return true;
|
|
1481
|
-
}
|
|
1482
|
-
}
|
|
1483
|
-
return false;
|
|
1252
|
+
console.log(chalk3.green("\n\u2705 All checks passed!"));
|
|
1253
|
+
});
|
|
1484
1254
|
}
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1255
|
+
|
|
1256
|
+
// src/commands/init.ts
|
|
1257
|
+
import { exec as exec2 } from "child_process";
|
|
1258
|
+
import path4 from "path";
|
|
1259
|
+
import { promisify as promisify2 } from "util";
|
|
1260
|
+
import chalk4 from "chalk";
|
|
1261
|
+
import { Command as Command3 } from "commander";
|
|
1262
|
+
import fs4 from "fs-extra";
|
|
1263
|
+
import inquirer2 from "inquirer";
|
|
1264
|
+
function initCommand() {
|
|
1265
|
+
return new Command3("init").description("Initialize FoundryKit in your project").option("-f, --force", "overwrite existing files").option("--skip-install", "skip installing dependencies").option("--skip-prompts", "use default paths without prompting").action(async (options) => {
|
|
1266
|
+
try {
|
|
1267
|
+
console.log(chalk4.blue("\u{1F680} Initializing FoundryKit..."));
|
|
1268
|
+
await validateProject2();
|
|
1269
|
+
if (!options.force && await isFoundryKitInitialized()) {
|
|
1270
|
+
const { shouldContinue } = await inquirer2.prompt([
|
|
1271
|
+
{
|
|
1272
|
+
type: "confirm",
|
|
1273
|
+
name: "shouldContinue",
|
|
1274
|
+
message: "FoundryKit is already initialized. Continue anyway?",
|
|
1275
|
+
default: false
|
|
1276
|
+
}
|
|
1277
|
+
]);
|
|
1278
|
+
if (!shouldContinue) {
|
|
1279
|
+
console.log(chalk4.yellow("\u274C Initialization cancelled."));
|
|
1280
|
+
return;
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
const projectStructure = await detectProjectStructure();
|
|
1284
|
+
console.log(
|
|
1285
|
+
chalk4.gray(
|
|
1286
|
+
`Detected project structure: ${projectStructure.hasSrc ? "src/" : "root"} based`
|
|
1287
|
+
)
|
|
1288
|
+
);
|
|
1289
|
+
const pathConfig = await getPathConfiguration(
|
|
1290
|
+
projectStructure,
|
|
1291
|
+
options.skipPrompts
|
|
1292
|
+
);
|
|
1293
|
+
if (!options.skipInstall) {
|
|
1294
|
+
await installDependencies();
|
|
1295
|
+
}
|
|
1296
|
+
console.log(pathConfig);
|
|
1297
|
+
await createConfigFile(options, projectStructure, pathConfig);
|
|
1298
|
+
await installUtils(pathConfig);
|
|
1299
|
+
await setupTailwindV4(
|
|
1300
|
+
pathConfig,
|
|
1301
|
+
projectStructure,
|
|
1302
|
+
options.skipPrompts
|
|
1303
|
+
);
|
|
1304
|
+
await createDirectories(pathConfig);
|
|
1305
|
+
await createExampleFiles(pathConfig, projectStructure);
|
|
1306
|
+
await updatePackageScripts();
|
|
1307
|
+
console.log(chalk4.green("\n\u2705 FoundryKit initialized successfully!"));
|
|
1308
|
+
console.log(chalk4.cyan("\n\u{1F4E6} Next steps:"));
|
|
1309
|
+
console.log(
|
|
1310
|
+
chalk4.gray(
|
|
1311
|
+
" 1. Add a component: pnpm dlx @foundrykit/cli add hero-minimal"
|
|
1312
|
+
)
|
|
1501
1313
|
);
|
|
1502
|
-
}
|
|
1503
|
-
const filePath = path3.join(basePath, resolvedPath);
|
|
1504
|
-
await fs3.ensureDir(path3.dirname(filePath));
|
|
1505
|
-
if (!file.content || file.content.trim() === "") {
|
|
1506
1314
|
console.log(
|
|
1507
|
-
chalk4.
|
|
1315
|
+
chalk4.gray(
|
|
1316
|
+
" 2. List available components: pnpm dlx @foundrykit/cli list"
|
|
1317
|
+
)
|
|
1508
1318
|
);
|
|
1509
|
-
|
|
1319
|
+
console.log(
|
|
1320
|
+
chalk4.gray(
|
|
1321
|
+
" 3. Check out the docs: https://foundry-docs.umiflow.com"
|
|
1322
|
+
)
|
|
1323
|
+
);
|
|
1324
|
+
} catch (error) {
|
|
1325
|
+
console.error(chalk4.red("\u274C Failed to initialize FoundryKit:"));
|
|
1326
|
+
console.error(
|
|
1327
|
+
chalk4.red(error instanceof Error ? error.message : String(error))
|
|
1328
|
+
);
|
|
1329
|
+
process.exit(1);
|
|
1510
1330
|
}
|
|
1511
|
-
|
|
1512
|
-
await fs3.writeFile(filePath, transformedContent);
|
|
1513
|
-
console.log(chalk4.gray(` \u2713 Created ${resolvedPath}`));
|
|
1514
|
-
}
|
|
1515
|
-
await updateConfigVersion();
|
|
1516
|
-
}
|
|
1517
|
-
async function trackInstalledComponent(componentData) {
|
|
1518
|
-
const configPath = path3.join(process.cwd(), "foundrykit.config.json");
|
|
1519
|
-
if (!fs3.existsSync(configPath)) return;
|
|
1520
|
-
const config = await fs3.readJson(configPath);
|
|
1521
|
-
config.installedComponents = config.installedComponents ?? {};
|
|
1522
|
-
config.installedComponents[componentData.id] = {
|
|
1523
|
-
id: componentData.id,
|
|
1524
|
-
version: componentData.version ?? null,
|
|
1525
|
-
installedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1526
|
-
};
|
|
1527
|
-
await fs3.writeJson(configPath, config, { spaces: 2 });
|
|
1331
|
+
});
|
|
1528
1332
|
}
|
|
1529
|
-
async function
|
|
1530
|
-
const
|
|
1531
|
-
if (
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
if (allDependencies.size === 0) {
|
|
1535
|
-
return;
|
|
1536
|
-
}
|
|
1537
|
-
const dependencies = Array.from(allDependencies);
|
|
1538
|
-
const forcePackageUpdate = componentData.files.length === 0 && (options.force || options.overwrite);
|
|
1539
|
-
const missingPackages = forcePackageUpdate ? dependencies : await getMissingPackages(dependencies);
|
|
1540
|
-
if (missingPackages.length === 0) {
|
|
1541
|
-
console.log(chalk4.green("\u2705 All required packages are already installed"));
|
|
1542
|
-
return;
|
|
1543
|
-
}
|
|
1544
|
-
const packagesToInstall = missingPackages.map(
|
|
1545
|
-
(pkg) => forcePackageUpdate ? getPackageInstallSpec(pkg, componentData.version) : pkg
|
|
1546
|
-
);
|
|
1547
|
-
console.log(
|
|
1548
|
-
chalk4.yellow(
|
|
1549
|
-
forcePackageUpdate ? "\n\u{1F4E6} Updating required packages..." : "\n\u{1F4E6} Installing required packages..."
|
|
1550
|
-
)
|
|
1551
|
-
);
|
|
1552
|
-
console.log(chalk4.gray(` ${packagesToInstall.join(", ")}`));
|
|
1553
|
-
const packageManager = await detectPackageManager2();
|
|
1554
|
-
try {
|
|
1555
|
-
const installCommand = `${packageManager} add ${packagesToInstall.join(" ")}`;
|
|
1556
|
-
console.log(chalk4.blue(` Running: ${installCommand}`));
|
|
1557
|
-
const { stdout, stderr } = await execAsync(installCommand);
|
|
1558
|
-
if (stderr && !stderr.includes("warning")) {
|
|
1559
|
-
console.error(chalk4.yellow(` Warning: ${stderr}`));
|
|
1560
|
-
}
|
|
1561
|
-
console.log(chalk4.green("\u2705 Packages installed successfully"));
|
|
1562
|
-
} catch (error) {
|
|
1563
|
-
console.log(chalk4.yellow("\n\u26A0\uFE0F Could not install packages automatically"));
|
|
1564
|
-
console.log(chalk4.gray(" Please install them manually:"));
|
|
1565
|
-
console.log(
|
|
1566
|
-
chalk4.cyan(` ${packageManager} add ${packagesToInstall.join(" ")}`)
|
|
1333
|
+
async function validateProject2() {
|
|
1334
|
+
const packageJsonPath = path4.join(process.cwd(), "package.json");
|
|
1335
|
+
if (!fs4.existsSync(packageJsonPath)) {
|
|
1336
|
+
throw new Error(
|
|
1337
|
+
"No package.json found. Please run this command in a project directory."
|
|
1567
1338
|
);
|
|
1568
1339
|
}
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1340
|
+
const packageJson2 = await fs4.readJson(packageJsonPath);
|
|
1341
|
+
const deps = {
|
|
1342
|
+
...packageJson2.dependencies,
|
|
1343
|
+
...packageJson2.devDependencies
|
|
1344
|
+
};
|
|
1345
|
+
if (!deps.next) {
|
|
1346
|
+
throw new Error(
|
|
1347
|
+
"Next.js not detected. FoundryKit currently requires Next.js."
|
|
1348
|
+
);
|
|
1573
1349
|
}
|
|
1574
|
-
|
|
1350
|
+
console.log(chalk4.green("\u2705 Next.js project detected"));
|
|
1575
1351
|
}
|
|
1576
|
-
async function
|
|
1577
|
-
|
|
1578
|
-
try {
|
|
1579
|
-
const packageJson2 = await fs3.readJson(packageJsonPath);
|
|
1580
|
-
const installedPackages = {
|
|
1581
|
-
...packageJson2.dependencies,
|
|
1582
|
-
...packageJson2.devDependencies
|
|
1583
|
-
};
|
|
1584
|
-
return packages.filter((pkg) => !installedPackages[pkg]);
|
|
1585
|
-
} catch (error) {
|
|
1586
|
-
return packages;
|
|
1587
|
-
}
|
|
1352
|
+
async function isFoundryKitInitialized() {
|
|
1353
|
+
return fs4.existsSync(path4.join(process.cwd(), "foundrykit.config.json"));
|
|
1588
1354
|
}
|
|
1589
|
-
async function
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1355
|
+
async function detectProjectStructure() {
|
|
1356
|
+
const cwd = process.cwd();
|
|
1357
|
+
const hasSrc = fs4.existsSync(path4.join(cwd, "src"));
|
|
1358
|
+
let baseDir = "./";
|
|
1359
|
+
let appPath;
|
|
1360
|
+
let componentsPath;
|
|
1361
|
+
let libPath;
|
|
1362
|
+
let hooksPath;
|
|
1363
|
+
let stylesPath;
|
|
1364
|
+
if (hasSrc) {
|
|
1365
|
+
const srcHasApp = fs4.existsSync(path4.join(cwd, "src/app"));
|
|
1366
|
+
if (srcHasApp) {
|
|
1367
|
+
baseDir = "./src/";
|
|
1368
|
+
appPath = "./src/app";
|
|
1369
|
+
} else {
|
|
1370
|
+
const rootHasApp = fs4.existsSync(path4.join(cwd, "app"));
|
|
1371
|
+
if (rootHasApp) {
|
|
1372
|
+
appPath = "./app";
|
|
1373
|
+
baseDir = "./src/";
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
if (fs4.existsSync(path4.join(cwd, "src/components"))) {
|
|
1377
|
+
componentsPath = "./src/components";
|
|
1378
|
+
}
|
|
1379
|
+
if (fs4.existsSync(path4.join(cwd, "src/lib"))) {
|
|
1380
|
+
libPath = "./src/lib";
|
|
1381
|
+
}
|
|
1382
|
+
if (fs4.existsSync(path4.join(cwd, "src/hooks"))) {
|
|
1383
|
+
hooksPath = "./src/hooks";
|
|
1384
|
+
}
|
|
1385
|
+
if (fs4.existsSync(path4.join(cwd, "src/styles"))) {
|
|
1386
|
+
stylesPath = "./src/styles";
|
|
1387
|
+
}
|
|
1388
|
+
} else {
|
|
1389
|
+
const hasApp = fs4.existsSync(path4.join(cwd, "app"));
|
|
1390
|
+
if (hasApp) {
|
|
1391
|
+
appPath = "./app";
|
|
1392
|
+
}
|
|
1393
|
+
if (fs4.existsSync(path4.join(cwd, "components"))) {
|
|
1394
|
+
componentsPath = "./components";
|
|
1395
|
+
}
|
|
1396
|
+
if (fs4.existsSync(path4.join(cwd, "lib"))) {
|
|
1397
|
+
libPath = "./lib";
|
|
1398
|
+
}
|
|
1399
|
+
if (fs4.existsSync(path4.join(cwd, "hooks"))) {
|
|
1400
|
+
hooksPath = "./hooks";
|
|
1401
|
+
}
|
|
1402
|
+
if (fs4.existsSync(path4.join(cwd, "styles"))) {
|
|
1403
|
+
stylesPath = "./styles";
|
|
1404
|
+
}
|
|
1601
1405
|
}
|
|
1602
|
-
|
|
1406
|
+
const isTypeScript = fs4.existsSync(path4.join(cwd, "tsconfig.json"));
|
|
1407
|
+
const packageManager = detectPackageManager2();
|
|
1408
|
+
return {
|
|
1409
|
+
hasSrc,
|
|
1410
|
+
hasApp: !!appPath,
|
|
1411
|
+
hasComponents: !!componentsPath,
|
|
1412
|
+
hasLib: !!libPath,
|
|
1413
|
+
hasHooks: !!hooksPath,
|
|
1414
|
+
hasStyles: !!stylesPath,
|
|
1415
|
+
baseDir,
|
|
1416
|
+
framework: "next",
|
|
1417
|
+
isTypeScript,
|
|
1418
|
+
packageManager,
|
|
1419
|
+
appPath,
|
|
1420
|
+
componentsPath,
|
|
1421
|
+
libPath,
|
|
1422
|
+
hooksPath,
|
|
1423
|
+
stylesPath
|
|
1424
|
+
};
|
|
1603
1425
|
}
|
|
1604
|
-
async function
|
|
1605
|
-
const
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
)
|
|
1611
|
-
|
|
1612
|
-
|
|
1426
|
+
async function getPathConfiguration(structure, skipPrompts) {
|
|
1427
|
+
const ext = structure.isTypeScript ? ".ts" : ".js";
|
|
1428
|
+
const defaults = {
|
|
1429
|
+
utils: path4.join(
|
|
1430
|
+
structure.libPath || path4.join(structure.baseDir, "lib"),
|
|
1431
|
+
`utils${ext}`
|
|
1432
|
+
),
|
|
1433
|
+
primitives: path4.join(
|
|
1434
|
+
structure.componentsPath || path4.join(structure.baseDir, "components"),
|
|
1435
|
+
"primitives"
|
|
1436
|
+
),
|
|
1437
|
+
components: path4.join(
|
|
1438
|
+
structure.componentsPath || path4.join(structure.baseDir, "components"),
|
|
1439
|
+
"ui"
|
|
1440
|
+
),
|
|
1441
|
+
blocks: path4.join(
|
|
1442
|
+
structure.componentsPath || path4.join(structure.baseDir, "components"),
|
|
1443
|
+
"blocks"
|
|
1444
|
+
),
|
|
1445
|
+
maps: path4.join(
|
|
1446
|
+
structure.componentsPath || path4.join(structure.baseDir, "components"),
|
|
1447
|
+
"maps"
|
|
1448
|
+
),
|
|
1449
|
+
animations: path4.join(
|
|
1450
|
+
structure.componentsPath || path4.join(structure.baseDir, "components"),
|
|
1451
|
+
"animations"
|
|
1452
|
+
),
|
|
1453
|
+
hooks: structure.hooksPath || path4.join(structure.baseDir, "hooks"),
|
|
1454
|
+
lib: structure.libPath || path4.join(structure.baseDir, "lib"),
|
|
1455
|
+
styles: path4.join(structure.appPath || structure.baseDir, "globals.css")
|
|
1456
|
+
};
|
|
1457
|
+
if (structure.appPath) {
|
|
1458
|
+
const possibleStylePaths = [
|
|
1459
|
+
path4.join(structure.appPath, "globals.css"),
|
|
1460
|
+
path4.join(structure.appPath, "global.css"),
|
|
1461
|
+
path4.join(structure.stylesPath || "", "globals.css"),
|
|
1462
|
+
path4.join(structure.stylesPath || "", "global.css")
|
|
1463
|
+
];
|
|
1464
|
+
for (const stylePath of possibleStylePaths) {
|
|
1465
|
+
if (fs4.existsSync(path4.join(process.cwd(), stylePath))) {
|
|
1466
|
+
defaults.styles = stylePath;
|
|
1467
|
+
break;
|
|
1468
|
+
}
|
|
1613
1469
|
}
|
|
1614
|
-
return;
|
|
1615
|
-
}
|
|
1616
|
-
const componentName = componentData.name.replace(/\s+/g, "");
|
|
1617
|
-
const importPath = getImportPath(componentData, config);
|
|
1618
|
-
console.log(chalk4.gray(`import { ${componentName} } from "${importPath}"`));
|
|
1619
|
-
if (componentData.usageExample) {
|
|
1620
|
-
console.log(chalk4.gray(`
|
|
1621
|
-
${componentData.usageExample}`));
|
|
1622
1470
|
}
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
if (!fs3.existsSync(configPath)) {
|
|
1627
|
-
throw new Error(
|
|
1628
|
-
'Configuration file not found. Run "foundrykit init" first.'
|
|
1471
|
+
if (skipPrompts) {
|
|
1472
|
+
console.log(
|
|
1473
|
+
chalk4.gray("Using smart defaults based on project structure...")
|
|
1629
1474
|
);
|
|
1475
|
+
return defaults;
|
|
1630
1476
|
}
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
let transformed = content;
|
|
1635
|
-
const importPaths = getConfiguredImportPaths(config);
|
|
1636
|
-
transformed = transformRegistryBarrelImports(
|
|
1637
|
-
transformed,
|
|
1638
|
-
["@foundrykit/primitives", "@/components/primitives", "@/components/ui"],
|
|
1639
|
-
importPaths.primitives,
|
|
1640
|
-
config,
|
|
1641
|
-
"primitives"
|
|
1642
|
-
);
|
|
1643
|
-
transformed = transformRegistryBarrelImports(
|
|
1644
|
-
transformed,
|
|
1645
|
-
["@foundrykit/components", "@/components/components"],
|
|
1646
|
-
importPaths.components,
|
|
1647
|
-
config,
|
|
1648
|
-
"components"
|
|
1649
|
-
);
|
|
1650
|
-
transformed = transformRegistryBarrelImports(
|
|
1651
|
-
transformed,
|
|
1652
|
-
["@foundrykit/blocks", "@/components/blocks"],
|
|
1653
|
-
importPaths.blocks,
|
|
1654
|
-
config,
|
|
1655
|
-
"blocks"
|
|
1656
|
-
);
|
|
1657
|
-
transformed = transformRegistryBarrelImports(
|
|
1658
|
-
transformed,
|
|
1659
|
-
["@foundrykit/animation", "@/components/animations"],
|
|
1660
|
-
importPaths.animations,
|
|
1661
|
-
config,
|
|
1662
|
-
"animations"
|
|
1663
|
-
);
|
|
1664
|
-
transformed = transformRegistryBarrelImports(
|
|
1665
|
-
transformed,
|
|
1666
|
-
["@foundrykit/maps", "@/components/maps"],
|
|
1667
|
-
importPaths.maps,
|
|
1668
|
-
config,
|
|
1669
|
-
"maps"
|
|
1670
|
-
);
|
|
1671
|
-
transformed = transformRegistryBarrelImports(
|
|
1672
|
-
transformed,
|
|
1673
|
-
["@foundrykit/hooks", "@/hooks"],
|
|
1674
|
-
importPaths.hooks,
|
|
1675
|
-
config,
|
|
1676
|
-
"hooks"
|
|
1477
|
+
console.log(chalk4.blue("\n\u{1F4C2} Configure installation paths:"));
|
|
1478
|
+
console.log(
|
|
1479
|
+
chalk4.gray("Press enter to use the default value shown in parentheses\n")
|
|
1677
1480
|
);
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
hooks: "hooks",
|
|
1688
|
-
maps: "components/maps",
|
|
1689
|
-
utils: "lib/utils"
|
|
1690
|
-
};
|
|
1691
|
-
return {
|
|
1692
|
-
primitives: resolveImportBasePath(paths.primitives, config, {
|
|
1693
|
-
preferRootAlias: true
|
|
1694
|
-
}),
|
|
1695
|
-
components: resolveImportBasePath(paths.components, config, {
|
|
1696
|
-
preferRootAlias: true
|
|
1697
|
-
}),
|
|
1698
|
-
blocks: resolveImportBasePath(paths.blocks, config, {
|
|
1699
|
-
preferRootAlias: true
|
|
1700
|
-
}),
|
|
1701
|
-
animations: resolveImportBasePath(paths.animations, config, {
|
|
1702
|
-
preferRootAlias: true
|
|
1703
|
-
}),
|
|
1704
|
-
maps: resolveImportBasePath(
|
|
1705
|
-
paths.maps ?? joinImportPath(paths.components, "maps"),
|
|
1706
|
-
config,
|
|
1707
|
-
{
|
|
1708
|
-
preferRootAlias: true
|
|
1481
|
+
const answers = await inquirer2.prompt([
|
|
1482
|
+
{
|
|
1483
|
+
type: "input",
|
|
1484
|
+
name: "utils",
|
|
1485
|
+
message: "Utils file path:",
|
|
1486
|
+
default: defaults.utils,
|
|
1487
|
+
validate: (input) => {
|
|
1488
|
+
if (!input) return "Path cannot be empty";
|
|
1489
|
+
return true;
|
|
1709
1490
|
}
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
}
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
""
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
}
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1491
|
+
},
|
|
1492
|
+
{
|
|
1493
|
+
type: "input",
|
|
1494
|
+
name: "components",
|
|
1495
|
+
message: "Components directory:",
|
|
1496
|
+
default: defaults.components
|
|
1497
|
+
},
|
|
1498
|
+
{
|
|
1499
|
+
type: "input",
|
|
1500
|
+
name: "primitives",
|
|
1501
|
+
message: "Primitives directory:",
|
|
1502
|
+
default: defaults.primitives
|
|
1503
|
+
},
|
|
1504
|
+
{
|
|
1505
|
+
type: "input",
|
|
1506
|
+
name: "blocks",
|
|
1507
|
+
message: "Blocks directory:",
|
|
1508
|
+
default: defaults.blocks
|
|
1509
|
+
},
|
|
1510
|
+
{
|
|
1511
|
+
type: "input",
|
|
1512
|
+
name: "hooks",
|
|
1513
|
+
message: "Hooks directory:",
|
|
1514
|
+
default: defaults.hooks
|
|
1515
|
+
},
|
|
1516
|
+
{
|
|
1517
|
+
type: "input",
|
|
1518
|
+
name: "maps",
|
|
1519
|
+
message: "Maps directory:",
|
|
1520
|
+
default: defaults.maps
|
|
1521
|
+
},
|
|
1522
|
+
{
|
|
1523
|
+
type: "input",
|
|
1524
|
+
name: "animations",
|
|
1525
|
+
message: "Animations directory:",
|
|
1526
|
+
default: defaults.animations
|
|
1527
|
+
},
|
|
1528
|
+
{
|
|
1529
|
+
type: "input",
|
|
1530
|
+
name: "styles",
|
|
1531
|
+
message: "Global styles file:",
|
|
1532
|
+
default: defaults.styles
|
|
1533
|
+
},
|
|
1534
|
+
{
|
|
1535
|
+
type: "input",
|
|
1536
|
+
name: "lib",
|
|
1537
|
+
message: "Lib directory:",
|
|
1538
|
+
default: defaults.lib
|
|
1738
1539
|
}
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
alias,
|
|
1742
|
-
target: normalizeConfigPath(target)
|
|
1743
|
-
})).filter(({ target }) => {
|
|
1744
|
-
return normalizedPath === target || target !== "" && normalizedPath.startsWith(`${target}/`) || target === "";
|
|
1745
|
-
}).sort((a, b) => b.target.length - a.target.length);
|
|
1746
|
-
const bestMatch = aliasMatches[0];
|
|
1747
|
-
if (bestMatch) {
|
|
1748
|
-
const relativePath = bestMatch.target === "" ? normalizedPath : normalizedPath.slice(bestMatch.target.length).replace(/^\//, "");
|
|
1749
|
-
return joinImportPath(bestMatch.alias, relativePath);
|
|
1750
|
-
}
|
|
1751
|
-
return joinImportPath("@", normalizedPath);
|
|
1540
|
+
]);
|
|
1541
|
+
return answers;
|
|
1752
1542
|
}
|
|
1753
|
-
function
|
|
1754
|
-
|
|
1543
|
+
async function installDependencies() {
|
|
1544
|
+
console.log(chalk4.blue("\u{1F4E6} Installing dependencies..."));
|
|
1545
|
+
const packageManager = detectPackageManager2();
|
|
1546
|
+
const execAsync2 = promisify2(exec2);
|
|
1547
|
+
const dependencies = [
|
|
1548
|
+
"clsx",
|
|
1549
|
+
"tailwind-merge",
|
|
1550
|
+
"framer-motion",
|
|
1551
|
+
"lucide-react",
|
|
1552
|
+
"next-themes",
|
|
1553
|
+
"cmdk",
|
|
1554
|
+
"@foundrykit/tailwind",
|
|
1555
|
+
"@radix-ui/react-dialog",
|
|
1556
|
+
"@radix-ui/react-dropdown-menu",
|
|
1557
|
+
"@radix-ui/react-label",
|
|
1558
|
+
"@radix-ui/react-popover",
|
|
1559
|
+
"@radix-ui/react-select",
|
|
1560
|
+
"@radix-ui/react-separator",
|
|
1561
|
+
"@radix-ui/react-slot",
|
|
1562
|
+
"@radix-ui/react-switch",
|
|
1563
|
+
"@radix-ui/react-tabs",
|
|
1564
|
+
"@radix-ui/react-tooltip"
|
|
1565
|
+
];
|
|
1566
|
+
const devDependencies = ["tailwindcss", "autoprefixer", "postcss"];
|
|
1567
|
+
try {
|
|
1568
|
+
const installCmd = packageManager === "npm" ? "install" : "add";
|
|
1569
|
+
await execAsync2(
|
|
1570
|
+
`${packageManager} ${installCmd} ${dependencies.join(" ")}`
|
|
1571
|
+
);
|
|
1572
|
+
const devFlag = packageManager === "npm" ? "--save-dev" : "-D";
|
|
1573
|
+
await execAsync2(
|
|
1574
|
+
`${packageManager} ${installCmd} ${devFlag} ${devDependencies.join(" ")}`
|
|
1575
|
+
);
|
|
1576
|
+
console.log(chalk4.green("\u2705 Dependencies installed"));
|
|
1577
|
+
} catch {
|
|
1578
|
+
console.error(chalk4.yellow("\u26A0\uFE0F Failed to install some dependencies"));
|
|
1579
|
+
console.error(chalk4.gray("You may need to install them manually"));
|
|
1580
|
+
}
|
|
1755
1581
|
}
|
|
1756
|
-
function
|
|
1757
|
-
|
|
1582
|
+
function detectPackageManager2() {
|
|
1583
|
+
if (fs4.existsSync(path4.join(process.cwd(), "pnpm-lock.yaml"))) return "pnpm";
|
|
1584
|
+
if (fs4.existsSync(path4.join(process.cwd(), "yarn.lock"))) return "yarn";
|
|
1585
|
+
if (fs4.existsSync(path4.join(process.cwd(), "bun.lockb"))) return "bun";
|
|
1586
|
+
return "npm";
|
|
1758
1587
|
}
|
|
1759
|
-
function
|
|
1760
|
-
|
|
1761
|
-
const
|
|
1762
|
-
if (
|
|
1763
|
-
|
|
1588
|
+
async function setupTailwindV4(pathConfig, projectStructure, skipPrompts) {
|
|
1589
|
+
console.log(chalk4.blue("\u{1F3A8} Setting up Tailwind CSS v4..."));
|
|
1590
|
+
const layoutPath = await findLayoutFile(projectStructure);
|
|
1591
|
+
if (layoutPath) {
|
|
1592
|
+
const layoutContent = await fs4.readFile(layoutPath, "utf-8");
|
|
1593
|
+
if (layoutContent.includes("@foundrykit/tailwind/globals.css")) {
|
|
1594
|
+
if (skipPrompts) {
|
|
1595
|
+
console.log(
|
|
1596
|
+
chalk4.green(
|
|
1597
|
+
"\u2705 Keeping existing import from @foundrykit/tailwind/globals.css"
|
|
1598
|
+
)
|
|
1599
|
+
);
|
|
1600
|
+
return;
|
|
1601
|
+
}
|
|
1602
|
+
const { importPreference } = await inquirer2.prompt([
|
|
1603
|
+
{
|
|
1604
|
+
type: "list",
|
|
1605
|
+
name: "importPreference",
|
|
1606
|
+
message: "FoundryKit styles are already imported directly. How would you like to proceed?",
|
|
1607
|
+
choices: [
|
|
1608
|
+
{
|
|
1609
|
+
name: "Keep direct import from @foundrykit/tailwind/globals.css",
|
|
1610
|
+
value: "direct"
|
|
1611
|
+
},
|
|
1612
|
+
{
|
|
1613
|
+
name: "Switch to local globals.css file (recommended for customization)",
|
|
1614
|
+
value: "local"
|
|
1615
|
+
}
|
|
1616
|
+
],
|
|
1617
|
+
default: "direct"
|
|
1618
|
+
}
|
|
1619
|
+
]);
|
|
1620
|
+
if (importPreference === "direct") {
|
|
1621
|
+
console.log(
|
|
1622
|
+
chalk4.green(
|
|
1623
|
+
"\u2705 Keeping direct import from @foundrykit/tailwind/globals.css"
|
|
1624
|
+
)
|
|
1625
|
+
);
|
|
1626
|
+
return;
|
|
1627
|
+
}
|
|
1628
|
+
await createOrUpdateGlobalsCss(pathConfig);
|
|
1629
|
+
await updateLayoutImport(layoutPath, pathConfig);
|
|
1630
|
+
return;
|
|
1631
|
+
}
|
|
1632
|
+
const globalsCssImportMatch = layoutContent.match(
|
|
1633
|
+
/import\s+['"]([^'"]*globals?\.css)['"]/
|
|
1634
|
+
);
|
|
1635
|
+
if (globalsCssImportMatch?.[1]) {
|
|
1636
|
+
const importPath = globalsCssImportMatch[1];
|
|
1637
|
+
const resolvedPath = resolveImportPath(layoutPath, importPath);
|
|
1638
|
+
if (fs4.existsSync(resolvedPath)) {
|
|
1639
|
+
await updateExistingGlobalsCss(resolvedPath);
|
|
1640
|
+
console.log(
|
|
1641
|
+
chalk4.green("\u2705 Updated existing globals.css with FoundryKit styles")
|
|
1642
|
+
);
|
|
1643
|
+
return;
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1764
1646
|
}
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1647
|
+
let setupPreference = "local";
|
|
1648
|
+
if (!skipPrompts) {
|
|
1649
|
+
const answer = await inquirer2.prompt([
|
|
1650
|
+
{
|
|
1651
|
+
type: "list",
|
|
1652
|
+
name: "setupPreference",
|
|
1653
|
+
message: "How would you like to import FoundryKit styles?",
|
|
1654
|
+
choices: [
|
|
1655
|
+
{
|
|
1656
|
+
name: "Create/update a local globals.css file (recommended for customization)",
|
|
1657
|
+
value: "local"
|
|
1658
|
+
},
|
|
1659
|
+
{
|
|
1660
|
+
name: "Import directly from @foundrykit/tailwind/globals.css",
|
|
1661
|
+
value: "direct"
|
|
1662
|
+
}
|
|
1663
|
+
],
|
|
1664
|
+
default: "local"
|
|
1778
1665
|
}
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1666
|
+
]);
|
|
1667
|
+
setupPreference = answer.setupPreference;
|
|
1668
|
+
}
|
|
1669
|
+
if (setupPreference === "direct") {
|
|
1670
|
+
await addDirectImportToLayout(layoutPath);
|
|
1671
|
+
} else {
|
|
1672
|
+
await createOrUpdateGlobalsCss(pathConfig);
|
|
1673
|
+
if (layoutPath) {
|
|
1674
|
+
await updateLayoutImport(layoutPath, pathConfig);
|
|
1783
1675
|
}
|
|
1784
|
-
);
|
|
1785
|
-
}
|
|
1786
|
-
function groupImportsByComponent(imports, config, category) {
|
|
1787
|
-
const groupedImports = /* @__PURE__ */ new Map();
|
|
1788
|
-
const exportMap = getInstalledComponentExportMap(config, category);
|
|
1789
|
-
const specifiers = imports.split(",").map((specifier) => specifier.trim()).filter(Boolean);
|
|
1790
|
-
const exportNames = specifiers.map(getExportNameFromSpecifier);
|
|
1791
|
-
for (const specifier of specifiers) {
|
|
1792
|
-
const componentPath = getComponentPathForSpecifier(
|
|
1793
|
-
specifier,
|
|
1794
|
-
exportNames,
|
|
1795
|
-
exportMap
|
|
1796
|
-
);
|
|
1797
|
-
const existing = groupedImports.get(componentPath) ?? [];
|
|
1798
|
-
existing.push(specifier);
|
|
1799
|
-
groupedImports.set(componentPath, existing);
|
|
1800
1676
|
}
|
|
1801
|
-
|
|
1677
|
+
console.log(chalk4.green("\u2705 Tailwind CSS v4 configured"));
|
|
1802
1678
|
}
|
|
1803
|
-
function
|
|
1804
|
-
const
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1679
|
+
async function createOrUpdateGlobalsCss(pathConfig) {
|
|
1680
|
+
const globalsCssPath = path4.join(process.cwd(), pathConfig.styles);
|
|
1681
|
+
if (fs4.existsSync(globalsCssPath)) {
|
|
1682
|
+
await updateExistingGlobalsCss(globalsCssPath);
|
|
1683
|
+
} else {
|
|
1684
|
+
const cssContent = `/* Import FoundryKit's Tailwind CSS v4 styles */
|
|
1685
|
+
@import "@foundrykit/tailwind/globals.css";
|
|
1686
|
+
|
|
1687
|
+
/* Your custom styles below */
|
|
1688
|
+
`;
|
|
1689
|
+
await fs4.ensureDir(path4.dirname(globalsCssPath));
|
|
1690
|
+
await fs4.writeFile(globalsCssPath, cssContent);
|
|
1691
|
+
console.log(chalk4.green(`\u2705 Created ${pathConfig.styles}`));
|
|
1808
1692
|
}
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1693
|
+
}
|
|
1694
|
+
async function updateExistingGlobalsCss(globalsCssPath) {
|
|
1695
|
+
const content = await fs4.readFile(globalsCssPath, "utf-8");
|
|
1696
|
+
if (content.includes("@foundrykit/tailwind/globals.css")) {
|
|
1697
|
+
console.log(chalk4.gray("globals.css already imports FoundryKit styles"));
|
|
1698
|
+
return;
|
|
1812
1699
|
}
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1700
|
+
if (content.includes('@import "tailwindcss"')) {
|
|
1701
|
+
const updatedContent = content.replace(
|
|
1702
|
+
'@import "tailwindcss"',
|
|
1703
|
+
`/* Import FoundryKit's Tailwind CSS v4 styles */
|
|
1704
|
+
@import "@foundrykit/tailwind/globals.css"`
|
|
1705
|
+
);
|
|
1706
|
+
await fs4.writeFile(globalsCssPath, updatedContent);
|
|
1707
|
+
console.log(chalk4.green("\u2705 Updated globals.css with FoundryKit styles"));
|
|
1708
|
+
} else {
|
|
1709
|
+
const updatedContent = `/* Import FoundryKit's Tailwind CSS v4 styles */
|
|
1710
|
+
@import "@foundrykit/tailwind/globals.css";
|
|
1711
|
+
|
|
1712
|
+
/* Your custom styles below */
|
|
1713
|
+
${content}`;
|
|
1714
|
+
await fs4.writeFile(globalsCssPath, updatedContent);
|
|
1715
|
+
console.log(chalk4.green("\u2705 Updated globals.css with FoundryKit styles"));
|
|
1816
1716
|
}
|
|
1817
|
-
return toKebabCase(exportName);
|
|
1818
|
-
}
|
|
1819
|
-
function getExportNameFromSpecifier(specifier) {
|
|
1820
|
-
return specifier.replace(/^type\s+/, "").split(/\s+as\s+/)[0]?.trim() || specifier;
|
|
1821
1717
|
}
|
|
1822
|
-
function
|
|
1823
|
-
const
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1718
|
+
async function findLayoutFile(projectStructure) {
|
|
1719
|
+
const possiblePaths = [];
|
|
1720
|
+
if (projectStructure.appPath) {
|
|
1721
|
+
const ext = projectStructure.isTypeScript ? ".tsx" : ".jsx";
|
|
1722
|
+
possiblePaths.push(
|
|
1723
|
+
path4.join(projectStructure.appPath, `layout${ext}`),
|
|
1724
|
+
path4.join(projectStructure.appPath, `layout.js`)
|
|
1725
|
+
);
|
|
1827
1726
|
}
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1727
|
+
possiblePaths.push(
|
|
1728
|
+
"app/layout.tsx",
|
|
1729
|
+
"app/layout.jsx",
|
|
1730
|
+
"app/layout.js",
|
|
1731
|
+
"src/app/layout.tsx",
|
|
1732
|
+
"src/app/layout.jsx",
|
|
1733
|
+
"src/app/layout.js"
|
|
1831
1734
|
);
|
|
1832
|
-
|
|
1833
|
-
|
|
1735
|
+
for (const layoutPath of possiblePaths) {
|
|
1736
|
+
const fullPath = path4.join(process.cwd(), layoutPath);
|
|
1737
|
+
if (fs4.existsSync(fullPath)) {
|
|
1738
|
+
return fullPath;
|
|
1739
|
+
}
|
|
1834
1740
|
}
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
const
|
|
1841
|
-
const
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1741
|
+
return null;
|
|
1742
|
+
}
|
|
1743
|
+
async function updateLayoutImport(layoutPath, pathConfig) {
|
|
1744
|
+
try {
|
|
1745
|
+
let content = await fs4.readFile(layoutPath, "utf-8");
|
|
1746
|
+
const fromPath = path4.dirname(layoutPath);
|
|
1747
|
+
const toPath = path4.join(process.cwd(), pathConfig.styles);
|
|
1748
|
+
const relativePath = path4.relative(fromPath, toPath).replace(/\\/g, "/");
|
|
1749
|
+
const importPath = relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
1750
|
+
const globalImportRegex = /import\s+['"]([^'"]*globals?\.css)['"]/;
|
|
1751
|
+
const match = content.match(globalImportRegex);
|
|
1752
|
+
if (match) {
|
|
1753
|
+
content = content.replace(globalImportRegex, `import '${importPath}'`);
|
|
1754
|
+
} else if (!content.includes(importPath)) {
|
|
1755
|
+
const importStatement = `import '${importPath}';
|
|
1756
|
+
`;
|
|
1757
|
+
const importRegex = /^(import\s+.*?;\s*)+/m;
|
|
1758
|
+
const importMatch = content.match(importRegex);
|
|
1759
|
+
if (importMatch) {
|
|
1760
|
+
const lastImportIndex = importMatch.index + importMatch[0].length;
|
|
1761
|
+
content = content.slice(0, lastImportIndex) + importStatement + content.slice(lastImportIndex);
|
|
1762
|
+
} else {
|
|
1763
|
+
content = importStatement + content;
|
|
1846
1764
|
}
|
|
1847
1765
|
}
|
|
1766
|
+
await fs4.writeFile(layoutPath, content);
|
|
1767
|
+
console.log(
|
|
1768
|
+
chalk4.gray(
|
|
1769
|
+
`Updated ${path4.relative(process.cwd(), layoutPath)} with CSS import`
|
|
1770
|
+
)
|
|
1771
|
+
);
|
|
1772
|
+
} catch {
|
|
1773
|
+
console.error(chalk4.yellow("\u26A0\uFE0F Failed to update layout with CSS import"));
|
|
1848
1774
|
}
|
|
1849
|
-
return exportMap;
|
|
1850
1775
|
}
|
|
1851
|
-
function
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
const
|
|
1859
|
-
if (
|
|
1860
|
-
|
|
1776
|
+
async function addDirectImportToLayout(layoutPath) {
|
|
1777
|
+
try {
|
|
1778
|
+
let content = await fs4.readFile(layoutPath, "utf-8");
|
|
1779
|
+
const importStatement = `import '@foundrykit/tailwind/globals.css';
|
|
1780
|
+
`;
|
|
1781
|
+
if (!content.includes("@foundrykit/tailwind/globals.css")) {
|
|
1782
|
+
const importRegex = /^(import\s+.*?;\s*)+/m;
|
|
1783
|
+
const match = content.match(importRegex);
|
|
1784
|
+
if (match) {
|
|
1785
|
+
const lastImportIndex = match.index + match[0].length;
|
|
1786
|
+
content = content.slice(0, lastImportIndex) + importStatement + content.slice(lastImportIndex);
|
|
1787
|
+
} else {
|
|
1788
|
+
content = importStatement + content;
|
|
1861
1789
|
}
|
|
1790
|
+
await fs4.writeFile(layoutPath, content);
|
|
1791
|
+
console.log(
|
|
1792
|
+
chalk4.green("\u2705 Added direct import of FoundryKit styles to layout")
|
|
1793
|
+
);
|
|
1862
1794
|
}
|
|
1795
|
+
} catch {
|
|
1796
|
+
console.error(chalk4.yellow("\u26A0\uFE0F Failed to add CSS import to layout"));
|
|
1863
1797
|
}
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1798
|
+
}
|
|
1799
|
+
function resolveImportPath(fromFile, importPath) {
|
|
1800
|
+
if (importPath.startsWith(".")) {
|
|
1801
|
+
return path4.join(path4.dirname(fromFile), importPath);
|
|
1802
|
+
} else if (importPath.startsWith("@/")) {
|
|
1803
|
+
return path4.join(process.cwd(), importPath.replace("@/", "src/"));
|
|
1804
|
+
} else if (importPath.startsWith("/")) {
|
|
1805
|
+
return path4.join(process.cwd(), importPath);
|
|
1868
1806
|
}
|
|
1869
|
-
return
|
|
1807
|
+
return path4.join(process.cwd(), importPath);
|
|
1870
1808
|
}
|
|
1871
|
-
function
|
|
1872
|
-
|
|
1809
|
+
async function createDirectories(pathConfig) {
|
|
1810
|
+
console.log(chalk4.blue("\u{1F4C1} Creating component directories..."));
|
|
1811
|
+
const dirs = [
|
|
1812
|
+
pathConfig.primitives,
|
|
1813
|
+
pathConfig.components,
|
|
1814
|
+
pathConfig.blocks,
|
|
1815
|
+
pathConfig.maps,
|
|
1816
|
+
pathConfig.animations,
|
|
1817
|
+
pathConfig.hooks,
|
|
1818
|
+
pathConfig.lib
|
|
1819
|
+
];
|
|
1820
|
+
for (const dir of dirs) {
|
|
1821
|
+
const fullPath = path4.join(process.cwd(), dir);
|
|
1822
|
+
await fs4.ensureDir(fullPath);
|
|
1823
|
+
console.log(chalk4.gray(`Created ${dir}`));
|
|
1824
|
+
}
|
|
1825
|
+
console.log(chalk4.green("\u2705 Directories created"));
|
|
1873
1826
|
}
|
|
1874
|
-
function
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1827
|
+
async function createExampleFiles(pathConfig, structure) {
|
|
1828
|
+
console.log(chalk4.blue("\u{1F4DD} Creating example files..."));
|
|
1829
|
+
const utilsPath = path4.join(process.cwd(), pathConfig.utils);
|
|
1830
|
+
const utilsContent = `import { type ClassValue, clsx } from 'clsx';
|
|
1831
|
+
import { twMerge } from 'tailwind-merge';
|
|
1832
|
+
|
|
1833
|
+
export function cn(...inputs: ClassValue[]) {
|
|
1834
|
+
return twMerge(clsx(inputs));
|
|
1835
|
+
}
|
|
1836
|
+
`;
|
|
1837
|
+
await fs4.ensureDir(path4.dirname(utilsPath));
|
|
1838
|
+
if (!fs4.existsSync(utilsPath)) {
|
|
1839
|
+
await fs4.writeFile(utilsPath, utilsContent);
|
|
1840
|
+
console.log(chalk4.gray(`Created ${pathConfig.utils}`));
|
|
1886
1841
|
}
|
|
1887
|
-
const
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1842
|
+
const providersPath = path4.join(
|
|
1843
|
+
process.cwd(),
|
|
1844
|
+
path4.dirname(pathConfig.components),
|
|
1845
|
+
`theme-provider${structure.isTypeScript ? ".tsx" : ".jsx"}`
|
|
1846
|
+
);
|
|
1847
|
+
const providersContent = `
|
|
1848
|
+
'use client';
|
|
1849
|
+
|
|
1850
|
+
import type * as React from 'react';
|
|
1851
|
+
import { ThemeProvider as NextThemesProvider } from 'next-themes';
|
|
1852
|
+
|
|
1853
|
+
export function ThemeProvider({ children }: { children: React.ReactNode }) {
|
|
1854
|
+
return (
|
|
1855
|
+
<NextThemesProvider
|
|
1856
|
+
attribute='class'
|
|
1857
|
+
defaultTheme='system'
|
|
1858
|
+
enableSystem
|
|
1859
|
+
disableTransitionOnChange
|
|
1860
|
+
enableColorScheme
|
|
1861
|
+
>
|
|
1862
|
+
{children}
|
|
1863
|
+
</NextThemesProvider>
|
|
1864
|
+
);
|
|
1865
|
+
}
|
|
1866
|
+
|
|
1867
|
+
`;
|
|
1868
|
+
if (!fs4.existsSync(providersPath)) {
|
|
1869
|
+
await fs4.writeFile(providersPath, providersContent);
|
|
1870
|
+
console.log(
|
|
1871
|
+
chalk4.gray(
|
|
1872
|
+
`Created theme-provider.${structure.isTypeScript ? "tsx" : "jsx"}`
|
|
1873
|
+
)
|
|
1911
1874
|
);
|
|
1912
|
-
} else if (category === "hooks") {
|
|
1913
|
-
return path3.join(paths.hooks || "hooks", componentName, fileName);
|
|
1914
|
-
} else if (category === "packages") {
|
|
1915
|
-
return path3.join(paths.components, componentName, fileName);
|
|
1916
1875
|
}
|
|
1917
|
-
|
|
1876
|
+
console.log(chalk4.green("\u2705 Example files created"));
|
|
1877
|
+
}
|
|
1878
|
+
async function updatePackageScripts() {
|
|
1879
|
+
console.log(chalk4.blue("\u{1F4DD} Updating package.json scripts..."));
|
|
1880
|
+
const packageJsonPath = path4.join(process.cwd(), "package.json");
|
|
1881
|
+
const packageJson2 = await fs4.readJson(packageJsonPath);
|
|
1882
|
+
packageJson2.scripts = {
|
|
1883
|
+
...packageJson2.scripts,
|
|
1884
|
+
"foundrykit:add": "pnpm dlx @foundrykit/cli add",
|
|
1885
|
+
"foundrykit:update": "pnpm dlx @foundrykit/cli update"
|
|
1886
|
+
};
|
|
1887
|
+
await fs4.writeJson(packageJsonPath, packageJson2, { spaces: 2 });
|
|
1888
|
+
console.log(chalk4.green("\u2705 Package scripts updated"));
|
|
1889
|
+
}
|
|
1890
|
+
async function createConfigFile(options, structure, pathConfig) {
|
|
1891
|
+
console.log(chalk4.blue("\u{1F4DD} Creating configuration file..."));
|
|
1892
|
+
const configPath = path4.join(process.cwd(), "foundrykit.config.json");
|
|
1893
|
+
if (fs4.existsSync(configPath) && !options.force) {
|
|
1894
|
+
console.log(chalk4.yellow("\u26A0\uFE0F Configuration file already exists"));
|
|
1895
|
+
return;
|
|
1896
|
+
}
|
|
1897
|
+
const normalizePath = (p) => {
|
|
1898
|
+
if (p.startsWith("./") || p.startsWith("../") || path4.isAbsolute(p)) {
|
|
1899
|
+
return p;
|
|
1900
|
+
}
|
|
1901
|
+
return `./${p}`;
|
|
1902
|
+
};
|
|
1903
|
+
const config = {
|
|
1904
|
+
version: CLI_VERSION,
|
|
1905
|
+
registry: DEFAULT_REGISTRY_URL,
|
|
1906
|
+
paths: {
|
|
1907
|
+
utils: normalizePath(pathConfig.utils),
|
|
1908
|
+
primitives: normalizePath(pathConfig.primitives),
|
|
1909
|
+
components: normalizePath(pathConfig.components),
|
|
1910
|
+
blocks: normalizePath(pathConfig.blocks),
|
|
1911
|
+
hooks: normalizePath(pathConfig.hooks),
|
|
1912
|
+
maps: normalizePath(pathConfig.maps),
|
|
1913
|
+
animations: normalizePath(pathConfig.animations)
|
|
1914
|
+
},
|
|
1915
|
+
packageManager: structure.packageManager,
|
|
1916
|
+
typescript: structure.isTypeScript,
|
|
1917
|
+
framework: structure.framework,
|
|
1918
|
+
tailwind: {
|
|
1919
|
+
css: normalizePath(pathConfig.styles)
|
|
1920
|
+
},
|
|
1921
|
+
aliases: {
|
|
1922
|
+
"@": normalizePath(structure.baseDir.replace(/\/$/, "") || "."),
|
|
1923
|
+
"@/components": normalizePath(
|
|
1924
|
+
path4.dirname(pathConfig.components).replace(/\/$/, "")
|
|
1925
|
+
),
|
|
1926
|
+
"@/lib": normalizePath(pathConfig.lib.replace(/\/$/, "")),
|
|
1927
|
+
"@/hooks": normalizePath(pathConfig.hooks.replace(/\/$/, ""))
|
|
1928
|
+
}
|
|
1929
|
+
};
|
|
1930
|
+
await fs4.writeJson(configPath, config, { spaces: 2 });
|
|
1931
|
+
console.log(chalk4.green("\u2705 Created foundrykit.config.json"));
|
|
1918
1932
|
}
|
|
1919
|
-
function
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
default:
|
|
1937
|
-
return void 0;
|
|
1933
|
+
async function installUtils(pathConfig) {
|
|
1934
|
+
console.log(chalk4.blue("\u{1F4E6} Installing utility functions..."));
|
|
1935
|
+
const utilsPath = path4.join(process.cwd(), pathConfig.utils);
|
|
1936
|
+
const utilsContent = `import { type ClassValue, clsx } from 'clsx';
|
|
1937
|
+
import { twMerge } from 'tailwind-merge';
|
|
1938
|
+
|
|
1939
|
+
export function cn(...inputs: ClassValue[]) {
|
|
1940
|
+
return twMerge(clsx(inputs));
|
|
1941
|
+
}
|
|
1942
|
+
`;
|
|
1943
|
+
const utilsDir = path4.dirname(utilsPath);
|
|
1944
|
+
await fs4.ensureDir(utilsDir);
|
|
1945
|
+
if (!fs4.existsSync(utilsPath)) {
|
|
1946
|
+
await fs4.writeFile(utilsPath, utilsContent);
|
|
1947
|
+
console.log(chalk4.green("\u2705 Utility functions installed"));
|
|
1948
|
+
} else {
|
|
1949
|
+
console.log(chalk4.gray("Utils file already exists, skipping..."));
|
|
1938
1950
|
}
|
|
1939
1951
|
}
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
+
|
|
1953
|
+
// src/commands/list.ts
|
|
1954
|
+
import chalk5 from "chalk";
|
|
1955
|
+
import { Command as Command4 } from "commander";
|
|
1956
|
+
function listCommand() {
|
|
1957
|
+
return new Command4("list").description("List all available FoundryKit components and blocks").option(
|
|
1958
|
+
"-c, --category <category>",
|
|
1959
|
+
"filter by category (primitives, components, blocks, animations)"
|
|
1960
|
+
).option("-s, --search <term>", "search components by name or description").action(async (options) => {
|
|
1961
|
+
try {
|
|
1962
|
+
console.log(chalk5.blue("\u{1F4E6} Available FoundryKit components:"));
|
|
1963
|
+
const registry = getRegistry();
|
|
1964
|
+
if (options.category) {
|
|
1965
|
+
const validCategories = REGISTRY_CATEGORY_ORDER;
|
|
1966
|
+
if (!validCategories.includes(options.category)) {
|
|
1967
|
+
console.error(chalk5.red(`Invalid category: ${options.category}`));
|
|
1968
|
+
console.log(
|
|
1969
|
+
chalk5.gray(`Valid categories: ${validCategories.join(", ")}`)
|
|
1970
|
+
);
|
|
1971
|
+
process.exit(1);
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
console.log(chalk5.gray("Fetching from registry..."));
|
|
1975
|
+
const components = await registry.getComponents(
|
|
1976
|
+
options.category,
|
|
1977
|
+
options.search
|
|
1978
|
+
);
|
|
1979
|
+
if (components.length === 0) {
|
|
1980
|
+
console.log(
|
|
1981
|
+
chalk5.yellow("\nNo components found matching your criteria.")
|
|
1982
|
+
);
|
|
1983
|
+
if (options.search) {
|
|
1984
|
+
console.log(chalk5.gray(`Search term: "${options.search}"`));
|
|
1985
|
+
}
|
|
1986
|
+
if (options.category) {
|
|
1987
|
+
console.log(chalk5.gray(`Category: ${options.category}`));
|
|
1988
|
+
}
|
|
1989
|
+
return;
|
|
1990
|
+
}
|
|
1991
|
+
displayComponents(components);
|
|
1992
|
+
console.log(chalk5.cyan("\n\u{1F4A1} Usage:"));
|
|
1993
|
+
console.log(
|
|
1994
|
+
chalk5.gray(" foundrykit add # Interactive mode")
|
|
1995
|
+
);
|
|
1996
|
+
console.log(
|
|
1997
|
+
chalk5.gray(" foundrykit add <id> # Add specific component")
|
|
1998
|
+
);
|
|
1999
|
+
console.log(chalk5.gray(" foundrykit add button # Example"));
|
|
2000
|
+
} catch (error) {
|
|
2001
|
+
console.error(chalk5.red("\u274C Failed to fetch component registry:"));
|
|
2002
|
+
console.error(
|
|
2003
|
+
chalk5.red(error instanceof Error ? error.message : String(error))
|
|
2004
|
+
);
|
|
2005
|
+
process.exit(1);
|
|
2006
|
+
}
|
|
2007
|
+
});
|
|
2008
|
+
}
|
|
2009
|
+
function displayComponents(components) {
|
|
2010
|
+
const grouped = components.reduce(
|
|
2011
|
+
(acc, component) => {
|
|
2012
|
+
if (!acc[component.category]) {
|
|
2013
|
+
acc[component.category] = [];
|
|
2014
|
+
}
|
|
2015
|
+
acc[component.category].push(component);
|
|
2016
|
+
return acc;
|
|
2017
|
+
},
|
|
2018
|
+
{}
|
|
1952
2019
|
);
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
2020
|
+
const knownCategories = new Set(
|
|
2021
|
+
REGISTRY_CATEGORY_ORDER
|
|
2022
|
+
);
|
|
2023
|
+
const categoryOrder = [
|
|
2024
|
+
...REGISTRY_CATEGORY_ORDER,
|
|
2025
|
+
...Object.keys(grouped).filter(
|
|
2026
|
+
(category) => !knownCategories.has(category)
|
|
2027
|
+
)
|
|
2028
|
+
];
|
|
2029
|
+
for (const category of categoryOrder) {
|
|
2030
|
+
const items = grouped[category];
|
|
2031
|
+
if (!items || items.length === 0) continue;
|
|
2032
|
+
console.log(`
|
|
2033
|
+
${chalk5.cyan.bold(category.toUpperCase())}`);
|
|
2034
|
+
console.log(chalk5.gray("\u2500".repeat(40)));
|
|
2035
|
+
for (const item of items) {
|
|
2036
|
+
console.log(
|
|
2037
|
+
`${chalk5.green("\u25CF")} ${chalk5.bold(item.name)} ${chalk5.gray(
|
|
2038
|
+
`(${item.id})`
|
|
2039
|
+
)}`
|
|
2040
|
+
);
|
|
2041
|
+
console.log(` ${chalk5.gray(item.description)}`);
|
|
2042
|
+
if (item.tags && item.tags.length > 0) {
|
|
2043
|
+
console.log(
|
|
2044
|
+
` ${chalk5.blue(item.tags.map((tag) => `#${tag}`).join(" "))}`
|
|
2045
|
+
);
|
|
1975
2046
|
}
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
2047
|
+
if (item.registryDependencies && item.registryDependencies.length > 0) {
|
|
2048
|
+
console.log(
|
|
2049
|
+
` ${chalk5.yellow("Requires:")} ${item.registryDependencies.join(
|
|
2050
|
+
", "
|
|
2051
|
+
)}`
|
|
2052
|
+
);
|
|
2053
|
+
}
|
|
2054
|
+
if (item.packageDependencies && item.packageDependencies.length > 0) {
|
|
2055
|
+
console.log(
|
|
2056
|
+
` ${chalk5.magenta("NPM packages:")} ${item.packageDependencies.join(
|
|
2057
|
+
", "
|
|
2058
|
+
)}`
|
|
2059
|
+
);
|
|
2060
|
+
}
|
|
2061
|
+
console.log();
|
|
2062
|
+
}
|
|
1981
2063
|
}
|
|
1982
|
-
|
|
2064
|
+
const total = components.length;
|
|
2065
|
+
const byCategory = Object.entries(grouped).map(([cat, items]) => `${items.length} ${cat}`).join(", ");
|
|
2066
|
+
console.log(chalk5.gray("\u2500".repeat(40)));
|
|
2067
|
+
console.log(chalk5.gray(`Total: ${total} components (${byCategory})`));
|
|
1983
2068
|
}
|
|
1984
2069
|
|
|
1985
2070
|
// src/commands/update.ts
|
|
1986
|
-
import
|
|
1987
|
-
import
|
|
2071
|
+
import path5 from "path";
|
|
2072
|
+
import chalk6 from "chalk";
|
|
2073
|
+
import { Command as Command5 } from "commander";
|
|
2074
|
+
import fs5 from "fs-extra";
|
|
1988
2075
|
import inquirer3 from "inquirer";
|
|
1989
|
-
import fs4 from "fs-extra";
|
|
1990
|
-
import path4 from "path";
|
|
1991
2076
|
function updateCommand() {
|
|
1992
|
-
return new
|
|
2077
|
+
return new Command5("update").description("Update installed components").argument("[id]", "Component or block ID (omit to update all installed)").option(
|
|
1993
2078
|
"-o, --opt",
|
|
1994
2079
|
"interactively select which components to update, showing available upgrades"
|
|
1995
2080
|
).option("-f, --force", "bypass cache and fetch fresh data from registry").option("-p, --path <path>", "Custom installation path").action(async (id, options) => {
|
|
1996
2081
|
if (id) {
|
|
1997
2082
|
try {
|
|
1998
|
-
console.log(
|
|
2083
|
+
console.log(chalk6.blue(`\u{1F504} Updating ${id}...`));
|
|
1999
2084
|
await addSingleComponent(id, {
|
|
2000
2085
|
...options,
|
|
2001
2086
|
overwrite: true,
|
|
2002
2087
|
force: true
|
|
2003
2088
|
});
|
|
2004
2089
|
} catch (error) {
|
|
2005
|
-
console.error(
|
|
2090
|
+
console.error(chalk6.red(`\u274C Failed to update ${id}:`));
|
|
2006
2091
|
console.error(
|
|
2007
|
-
|
|
2092
|
+
chalk6.red(error instanceof Error ? error.message : String(error))
|
|
2008
2093
|
);
|
|
2009
2094
|
process.exit(1);
|
|
2010
2095
|
}
|
|
2011
2096
|
return;
|
|
2012
2097
|
}
|
|
2013
|
-
const configPath =
|
|
2014
|
-
if (!
|
|
2098
|
+
const configPath = path5.join(process.cwd(), "foundrykit.config.json");
|
|
2099
|
+
if (!fs5.existsSync(configPath)) {
|
|
2015
2100
|
console.error(
|
|
2016
|
-
|
|
2101
|
+
chalk6.red(
|
|
2017
2102
|
'\u274C FoundryKit not initialized. Run "foundrykit init" first.'
|
|
2018
2103
|
)
|
|
2019
2104
|
);
|
|
2020
2105
|
process.exit(1);
|
|
2021
2106
|
}
|
|
2022
|
-
const config = await
|
|
2023
|
-
|
|
2107
|
+
const config = await fs5.readJson(configPath);
|
|
2108
|
+
const installed = config.installedComponents ?? {};
|
|
2024
2109
|
const installedFoundryKitPackages = await getInstalledFoundryKitPackageVersions();
|
|
2025
2110
|
for (const [pkgId, version] of Object.entries(
|
|
2026
2111
|
installedFoundryKitPackages
|
|
@@ -2034,7 +2119,7 @@ function updateCommand() {
|
|
|
2034
2119
|
let installedIds = Object.keys(installed);
|
|
2035
2120
|
if (installedIds.length === 0) {
|
|
2036
2121
|
console.log(
|
|
2037
|
-
|
|
2122
|
+
chalk6.gray(
|
|
2038
2123
|
"No install tracking found. Scanning filesystem for installed components..."
|
|
2039
2124
|
)
|
|
2040
2125
|
);
|
|
@@ -2043,9 +2128,9 @@ function updateCommand() {
|
|
|
2043
2128
|
try {
|
|
2044
2129
|
allComponents = await registry.getComponents();
|
|
2045
2130
|
} catch (error) {
|
|
2046
|
-
console.error(
|
|
2131
|
+
console.error(chalk6.red("\u274C Failed to fetch registry:"));
|
|
2047
2132
|
console.error(
|
|
2048
|
-
|
|
2133
|
+
chalk6.red(error instanceof Error ? error.message : String(error))
|
|
2049
2134
|
);
|
|
2050
2135
|
process.exit(1);
|
|
2051
2136
|
}
|
|
@@ -2065,21 +2150,21 @@ function updateCommand() {
|
|
|
2065
2150
|
installedIds = Object.keys(installed);
|
|
2066
2151
|
if (installedIds.length === 0) {
|
|
2067
2152
|
console.log(
|
|
2068
|
-
|
|
2153
|
+
chalk6.yellow(
|
|
2069
2154
|
'No installed components found. Use "foundrykit add" to install components.'
|
|
2070
2155
|
)
|
|
2071
2156
|
);
|
|
2072
2157
|
return;
|
|
2073
2158
|
}
|
|
2074
2159
|
console.log(
|
|
2075
|
-
|
|
2160
|
+
chalk6.gray(
|
|
2076
2161
|
`Found ${installedIds.length} installed component(s) via filesystem scan.`
|
|
2077
2162
|
)
|
|
2078
2163
|
);
|
|
2079
2164
|
}
|
|
2080
2165
|
if (options.opt) {
|
|
2081
2166
|
console.log(
|
|
2082
|
-
|
|
2167
|
+
chalk6.blue(
|
|
2083
2168
|
`\u{1F50D} Checking for updates across ${installedIds.length} installed component(s)...`
|
|
2084
2169
|
)
|
|
2085
2170
|
);
|
|
@@ -2112,29 +2197,29 @@ function updateCommand() {
|
|
|
2112
2197
|
}
|
|
2113
2198
|
if (upToDate.length > 0) {
|
|
2114
2199
|
console.log(
|
|
2115
|
-
|
|
2200
|
+
chalk6.gray(`
|
|
2116
2201
|
\u2713 Already up to date: ${upToDate.join(", ")}`)
|
|
2117
2202
|
);
|
|
2118
2203
|
}
|
|
2119
2204
|
if (withUpdates.length === 0) {
|
|
2120
|
-
console.log(
|
|
2205
|
+
console.log(chalk6.green("\n\u2705 All components are up to date."));
|
|
2121
2206
|
return;
|
|
2122
2207
|
}
|
|
2123
2208
|
const choices = withUpdates.map(
|
|
2124
2209
|
({ id: compId, installed: inst, latest }) => {
|
|
2125
2210
|
let versionLabel;
|
|
2126
2211
|
if (inst === null && latest === null) {
|
|
2127
|
-
versionLabel =
|
|
2212
|
+
versionLabel = chalk6.gray("(version unknown)");
|
|
2128
2213
|
} else if (latest === null) {
|
|
2129
|
-
versionLabel =
|
|
2214
|
+
versionLabel = chalk6.gray(
|
|
2130
2215
|
`(installed: ${inst} \u2014 registry version unknown)`
|
|
2131
2216
|
);
|
|
2132
2217
|
} else if (inst === null) {
|
|
2133
|
-
versionLabel =
|
|
2218
|
+
versionLabel = chalk6.cyan(
|
|
2134
2219
|
`(latest: ${latest} \u2014 install version not tracked)`
|
|
2135
2220
|
);
|
|
2136
2221
|
} else {
|
|
2137
|
-
versionLabel =
|
|
2222
|
+
versionLabel = chalk6.cyan(`(${inst} \u2192 ${latest})`);
|
|
2138
2223
|
}
|
|
2139
2224
|
return {
|
|
2140
2225
|
name: `${compId} ${versionLabel}`,
|
|
@@ -2153,13 +2238,13 @@ function updateCommand() {
|
|
|
2153
2238
|
}
|
|
2154
2239
|
]);
|
|
2155
2240
|
if (selectedIds.length === 0) {
|
|
2156
|
-
console.log(
|
|
2241
|
+
console.log(chalk6.yellow("No components selected."));
|
|
2157
2242
|
return;
|
|
2158
2243
|
}
|
|
2159
2244
|
await runUpdates(selectedIds, options);
|
|
2160
2245
|
} else {
|
|
2161
2246
|
console.log(
|
|
2162
|
-
|
|
2247
|
+
chalk6.blue(
|
|
2163
2248
|
`\u{1F504} Updating all ${installedIds.length} installed component(s)...`
|
|
2164
2249
|
)
|
|
2165
2250
|
);
|
|
@@ -2168,11 +2253,11 @@ function updateCommand() {
|
|
|
2168
2253
|
});
|
|
2169
2254
|
}
|
|
2170
2255
|
async function getInstalledFoundryKitPackageVersions() {
|
|
2171
|
-
const packageJsonPath =
|
|
2172
|
-
if (!
|
|
2256
|
+
const packageJsonPath = path5.join(process.cwd(), "package.json");
|
|
2257
|
+
if (!fs5.existsSync(packageJsonPath)) {
|
|
2173
2258
|
return {};
|
|
2174
2259
|
}
|
|
2175
|
-
const packageJson2 = await
|
|
2260
|
+
const packageJson2 = await fs5.readJson(packageJsonPath);
|
|
2176
2261
|
const dependencies = {
|
|
2177
2262
|
...packageJson2.dependencies,
|
|
2178
2263
|
...packageJson2.devDependencies,
|
|
@@ -2205,7 +2290,7 @@ async function runUpdates(ids, options) {
|
|
|
2205
2290
|
let failed = 0;
|
|
2206
2291
|
for (const compId of ids) {
|
|
2207
2292
|
try {
|
|
2208
|
-
console.log(
|
|
2293
|
+
console.log(chalk6.blue(`
|
|
2209
2294
|
\u{1F504} Updating ${compId}...`));
|
|
2210
2295
|
await addSingleComponent(compId, {
|
|
2211
2296
|
...options,
|
|
@@ -2213,108 +2298,25 @@ async function runUpdates(ids, options) {
|
|
|
2213
2298
|
force: true
|
|
2214
2299
|
});
|
|
2215
2300
|
} catch (error) {
|
|
2216
|
-
console.error(
|
|
2301
|
+
console.error(chalk6.red(`\u274C Failed to update ${compId}:`));
|
|
2217
2302
|
console.error(
|
|
2218
|
-
|
|
2303
|
+
chalk6.red(error instanceof Error ? error.message : String(error))
|
|
2219
2304
|
);
|
|
2220
2305
|
failed++;
|
|
2221
2306
|
}
|
|
2222
2307
|
}
|
|
2223
2308
|
if (failed > 0) {
|
|
2224
|
-
console.log(
|
|
2309
|
+
console.log(chalk6.yellow(`
|
|
2225
2310
|
\u26A0 ${failed} component(s) failed to update.`));
|
|
2226
2311
|
process.exit(1);
|
|
2227
2312
|
} else {
|
|
2228
2313
|
console.log(
|
|
2229
|
-
|
|
2314
|
+
chalk6.green(`
|
|
2230
2315
|
\u2705 ${ids.length} component(s) updated successfully!`)
|
|
2231
2316
|
);
|
|
2232
2317
|
}
|
|
2233
2318
|
}
|
|
2234
2319
|
|
|
2235
|
-
// src/commands/doctor.ts
|
|
2236
|
-
import { Command as Command5 } from "commander";
|
|
2237
|
-
import chalk6 from "chalk";
|
|
2238
|
-
import fs5 from "fs-extra";
|
|
2239
|
-
import path5 from "path";
|
|
2240
|
-
function doctorCommand() {
|
|
2241
|
-
return new Command5("doctor").description("Check project health and configuration").action(async () => {
|
|
2242
|
-
console.log(chalk6.blue("\u{1F50D} Checking project health..."));
|
|
2243
|
-
const results = [];
|
|
2244
|
-
const packageJsonPath = path5.join(process.cwd(), "package.json");
|
|
2245
|
-
const hasPackageJson = await fs5.pathExists(packageJsonPath);
|
|
2246
|
-
results.push({
|
|
2247
|
-
label: "package.json",
|
|
2248
|
-
ok: hasPackageJson,
|
|
2249
|
-
detail: hasPackageJson ? "Project manifest found" : "Run this command in a project root"
|
|
2250
|
-
});
|
|
2251
|
-
let packageJson2 = null;
|
|
2252
|
-
if (hasPackageJson) {
|
|
2253
|
-
packageJson2 = await fs5.readJson(packageJsonPath);
|
|
2254
|
-
}
|
|
2255
|
-
const hasNext = !!packageJson2 && !!(packageJson2.dependencies?.next || packageJson2.devDependencies?.next);
|
|
2256
|
-
results.push({
|
|
2257
|
-
label: "Framework",
|
|
2258
|
-
ok: hasNext,
|
|
2259
|
-
detail: hasNext ? "Next.js dependency detected" : "FoundryKit currently expects a Next.js project"
|
|
2260
|
-
});
|
|
2261
|
-
const configPath = path5.join(process.cwd(), "foundrykit.config.json");
|
|
2262
|
-
const hasConfig = await fs5.pathExists(configPath);
|
|
2263
|
-
results.push({
|
|
2264
|
-
label: "FoundryKit config",
|
|
2265
|
-
ok: hasConfig,
|
|
2266
|
-
detail: hasConfig ? "foundrykit.config.json found" : 'Run "foundrykit init" to create the configuration file'
|
|
2267
|
-
});
|
|
2268
|
-
let config = null;
|
|
2269
|
-
if (hasConfig) {
|
|
2270
|
-
try {
|
|
2271
|
-
config = await loadConfig();
|
|
2272
|
-
const hasRequiredPaths = !!config.paths?.utils && !!config.paths?.primitives && !!config.paths?.components && !!config.paths?.blocks && !!config.paths?.animations;
|
|
2273
|
-
results.push({
|
|
2274
|
-
label: "Config shape",
|
|
2275
|
-
ok: hasRequiredPaths,
|
|
2276
|
-
detail: hasRequiredPaths ? "Required install paths are configured" : "Configuration is missing one or more required install paths"
|
|
2277
|
-
});
|
|
2278
|
-
const registryUrl = config.registry || DEFAULT_REGISTRY_URL;
|
|
2279
|
-
try {
|
|
2280
|
-
const response = await fetch(`${registryUrl}/registry`, {
|
|
2281
|
-
headers: { Accept: "application/json" }
|
|
2282
|
-
});
|
|
2283
|
-
results.push({
|
|
2284
|
-
label: "Registry",
|
|
2285
|
-
ok: response.ok,
|
|
2286
|
-
detail: response.ok ? `Registry reachable at ${registryUrl}` : `Registry returned ${response.status} ${response.statusText}`
|
|
2287
|
-
});
|
|
2288
|
-
} catch (error) {
|
|
2289
|
-
results.push({
|
|
2290
|
-
label: "Registry",
|
|
2291
|
-
ok: false,
|
|
2292
|
-
detail: `Unable to reach ${registryUrl}: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
2293
|
-
});
|
|
2294
|
-
}
|
|
2295
|
-
} catch (error) {
|
|
2296
|
-
results.push({
|
|
2297
|
-
label: "Config shape",
|
|
2298
|
-
ok: false,
|
|
2299
|
-
detail: `Failed to read foundrykit.config.json: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
2300
|
-
});
|
|
2301
|
-
}
|
|
2302
|
-
}
|
|
2303
|
-
for (const result of results) {
|
|
2304
|
-
const icon = result.ok ? chalk6.green("\u2705") : chalk6.red("\u274C");
|
|
2305
|
-
console.log(`${icon} ${result.label}: ${result.detail}`);
|
|
2306
|
-
}
|
|
2307
|
-
const hasFailures = results.some((result) => !result.ok);
|
|
2308
|
-
if (hasFailures) {
|
|
2309
|
-
console.log(
|
|
2310
|
-
chalk6.yellow("\n\u26A0\uFE0F Found issues that should be resolved before continuing.")
|
|
2311
|
-
);
|
|
2312
|
-
process.exit(1);
|
|
2313
|
-
}
|
|
2314
|
-
console.log(chalk6.green("\n\u2705 All checks passed!"));
|
|
2315
|
-
});
|
|
2316
|
-
}
|
|
2317
|
-
|
|
2318
2320
|
// src/index.ts
|
|
2319
2321
|
var __filename = fileURLToPath(import.meta.url);
|
|
2320
2322
|
var __dirname = dirname(__filename);
|