@foundrykit/cli 0.1.0 → 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.
@@ -44,8 +44,8 @@ export function initCommand() {
44
44
  await installDependencies();
45
45
  }
46
46
 
47
- // Setup Tailwind config
48
- await setupTailwindConfig();
47
+ // Setup CSS with Tailwind v4
48
+ await setupTailwindV4();
49
49
 
50
50
  // Create components directory
51
51
  await createDirectories();
@@ -104,17 +104,19 @@ async function validateNextJsProject(): Promise<void> {
104
104
  }
105
105
 
106
106
  async function isFoundryKitInitialized(): Promise<boolean> {
107
- const tailwindConfigPath = path.join(process.cwd(), 'tailwind.config.js');
108
- const tailwindConfigTsPath = path.join(process.cwd(), 'tailwind.config.ts');
107
+ const packageJsonPath = path.join(process.cwd(), 'package.json');
109
108
 
110
- if (fs.existsSync(tailwindConfigPath)) {
111
- const config = await fs.readFile(tailwindConfigPath, 'utf-8');
112
- return config.includes('@foundrykit/tailwind-config');
113
- }
109
+ if (fs.existsSync(packageJsonPath)) {
110
+ const packageJson = await fs.readJson(packageJsonPath);
111
+ const dependencies = {
112
+ ...packageJson.dependencies,
113
+ ...packageJson.devDependencies,
114
+ };
114
115
 
115
- if (fs.existsSync(tailwindConfigTsPath)) {
116
- const config = await fs.readFile(tailwindConfigTsPath, 'utf-8');
117
- return config.includes('@foundrykit/tailwind-config');
116
+ // Check if any FoundryKit packages are installed
117
+ return Object.keys(dependencies).some(dep =>
118
+ dep.startsWith('@foundrykit/')
119
+ );
118
120
  }
119
121
 
120
122
  return false;
@@ -123,14 +125,24 @@ async function isFoundryKitInitialized(): Promise<boolean> {
123
125
  async function installDependencies(): Promise<void> {
124
126
  console.log(chalk.blue('📦 Installing FoundryKit dependencies...'));
125
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
+ }
138
+
126
139
  const dependencies = [
127
140
  '@foundrykit/primitives',
128
141
  '@foundrykit/components',
129
142
  '@foundrykit/blocks',
130
143
  '@foundrykit/hooks',
131
144
  '@foundrykit/animation',
132
- '@foundrykit/tokens',
133
- '@foundrykit/tailwind-config',
145
+ '@foundrykit/tailwind',
134
146
  ];
135
147
 
136
148
  try {
@@ -154,37 +166,375 @@ async function installDependencies(): Promise<void> {
154
166
  }
155
167
  }
156
168
 
169
+ async function checkIfWorkspace(): Promise<boolean> {
170
+ try {
171
+ // Check for pnpm workspace
172
+ const pnpmWorkspacePath = path.join(
173
+ process.cwd(),
174
+ '../../pnpm-workspace.yaml'
175
+ );
176
+ if (fs.existsSync(pnpmWorkspacePath)) {
177
+ return true;
178
+ }
179
+
180
+ // Check package.json for workspace packages
181
+ const packageJsonPath = path.join(process.cwd(), 'package.json');
182
+ if (fs.existsSync(packageJsonPath)) {
183
+ const packageJson = await fs.readJson(packageJsonPath);
184
+ const allDeps = {
185
+ ...packageJson.dependencies,
186
+ ...packageJson.devDependencies,
187
+ };
188
+
189
+ // Check if any FoundryKit packages use workspace protocol
190
+ const foundryKitPackages = Object.keys(allDeps).filter(key =>
191
+ key.startsWith('@foundrykit/')
192
+ );
193
+ for (const pkg of foundryKitPackages) {
194
+ if (allDeps[pkg]?.includes('workspace:')) {
195
+ return true;
196
+ }
197
+ }
198
+ }
199
+
200
+ return false;
201
+ } catch {
202
+ return false;
203
+ }
204
+ }
205
+
157
206
  function detectPackageManager(): string {
158
207
  if (fs.existsSync('pnpm-lock.yaml')) return 'pnpm';
159
208
  if (fs.existsSync('yarn.lock')) return 'yarn';
160
209
  return 'npm';
161
210
  }
162
211
 
163
- async function setupTailwindConfig(): Promise<void> {
164
- console.log(chalk.blue('⚙️ Setting up Tailwind configuration...'));
165
-
166
- const configPath = path.join(process.cwd(), 'tailwind.config.ts');
167
- const configContent = `import type { Config } from 'tailwindcss';
168
- import { withFoundryKit } from '@foundrykit/tailwind-config';
169
-
170
- const config: Config = withFoundryKit({
171
- content: [
172
- './pages/**/*.{js,ts,jsx,tsx,mdx}',
173
- './components/**/*.{js,ts,jsx,tsx,mdx}',
174
- './app/**/*.{js,ts,jsx,tsx,mdx}',
175
- './src/**/*.{js,ts,jsx,tsx,mdx}',
176
- ],
177
- theme: {
178
- extend: {},
179
- },
180
- plugins: [],
181
- });
182
-
183
- export default config;
184
- `;
212
+ async function setupTailwindV4(): Promise<void> {
213
+ console.log(chalk.blue('⚙️ Setting up Tailwind CSS v4...'));
214
+
215
+ // First check if layout already imports FoundryKit styles
216
+ const layoutInfo = await findLayoutFile();
217
+ if (layoutInfo) {
218
+ const layoutContent = await fs.readFile(layoutInfo.path, 'utf-8');
219
+
220
+ // Check if already importing FoundryKit styles directly
221
+ if (layoutContent.includes('@foundrykit/tailwind/globals.css')) {
222
+ const { importPreference } = await inquirer.prompt([
223
+ {
224
+ type: 'list',
225
+ name: 'importPreference',
226
+ message:
227
+ 'FoundryKit styles are already imported directly. How would you like to proceed?',
228
+ choices: [
229
+ {
230
+ name: 'Keep direct import from @foundrykit/tailwind/globals.css',
231
+ value: 'direct',
232
+ },
233
+ {
234
+ name: 'Switch to local globals.css file (recommended for customization)',
235
+ value: 'local',
236
+ },
237
+ ],
238
+ default: 'direct',
239
+ },
240
+ ]);
241
+
242
+ if (importPreference === 'direct') {
243
+ console.log(
244
+ chalk.green(
245
+ '✅ Keeping direct import from @foundrykit/tailwind/globals.css'
246
+ )
247
+ );
248
+ return;
249
+ }
185
250
 
186
- await fs.writeFile(configPath, configContent);
187
- console.log(chalk.green('✅ Tailwind config created'));
251
+ // User wants to switch to local globals.css
252
+ await createLocalGlobalsAndUpdateLayout(layoutInfo.path, layoutContent);
253
+ return;
254
+ }
255
+
256
+ // Check if importing a local globals.css
257
+ const globalsCssImportMatch = layoutContent.match(
258
+ /import\s+['"]([^'"]*globals\.css)['"]/
259
+ );
260
+ if (globalsCssImportMatch && globalsCssImportMatch[1]) {
261
+ // Local globals.css is imported, check if it needs updating
262
+ const importPath = globalsCssImportMatch[1];
263
+ const resolvedPath = importPath.startsWith('.')
264
+ ? path.join(path.dirname(layoutInfo.path), importPath)
265
+ : path.join(process.cwd(), importPath.replace(/^@\//, 'app/'));
266
+
267
+ if (fs.existsSync(resolvedPath)) {
268
+ const globalsCssContent = await fs.readFile(resolvedPath, 'utf-8');
269
+ if (globalsCssContent.includes('@foundrykit/tailwind/globals.css')) {
270
+ console.log(chalk.green('✅ FoundryKit styles already configured'));
271
+ return;
272
+ }
273
+
274
+ // Update existing globals.css
275
+ const updatedContent = `/* Import FoundryKit's Tailwind CSS v4 styles */
276
+ @import "@foundrykit/tailwind/globals.css";
277
+
278
+ /* Your custom styles below */
279
+ ${globalsCssContent}`;
280
+
281
+ await fs.writeFile(resolvedPath, updatedContent);
282
+ console.log(
283
+ chalk.green('✅ Updated existing globals.css with FoundryKit styles')
284
+ );
285
+ return;
286
+ }
287
+ }
288
+ }
289
+
290
+ // No existing setup found, ask user preference
291
+ const { setupPreference } = await inquirer.prompt([
292
+ {
293
+ type: 'list',
294
+ name: 'setupPreference',
295
+ message: 'How would you like to import FoundryKit styles?',
296
+ choices: [
297
+ {
298
+ name: 'Create a local globals.css file (recommended for customization)',
299
+ value: 'local',
300
+ },
301
+ {
302
+ name: 'Import directly from @foundrykit/tailwind/globals.css',
303
+ value: 'direct',
304
+ },
305
+ ],
306
+ default: 'local',
307
+ },
308
+ ]);
309
+
310
+ if (setupPreference === 'direct') {
311
+ // Add direct import to layout
312
+ await addDirectImportToLayout();
313
+ } else {
314
+ // Create local globals.css and update layout
315
+ await createLocalGlobalsAndUpdateLayout();
316
+ }
317
+ }
318
+
319
+ async function createLocalGlobalsAndUpdateLayout(
320
+ existingLayoutPath?: string,
321
+ existingLayoutContent?: string
322
+ ): Promise<void> {
323
+ // Find or create globals.css
324
+ const possiblePaths = [
325
+ 'app/globals.css',
326
+ 'src/app/globals.css',
327
+ 'styles/globals.css',
328
+ 'src/styles/globals.css',
329
+ ];
330
+
331
+ let globalCssPath: string | null = null;
332
+ for (const p of possiblePaths) {
333
+ const fullPath = path.join(process.cwd(), p);
334
+ if (fs.existsSync(fullPath)) {
335
+ globalCssPath = fullPath;
336
+ break;
337
+ }
338
+ }
339
+
340
+ if (!globalCssPath) {
341
+ // Create in app directory by default
342
+ globalCssPath = path.join(process.cwd(), 'app/globals.css');
343
+ await fs.ensureDir(path.dirname(globalCssPath));
344
+ }
345
+
346
+ // Check if the file already imports FoundryKit styles
347
+ const existingContent = fs.existsSync(globalCssPath)
348
+ ? await fs.readFile(globalCssPath, 'utf-8')
349
+ : '';
350
+
351
+ if (!existingContent.includes('@foundrykit/tailwind/globals.css')) {
352
+ // Add FoundryKit import to globals.css
353
+ const cssContent = `/* Import FoundryKit's Tailwind CSS v4 styles */
354
+ @import "@foundrykit/tailwind/globals.css";
355
+
356
+ /* Your custom styles below */
357
+ ${existingContent}`;
358
+
359
+ await fs.writeFile(globalCssPath, cssContent);
360
+ console.log(
361
+ chalk.green('✅ Created/updated globals.css with FoundryKit styles')
362
+ );
363
+ }
364
+
365
+ // Update layout file
366
+ if (existingLayoutPath && existingLayoutContent) {
367
+ // Replace direct import with local globals.css
368
+ const layoutDir = path.dirname(existingLayoutPath);
369
+ const cssRelativePath = path
370
+ .relative(layoutDir, globalCssPath)
371
+ .replace(/\\/g, '/');
372
+ const importPath = cssRelativePath.startsWith('.')
373
+ ? cssRelativePath
374
+ : `./${cssRelativePath}`;
375
+
376
+ const updatedContent = existingLayoutContent.replace(
377
+ /@foundrykit\/tailwind\/globals\.css/g,
378
+ importPath
379
+ );
380
+
381
+ await fs.writeFile(existingLayoutPath, updatedContent);
382
+ console.log(chalk.green('✅ Updated layout to use local globals.css'));
383
+ } else {
384
+ // Add import to layout
385
+ await updateLayoutImport(globalCssPath);
386
+ }
387
+ }
388
+
389
+ async function addDirectImportToLayout(): Promise<void> {
390
+ const layoutInfo = await findLayoutFile();
391
+
392
+ if (!layoutInfo) {
393
+ console.log(
394
+ chalk.yellow(
395
+ '⚠️ No layout file found. Please add this import to your layout manually:'
396
+ )
397
+ );
398
+ console.log(chalk.gray(` import '@foundrykit/tailwind/globals.css';`));
399
+ return;
400
+ }
401
+
402
+ const layoutContent = await fs.readFile(layoutInfo.path, 'utf-8');
403
+
404
+ // Check if already importing
405
+ if (layoutContent.includes('@foundrykit/tailwind/globals.css')) {
406
+ console.log(
407
+ chalk.gray('Layout already imports FoundryKit styles directly')
408
+ );
409
+ return;
410
+ }
411
+
412
+ // Add import statement after existing imports
413
+ const importStatement = `import '@foundrykit/tailwind/globals.css';`;
414
+
415
+ // Find a good place to insert the import (after other imports)
416
+ const importRegex = /^import\s+.*$/gm;
417
+ const imports = layoutContent.match(importRegex);
418
+
419
+ let updatedContent: string;
420
+ if (imports && imports.length > 0) {
421
+ const lastImport = imports[imports.length - 1];
422
+ const lastImportIndex = layoutContent.lastIndexOf(lastImport!);
423
+ const insertPosition = lastImportIndex + lastImport!.length;
424
+
425
+ updatedContent =
426
+ layoutContent.slice(0, insertPosition) +
427
+ '\n' +
428
+ importStatement +
429
+ layoutContent.slice(insertPosition);
430
+ } else {
431
+ // No imports found, add at the beginning
432
+ updatedContent = importStatement + '\n' + layoutContent;
433
+ }
434
+
435
+ await fs.writeFile(layoutInfo.path, updatedContent);
436
+ console.log(
437
+ chalk.green('✅ Added direct import of FoundryKit styles to layout')
438
+ );
439
+ }
440
+
441
+ async function findLayoutFile(): Promise<{ path: string } | null> {
442
+ const layoutPaths = [
443
+ 'app/layout.tsx',
444
+ 'app/layout.jsx',
445
+ 'app/layout.js',
446
+ 'src/app/layout.tsx',
447
+ 'src/app/layout.jsx',
448
+ 'src/app/layout.js',
449
+ ];
450
+
451
+ for (const p of layoutPaths) {
452
+ const fullPath = path.join(process.cwd(), p);
453
+ if (fs.existsSync(fullPath)) {
454
+ return { path: fullPath };
455
+ }
456
+ }
457
+
458
+ return null;
459
+ }
460
+
461
+ async function updateLayoutImport(globalCssPath: string): Promise<void> {
462
+ const layoutInfo = await findLayoutFile();
463
+
464
+ if (!layoutInfo) {
465
+ console.log(
466
+ chalk.yellow(
467
+ '⚠️ No layout file found. Please import globals.css manually in your layout.'
468
+ )
469
+ );
470
+ return;
471
+ }
472
+
473
+ const layoutContent = await fs.readFile(layoutInfo.path, 'utf-8');
474
+
475
+ // Check if already importing any globals.css
476
+ if (layoutContent.match(/import\s+['"][^'"]*globals\.css['"]/)) {
477
+ console.log(chalk.gray('Layout already has a globals.css import'));
478
+ return;
479
+ }
480
+
481
+ // Check if already importing FoundryKit styles directly
482
+ if (layoutContent.includes('@foundrykit/tailwind/globals.css')) {
483
+ // Replace direct FoundryKit import with local globals.css
484
+ const layoutDir = path.dirname(layoutInfo.path);
485
+ const cssRelativePath = path
486
+ .relative(layoutDir, globalCssPath)
487
+ .replace(/\\/g, '/');
488
+ const importPath = cssRelativePath.startsWith('.')
489
+ ? cssRelativePath
490
+ : `./${cssRelativePath}`;
491
+
492
+ const updatedContent = layoutContent.replace(
493
+ /@foundrykit\/tailwind\/globals\.css/g,
494
+ importPath
495
+ );
496
+
497
+ await fs.writeFile(layoutInfo.path, updatedContent);
498
+ console.log(
499
+ chalk.green('✅ Updated layout import to use local globals.css')
500
+ );
501
+ return;
502
+ }
503
+
504
+ // Calculate relative import path
505
+ const layoutDir = path.dirname(layoutInfo.path);
506
+ const cssRelativePath = path
507
+ .relative(layoutDir, globalCssPath)
508
+ .replace(/\\/g, '/');
509
+ const importPath = cssRelativePath.startsWith('.')
510
+ ? cssRelativePath
511
+ : `./${cssRelativePath}`;
512
+
513
+ // Add import statement after existing imports
514
+ const importStatement = `import '${importPath}';`;
515
+
516
+ // Find a good place to insert the import (after other imports)
517
+ const importRegex = /^import\s+.*$/gm;
518
+ const imports = layoutContent.match(importRegex);
519
+
520
+ let updatedContent: string;
521
+ if (imports && imports.length > 0) {
522
+ const lastImport = imports[imports.length - 1];
523
+ const lastImportIndex = layoutContent.lastIndexOf(lastImport!);
524
+ const insertPosition = lastImportIndex + lastImport!.length;
525
+
526
+ updatedContent =
527
+ layoutContent.slice(0, insertPosition) +
528
+ '\n' +
529
+ importStatement +
530
+ layoutContent.slice(insertPosition);
531
+ } else {
532
+ // No imports found, add at the beginning
533
+ updatedContent = importStatement + '\n' + layoutContent;
534
+ }
535
+
536
+ await fs.writeFile(layoutInfo.path, updatedContent);
537
+ console.log(chalk.green('✅ Layout file updated with globals.css import'));
188
538
  }
189
539
 
190
540
  async function createDirectories(): Promise<void> {
@@ -212,83 +562,29 @@ export function cn(...inputs: ClassValue[]) {
212
562
  }
213
563
  `;
214
564
 
215
- await fs.writeFile(utilsPath, utilsContent);
216
-
217
- // Create a basic globals.css if it doesn't exist
218
- const globalsCssPath = path.join(process.cwd(), 'app/globals.css');
219
- const srcGlobalsCssPath = path.join(process.cwd(), 'src/app/globals.css');
220
-
221
- const globalsCssContent = `@import "tailwindcss";
222
-
223
- @layer base {
224
- :root {
225
- --background: 0 0% 100%;
226
- --foreground: 222.2 84% 4.9%;
227
- --card: 0 0% 100%;
228
- --card-foreground: 222.2 84% 4.9%;
229
- --popover: 0 0% 100%;
230
- --popover-foreground: 222.2 84% 4.9%;
231
- --primary: 222.2 47.4% 11.2%;
232
- --primary-foreground: 210 40% 98%;
233
- --secondary: 210 40% 96%;
234
- --secondary-foreground: 222.2 84% 4.9%;
235
- --muted: 210 40% 96%;
236
- --muted-foreground: 215.4 16.3% 46.9%;
237
- --accent: 210 40% 96%;
238
- --accent-foreground: 222.2 84% 4.9%;
239
- --destructive: 0 84.2% 60.2%;
240
- --destructive-foreground: 210 40% 98%;
241
- --border: 214.3 31.8% 91.4%;
242
- --input: 214.3 31.8% 91.4%;
243
- --ring: 222.2 84% 4.9%;
244
- --radius: 0.5rem;
565
+ if (!fs.existsSync(utilsPath)) {
566
+ await fs.writeFile(utilsPath, utilsContent);
567
+ console.log(chalk.gray('Created lib/utils.ts'));
245
568
  }
246
569
 
247
- .dark {
248
- --background: 222.2 84% 4.9%;
249
- --foreground: 210 40% 98%;
250
- --card: 222.2 84% 4.9%;
251
- --card-foreground: 210 40% 98%;
252
- --popover: 222.2 84% 4.9%;
253
- --popover-foreground: 210 40% 98%;
254
- --primary: 210 40% 98%;
255
- --primary-foreground: 222.2 47.4% 11.2%;
256
- --secondary: 217.2 32.6% 17.5%;
257
- --secondary-foreground: 210 40% 98%;
258
- --muted: 217.2 32.6% 17.5%;
259
- --muted-foreground: 215 20.2% 65.1%;
260
- --accent: 217.2 32.6% 17.5%;
261
- --accent-foreground: 210 40% 98%;
262
- --destructive: 0 62.8% 30.6%;
263
- --destructive-foreground: 210 40% 98%;
264
- --border: 217.2 32.6% 17.5%;
265
- --input: 217.2 32.6% 17.5%;
266
- --ring: 212.7 26.8% 83.9%;
267
- }
268
- }
570
+ // Create providers.tsx if using theme support
571
+ const providersPath = path.join(process.cwd(), 'components/providers.tsx');
572
+ const providersContent = `'use client';
269
573
 
270
- @layer base {
271
- body {
272
- @apply bg-background text-foreground;
273
- }
574
+ import { ThemeProvider } from 'next-themes';
575
+
576
+ export function Providers({ children }: { children: React.ReactNode }) {
577
+ return (
578
+ <ThemeProvider attribute="class" defaultTheme="system" enableSystem>
579
+ {children}
580
+ </ThemeProvider>
581
+ );
274
582
  }
275
583
  `;
276
584
 
277
- // Try to update existing globals.css or create new one
278
- if (fs.existsSync(globalsCssPath)) {
279
- const existing = await fs.readFile(globalsCssPath, 'utf-8');
280
- if (!existing.includes('--background')) {
281
- await fs.writeFile(globalsCssPath, globalsCssContent);
282
- }
283
- } else if (fs.existsSync(srcGlobalsCssPath)) {
284
- const existing = await fs.readFile(srcGlobalsCssPath, 'utf-8');
285
- if (!existing.includes('--background')) {
286
- await fs.writeFile(srcGlobalsCssPath, globalsCssContent);
287
- }
288
- } else {
289
- // Create in app directory by default
290
- await fs.ensureDir(path.join(process.cwd(), 'app'));
291
- await fs.writeFile(globalsCssPath, globalsCssContent);
585
+ if (!fs.existsSync(providersPath)) {
586
+ await fs.writeFile(providersPath, providersContent);
587
+ console.log(chalk.gray('Created components/providers.tsx'));
292
588
  }
293
589
 
294
590
  console.log(chalk.green('✅ Example files created'));