@foundrykit/cli 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/README.md +187 -219
- package/dist/cli.js +1015 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.js +748 -494
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
- package/src/commands/add.ts +230 -265
- package/src/commands/init.ts +404 -108
- package/src/commands/list.ts +113 -198
- package/src/lib/registry.ts +293 -0
- package/tsup.config.ts +7 -2
- package/.turbo/turbo-build.log +0 -18
- package/.turbo/turbo-lint.log +0 -5
- package/.turbo/turbo-type-check.log +0 -5
package/dist/index.js
CHANGED
|
@@ -32,7 +32,7 @@ function initCommand() {
|
|
|
32
32
|
if (!options.skipInstall) {
|
|
33
33
|
await installDependencies();
|
|
34
34
|
}
|
|
35
|
-
await
|
|
35
|
+
await setupTailwindV4();
|
|
36
36
|
await createDirectories();
|
|
37
37
|
await createExampleFiles();
|
|
38
38
|
await updatePackageScripts();
|
|
@@ -78,28 +78,36 @@ async function validateNextJsProject() {
|
|
|
78
78
|
console.log(chalk.green("\u2705 Next.js project detected"));
|
|
79
79
|
}
|
|
80
80
|
async function isFoundryKitInitialized() {
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
81
|
+
const packageJsonPath = path.join(process.cwd(), "package.json");
|
|
82
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
83
|
+
const packageJson = await fs.readJson(packageJsonPath);
|
|
84
|
+
const dependencies = {
|
|
85
|
+
...packageJson.dependencies,
|
|
86
|
+
...packageJson.devDependencies
|
|
87
|
+
};
|
|
88
|
+
return Object.keys(dependencies).some(
|
|
89
|
+
(dep) => dep.startsWith("@foundrykit/")
|
|
90
|
+
);
|
|
90
91
|
}
|
|
91
92
|
return false;
|
|
92
93
|
}
|
|
93
94
|
async function installDependencies() {
|
|
94
95
|
console.log(chalk.blue("\u{1F4E6} Installing FoundryKit dependencies..."));
|
|
96
|
+
const isWorkspace = await checkIfWorkspace();
|
|
97
|
+
if (isWorkspace) {
|
|
98
|
+
console.log(
|
|
99
|
+
chalk.yellow("\u26A0\uFE0F Workspace detected - skipping dependency installation")
|
|
100
|
+
);
|
|
101
|
+
console.log(chalk.gray("Dependencies are already available via workspace"));
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
95
104
|
const dependencies = [
|
|
96
105
|
"@foundrykit/primitives",
|
|
97
106
|
"@foundrykit/components",
|
|
98
107
|
"@foundrykit/blocks",
|
|
99
108
|
"@foundrykit/hooks",
|
|
100
109
|
"@foundrykit/animation",
|
|
101
|
-
"@foundrykit/
|
|
102
|
-
"@foundrykit/tailwind-config"
|
|
110
|
+
"@foundrykit/tailwind"
|
|
103
111
|
];
|
|
104
112
|
try {
|
|
105
113
|
const packageManager = detectPackageManager();
|
|
@@ -113,34 +121,268 @@ async function installDependencies() {
|
|
|
113
121
|
);
|
|
114
122
|
}
|
|
115
123
|
}
|
|
124
|
+
async function checkIfWorkspace() {
|
|
125
|
+
try {
|
|
126
|
+
const pnpmWorkspacePath = path.join(
|
|
127
|
+
process.cwd(),
|
|
128
|
+
"../../pnpm-workspace.yaml"
|
|
129
|
+
);
|
|
130
|
+
if (fs.existsSync(pnpmWorkspacePath)) {
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
const packageJsonPath = path.join(process.cwd(), "package.json");
|
|
134
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
135
|
+
const packageJson = await fs.readJson(packageJsonPath);
|
|
136
|
+
const allDeps = {
|
|
137
|
+
...packageJson.dependencies,
|
|
138
|
+
...packageJson.devDependencies
|
|
139
|
+
};
|
|
140
|
+
const foundryKitPackages = Object.keys(allDeps).filter(
|
|
141
|
+
(key) => key.startsWith("@foundrykit/")
|
|
142
|
+
);
|
|
143
|
+
for (const pkg of foundryKitPackages) {
|
|
144
|
+
if (allDeps[pkg]?.includes("workspace:")) {
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return false;
|
|
150
|
+
} catch {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
116
154
|
function detectPackageManager() {
|
|
117
155
|
if (fs.existsSync("pnpm-lock.yaml")) return "pnpm";
|
|
118
156
|
if (fs.existsSync("yarn.lock")) return "yarn";
|
|
119
157
|
return "npm";
|
|
120
158
|
}
|
|
121
|
-
async function
|
|
122
|
-
console.log(chalk.blue("\u2699\uFE0F Setting up Tailwind
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
159
|
+
async function setupTailwindV4() {
|
|
160
|
+
console.log(chalk.blue("\u2699\uFE0F Setting up Tailwind CSS v4..."));
|
|
161
|
+
const layoutInfo = await findLayoutFile();
|
|
162
|
+
if (layoutInfo) {
|
|
163
|
+
const layoutContent = await fs.readFile(layoutInfo.path, "utf-8");
|
|
164
|
+
if (layoutContent.includes("@foundrykit/tailwind/globals.css")) {
|
|
165
|
+
const { importPreference } = await inquirer.prompt([
|
|
166
|
+
{
|
|
167
|
+
type: "list",
|
|
168
|
+
name: "importPreference",
|
|
169
|
+
message: "FoundryKit styles are already imported directly. How would you like to proceed?",
|
|
170
|
+
choices: [
|
|
171
|
+
{
|
|
172
|
+
name: "Keep direct import from @foundrykit/tailwind/globals.css",
|
|
173
|
+
value: "direct"
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
name: "Switch to local globals.css file (recommended for customization)",
|
|
177
|
+
value: "local"
|
|
178
|
+
}
|
|
179
|
+
],
|
|
180
|
+
default: "direct"
|
|
181
|
+
}
|
|
182
|
+
]);
|
|
183
|
+
if (importPreference === "direct") {
|
|
184
|
+
console.log(
|
|
185
|
+
chalk.green(
|
|
186
|
+
"\u2705 Keeping direct import from @foundrykit/tailwind/globals.css"
|
|
187
|
+
)
|
|
188
|
+
);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
await createLocalGlobalsAndUpdateLayout(layoutInfo.path, layoutContent);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
const globalsCssImportMatch = layoutContent.match(
|
|
195
|
+
/import\s+['"]([^'"]*globals\.css)['"]/
|
|
196
|
+
);
|
|
197
|
+
if (globalsCssImportMatch && globalsCssImportMatch[1]) {
|
|
198
|
+
const importPath = globalsCssImportMatch[1];
|
|
199
|
+
const resolvedPath = importPath.startsWith(".") ? path.join(path.dirname(layoutInfo.path), importPath) : path.join(process.cwd(), importPath.replace(/^@\//, "app/"));
|
|
200
|
+
if (fs.existsSync(resolvedPath)) {
|
|
201
|
+
const globalsCssContent = await fs.readFile(resolvedPath, "utf-8");
|
|
202
|
+
if (globalsCssContent.includes("@foundrykit/tailwind/globals.css")) {
|
|
203
|
+
console.log(chalk.green("\u2705 FoundryKit styles already configured"));
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const updatedContent = `/* Import FoundryKit's Tailwind CSS v4 styles */
|
|
207
|
+
@import "@foundrykit/tailwind/globals.css";
|
|
126
208
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
209
|
+
/* Your custom styles below */
|
|
210
|
+
${globalsCssContent}`;
|
|
211
|
+
await fs.writeFile(resolvedPath, updatedContent);
|
|
212
|
+
console.log(
|
|
213
|
+
chalk.green("\u2705 Updated existing globals.css with FoundryKit styles")
|
|
214
|
+
);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
const { setupPreference } = await inquirer.prompt([
|
|
220
|
+
{
|
|
221
|
+
type: "list",
|
|
222
|
+
name: "setupPreference",
|
|
223
|
+
message: "How would you like to import FoundryKit styles?",
|
|
224
|
+
choices: [
|
|
225
|
+
{
|
|
226
|
+
name: "Create a local globals.css file (recommended for customization)",
|
|
227
|
+
value: "local"
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
name: "Import directly from @foundrykit/tailwind/globals.css",
|
|
231
|
+
value: "direct"
|
|
232
|
+
}
|
|
233
|
+
],
|
|
234
|
+
default: "local"
|
|
235
|
+
}
|
|
236
|
+
]);
|
|
237
|
+
if (setupPreference === "direct") {
|
|
238
|
+
await addDirectImportToLayout();
|
|
239
|
+
} else {
|
|
240
|
+
await createLocalGlobalsAndUpdateLayout();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
async function createLocalGlobalsAndUpdateLayout(existingLayoutPath, existingLayoutContent) {
|
|
244
|
+
const possiblePaths = [
|
|
245
|
+
"app/globals.css",
|
|
246
|
+
"src/app/globals.css",
|
|
247
|
+
"styles/globals.css",
|
|
248
|
+
"src/styles/globals.css"
|
|
249
|
+
];
|
|
250
|
+
let globalCssPath = null;
|
|
251
|
+
for (const p of possiblePaths) {
|
|
252
|
+
const fullPath = path.join(process.cwd(), p);
|
|
253
|
+
if (fs.existsSync(fullPath)) {
|
|
254
|
+
globalCssPath = fullPath;
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (!globalCssPath) {
|
|
259
|
+
globalCssPath = path.join(process.cwd(), "app/globals.css");
|
|
260
|
+
await fs.ensureDir(path.dirname(globalCssPath));
|
|
261
|
+
}
|
|
262
|
+
const existingContent = fs.existsSync(globalCssPath) ? await fs.readFile(globalCssPath, "utf-8") : "";
|
|
263
|
+
if (!existingContent.includes("@foundrykit/tailwind/globals.css")) {
|
|
264
|
+
const cssContent = `/* Import FoundryKit's Tailwind CSS v4 styles */
|
|
265
|
+
@import "@foundrykit/tailwind/globals.css";
|
|
139
266
|
|
|
140
|
-
|
|
141
|
-
`;
|
|
142
|
-
|
|
143
|
-
|
|
267
|
+
/* Your custom styles below */
|
|
268
|
+
${existingContent}`;
|
|
269
|
+
await fs.writeFile(globalCssPath, cssContent);
|
|
270
|
+
console.log(
|
|
271
|
+
chalk.green("\u2705 Created/updated globals.css with FoundryKit styles")
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
if (existingLayoutPath && existingLayoutContent) {
|
|
275
|
+
const layoutDir = path.dirname(existingLayoutPath);
|
|
276
|
+
const cssRelativePath = path.relative(layoutDir, globalCssPath).replace(/\\/g, "/");
|
|
277
|
+
const importPath = cssRelativePath.startsWith(".") ? cssRelativePath : `./${cssRelativePath}`;
|
|
278
|
+
const updatedContent = existingLayoutContent.replace(
|
|
279
|
+
/@foundrykit\/tailwind\/globals\.css/g,
|
|
280
|
+
importPath
|
|
281
|
+
);
|
|
282
|
+
await fs.writeFile(existingLayoutPath, updatedContent);
|
|
283
|
+
console.log(chalk.green("\u2705 Updated layout to use local globals.css"));
|
|
284
|
+
} else {
|
|
285
|
+
await updateLayoutImport(globalCssPath);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
async function addDirectImportToLayout() {
|
|
289
|
+
const layoutInfo = await findLayoutFile();
|
|
290
|
+
if (!layoutInfo) {
|
|
291
|
+
console.log(
|
|
292
|
+
chalk.yellow(
|
|
293
|
+
"\u26A0\uFE0F No layout file found. Please add this import to your layout manually:"
|
|
294
|
+
)
|
|
295
|
+
);
|
|
296
|
+
console.log(chalk.gray(` import '@foundrykit/tailwind/globals.css';`));
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
const layoutContent = await fs.readFile(layoutInfo.path, "utf-8");
|
|
300
|
+
if (layoutContent.includes("@foundrykit/tailwind/globals.css")) {
|
|
301
|
+
console.log(
|
|
302
|
+
chalk.gray("Layout already imports FoundryKit styles directly")
|
|
303
|
+
);
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
const importStatement = `import '@foundrykit/tailwind/globals.css';`;
|
|
307
|
+
const importRegex = /^import\s+.*$/gm;
|
|
308
|
+
const imports = layoutContent.match(importRegex);
|
|
309
|
+
let updatedContent;
|
|
310
|
+
if (imports && imports.length > 0) {
|
|
311
|
+
const lastImport = imports[imports.length - 1];
|
|
312
|
+
const lastImportIndex = layoutContent.lastIndexOf(lastImport);
|
|
313
|
+
const insertPosition = lastImportIndex + lastImport.length;
|
|
314
|
+
updatedContent = layoutContent.slice(0, insertPosition) + "\n" + importStatement + layoutContent.slice(insertPosition);
|
|
315
|
+
} else {
|
|
316
|
+
updatedContent = importStatement + "\n" + layoutContent;
|
|
317
|
+
}
|
|
318
|
+
await fs.writeFile(layoutInfo.path, updatedContent);
|
|
319
|
+
console.log(
|
|
320
|
+
chalk.green("\u2705 Added direct import of FoundryKit styles to layout")
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
async function findLayoutFile() {
|
|
324
|
+
const layoutPaths = [
|
|
325
|
+
"app/layout.tsx",
|
|
326
|
+
"app/layout.jsx",
|
|
327
|
+
"app/layout.js",
|
|
328
|
+
"src/app/layout.tsx",
|
|
329
|
+
"src/app/layout.jsx",
|
|
330
|
+
"src/app/layout.js"
|
|
331
|
+
];
|
|
332
|
+
for (const p of layoutPaths) {
|
|
333
|
+
const fullPath = path.join(process.cwd(), p);
|
|
334
|
+
if (fs.existsSync(fullPath)) {
|
|
335
|
+
return { path: fullPath };
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return null;
|
|
339
|
+
}
|
|
340
|
+
async function updateLayoutImport(globalCssPath) {
|
|
341
|
+
const layoutInfo = await findLayoutFile();
|
|
342
|
+
if (!layoutInfo) {
|
|
343
|
+
console.log(
|
|
344
|
+
chalk.yellow(
|
|
345
|
+
"\u26A0\uFE0F No layout file found. Please import globals.css manually in your layout."
|
|
346
|
+
)
|
|
347
|
+
);
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
const layoutContent = await fs.readFile(layoutInfo.path, "utf-8");
|
|
351
|
+
if (layoutContent.match(/import\s+['"][^'"]*globals\.css['"]/)) {
|
|
352
|
+
console.log(chalk.gray("Layout already has a globals.css import"));
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
if (layoutContent.includes("@foundrykit/tailwind/globals.css")) {
|
|
356
|
+
const layoutDir2 = path.dirname(layoutInfo.path);
|
|
357
|
+
const cssRelativePath2 = path.relative(layoutDir2, globalCssPath).replace(/\\/g, "/");
|
|
358
|
+
const importPath2 = cssRelativePath2.startsWith(".") ? cssRelativePath2 : `./${cssRelativePath2}`;
|
|
359
|
+
const updatedContent2 = layoutContent.replace(
|
|
360
|
+
/@foundrykit\/tailwind\/globals\.css/g,
|
|
361
|
+
importPath2
|
|
362
|
+
);
|
|
363
|
+
await fs.writeFile(layoutInfo.path, updatedContent2);
|
|
364
|
+
console.log(
|
|
365
|
+
chalk.green("\u2705 Updated layout import to use local globals.css")
|
|
366
|
+
);
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
const layoutDir = path.dirname(layoutInfo.path);
|
|
370
|
+
const cssRelativePath = path.relative(layoutDir, globalCssPath).replace(/\\/g, "/");
|
|
371
|
+
const importPath = cssRelativePath.startsWith(".") ? cssRelativePath : `./${cssRelativePath}`;
|
|
372
|
+
const importStatement = `import '${importPath}';`;
|
|
373
|
+
const importRegex = /^import\s+.*$/gm;
|
|
374
|
+
const imports = layoutContent.match(importRegex);
|
|
375
|
+
let updatedContent;
|
|
376
|
+
if (imports && imports.length > 0) {
|
|
377
|
+
const lastImport = imports[imports.length - 1];
|
|
378
|
+
const lastImportIndex = layoutContent.lastIndexOf(lastImport);
|
|
379
|
+
const insertPosition = lastImportIndex + lastImport.length;
|
|
380
|
+
updatedContent = layoutContent.slice(0, insertPosition) + "\n" + importStatement + layoutContent.slice(insertPosition);
|
|
381
|
+
} else {
|
|
382
|
+
updatedContent = importStatement + "\n" + layoutContent;
|
|
383
|
+
}
|
|
384
|
+
await fs.writeFile(layoutInfo.path, updatedContent);
|
|
385
|
+
console.log(chalk.green("\u2705 Layout file updated with globals.css import"));
|
|
144
386
|
}
|
|
145
387
|
async function createDirectories() {
|
|
146
388
|
console.log(chalk.blue("\u{1F4C1} Creating component directories..."));
|
|
@@ -160,77 +402,26 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
160
402
|
return twMerge(clsx(inputs));
|
|
161
403
|
}
|
|
162
404
|
`;
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
const globalsCssContent = `@import "tailwindcss";
|
|
167
|
-
|
|
168
|
-
@layer base {
|
|
169
|
-
:root {
|
|
170
|
-
--background: 0 0% 100%;
|
|
171
|
-
--foreground: 222.2 84% 4.9%;
|
|
172
|
-
--card: 0 0% 100%;
|
|
173
|
-
--card-foreground: 222.2 84% 4.9%;
|
|
174
|
-
--popover: 0 0% 100%;
|
|
175
|
-
--popover-foreground: 222.2 84% 4.9%;
|
|
176
|
-
--primary: 222.2 47.4% 11.2%;
|
|
177
|
-
--primary-foreground: 210 40% 98%;
|
|
178
|
-
--secondary: 210 40% 96%;
|
|
179
|
-
--secondary-foreground: 222.2 84% 4.9%;
|
|
180
|
-
--muted: 210 40% 96%;
|
|
181
|
-
--muted-foreground: 215.4 16.3% 46.9%;
|
|
182
|
-
--accent: 210 40% 96%;
|
|
183
|
-
--accent-foreground: 222.2 84% 4.9%;
|
|
184
|
-
--destructive: 0 84.2% 60.2%;
|
|
185
|
-
--destructive-foreground: 210 40% 98%;
|
|
186
|
-
--border: 214.3 31.8% 91.4%;
|
|
187
|
-
--input: 214.3 31.8% 91.4%;
|
|
188
|
-
--ring: 222.2 84% 4.9%;
|
|
189
|
-
--radius: 0.5rem;
|
|
405
|
+
if (!fs.existsSync(utilsPath)) {
|
|
406
|
+
await fs.writeFile(utilsPath, utilsContent);
|
|
407
|
+
console.log(chalk.gray("Created lib/utils.ts"));
|
|
190
408
|
}
|
|
409
|
+
const providersPath = path.join(process.cwd(), "components/providers.tsx");
|
|
410
|
+
const providersContent = `'use client';
|
|
191
411
|
|
|
192
|
-
|
|
193
|
-
--background: 222.2 84% 4.9%;
|
|
194
|
-
--foreground: 210 40% 98%;
|
|
195
|
-
--card: 222.2 84% 4.9%;
|
|
196
|
-
--card-foreground: 210 40% 98%;
|
|
197
|
-
--popover: 222.2 84% 4.9%;
|
|
198
|
-
--popover-foreground: 210 40% 98%;
|
|
199
|
-
--primary: 210 40% 98%;
|
|
200
|
-
--primary-foreground: 222.2 47.4% 11.2%;
|
|
201
|
-
--secondary: 217.2 32.6% 17.5%;
|
|
202
|
-
--secondary-foreground: 210 40% 98%;
|
|
203
|
-
--muted: 217.2 32.6% 17.5%;
|
|
204
|
-
--muted-foreground: 215 20.2% 65.1%;
|
|
205
|
-
--accent: 217.2 32.6% 17.5%;
|
|
206
|
-
--accent-foreground: 210 40% 98%;
|
|
207
|
-
--destructive: 0 62.8% 30.6%;
|
|
208
|
-
--destructive-foreground: 210 40% 98%;
|
|
209
|
-
--border: 217.2 32.6% 17.5%;
|
|
210
|
-
--input: 217.2 32.6% 17.5%;
|
|
211
|
-
--ring: 212.7 26.8% 83.9%;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
412
|
+
import { ThemeProvider } from 'next-themes';
|
|
214
413
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
414
|
+
export function Providers({ children }: { children: React.ReactNode }) {
|
|
415
|
+
return (
|
|
416
|
+
<ThemeProvider attribute="class" defaultTheme="system" enableSystem>
|
|
417
|
+
{children}
|
|
418
|
+
</ThemeProvider>
|
|
419
|
+
);
|
|
219
420
|
}
|
|
220
421
|
`;
|
|
221
|
-
if (fs.existsSync(
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
await fs.writeFile(globalsCssPath, globalsCssContent);
|
|
225
|
-
}
|
|
226
|
-
} else if (fs.existsSync(srcGlobalsCssPath)) {
|
|
227
|
-
const existing = await fs.readFile(srcGlobalsCssPath, "utf-8");
|
|
228
|
-
if (!existing.includes("--background")) {
|
|
229
|
-
await fs.writeFile(srcGlobalsCssPath, globalsCssContent);
|
|
230
|
-
}
|
|
231
|
-
} else {
|
|
232
|
-
await fs.ensureDir(path.join(process.cwd(), "app"));
|
|
233
|
-
await fs.writeFile(globalsCssPath, globalsCssContent);
|
|
422
|
+
if (!fs.existsSync(providersPath)) {
|
|
423
|
+
await fs.writeFile(providersPath, providersContent);
|
|
424
|
+
console.log(chalk.gray("Created components/providers.tsx"));
|
|
234
425
|
}
|
|
235
426
|
console.log(chalk.green("\u2705 Example files created"));
|
|
236
427
|
}
|
|
@@ -253,433 +444,487 @@ async function updatePackageScripts() {
|
|
|
253
444
|
|
|
254
445
|
// src/commands/list.ts
|
|
255
446
|
import { Command as Command2 } from "commander";
|
|
447
|
+
import chalk3 from "chalk";
|
|
448
|
+
|
|
449
|
+
// src/lib/registry.ts
|
|
450
|
+
import fs2 from "fs-extra";
|
|
451
|
+
import path2 from "path";
|
|
452
|
+
import os from "os";
|
|
256
453
|
import chalk2 from "chalk";
|
|
257
|
-
|
|
454
|
+
var DEFAULT_CONFIG = {
|
|
455
|
+
registryUrl: process.env.FOUNDRYKIT_REGISTRY_URL || "https://foundry.umiflow.com",
|
|
456
|
+
cacheDir: path2.join(os.homedir(), ".foundrykit", "cache"),
|
|
457
|
+
cacheMaxAge: 1e3 * 60 * 60 * 24
|
|
458
|
+
// 24 hours
|
|
459
|
+
};
|
|
460
|
+
var RegistryService = class {
|
|
461
|
+
config;
|
|
462
|
+
cacheFile;
|
|
463
|
+
constructor(config) {
|
|
464
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
465
|
+
this.cacheFile = path2.join(this.config.cacheDir, "registry.json");
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Fetch all components from the registry
|
|
469
|
+
*/
|
|
470
|
+
async getComponents(category, search) {
|
|
471
|
+
try {
|
|
472
|
+
const params = new URLSearchParams();
|
|
473
|
+
if (category) params.append("category", category);
|
|
474
|
+
if (search) params.append("search", search);
|
|
475
|
+
const url = `${this.config.registryUrl}/registry${params.toString() ? "?" + params.toString() : ""}`;
|
|
476
|
+
console.log(chalk2.gray(`Fetching from: ${url}`));
|
|
477
|
+
const response = await fetch(url);
|
|
478
|
+
if (!response.ok) {
|
|
479
|
+
throw new Error(
|
|
480
|
+
`Registry returned ${response.status}: ${response.statusText}`
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
const components = await response.json();
|
|
484
|
+
await this.updateCache(components);
|
|
485
|
+
return components;
|
|
486
|
+
} catch (error) {
|
|
487
|
+
const cache = await this.loadCache();
|
|
488
|
+
if (cache && this.isCacheValid(cache)) {
|
|
489
|
+
console.log(chalk2.yellow("Using cached registry data"));
|
|
490
|
+
return this.filterComponents(cache.components, category, search);
|
|
491
|
+
}
|
|
492
|
+
throw new Error(
|
|
493
|
+
`Failed to connect to registry: ${error instanceof Error ? error.message : "Unknown error"}
|
|
494
|
+
Registry URL: ${this.config.registryUrl}
|
|
495
|
+
Try again later or check your internet connection.`
|
|
496
|
+
);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Fetch a specific component by ID
|
|
501
|
+
*/
|
|
502
|
+
async getComponent(id) {
|
|
503
|
+
try {
|
|
504
|
+
const url = `${this.config.registryUrl}/registry/${id}`;
|
|
505
|
+
console.log(chalk2.gray(`Fetching component: ${url}`));
|
|
506
|
+
const response = await fetch(url);
|
|
507
|
+
if (!response.ok) {
|
|
508
|
+
if (response.status === 404) {
|
|
509
|
+
throw new Error(`Component "${id}" not found in registry`);
|
|
510
|
+
}
|
|
511
|
+
throw new Error(
|
|
512
|
+
`Registry returned ${response.status}: ${response.statusText}`
|
|
513
|
+
);
|
|
514
|
+
}
|
|
515
|
+
const component = await response.json();
|
|
516
|
+
await this.cacheComponent(component);
|
|
517
|
+
return component;
|
|
518
|
+
} catch (error) {
|
|
519
|
+
const cache = await this.loadCache();
|
|
520
|
+
if (cache?.componentData?.[id]) {
|
|
521
|
+
console.log(chalk2.yellow(`Using cached data for component: ${id}`));
|
|
522
|
+
return cache.componentData[id];
|
|
523
|
+
}
|
|
524
|
+
throw new Error(
|
|
525
|
+
`Failed to fetch component "${id}": ${error instanceof Error ? error.message : "Unknown error"}
|
|
526
|
+
Registry URL: ${this.config.registryUrl}
|
|
527
|
+
Try again later or check your internet connection.`
|
|
528
|
+
);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Update the local cache with new component list
|
|
533
|
+
*/
|
|
534
|
+
async updateCache(components) {
|
|
535
|
+
try {
|
|
536
|
+
const cache = await this.loadCache();
|
|
537
|
+
const newCache = {
|
|
538
|
+
version: "1.0.0",
|
|
539
|
+
lastUpdated: (/* @__PURE__ */ new Date()).toISOString(),
|
|
540
|
+
components,
|
|
541
|
+
componentData: cache?.componentData || {}
|
|
542
|
+
};
|
|
543
|
+
await fs2.ensureDir(this.config.cacheDir);
|
|
544
|
+
await fs2.writeJson(this.cacheFile, newCache, { spaces: 2 });
|
|
545
|
+
} catch (error) {
|
|
546
|
+
console.log(chalk2.gray("Failed to update cache"));
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Cache a specific component
|
|
551
|
+
*/
|
|
552
|
+
async cacheComponent(component) {
|
|
553
|
+
try {
|
|
554
|
+
const cache = await this.loadCache();
|
|
555
|
+
if (!cache) return;
|
|
556
|
+
cache.componentData[component.id] = component;
|
|
557
|
+
cache.lastUpdated = (/* @__PURE__ */ new Date()).toISOString();
|
|
558
|
+
await fs2.writeJson(this.cacheFile, cache, { spaces: 2 });
|
|
559
|
+
} catch (error) {
|
|
560
|
+
console.log(chalk2.gray("Failed to cache component"));
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* Load the local cache
|
|
565
|
+
*/
|
|
566
|
+
async loadCache() {
|
|
567
|
+
try {
|
|
568
|
+
if (await fs2.pathExists(this.cacheFile)) {
|
|
569
|
+
return await fs2.readJson(this.cacheFile);
|
|
570
|
+
}
|
|
571
|
+
} catch (error) {
|
|
572
|
+
console.log(chalk2.gray("Failed to load cache"));
|
|
573
|
+
}
|
|
574
|
+
return null;
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* Check if cache is still valid
|
|
578
|
+
*/
|
|
579
|
+
isCacheValid(cache) {
|
|
580
|
+
const lastUpdated = new Date(cache.lastUpdated).getTime();
|
|
581
|
+
const now = Date.now();
|
|
582
|
+
return now - lastUpdated < this.config.cacheMaxAge;
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* Filter components by category and search
|
|
586
|
+
*/
|
|
587
|
+
filterComponents(components, category, search) {
|
|
588
|
+
let filtered = components;
|
|
589
|
+
if (category) {
|
|
590
|
+
filtered = filtered.filter((c) => c.category === category);
|
|
591
|
+
}
|
|
592
|
+
if (search) {
|
|
593
|
+
const searchLower = search.toLowerCase();
|
|
594
|
+
filtered = filtered.filter(
|
|
595
|
+
(c) => c.name.toLowerCase().includes(searchLower) || c.description.toLowerCase().includes(searchLower) || c.id.toLowerCase().includes(searchLower) || c.tags?.some((tag) => tag.toLowerCase().includes(searchLower))
|
|
596
|
+
);
|
|
597
|
+
}
|
|
598
|
+
return filtered;
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Clear the local cache
|
|
602
|
+
*/
|
|
603
|
+
async clearCache() {
|
|
604
|
+
try {
|
|
605
|
+
if (await fs2.pathExists(this.cacheFile)) {
|
|
606
|
+
await fs2.remove(this.cacheFile);
|
|
607
|
+
console.log(chalk2.green("Cache cleared successfully"));
|
|
608
|
+
}
|
|
609
|
+
} catch (error) {
|
|
610
|
+
throw new Error(
|
|
611
|
+
`Failed to clear cache: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
612
|
+
);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* Get cache statistics
|
|
617
|
+
*/
|
|
618
|
+
async getCacheStats() {
|
|
619
|
+
try {
|
|
620
|
+
if (await fs2.pathExists(this.cacheFile)) {
|
|
621
|
+
const cache = await this.loadCache();
|
|
622
|
+
const stats = await fs2.stat(this.cacheFile);
|
|
623
|
+
return {
|
|
624
|
+
exists: true,
|
|
625
|
+
size: stats.size,
|
|
626
|
+
lastUpdated: cache?.lastUpdated || null,
|
|
627
|
+
componentCount: cache?.components.length || 0
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
} catch (error) {
|
|
631
|
+
}
|
|
632
|
+
return {
|
|
633
|
+
exists: false,
|
|
634
|
+
size: 0,
|
|
635
|
+
lastUpdated: null,
|
|
636
|
+
componentCount: 0
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
var registryInstance = null;
|
|
641
|
+
function getRegistry(config) {
|
|
642
|
+
if (!registryInstance) {
|
|
643
|
+
registryInstance = new RegistryService(config);
|
|
644
|
+
}
|
|
645
|
+
return registryInstance;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
// src/commands/list.ts
|
|
258
649
|
function listCommand() {
|
|
259
650
|
return new Command2("list").description("List all available FoundryKit components and blocks").option(
|
|
260
651
|
"-c, --category <category>",
|
|
261
|
-
"filter by category (primitives, components, blocks)"
|
|
652
|
+
"filter by category (primitives, components, blocks, animations)"
|
|
262
653
|
).option("-s, --search <term>", "search components by name or description").action(async (options) => {
|
|
263
654
|
try {
|
|
264
|
-
console.log(
|
|
265
|
-
const registry =
|
|
266
|
-
let categories = [
|
|
267
|
-
"primitives",
|
|
268
|
-
"components",
|
|
269
|
-
"blocks"
|
|
270
|
-
];
|
|
655
|
+
console.log(chalk3.blue("\u{1F4E6} Available FoundryKit components:"));
|
|
656
|
+
const registry = getRegistry();
|
|
271
657
|
if (options.category) {
|
|
272
|
-
|
|
273
|
-
|
|
658
|
+
const validCategories = [
|
|
659
|
+
"primitives",
|
|
660
|
+
"components",
|
|
661
|
+
"blocks",
|
|
662
|
+
"animations"
|
|
663
|
+
];
|
|
664
|
+
if (!validCategories.includes(options.category)) {
|
|
665
|
+
console.error(chalk3.red(`Invalid category: ${options.category}`));
|
|
274
666
|
console.log(
|
|
275
|
-
|
|
667
|
+
chalk3.gray(`Valid categories: ${validCategories.join(", ")}`)
|
|
276
668
|
);
|
|
277
|
-
|
|
669
|
+
process.exit(1);
|
|
278
670
|
}
|
|
279
|
-
categories = [
|
|
280
|
-
options.category
|
|
281
|
-
];
|
|
282
671
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
console.log(
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
console.log(
|
|
294
|
-
console.log(` ${chalk2.gray(item.description)}`);
|
|
295
|
-
if (item.tags && item.tags.length > 0) {
|
|
296
|
-
console.log(
|
|
297
|
-
` ${chalk2.blue(item.tags.map((tag) => `#${tag}`).join(" "))}`
|
|
298
|
-
);
|
|
299
|
-
}
|
|
300
|
-
console.log();
|
|
672
|
+
console.log(chalk3.gray("Fetching from registry..."));
|
|
673
|
+
const components = await registry.getComponents(
|
|
674
|
+
options.category,
|
|
675
|
+
options.search
|
|
676
|
+
);
|
|
677
|
+
if (components.length === 0) {
|
|
678
|
+
console.log(
|
|
679
|
+
chalk3.yellow("\nNo components found matching your criteria.")
|
|
680
|
+
);
|
|
681
|
+
if (options.search) {
|
|
682
|
+
console.log(chalk3.gray(`Search term: "${options.search}"`));
|
|
301
683
|
}
|
|
684
|
+
if (options.category) {
|
|
685
|
+
console.log(chalk3.gray(`Category: ${options.category}`));
|
|
686
|
+
}
|
|
687
|
+
return;
|
|
302
688
|
}
|
|
303
|
-
|
|
304
|
-
console.log(
|
|
305
|
-
console.log(
|
|
689
|
+
displayComponents(components);
|
|
690
|
+
console.log(chalk3.cyan("\n\u{1F4A1} Usage:"));
|
|
691
|
+
console.log(
|
|
692
|
+
chalk3.gray(" foundrykit add # Interactive mode")
|
|
693
|
+
);
|
|
694
|
+
console.log(
|
|
695
|
+
chalk3.gray(" foundrykit add <id> # Add specific component")
|
|
696
|
+
);
|
|
697
|
+
console.log(chalk3.gray(" foundrykit add button # Example"));
|
|
306
698
|
} catch (error) {
|
|
307
|
-
console.error(
|
|
699
|
+
console.error(chalk3.red("\u274C Failed to fetch component registry:"));
|
|
308
700
|
console.error(
|
|
309
|
-
|
|
701
|
+
chalk3.red(error instanceof Error ? error.message : String(error))
|
|
310
702
|
);
|
|
311
|
-
|
|
312
|
-
displayLocalRegistry(options);
|
|
703
|
+
process.exit(1);
|
|
313
704
|
}
|
|
314
705
|
});
|
|
315
706
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
return data;
|
|
322
|
-
}
|
|
323
|
-
} catch (error) {
|
|
324
|
-
}
|
|
325
|
-
return getLocalRegistry();
|
|
326
|
-
}
|
|
327
|
-
function getLocalRegistry() {
|
|
328
|
-
return {
|
|
329
|
-
primitives: [
|
|
330
|
-
{
|
|
331
|
-
name: "button",
|
|
332
|
-
description: "Displays a button or a component that looks like a button.",
|
|
333
|
-
category: "primitives",
|
|
334
|
-
tags: ["form", "interactive"]
|
|
335
|
-
},
|
|
336
|
-
{
|
|
337
|
-
name: "input",
|
|
338
|
-
description: "Displays a form input field or a component that looks like an input.",
|
|
339
|
-
category: "primitives",
|
|
340
|
-
tags: ["form"]
|
|
341
|
-
},
|
|
342
|
-
{
|
|
343
|
-
name: "badge",
|
|
344
|
-
description: "Displays a badge or a component that looks like a badge.",
|
|
345
|
-
category: "primitives",
|
|
346
|
-
tags: ["status", "label"]
|
|
347
|
-
},
|
|
348
|
-
{
|
|
349
|
-
name: "card",
|
|
350
|
-
description: "Displays a card with header, content, and footer.",
|
|
351
|
-
category: "primitives",
|
|
352
|
-
tags: ["layout", "container"]
|
|
353
|
-
},
|
|
354
|
-
{
|
|
355
|
-
name: "avatar",
|
|
356
|
-
description: "An image element with a fallback for representing the user.",
|
|
357
|
-
category: "primitives",
|
|
358
|
-
tags: ["user", "profile"]
|
|
359
|
-
}
|
|
360
|
-
],
|
|
361
|
-
components: [
|
|
362
|
-
{
|
|
363
|
-
name: "search-bar",
|
|
364
|
-
description: "A search input with suggestions and keyboard navigation.",
|
|
365
|
-
category: "components",
|
|
366
|
-
dependencies: ["input", "popover"],
|
|
367
|
-
tags: ["search", "form"]
|
|
368
|
-
},
|
|
369
|
-
{
|
|
370
|
-
name: "combobox",
|
|
371
|
-
description: "Combines a text input with a listbox, allowing users to filter a list.",
|
|
372
|
-
category: "components",
|
|
373
|
-
dependencies: ["input", "popover", "command"],
|
|
374
|
-
tags: ["form", "selection"]
|
|
375
|
-
},
|
|
376
|
-
{
|
|
377
|
-
name: "date-picker",
|
|
378
|
-
description: "A date picker component with calendar popup.",
|
|
379
|
-
category: "components",
|
|
380
|
-
dependencies: ["input", "popover", "calendar"],
|
|
381
|
-
tags: ["form", "date"]
|
|
382
|
-
}
|
|
383
|
-
],
|
|
384
|
-
blocks: [
|
|
385
|
-
{
|
|
386
|
-
name: "hero-minimal",
|
|
387
|
-
description: "A minimal hero section with heading, description, and CTA button.",
|
|
388
|
-
category: "blocks",
|
|
389
|
-
dependencies: ["button"],
|
|
390
|
-
tags: ["landing", "marketing"]
|
|
391
|
-
},
|
|
392
|
-
{
|
|
393
|
-
name: "hero-with-image",
|
|
394
|
-
description: "A hero section with background image and content overlay.",
|
|
395
|
-
category: "blocks",
|
|
396
|
-
dependencies: ["button"],
|
|
397
|
-
tags: ["landing", "marketing", "image"]
|
|
398
|
-
},
|
|
399
|
-
{
|
|
400
|
-
name: "pricing",
|
|
401
|
-
description: "A pricing section with multiple tiers and feature comparison.",
|
|
402
|
-
category: "blocks",
|
|
403
|
-
dependencies: ["card", "button", "badge"],
|
|
404
|
-
tags: ["pricing", "marketing"]
|
|
405
|
-
},
|
|
406
|
-
{
|
|
407
|
-
name: "testimonials",
|
|
408
|
-
description: "A testimonials section with customer quotes and avatars.",
|
|
409
|
-
category: "blocks",
|
|
410
|
-
dependencies: ["avatar", "card"],
|
|
411
|
-
tags: ["social-proof", "marketing"]
|
|
707
|
+
function displayComponents(components) {
|
|
708
|
+
const grouped = components.reduce(
|
|
709
|
+
(acc, component) => {
|
|
710
|
+
if (!acc[component.category]) {
|
|
711
|
+
acc[component.category] = [];
|
|
412
712
|
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
713
|
+
acc[component.category].push(component);
|
|
714
|
+
return acc;
|
|
715
|
+
},
|
|
716
|
+
{}
|
|
717
|
+
);
|
|
718
|
+
const categoryOrder = [
|
|
419
719
|
"primitives",
|
|
420
720
|
"components",
|
|
421
|
-
"blocks"
|
|
721
|
+
"blocks",
|
|
722
|
+
"animations"
|
|
422
723
|
];
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
for (const category of categories) {
|
|
427
|
-
const items = registry[category];
|
|
428
|
-
const filteredItems = options.search ? items.filter(
|
|
429
|
-
(item) => item.name.toLowerCase().includes(options.search.toLowerCase()) || item.description.toLowerCase().includes(options.search.toLowerCase())
|
|
430
|
-
) : items;
|
|
431
|
-
if (filteredItems.length === 0) continue;
|
|
724
|
+
for (const category of categoryOrder) {
|
|
725
|
+
const items = grouped[category];
|
|
726
|
+
if (!items || items.length === 0) continue;
|
|
432
727
|
console.log(`
|
|
433
|
-
${
|
|
434
|
-
console.log(
|
|
435
|
-
for (const item of
|
|
436
|
-
console.log(
|
|
437
|
-
|
|
728
|
+
${chalk3.cyan.bold(category.toUpperCase())}`);
|
|
729
|
+
console.log(chalk3.gray("\u2500".repeat(40)));
|
|
730
|
+
for (const item of items) {
|
|
731
|
+
console.log(
|
|
732
|
+
`${chalk3.green("\u25CF")} ${chalk3.bold(item.name)} ${chalk3.gray(
|
|
733
|
+
`(${item.id})`
|
|
734
|
+
)}`
|
|
735
|
+
);
|
|
736
|
+
console.log(` ${chalk3.gray(item.description)}`);
|
|
438
737
|
if (item.tags && item.tags.length > 0) {
|
|
439
738
|
console.log(
|
|
440
|
-
` ${
|
|
739
|
+
` ${chalk3.blue(item.tags.map((tag) => `#${tag}`).join(" "))}`
|
|
740
|
+
);
|
|
741
|
+
}
|
|
742
|
+
if (item.registryDependencies && item.registryDependencies.length > 0) {
|
|
743
|
+
console.log(
|
|
744
|
+
` ${chalk3.yellow("Requires:")} ${item.registryDependencies.join(
|
|
745
|
+
", "
|
|
746
|
+
)}`
|
|
747
|
+
);
|
|
748
|
+
}
|
|
749
|
+
if (item.packageDependencies && item.packageDependencies.length > 0) {
|
|
750
|
+
console.log(
|
|
751
|
+
` ${chalk3.magenta("NPM packages:")} ${item.packageDependencies.join(
|
|
752
|
+
", "
|
|
753
|
+
)}`
|
|
441
754
|
);
|
|
442
755
|
}
|
|
443
756
|
console.log();
|
|
444
757
|
}
|
|
445
758
|
}
|
|
759
|
+
const total = components.length;
|
|
760
|
+
const byCategory = Object.entries(grouped).map(([cat, items]) => `${items.length} ${cat}`).join(", ");
|
|
761
|
+
console.log(chalk3.gray("\u2500".repeat(40)));
|
|
762
|
+
console.log(chalk3.gray(`Total: ${total} components (${byCategory})`));
|
|
446
763
|
}
|
|
447
764
|
|
|
448
765
|
// src/commands/add.ts
|
|
449
766
|
import { Command as Command3 } from "commander";
|
|
450
|
-
import
|
|
451
|
-
import
|
|
452
|
-
import
|
|
453
|
-
import fetch2 from "node-fetch";
|
|
767
|
+
import chalk4 from "chalk";
|
|
768
|
+
import fs3 from "fs-extra";
|
|
769
|
+
import path3 from "path";
|
|
454
770
|
import inquirer2 from "inquirer";
|
|
455
771
|
function addCommand() {
|
|
456
|
-
return new Command3("add").description("Add a component or block to your project").argument("
|
|
772
|
+
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) => {
|
|
457
773
|
try {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
console.error(chalk3.red(`\u274C Component "${id}" not found.`));
|
|
463
|
-
console.log(
|
|
464
|
-
chalk3.gray('\nUse "foundrykit list" to see available components.')
|
|
465
|
-
);
|
|
466
|
-
return;
|
|
467
|
-
}
|
|
468
|
-
if (!options.force && await hasConflictingFiles(componentData, options)) {
|
|
469
|
-
const { shouldContinue } = await inquirer2.prompt([
|
|
470
|
-
{
|
|
471
|
-
type: "confirm",
|
|
472
|
-
name: "shouldContinue",
|
|
473
|
-
message: "Some files already exist. Continue and overwrite?",
|
|
474
|
-
default: false
|
|
475
|
-
}
|
|
476
|
-
]);
|
|
477
|
-
if (!shouldContinue) {
|
|
478
|
-
console.log(chalk3.yellow("\u274C Installation cancelled."));
|
|
774
|
+
if (!id) {
|
|
775
|
+
const selectedIds = await selectComponentsInteractively();
|
|
776
|
+
if (selectedIds.length === 0) {
|
|
777
|
+
console.log(chalk4.yellow("No components selected."));
|
|
479
778
|
return;
|
|
480
779
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
console.log(chalk3.blue("\u{1F4E6} Installing required components..."));
|
|
484
|
-
for (const dep of componentData.registryDependencies) {
|
|
485
|
-
await addComponent(dep, { ...options, force: true });
|
|
780
|
+
for (const componentId of selectedIds) {
|
|
781
|
+
await addSingleComponent(componentId, options);
|
|
486
782
|
}
|
|
783
|
+
} else {
|
|
784
|
+
await addSingleComponent(id, options);
|
|
487
785
|
}
|
|
488
|
-
await installComponentFiles(componentData, options);
|
|
489
|
-
await updateImports(componentData);
|
|
490
|
-
console.log(
|
|
491
|
-
chalk3.green(`
|
|
492
|
-
\u2705 ${componentData.name} added successfully!`)
|
|
493
|
-
);
|
|
494
|
-
showUsageExample(componentData);
|
|
495
786
|
} catch (error) {
|
|
496
|
-
console.error(
|
|
787
|
+
console.error(chalk4.red("\u274C Failed to add component:"));
|
|
497
788
|
console.error(
|
|
498
|
-
|
|
789
|
+
chalk4.red(error instanceof Error ? error.message : String(error))
|
|
499
790
|
);
|
|
500
791
|
process.exit(1);
|
|
501
792
|
}
|
|
502
793
|
});
|
|
503
794
|
}
|
|
504
|
-
async function
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
const
|
|
511
|
-
const config = await fs2.readFile(configPath, "utf-8");
|
|
512
|
-
if (!config.includes("@foundrykit/tailwind-config")) {
|
|
513
|
-
throw new Error(
|
|
514
|
-
'FoundryKit not properly configured. Run "foundrykit init" first.'
|
|
515
|
-
);
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
async function getComponentData(id) {
|
|
795
|
+
async function selectComponentsInteractively() {
|
|
796
|
+
console.log(chalk4.blue("\u{1F4E6} Select components to add:"));
|
|
797
|
+
console.log(
|
|
798
|
+
chalk4.gray(" Use arrow keys to navigate, space to select, a to toggle all")
|
|
799
|
+
);
|
|
800
|
+
console.log(chalk4.gray(" Press enter when done\n"));
|
|
801
|
+
const registry = getRegistry();
|
|
519
802
|
try {
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
803
|
+
console.log(chalk4.gray("Fetching components from registry..."));
|
|
804
|
+
const allComponents = await registry.getComponents();
|
|
805
|
+
if (allComponents.length === 0) {
|
|
806
|
+
console.log(chalk4.yellow("No components available in the registry."));
|
|
807
|
+
return [];
|
|
524
808
|
}
|
|
809
|
+
const groupedChoices = createGroupedChoices(allComponents);
|
|
810
|
+
const { selectedComponents } = await inquirer2.prompt([
|
|
811
|
+
{
|
|
812
|
+
type: "checkbox",
|
|
813
|
+
name: "selectedComponents",
|
|
814
|
+
message: "Which components would you like to add?",
|
|
815
|
+
choices: groupedChoices,
|
|
816
|
+
pageSize: 20,
|
|
817
|
+
loop: false
|
|
818
|
+
}
|
|
819
|
+
]);
|
|
820
|
+
return selectedComponents;
|
|
525
821
|
} catch (error) {
|
|
822
|
+
console.error(chalk4.red("Failed to fetch components from registry:"));
|
|
823
|
+
console.error(
|
|
824
|
+
chalk4.red(error instanceof Error ? error.message : String(error))
|
|
825
|
+
);
|
|
826
|
+
throw error;
|
|
526
827
|
}
|
|
527
|
-
return getLocalComponentData(id);
|
|
528
828
|
}
|
|
529
|
-
function
|
|
530
|
-
const
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
const
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
destructive:
|
|
553
|
-
"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
|
|
554
|
-
outline:
|
|
555
|
-
"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
|
|
556
|
-
secondary:
|
|
557
|
-
"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
|
|
558
|
-
ghost: "hover:bg-accent hover:text-accent-foreground",
|
|
559
|
-
link: "text-primary underline-offset-4 hover:underline",
|
|
560
|
-
},
|
|
561
|
-
size: {
|
|
562
|
-
default: "h-9 px-4 py-2",
|
|
563
|
-
sm: "h-8 rounded-md px-3 text-xs",
|
|
564
|
-
lg: "h-10 rounded-md px-8",
|
|
565
|
-
icon: "h-9 w-9",
|
|
566
|
-
},
|
|
567
|
-
},
|
|
568
|
-
defaultVariants: {
|
|
569
|
-
variant: "default",
|
|
570
|
-
size: "default",
|
|
571
|
-
},
|
|
829
|
+
function createGroupedChoices(components) {
|
|
830
|
+
const categories = [
|
|
831
|
+
"primitives",
|
|
832
|
+
"components",
|
|
833
|
+
"blocks",
|
|
834
|
+
"animations"
|
|
835
|
+
];
|
|
836
|
+
const choices = [];
|
|
837
|
+
for (const category of categories) {
|
|
838
|
+
const categoryComponents = components.filter((c) => c.category === category);
|
|
839
|
+
if (categoryComponents.length === 0) continue;
|
|
840
|
+
choices.push({
|
|
841
|
+
name: chalk4.bold.cyan(`\u2500\u2500\u2500 ${category.toUpperCase()} \u2500\u2500\u2500`),
|
|
842
|
+
disabled: true,
|
|
843
|
+
value: `separator-${category}`
|
|
844
|
+
});
|
|
845
|
+
for (const component of categoryComponents) {
|
|
846
|
+
choices.push({
|
|
847
|
+
name: `${component.name} - ${chalk4.gray(component.description)}`,
|
|
848
|
+
value: component.id,
|
|
849
|
+
short: component.name
|
|
850
|
+
});
|
|
851
|
+
}
|
|
572
852
|
}
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
export interface ButtonProps
|
|
576
|
-
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
|
577
|
-
VariantProps<typeof buttonVariants> {
|
|
578
|
-
asChild?: boolean
|
|
853
|
+
return choices;
|
|
579
854
|
}
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
/>
|
|
590
|
-
)
|
|
591
|
-
}
|
|
592
|
-
)
|
|
593
|
-
Button.displayName = "Button"
|
|
594
|
-
|
|
595
|
-
export { Button, buttonVariants }
|
|
596
|
-
`
|
|
597
|
-
}
|
|
598
|
-
]
|
|
599
|
-
},
|
|
600
|
-
input: {
|
|
601
|
-
name: "Input",
|
|
602
|
-
category: "primitives",
|
|
603
|
-
description: "A form input component.",
|
|
604
|
-
files: [
|
|
855
|
+
async function addSingleComponent(id, options) {
|
|
856
|
+
console.log(chalk4.blue(`
|
|
857
|
+
\u{1F4E6} Adding ${id} to your project...`));
|
|
858
|
+
await validateProject();
|
|
859
|
+
const registry = getRegistry();
|
|
860
|
+
try {
|
|
861
|
+
const componentData = await registry.getComponent(id);
|
|
862
|
+
if (!options.overwrite && await hasConflictingFiles(componentData, options)) {
|
|
863
|
+
const { shouldContinue } = await inquirer2.prompt([
|
|
605
864
|
{
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
import { cn } from "@/lib/utils"
|
|
611
|
-
|
|
612
|
-
export interface InputProps
|
|
613
|
-
extends React.InputHTMLAttributes<HTMLInputElement> {}
|
|
614
|
-
|
|
615
|
-
const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
|
616
|
-
({ className, type, ...props }, ref) => {
|
|
617
|
-
return (
|
|
618
|
-
<input
|
|
619
|
-
type={type}
|
|
620
|
-
className={cn(
|
|
621
|
-
"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",
|
|
622
|
-
className
|
|
623
|
-
)}
|
|
624
|
-
ref={ref}
|
|
625
|
-
{...props}
|
|
626
|
-
/>
|
|
627
|
-
)
|
|
628
|
-
}
|
|
629
|
-
)
|
|
630
|
-
Input.displayName = "Input"
|
|
631
|
-
|
|
632
|
-
export { Input }
|
|
633
|
-
`
|
|
865
|
+
type: "confirm",
|
|
866
|
+
name: "shouldContinue",
|
|
867
|
+
message: `Some files for ${componentData.name} already exist. Overwrite?`,
|
|
868
|
+
default: false
|
|
634
869
|
}
|
|
635
|
-
]
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
export function HeroMinimal() {
|
|
649
|
-
return (
|
|
650
|
-
<section className="w-full py-12 md:py-24 lg:py-32">
|
|
651
|
-
<div className="container px-4 md:px-6">
|
|
652
|
-
<div className="flex flex-col items-center space-y-4 text-center">
|
|
653
|
-
<div className="space-y-2">
|
|
654
|
-
<h1 className="text-3xl font-bold tracking-tighter sm:text-4xl md:text-5xl lg:text-6xl/none">
|
|
655
|
-
Welcome to FoundryKit
|
|
656
|
-
</h1>
|
|
657
|
-
<p className="mx-auto max-w-[700px] text-gray-500 md:text-xl dark:text-gray-400">
|
|
658
|
-
Build beautiful, accessible React components with our comprehensive design system.
|
|
659
|
-
Fast, flexible, and ready for production.
|
|
660
|
-
</p>
|
|
661
|
-
</div>
|
|
662
|
-
<div className="space-x-4">
|
|
663
|
-
<Button>Get Started</Button>
|
|
664
|
-
<Button variant="outline">Learn More</Button>
|
|
665
|
-
</div>
|
|
666
|
-
</div>
|
|
667
|
-
</div>
|
|
668
|
-
</section>
|
|
669
|
-
)
|
|
670
|
-
}
|
|
671
|
-
`
|
|
870
|
+
]);
|
|
871
|
+
if (!shouldContinue) {
|
|
872
|
+
console.log(chalk4.yellow(`\u23ED\uFE0F Skipping ${componentData.name}.`));
|
|
873
|
+
return;
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
if (componentData.registryDependencies?.length) {
|
|
877
|
+
console.log(chalk4.blue("\u{1F4E6} Installing required dependencies..."));
|
|
878
|
+
for (const dep of componentData.registryDependencies) {
|
|
879
|
+
const depData = await registry.getComponent(dep);
|
|
880
|
+
if (!await hasConflictingFiles(depData, options)) {
|
|
881
|
+
await installComponentFiles(depData, options);
|
|
882
|
+
console.log(chalk4.green(` \u2713 Installed ${dep}`));
|
|
672
883
|
}
|
|
673
|
-
|
|
884
|
+
}
|
|
674
885
|
}
|
|
886
|
+
await installComponentFiles(componentData, options);
|
|
887
|
+
console.log(chalk4.green(`\u2705 ${componentData.name} added successfully!`));
|
|
888
|
+
showUsageExample(componentData);
|
|
889
|
+
if (componentData.packageDependencies?.length) {
|
|
890
|
+
console.log(chalk4.yellow("\n\u{1F4E6} Required npm packages:"));
|
|
891
|
+
console.log(
|
|
892
|
+
chalk4.gray(` ${componentData.packageDependencies.join(", ")}`)
|
|
893
|
+
);
|
|
894
|
+
console.log(chalk4.gray(" Install them with:"));
|
|
895
|
+
console.log(
|
|
896
|
+
chalk4.cyan(` pnpm add ${componentData.packageDependencies.join(" ")}`)
|
|
897
|
+
);
|
|
898
|
+
}
|
|
899
|
+
} catch (error) {
|
|
900
|
+
console.error(chalk4.red(`Failed to add ${id}:`));
|
|
901
|
+
throw error;
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
async function validateProject() {
|
|
905
|
+
const packageJsonPath = path3.join(process.cwd(), "package.json");
|
|
906
|
+
if (!fs3.existsSync(packageJsonPath)) {
|
|
907
|
+
throw new Error(
|
|
908
|
+
"No package.json found. Please run this command in a project root."
|
|
909
|
+
);
|
|
910
|
+
}
|
|
911
|
+
const packageJson = await fs3.readJson(packageJsonPath);
|
|
912
|
+
const dependencies = {
|
|
913
|
+
...packageJson.dependencies,
|
|
914
|
+
...packageJson.devDependencies
|
|
675
915
|
};
|
|
676
|
-
|
|
916
|
+
const hasFoundryKit = Object.keys(dependencies).some(
|
|
917
|
+
(dep) => dep.startsWith("@foundrykit/")
|
|
918
|
+
);
|
|
919
|
+
if (!hasFoundryKit && !dependencies.next) {
|
|
920
|
+
throw new Error('FoundryKit not initialized. Run "foundrykit init" first.');
|
|
921
|
+
}
|
|
677
922
|
}
|
|
678
923
|
async function hasConflictingFiles(componentData, options) {
|
|
679
924
|
const basePath = options.path || process.cwd();
|
|
680
925
|
for (const file of componentData.files) {
|
|
681
|
-
const filePath =
|
|
682
|
-
if (
|
|
926
|
+
const filePath = path3.join(basePath, file.path);
|
|
927
|
+
if (fs3.existsSync(filePath)) {
|
|
683
928
|
return true;
|
|
684
929
|
}
|
|
685
930
|
}
|
|
@@ -687,65 +932,74 @@ async function hasConflictingFiles(componentData, options) {
|
|
|
687
932
|
}
|
|
688
933
|
async function installComponentFiles(componentData, options) {
|
|
689
934
|
const basePath = options.path || process.cwd();
|
|
690
|
-
console.log(
|
|
935
|
+
console.log(chalk4.blue("\u{1F4DD} Installing component files..."));
|
|
691
936
|
for (const file of componentData.files) {
|
|
692
|
-
const filePath =
|
|
693
|
-
await
|
|
694
|
-
await
|
|
695
|
-
console.log(
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
async function updateImports(componentData) {
|
|
699
|
-
}
|
|
700
|
-
async function addComponent(id, options) {
|
|
701
|
-
const componentData = await getComponentData(id);
|
|
702
|
-
if (!componentData) {
|
|
703
|
-
throw new Error(`Dependency component "${id}" not found.`);
|
|
937
|
+
const filePath = path3.join(basePath, file.path);
|
|
938
|
+
await fs3.ensureDir(path3.dirname(filePath));
|
|
939
|
+
await fs3.writeFile(filePath, file.content);
|
|
940
|
+
console.log(chalk4.green(` \u2713 ${file.path}`));
|
|
704
941
|
}
|
|
705
|
-
await installComponentFiles(componentData, options);
|
|
706
942
|
}
|
|
707
943
|
function showUsageExample(componentData) {
|
|
708
|
-
console.log(
|
|
709
|
-
|
|
944
|
+
console.log(chalk4.cyan("\n\u{1F4A1} Usage:"));
|
|
945
|
+
const componentName = componentData.name.replace(/\s+/g, "");
|
|
946
|
+
if (componentData.category === "primitives" || componentData.category === "components") {
|
|
710
947
|
console.log(
|
|
711
|
-
|
|
712
|
-
`import { ${
|
|
948
|
+
chalk4.gray(
|
|
949
|
+
`import { ${componentName} } from "@/components/ui/${componentData.id}"`
|
|
713
950
|
)
|
|
714
951
|
);
|
|
715
952
|
} else if (componentData.category === "blocks") {
|
|
716
953
|
console.log(
|
|
717
|
-
|
|
718
|
-
`import { ${
|
|
954
|
+
chalk4.gray(
|
|
955
|
+
`import { ${componentName} } from "@/components/blocks/${componentData.id}"`
|
|
956
|
+
)
|
|
957
|
+
);
|
|
958
|
+
} else if (componentData.category === "animations") {
|
|
959
|
+
console.log(
|
|
960
|
+
chalk4.gray(
|
|
961
|
+
`import { ${componentName} } from "@/components/animations/${componentData.id}"`
|
|
719
962
|
)
|
|
720
963
|
);
|
|
721
964
|
}
|
|
722
|
-
if (componentData.
|
|
723
|
-
console.log(
|
|
724
|
-
console.log(
|
|
725
|
-
} else if (componentData.
|
|
726
|
-
console.log(
|
|
727
|
-
} else if (componentData.
|
|
728
|
-
console.log(
|
|
965
|
+
if (componentData.id === "button") {
|
|
966
|
+
console.log(chalk4.gray("\n<Button>Click me</Button>"));
|
|
967
|
+
console.log(chalk4.gray('<Button variant="outline">Outline</Button>'));
|
|
968
|
+
} else if (componentData.id === "input") {
|
|
969
|
+
console.log(chalk4.gray('\n<Input placeholder="Enter text..." />'));
|
|
970
|
+
} else if (componentData.id.includes("hero")) {
|
|
971
|
+
console.log(chalk4.gray(`
|
|
972
|
+
<${componentName} />`));
|
|
973
|
+
} else if (componentData.id === "card") {
|
|
974
|
+
console.log(chalk4.gray("\n<Card>"));
|
|
975
|
+
console.log(chalk4.gray(" <CardHeader>"));
|
|
976
|
+
console.log(chalk4.gray(" <CardTitle>Title</CardTitle>"));
|
|
977
|
+
console.log(
|
|
978
|
+
chalk4.gray(" <CardDescription>Description</CardDescription>")
|
|
979
|
+
);
|
|
980
|
+
console.log(chalk4.gray(" </CardHeader>"));
|
|
981
|
+
console.log(chalk4.gray(" <CardContent>Content</CardContent>"));
|
|
982
|
+
console.log(chalk4.gray("</Card>"));
|
|
729
983
|
}
|
|
730
984
|
}
|
|
731
985
|
|
|
732
986
|
// src/commands/update.ts
|
|
733
987
|
import { Command as Command4 } from "commander";
|
|
734
|
-
import
|
|
988
|
+
import chalk5 from "chalk";
|
|
735
989
|
function updateCommand() {
|
|
736
990
|
return new Command4("update").description("Update an existing component or block").argument("<id>", "Component or block ID").action(async (id) => {
|
|
737
|
-
console.log(
|
|
738
|
-
console.log(
|
|
991
|
+
console.log(chalk5.blue(`\u{1F504} Updating ${id}...`));
|
|
992
|
+
console.log(chalk5.green(`\u2705 ${id} updated successfully!`));
|
|
739
993
|
});
|
|
740
994
|
}
|
|
741
995
|
|
|
742
996
|
// src/commands/doctor.ts
|
|
743
997
|
import { Command as Command5 } from "commander";
|
|
744
|
-
import
|
|
998
|
+
import chalk6 from "chalk";
|
|
745
999
|
function doctorCommand() {
|
|
746
1000
|
return new Command5("doctor").description("Check project health and configuration").action(async () => {
|
|
747
|
-
console.log(
|
|
748
|
-
console.log(
|
|
1001
|
+
console.log(chalk6.blue("\u{1F50D} Checking project health..."));
|
|
1002
|
+
console.log(chalk6.green("\u2705 All checks passed!"));
|
|
749
1003
|
});
|
|
750
1004
|
}
|
|
751
1005
|
|