@foundrykit/cli 1.0.1 ā 1.0.3
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 +12 -0
- package/dist/cli.js +214 -196
- package/dist/cli.js.map +1 -1
- package/dist/index.js +214 -196
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/commands/add.ts +143 -77
- package/src/commands/init.ts +154 -46
- package/src/lib/registry.ts +0 -71
package/src/commands/add.ts
CHANGED
|
@@ -8,6 +8,8 @@ import chalk from 'chalk';
|
|
|
8
8
|
import fs from 'fs-extra';
|
|
9
9
|
import path from 'path';
|
|
10
10
|
import inquirer from 'inquirer';
|
|
11
|
+
import { exec } from 'child_process';
|
|
12
|
+
import { promisify } from 'util';
|
|
11
13
|
import type {
|
|
12
14
|
ComponentMeta,
|
|
13
15
|
ComponentData,
|
|
@@ -15,6 +17,8 @@ import type {
|
|
|
15
17
|
} from '@foundrykit/types';
|
|
16
18
|
import { getRegistry } from '../lib/registry.js';
|
|
17
19
|
|
|
20
|
+
const execAsync = promisify(exec);
|
|
21
|
+
|
|
18
22
|
interface AddOptions {
|
|
19
23
|
withAnimation?: boolean;
|
|
20
24
|
path?: string;
|
|
@@ -183,39 +187,27 @@ async function addSingleComponent(
|
|
|
183
187
|
console.log(chalk.blue('š¦ Installing required dependencies...'));
|
|
184
188
|
for (const dep of componentData.registryDependencies) {
|
|
185
189
|
try {
|
|
186
|
-
//
|
|
187
|
-
if (dep === '
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
190
|
+
// Skip 'primitives' as it's not a single component but a category
|
|
191
|
+
if (dep === 'primitives') {
|
|
192
|
+
console.log(
|
|
193
|
+
chalk.gray(
|
|
194
|
+
` ā Skipping "${dep}" - primitive dependencies will be handled separately`
|
|
195
|
+
)
|
|
192
196
|
);
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
`
|
|
205
|
-
);
|
|
206
|
-
console.log(chalk.green(` ā Created ${dep} file`));
|
|
207
|
-
} else {
|
|
208
|
-
console.log(chalk.gray(` ā ${dep} already exists`));
|
|
209
|
-
}
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Fetch dependency from registry
|
|
201
|
+
const depData = await registry.getComponent(dep);
|
|
202
|
+
|
|
203
|
+
// Check if dependency files already exist
|
|
204
|
+
const hasExisting = await hasConflictingFiles(depData, options);
|
|
205
|
+
|
|
206
|
+
if (!hasExisting) {
|
|
207
|
+
await installComponentFiles(depData, options);
|
|
208
|
+
console.log(chalk.green(` ā Installed ${dep}`));
|
|
210
209
|
} else {
|
|
211
|
-
|
|
212
|
-
const depData = await registry.getComponent(dep);
|
|
213
|
-
if (!(await hasConflictingFiles(depData, options))) {
|
|
214
|
-
await installComponentFiles(depData, options);
|
|
215
|
-
console.log(chalk.green(` ā Installed ${dep}`));
|
|
216
|
-
} else {
|
|
217
|
-
console.log(chalk.gray(` ā ${dep} already exists`));
|
|
218
|
-
}
|
|
210
|
+
console.log(chalk.gray(` ā ${dep} already exists`));
|
|
219
211
|
}
|
|
220
212
|
} catch (error) {
|
|
221
213
|
// If dependency fetch fails, log warning but continue
|
|
@@ -226,32 +218,6 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
226
218
|
}`
|
|
227
219
|
)
|
|
228
220
|
);
|
|
229
|
-
|
|
230
|
-
// For utils specifically, create it if missing
|
|
231
|
-
if (
|
|
232
|
-
dep === 'utils' &&
|
|
233
|
-
error instanceof Error &&
|
|
234
|
-
error.message.includes('not found')
|
|
235
|
-
) {
|
|
236
|
-
const utilsPath = path.join(
|
|
237
|
-
options.path || process.cwd(),
|
|
238
|
-
'lib/utils.ts'
|
|
239
|
-
);
|
|
240
|
-
if (!fs.existsSync(utilsPath)) {
|
|
241
|
-
await fs.ensureDir(path.dirname(utilsPath));
|
|
242
|
-
await fs.writeFile(
|
|
243
|
-
utilsPath,
|
|
244
|
-
`import { type ClassValue, clsx } from "clsx"
|
|
245
|
-
import { twMerge } from "tailwind-merge"
|
|
246
|
-
|
|
247
|
-
export function cn(...inputs: ClassValue[]) {
|
|
248
|
-
return twMerge(clsx(inputs))
|
|
249
|
-
}
|
|
250
|
-
`
|
|
251
|
-
);
|
|
252
|
-
console.log(chalk.green(` ā Created ${dep} file`));
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
221
|
}
|
|
256
222
|
}
|
|
257
223
|
}
|
|
@@ -264,26 +230,8 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
264
230
|
// Show usage example
|
|
265
231
|
showUsageExample(componentData);
|
|
266
232
|
|
|
267
|
-
//
|
|
268
|
-
|
|
269
|
-
console.log(chalk.yellow('\nš¦ Required npm packages:'));
|
|
270
|
-
console.log(
|
|
271
|
-
chalk.gray(` ${componentData.packageDependencies.join(', ')}`)
|
|
272
|
-
);
|
|
273
|
-
console.log(chalk.gray(' Install them with:'));
|
|
274
|
-
console.log(
|
|
275
|
-
chalk.cyan(` pnpm add ${componentData.packageDependencies.join(' ')}`)
|
|
276
|
-
);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
// Additional dependencies for utils
|
|
280
|
-
if (componentData.registryDependencies?.includes('utils')) {
|
|
281
|
-
const utilsDeps = ['clsx', 'tailwind-merge'];
|
|
282
|
-
console.log(chalk.yellow('\nš¦ Required packages for utils:'));
|
|
283
|
-
console.log(chalk.gray(` ${utilsDeps.join(', ')}`));
|
|
284
|
-
console.log(chalk.gray(' Install them with:'));
|
|
285
|
-
console.log(chalk.cyan(` pnpm add ${utilsDeps.join(' ')}`));
|
|
286
|
-
}
|
|
233
|
+
// Handle package dependencies
|
|
234
|
+
await handlePackageDependencies(componentData);
|
|
287
235
|
} catch (error) {
|
|
288
236
|
console.error(chalk.red(`Failed to add ${id}:`));
|
|
289
237
|
throw error;
|
|
@@ -361,6 +309,124 @@ async function installComponentFiles(
|
|
|
361
309
|
}
|
|
362
310
|
}
|
|
363
311
|
|
|
312
|
+
/**
|
|
313
|
+
* Handle package dependencies - check and auto-install if needed
|
|
314
|
+
*/
|
|
315
|
+
async function handlePackageDependencies(
|
|
316
|
+
componentData: ComponentData
|
|
317
|
+
): Promise<void> {
|
|
318
|
+
const allDependencies = new Set<string>();
|
|
319
|
+
|
|
320
|
+
// Add component's package dependencies
|
|
321
|
+
if (componentData.packageDependencies?.length) {
|
|
322
|
+
componentData.packageDependencies.forEach(dep => allDependencies.add(dep));
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// Add utils dependencies if utils is a dependency
|
|
326
|
+
if (componentData.registryDependencies?.includes('utils')) {
|
|
327
|
+
allDependencies.add('clsx');
|
|
328
|
+
allDependencies.add('tailwind-merge');
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// Add primitives dependencies if primitives is a dependency
|
|
332
|
+
if (componentData.registryDependencies?.includes('primitives')) {
|
|
333
|
+
// Common primitives dependencies
|
|
334
|
+
allDependencies.add('@radix-ui/react-slot');
|
|
335
|
+
allDependencies.add('class-variance-authority');
|
|
336
|
+
allDependencies.add('clsx');
|
|
337
|
+
allDependencies.add('tailwind-merge');
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// Add class-variance-authority for button
|
|
341
|
+
if (componentData.id === 'button') {
|
|
342
|
+
allDependencies.add('class-variance-authority');
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// Add lucide-react for components that use icons
|
|
346
|
+
if (componentData.id === 'search-bar') {
|
|
347
|
+
allDependencies.add('lucide-react');
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
if (allDependencies.size === 0) {
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// Check which packages are already installed
|
|
355
|
+
const missingPackages = await getMissingPackages(Array.from(allDependencies));
|
|
356
|
+
|
|
357
|
+
if (missingPackages.length === 0) {
|
|
358
|
+
console.log(chalk.green('ā
All required packages are already installed'));
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
console.log(chalk.yellow('\nš¦ Installing required packages...'));
|
|
363
|
+
console.log(chalk.gray(` ${missingPackages.join(', ')}`));
|
|
364
|
+
|
|
365
|
+
// Try to detect package manager
|
|
366
|
+
const packageManager = await detectPackageManager();
|
|
367
|
+
|
|
368
|
+
try {
|
|
369
|
+
const installCommand = `${packageManager} add ${missingPackages.join(' ')}`;
|
|
370
|
+
console.log(chalk.blue(` Running: ${installCommand}`));
|
|
371
|
+
|
|
372
|
+
const { stdout, stderr } = await execAsync(installCommand);
|
|
373
|
+
|
|
374
|
+
if (stderr && !stderr.includes('warning')) {
|
|
375
|
+
console.error(chalk.yellow(` Warning: ${stderr}`));
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
console.log(chalk.green('ā
Packages installed successfully'));
|
|
379
|
+
} catch (error) {
|
|
380
|
+
console.log(chalk.yellow('\nā ļø Could not install packages automatically'));
|
|
381
|
+
console.log(chalk.gray(' Please install them manually:'));
|
|
382
|
+
console.log(
|
|
383
|
+
chalk.cyan(` ${packageManager} add ${missingPackages.join(' ')}`)
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Check which packages are missing from the project
|
|
390
|
+
*/
|
|
391
|
+
async function getMissingPackages(packages: string[]): Promise<string[]> {
|
|
392
|
+
const packageJsonPath = path.join(process.cwd(), 'package.json');
|
|
393
|
+
|
|
394
|
+
try {
|
|
395
|
+
const packageJson = await fs.readJson(packageJsonPath);
|
|
396
|
+
const installedPackages = {
|
|
397
|
+
...packageJson.dependencies,
|
|
398
|
+
...packageJson.devDependencies,
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
return packages.filter(pkg => !installedPackages[pkg]);
|
|
402
|
+
} catch (error) {
|
|
403
|
+
// If we can't read package.json, assume all packages are missing
|
|
404
|
+
return packages;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Detect which package manager is being used
|
|
410
|
+
*/
|
|
411
|
+
async function detectPackageManager(): Promise<string> {
|
|
412
|
+
// Check for lock files
|
|
413
|
+
if (await fs.pathExists(path.join(process.cwd(), 'pnpm-lock.yaml'))) {
|
|
414
|
+
return 'pnpm';
|
|
415
|
+
}
|
|
416
|
+
if (await fs.pathExists(path.join(process.cwd(), 'yarn.lock'))) {
|
|
417
|
+
return 'yarn';
|
|
418
|
+
}
|
|
419
|
+
if (await fs.pathExists(path.join(process.cwd(), 'package-lock.json'))) {
|
|
420
|
+
return 'npm';
|
|
421
|
+
}
|
|
422
|
+
if (await fs.pathExists(path.join(process.cwd(), 'bun.lockb'))) {
|
|
423
|
+
return 'bun';
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// Default to pnpm as it's what FoundryKit uses
|
|
427
|
+
return 'pnpm';
|
|
428
|
+
}
|
|
429
|
+
|
|
364
430
|
/**
|
|
365
431
|
* Show usage example for the installed component
|
|
366
432
|
*/
|
package/src/commands/init.ts
CHANGED
|
@@ -12,15 +12,15 @@ interface InitOptions {
|
|
|
12
12
|
|
|
13
13
|
export function initCommand() {
|
|
14
14
|
return new Command('init')
|
|
15
|
-
.description('Initialize FoundryKit in your
|
|
15
|
+
.description('Initialize FoundryKit in your project')
|
|
16
16
|
.option('-f, --force', 'overwrite existing files')
|
|
17
17
|
.option('--skip-install', 'skip installing dependencies')
|
|
18
18
|
.action(async (options: InitOptions) => {
|
|
19
19
|
try {
|
|
20
20
|
console.log(chalk.blue('š Initializing FoundryKit...'));
|
|
21
21
|
|
|
22
|
-
//
|
|
23
|
-
await
|
|
22
|
+
// Validate project
|
|
23
|
+
await validateProject();
|
|
24
24
|
|
|
25
25
|
// Check if already initialized
|
|
26
26
|
if (!options.force && (await isFoundryKitInitialized())) {
|
|
@@ -44,6 +44,12 @@ export function initCommand() {
|
|
|
44
44
|
await installDependencies();
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
// Create configuration file
|
|
48
|
+
await createConfigFile(options);
|
|
49
|
+
|
|
50
|
+
// Install utils
|
|
51
|
+
await installUtils();
|
|
52
|
+
|
|
47
53
|
// Setup CSS with Tailwind v4
|
|
48
54
|
await setupTailwindV4();
|
|
49
55
|
|
|
@@ -60,14 +66,18 @@ export function initCommand() {
|
|
|
60
66
|
console.log(chalk.cyan('\nš¦ Next steps:'));
|
|
61
67
|
console.log(
|
|
62
68
|
chalk.gray(
|
|
63
|
-
' 1. Add a component:
|
|
69
|
+
' 1. Add a component: pnpm dlx @foundrykit/cli add hero-minimal'
|
|
64
70
|
)
|
|
65
71
|
);
|
|
66
72
|
console.log(
|
|
67
|
-
chalk.gray(
|
|
73
|
+
chalk.gray(
|
|
74
|
+
' 2. List available components: pnpm dlx @foundrykit/cli list'
|
|
75
|
+
)
|
|
68
76
|
);
|
|
69
77
|
console.log(
|
|
70
|
-
chalk.gray(
|
|
78
|
+
chalk.gray(
|
|
79
|
+
' 3. Check out the docs: https://foundry-docs.umiflow.com'
|
|
80
|
+
)
|
|
71
81
|
);
|
|
72
82
|
} catch (error) {
|
|
73
83
|
console.error(chalk.red('ā Failed to initialize FoundryKit:'));
|
|
@@ -79,7 +89,7 @@ export function initCommand() {
|
|
|
79
89
|
});
|
|
80
90
|
}
|
|
81
91
|
|
|
82
|
-
async function
|
|
92
|
+
async function validateProject(): Promise<void> {
|
|
83
93
|
const packageJsonPath = path.join(process.cwd(), 'package.json');
|
|
84
94
|
|
|
85
95
|
if (!fs.existsSync(packageJsonPath)) {
|
|
@@ -104,46 +114,15 @@ async function validateNextJsProject(): Promise<void> {
|
|
|
104
114
|
}
|
|
105
115
|
|
|
106
116
|
async function isFoundryKitInitialized(): Promise<boolean> {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const packageJson = await fs.readJson(packageJsonPath);
|
|
111
|
-
const dependencies = {
|
|
112
|
-
...packageJson.dependencies,
|
|
113
|
-
...packageJson.devDependencies,
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
// Check if any FoundryKit packages are installed
|
|
117
|
-
return Object.keys(dependencies).some(dep =>
|
|
118
|
-
dep.startsWith('@foundrykit/')
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return false;
|
|
117
|
+
// Check for foundrykit.config.json
|
|
118
|
+
const configPath = path.join(process.cwd(), 'foundrykit.config.json');
|
|
119
|
+
return fs.existsSync(configPath);
|
|
123
120
|
}
|
|
124
121
|
|
|
125
122
|
async function installDependencies(): Promise<void> {
|
|
126
|
-
console.log(chalk.blue('š¦ Installing
|
|
127
|
-
|
|
128
|
-
// Check if we're in a workspace (local development)
|
|
129
|
-
const isWorkspace = await checkIfWorkspace();
|
|
130
|
-
|
|
131
|
-
if (isWorkspace) {
|
|
132
|
-
console.log(
|
|
133
|
-
chalk.yellow('ā ļø Workspace detected - skipping dependency installation')
|
|
134
|
-
);
|
|
135
|
-
console.log(chalk.gray('Dependencies are already available via workspace'));
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
123
|
+
console.log(chalk.blue('š¦ Installing base dependencies...'));
|
|
138
124
|
|
|
139
|
-
const dependencies = [
|
|
140
|
-
'@foundrykit/primitives',
|
|
141
|
-
'@foundrykit/components',
|
|
142
|
-
'@foundrykit/blocks',
|
|
143
|
-
'@foundrykit/hooks',
|
|
144
|
-
'@foundrykit/animation',
|
|
145
|
-
'@foundrykit/tailwind',
|
|
146
|
-
];
|
|
125
|
+
const dependencies = ['clsx', 'tailwind-merge'];
|
|
147
126
|
|
|
148
127
|
try {
|
|
149
128
|
// Detect package manager
|
|
@@ -155,13 +134,19 @@ async function installDependencies(): Promise<void> {
|
|
|
155
134
|
? `npm install ${dependencies.join(' ')}`
|
|
156
135
|
: packageManager === 'yarn'
|
|
157
136
|
? `yarn add ${dependencies.join(' ')}`
|
|
158
|
-
:
|
|
137
|
+
: packageManager === 'bun'
|
|
138
|
+
? `bun add ${dependencies.join(' ')}`
|
|
139
|
+
: `pnpm add ${dependencies.join(' ')}`;
|
|
159
140
|
|
|
160
141
|
execSync(installCmd, { stdio: 'inherit' });
|
|
161
142
|
console.log(chalk.green('ā
Dependencies installed'));
|
|
162
143
|
} catch (error) {
|
|
163
|
-
|
|
164
|
-
'
|
|
144
|
+
console.log(
|
|
145
|
+
chalk.yellow('ā ļø Could not install dependencies automatically')
|
|
146
|
+
);
|
|
147
|
+
console.log(chalk.gray('Please install them manually:'));
|
|
148
|
+
console.log(
|
|
149
|
+
chalk.cyan(` ${detectPackageManager()} add ${dependencies.join(' ')}`)
|
|
165
150
|
);
|
|
166
151
|
}
|
|
167
152
|
}
|
|
@@ -206,6 +191,7 @@ async function checkIfWorkspace(): Promise<boolean> {
|
|
|
206
191
|
function detectPackageManager(): string {
|
|
207
192
|
if (fs.existsSync('pnpm-lock.yaml')) return 'pnpm';
|
|
208
193
|
if (fs.existsSync('yarn.lock')) return 'yarn';
|
|
194
|
+
if (fs.existsSync('bun.lockb')) return 'bun';
|
|
209
195
|
return 'npm';
|
|
210
196
|
}
|
|
211
197
|
|
|
@@ -612,3 +598,125 @@ async function updatePackageScripts(): Promise<void> {
|
|
|
612
598
|
await fs.writeJson(packageJsonPath, packageJson, { spaces: 2 });
|
|
613
599
|
console.log(chalk.green('ā
Package scripts updated'));
|
|
614
600
|
}
|
|
601
|
+
|
|
602
|
+
async function createConfigFile(options: InitOptions): Promise<void> {
|
|
603
|
+
console.log(chalk.blue('š Creating configuration file...'));
|
|
604
|
+
|
|
605
|
+
const configPath = path.join(process.cwd(), 'foundrykit.config.json');
|
|
606
|
+
|
|
607
|
+
if (fs.existsSync(configPath) && !options.force) {
|
|
608
|
+
console.log(chalk.yellow('ā ļø Configuration file already exists'));
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
// Detect framework
|
|
613
|
+
const framework = await detectFramework();
|
|
614
|
+
|
|
615
|
+
// Detect TypeScript
|
|
616
|
+
const isTypeScript = fs.existsSync(path.join(process.cwd(), 'tsconfig.json'));
|
|
617
|
+
|
|
618
|
+
// Create configuration
|
|
619
|
+
const config = {
|
|
620
|
+
version: '1.0.0',
|
|
621
|
+
registry: 'https://foundry.umiflow.com',
|
|
622
|
+
paths: {
|
|
623
|
+
utils: './src/lib/utils.ts',
|
|
624
|
+
primitives: './src/components/ui',
|
|
625
|
+
components: './src/components',
|
|
626
|
+
blocks: './src/components/blocks',
|
|
627
|
+
hooks: './src/hooks',
|
|
628
|
+
animations: './src/components/animations',
|
|
629
|
+
},
|
|
630
|
+
packageManager: detectPackageManager(),
|
|
631
|
+
typescript: isTypeScript,
|
|
632
|
+
framework,
|
|
633
|
+
tailwind: {
|
|
634
|
+
config: './tailwind.config.js',
|
|
635
|
+
css: './src/styles/globals.css',
|
|
636
|
+
},
|
|
637
|
+
aliases: {
|
|
638
|
+
'@': './src',
|
|
639
|
+
'@/components': './src/components',
|
|
640
|
+
'@/lib': './src/lib',
|
|
641
|
+
'@/hooks': './src/hooks',
|
|
642
|
+
},
|
|
643
|
+
};
|
|
644
|
+
|
|
645
|
+
// Adjust paths based on framework
|
|
646
|
+
if (framework === 'next') {
|
|
647
|
+
const hasAppDir = fs.existsSync(path.join(process.cwd(), 'app'));
|
|
648
|
+
if (hasAppDir && !fs.existsSync(path.join(process.cwd(), 'src/app'))) {
|
|
649
|
+
// Using app directory without src
|
|
650
|
+
config.paths = {
|
|
651
|
+
utils: './lib/utils.ts',
|
|
652
|
+
primitives: './components/ui',
|
|
653
|
+
components: './components',
|
|
654
|
+
blocks: './components/blocks',
|
|
655
|
+
hooks: './hooks',
|
|
656
|
+
animations: './components/animations',
|
|
657
|
+
};
|
|
658
|
+
config.tailwind.css = './app/globals.css';
|
|
659
|
+
config.aliases = {
|
|
660
|
+
'@': './',
|
|
661
|
+
'@/components': './components',
|
|
662
|
+
'@/lib': './lib',
|
|
663
|
+
'@/hooks': './hooks',
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
await fs.writeJson(configPath, config, { spaces: 2 });
|
|
669
|
+
console.log(chalk.green('ā
Created foundrykit.config.json'));
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
async function installUtils(): Promise<void> {
|
|
673
|
+
console.log(chalk.blue('š¦ Installing utils...'));
|
|
674
|
+
|
|
675
|
+
// Read config to get utils path
|
|
676
|
+
const configPath = path.join(process.cwd(), 'foundrykit.config.json');
|
|
677
|
+
if (!fs.existsSync(configPath)) {
|
|
678
|
+
console.log(chalk.yellow('ā ļø Configuration file not found'));
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
const config = await fs.readJson(configPath);
|
|
683
|
+
const utilsPath = path.join(process.cwd(), config.paths.utils);
|
|
684
|
+
|
|
685
|
+
// Check if utils already exists
|
|
686
|
+
if (fs.existsSync(utilsPath)) {
|
|
687
|
+
console.log(chalk.yellow('ā ļø Utils file already exists'));
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
// Create utils file
|
|
692
|
+
await fs.ensureDir(path.dirname(utilsPath));
|
|
693
|
+
|
|
694
|
+
const utilsContent = `import { type ClassValue, clsx } from 'clsx';
|
|
695
|
+
import { twMerge } from 'tailwind-merge';
|
|
696
|
+
|
|
697
|
+
export function cn(...inputs: ClassValue[]) {
|
|
698
|
+
return twMerge(clsx(inputs));
|
|
699
|
+
}
|
|
700
|
+
`;
|
|
701
|
+
|
|
702
|
+
await fs.writeFile(utilsPath, utilsContent);
|
|
703
|
+
console.log(chalk.green('ā
Created utils file'));
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
async function detectFramework(): Promise<string> {
|
|
707
|
+
const packageJsonPath = path.join(process.cwd(), 'package.json');
|
|
708
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
709
|
+
const packageJson = await fs.readJson(packageJsonPath);
|
|
710
|
+
const deps = {
|
|
711
|
+
...packageJson.dependencies,
|
|
712
|
+
...packageJson.devDependencies,
|
|
713
|
+
};
|
|
714
|
+
|
|
715
|
+
if (deps.next) return 'next';
|
|
716
|
+
if (deps.remix) return 'remix';
|
|
717
|
+
if (deps.vite) return 'vite';
|
|
718
|
+
if (deps.react) return 'react';
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
return 'react';
|
|
722
|
+
}
|
package/src/lib/registry.ts
CHANGED
|
@@ -93,12 +93,6 @@ export class RegistryService {
|
|
|
93
93
|
*/
|
|
94
94
|
async getComponent(id: string): Promise<ComponentData> {
|
|
95
95
|
try {
|
|
96
|
-
// Special handling for common utility dependencies
|
|
97
|
-
if (id === 'utils') {
|
|
98
|
-
console.log(chalk.gray(`Creating utils dependency...`));
|
|
99
|
-
return this.createUtilsComponent();
|
|
100
|
-
}
|
|
101
|
-
|
|
102
96
|
const url = `${this.config.registryUrl}/registry/${id}`;
|
|
103
97
|
console.log(chalk.gray(`Fetching component: ${url}`));
|
|
104
98
|
|
|
@@ -106,15 +100,6 @@ export class RegistryService {
|
|
|
106
100
|
|
|
107
101
|
if (!response.ok) {
|
|
108
102
|
if (response.status === 404) {
|
|
109
|
-
// Check if it's a known special dependency
|
|
110
|
-
if (this.isSpecialDependency(id)) {
|
|
111
|
-
console.log(
|
|
112
|
-
chalk.yellow(
|
|
113
|
-
`Special dependency "${id}" will be handled separately`
|
|
114
|
-
)
|
|
115
|
-
);
|
|
116
|
-
return this.createSpecialDependency(id);
|
|
117
|
-
}
|
|
118
103
|
throw new Error(`Component "${id}" not found in registry`);
|
|
119
104
|
}
|
|
120
105
|
throw new Error(
|
|
@@ -136,12 +121,6 @@ export class RegistryService {
|
|
|
136
121
|
return cache.componentData[id];
|
|
137
122
|
}
|
|
138
123
|
|
|
139
|
-
// Check if it's a special dependency that we can handle locally
|
|
140
|
-
if (this.isSpecialDependency(id)) {
|
|
141
|
-
console.log(chalk.yellow(`Creating local version of "${id}"`));
|
|
142
|
-
return this.createSpecialDependency(id);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
124
|
// No cached data, throw error
|
|
146
125
|
throw new Error(
|
|
147
126
|
`Failed to fetch component "${id}": ${error instanceof Error ? error.message : 'Unknown error'}\n` +
|
|
@@ -151,56 +130,6 @@ export class RegistryService {
|
|
|
151
130
|
}
|
|
152
131
|
}
|
|
153
132
|
|
|
154
|
-
/**
|
|
155
|
-
* Check if a dependency is a special/utility dependency
|
|
156
|
-
*/
|
|
157
|
-
private isSpecialDependency(id: string): boolean {
|
|
158
|
-
const specialDeps = ['utils', 'lib', 'helpers', 'cn'];
|
|
159
|
-
return specialDeps.includes(id);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Create a special dependency component
|
|
164
|
-
*/
|
|
165
|
-
private createSpecialDependency(id: string): ComponentData {
|
|
166
|
-
switch (id) {
|
|
167
|
-
case 'utils':
|
|
168
|
-
case 'lib':
|
|
169
|
-
case 'helpers':
|
|
170
|
-
case 'cn':
|
|
171
|
-
return this.createUtilsComponent();
|
|
172
|
-
default:
|
|
173
|
-
throw new Error(`Unknown special dependency: ${id}`);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Create a utils component with the cn function
|
|
179
|
-
*/
|
|
180
|
-
private createUtilsComponent(): ComponentData {
|
|
181
|
-
return {
|
|
182
|
-
id: 'utils',
|
|
183
|
-
name: 'Utils',
|
|
184
|
-
category: 'primitives',
|
|
185
|
-
description: 'Utility functions for className merging',
|
|
186
|
-
tags: ['utility', 'helper'],
|
|
187
|
-
packageDependencies: ['clsx', 'tailwind-merge'],
|
|
188
|
-
files: [
|
|
189
|
-
{
|
|
190
|
-
path: 'lib/utils.ts',
|
|
191
|
-
type: 'util',
|
|
192
|
-
content: `import { type ClassValue, clsx } from 'clsx';
|
|
193
|
-
import { twMerge } from 'tailwind-merge';
|
|
194
|
-
|
|
195
|
-
export function cn(...inputs: ClassValue[]) {
|
|
196
|
-
return twMerge(clsx(inputs));
|
|
197
|
-
}
|
|
198
|
-
`,
|
|
199
|
-
},
|
|
200
|
-
],
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
|
|
204
133
|
/**
|
|
205
134
|
* Update the local cache with new component list
|
|
206
135
|
*/
|