@foundrykit/cli 2.0.12 → 3.0.0
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/README.md +71 -6
- package/dist/cli.js +2130 -677
- package/dist/cli.js.map +1 -1
- package/dist/index.js +2130 -677
- package/dist/index.js.map +1 -1
- package/package.json +9 -4
- package/schema.json +60 -0
- package/.turbo/turbo-type-check.log +0 -4
- package/CHANGELOG.md +0 -254
- package/docs/DEPENDENCY_RESOLUTION.md +0 -201
- package/postcss.config.mjs +0 -6
- package/src/commands/add.ts +0 -1069
- package/src/commands/doctor.ts +0 -130
- package/src/commands/init.ts +0 -928
- package/src/commands/list.ts +0 -167
- package/src/commands/update.ts +0 -323
- package/src/index.ts +0 -34
- package/src/lib/constants.ts +0 -42
- package/src/lib/registry.ts +0 -627
- package/tests/dependency-resolution.test.ts +0 -579
- package/tsconfig.json +0 -11
- package/tsconfig.lint.json +0 -8
- package/tsup.config.ts +0 -16
package/src/commands/init.ts
DELETED
|
@@ -1,928 +0,0 @@
|
|
|
1
|
-
import { exec } from 'node:child_process';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { promisify } from 'node:util';
|
|
4
|
-
import chalk from 'chalk';
|
|
5
|
-
import { Command } from 'commander';
|
|
6
|
-
import fs from 'fs-extra';
|
|
7
|
-
import inquirer from 'inquirer';
|
|
8
|
-
import { CLI_VERSION, DEFAULT_REGISTRY_URL } from '../lib/constants.js';
|
|
9
|
-
|
|
10
|
-
interface InitOptions {
|
|
11
|
-
force?: boolean;
|
|
12
|
-
skipInstall?: boolean;
|
|
13
|
-
skipPrompts?: boolean;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
interface ProjectStructure {
|
|
17
|
-
hasSrc: boolean;
|
|
18
|
-
hasApp: boolean;
|
|
19
|
-
hasComponents: boolean;
|
|
20
|
-
hasLib: boolean;
|
|
21
|
-
hasHooks: boolean;
|
|
22
|
-
hasStyles: boolean;
|
|
23
|
-
baseDir: string;
|
|
24
|
-
framework: string;
|
|
25
|
-
isTypeScript: boolean;
|
|
26
|
-
packageManager: string;
|
|
27
|
-
appPath?: string;
|
|
28
|
-
componentsPath?: string;
|
|
29
|
-
libPath?: string;
|
|
30
|
-
hooksPath?: string;
|
|
31
|
-
stylesPath?: string;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
interface PathConfig {
|
|
35
|
-
utils: string;
|
|
36
|
-
primitives: string;
|
|
37
|
-
components: string;
|
|
38
|
-
blocks: string;
|
|
39
|
-
hooks: string;
|
|
40
|
-
maps: string;
|
|
41
|
-
animations: string;
|
|
42
|
-
styles: string;
|
|
43
|
-
lib: string;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function initCommand() {
|
|
47
|
-
return new Command('init')
|
|
48
|
-
.description('Initialize FoundryKit in your project')
|
|
49
|
-
.option('-f, --force', 'overwrite existing files')
|
|
50
|
-
.option('--skip-install', 'skip installing dependencies')
|
|
51
|
-
.option('--skip-prompts', 'use default paths without prompting')
|
|
52
|
-
.action(async (options: InitOptions) => {
|
|
53
|
-
try {
|
|
54
|
-
console.log(chalk.blue('🚀 Initializing FoundryKit...'));
|
|
55
|
-
|
|
56
|
-
// Validate project
|
|
57
|
-
await validateProject();
|
|
58
|
-
|
|
59
|
-
// Check if already initialized
|
|
60
|
-
if (!options.force && (await isFoundryKitInitialized())) {
|
|
61
|
-
const { shouldContinue } = await inquirer.prompt([
|
|
62
|
-
{
|
|
63
|
-
type: 'confirm',
|
|
64
|
-
name: 'shouldContinue',
|
|
65
|
-
message: 'FoundryKit is already initialized. Continue anyway?',
|
|
66
|
-
default: false,
|
|
67
|
-
},
|
|
68
|
-
]);
|
|
69
|
-
|
|
70
|
-
if (!shouldContinue) {
|
|
71
|
-
console.log(chalk.yellow('❌ Initialization cancelled.'));
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Detect project structure
|
|
77
|
-
const projectStructure = await detectProjectStructure();
|
|
78
|
-
console.log(
|
|
79
|
-
chalk.gray(
|
|
80
|
-
`Detected project structure: ${projectStructure.hasSrc ? 'src/' : 'root'} based`
|
|
81
|
-
)
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
// Get path configuration (with prompts or defaults)
|
|
85
|
-
const pathConfig = await getPathConfiguration(
|
|
86
|
-
projectStructure,
|
|
87
|
-
options.skipPrompts
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
// Install dependencies
|
|
91
|
-
if (!options.skipInstall) {
|
|
92
|
-
await installDependencies();
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
console.log(pathConfig);
|
|
96
|
-
|
|
97
|
-
// Create configuration file with custom paths
|
|
98
|
-
await createConfigFile(options, projectStructure, pathConfig);
|
|
99
|
-
|
|
100
|
-
// Install utils with custom path
|
|
101
|
-
await installUtils(pathConfig);
|
|
102
|
-
|
|
103
|
-
// Setup CSS with Tailwind v4
|
|
104
|
-
await setupTailwindV4(
|
|
105
|
-
pathConfig,
|
|
106
|
-
projectStructure,
|
|
107
|
-
options.skipPrompts
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
// Create components directory with custom paths
|
|
111
|
-
await createDirectories(pathConfig);
|
|
112
|
-
|
|
113
|
-
// Create example files with custom paths
|
|
114
|
-
await createExampleFiles(pathConfig, projectStructure);
|
|
115
|
-
|
|
116
|
-
// Update package.json scripts
|
|
117
|
-
await updatePackageScripts();
|
|
118
|
-
|
|
119
|
-
console.log(chalk.green('\n✅ FoundryKit initialized successfully!'));
|
|
120
|
-
console.log(chalk.cyan('\n📦 Next steps:'));
|
|
121
|
-
console.log(
|
|
122
|
-
chalk.gray(
|
|
123
|
-
' 1. Add a component: pnpm dlx @foundrykit/cli add hero-minimal'
|
|
124
|
-
)
|
|
125
|
-
);
|
|
126
|
-
console.log(
|
|
127
|
-
chalk.gray(
|
|
128
|
-
' 2. List available components: pnpm dlx @foundrykit/cli list'
|
|
129
|
-
)
|
|
130
|
-
);
|
|
131
|
-
console.log(
|
|
132
|
-
chalk.gray(
|
|
133
|
-
' 3. Check out the docs: https://foundry-docs.umiflow.com'
|
|
134
|
-
)
|
|
135
|
-
);
|
|
136
|
-
} catch (error) {
|
|
137
|
-
console.error(chalk.red('❌ Failed to initialize FoundryKit:'));
|
|
138
|
-
console.error(
|
|
139
|
-
chalk.red(error instanceof Error ? error.message : String(error))
|
|
140
|
-
);
|
|
141
|
-
process.exit(1);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
async function validateProject(): Promise<void> {
|
|
147
|
-
const packageJsonPath = path.join(process.cwd(), 'package.json');
|
|
148
|
-
|
|
149
|
-
if (!fs.existsSync(packageJsonPath)) {
|
|
150
|
-
throw new Error(
|
|
151
|
-
'No package.json found. Please run this command in a project directory.'
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const packageJson = await fs.readJson(packageJsonPath);
|
|
156
|
-
const deps = {
|
|
157
|
-
...packageJson.dependencies,
|
|
158
|
-
...packageJson.devDependencies,
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
if (!deps.next) {
|
|
162
|
-
throw new Error(
|
|
163
|
-
'Next.js not detected. FoundryKit currently requires Next.js.'
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
console.log(chalk.green('✅ Next.js project detected'));
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
async function isFoundryKitInitialized(): Promise<boolean> {
|
|
171
|
-
return fs.existsSync(path.join(process.cwd(), 'foundrykit.config.json'));
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
async function detectProjectStructure(): Promise<ProjectStructure> {
|
|
175
|
-
const cwd = process.cwd();
|
|
176
|
-
|
|
177
|
-
// Check for src directory
|
|
178
|
-
const hasSrc = fs.existsSync(path.join(cwd, 'src'));
|
|
179
|
-
|
|
180
|
-
// Determine base directory
|
|
181
|
-
let baseDir = './';
|
|
182
|
-
let appPath: string | undefined;
|
|
183
|
-
let componentsPath: string | undefined;
|
|
184
|
-
let libPath: string | undefined;
|
|
185
|
-
let hooksPath: string | undefined;
|
|
186
|
-
let stylesPath: string | undefined;
|
|
187
|
-
|
|
188
|
-
if (hasSrc) {
|
|
189
|
-
// Check if src contains app directory
|
|
190
|
-
const srcHasApp = fs.existsSync(path.join(cwd, 'src/app'));
|
|
191
|
-
if (srcHasApp) {
|
|
192
|
-
baseDir = './src/';
|
|
193
|
-
appPath = './src/app';
|
|
194
|
-
} else {
|
|
195
|
-
// Check if there's an app directory in root
|
|
196
|
-
const rootHasApp = fs.existsSync(path.join(cwd, 'app'));
|
|
197
|
-
if (rootHasApp) {
|
|
198
|
-
// Mixed structure - app in root, other dirs might be in src
|
|
199
|
-
appPath = './app';
|
|
200
|
-
baseDir = './src/';
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
// Check for existing directories in src
|
|
205
|
-
if (fs.existsSync(path.join(cwd, 'src/components'))) {
|
|
206
|
-
componentsPath = './src/components';
|
|
207
|
-
}
|
|
208
|
-
if (fs.existsSync(path.join(cwd, 'src/lib'))) {
|
|
209
|
-
libPath = './src/lib';
|
|
210
|
-
}
|
|
211
|
-
if (fs.existsSync(path.join(cwd, 'src/hooks'))) {
|
|
212
|
-
hooksPath = './src/hooks';
|
|
213
|
-
}
|
|
214
|
-
if (fs.existsSync(path.join(cwd, 'src/styles'))) {
|
|
215
|
-
stylesPath = './src/styles';
|
|
216
|
-
}
|
|
217
|
-
} else {
|
|
218
|
-
// No src directory - check for app directory in root
|
|
219
|
-
const hasApp = fs.existsSync(path.join(cwd, 'app'));
|
|
220
|
-
if (hasApp) {
|
|
221
|
-
appPath = './app';
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// Check for existing directories in root
|
|
225
|
-
if (fs.existsSync(path.join(cwd, 'components'))) {
|
|
226
|
-
componentsPath = './components';
|
|
227
|
-
}
|
|
228
|
-
if (fs.existsSync(path.join(cwd, 'lib'))) {
|
|
229
|
-
libPath = './lib';
|
|
230
|
-
}
|
|
231
|
-
if (fs.existsSync(path.join(cwd, 'hooks'))) {
|
|
232
|
-
hooksPath = './hooks';
|
|
233
|
-
}
|
|
234
|
-
if (fs.existsSync(path.join(cwd, 'styles'))) {
|
|
235
|
-
stylesPath = './styles';
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// Detect TypeScript
|
|
240
|
-
const isTypeScript = fs.existsSync(path.join(cwd, 'tsconfig.json'));
|
|
241
|
-
|
|
242
|
-
// Detect package manager
|
|
243
|
-
const packageManager = detectPackageManager();
|
|
244
|
-
|
|
245
|
-
return {
|
|
246
|
-
hasSrc,
|
|
247
|
-
hasApp: !!appPath,
|
|
248
|
-
hasComponents: !!componentsPath,
|
|
249
|
-
hasLib: !!libPath,
|
|
250
|
-
hasHooks: !!hooksPath,
|
|
251
|
-
hasStyles: !!stylesPath,
|
|
252
|
-
baseDir,
|
|
253
|
-
framework: 'next',
|
|
254
|
-
isTypeScript,
|
|
255
|
-
packageManager,
|
|
256
|
-
appPath,
|
|
257
|
-
componentsPath,
|
|
258
|
-
libPath,
|
|
259
|
-
hooksPath,
|
|
260
|
-
stylesPath,
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
async function getPathConfiguration(
|
|
265
|
-
structure: ProjectStructure,
|
|
266
|
-
skipPrompts?: boolean
|
|
267
|
-
): Promise<PathConfig> {
|
|
268
|
-
const ext = structure.isTypeScript ? '.ts' : '.js';
|
|
269
|
-
|
|
270
|
-
// Smart defaults based on existing structure
|
|
271
|
-
const defaults: PathConfig = {
|
|
272
|
-
utils: path.join(
|
|
273
|
-
structure.libPath || path.join(structure.baseDir, 'lib'),
|
|
274
|
-
`utils${ext}`
|
|
275
|
-
),
|
|
276
|
-
primitives: path.join(
|
|
277
|
-
structure.componentsPath || path.join(structure.baseDir, 'components'),
|
|
278
|
-
'primitives'
|
|
279
|
-
),
|
|
280
|
-
components: path.join(
|
|
281
|
-
structure.componentsPath || path.join(structure.baseDir, 'components'),
|
|
282
|
-
'ui'
|
|
283
|
-
),
|
|
284
|
-
blocks: path.join(
|
|
285
|
-
structure.componentsPath || path.join(structure.baseDir, 'components'),
|
|
286
|
-
'blocks'
|
|
287
|
-
),
|
|
288
|
-
maps: path.join(
|
|
289
|
-
structure.componentsPath || path.join(structure.baseDir, 'components'),
|
|
290
|
-
'maps'
|
|
291
|
-
),
|
|
292
|
-
animations: path.join(
|
|
293
|
-
structure.componentsPath || path.join(structure.baseDir, 'components'),
|
|
294
|
-
'animations'
|
|
295
|
-
),
|
|
296
|
-
hooks: structure.hooksPath || path.join(structure.baseDir, 'hooks'),
|
|
297
|
-
lib: structure.libPath || path.join(structure.baseDir, 'lib'),
|
|
298
|
-
styles: path.join(structure.appPath || structure.baseDir, 'globals.css'),
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
// If app directory exists, look for existing globals.css
|
|
302
|
-
if (structure.appPath) {
|
|
303
|
-
const possibleStylePaths = [
|
|
304
|
-
path.join(structure.appPath, 'globals.css'),
|
|
305
|
-
path.join(structure.appPath, 'global.css'),
|
|
306
|
-
path.join(structure.stylesPath || '', 'globals.css'),
|
|
307
|
-
path.join(structure.stylesPath || '', 'global.css'),
|
|
308
|
-
];
|
|
309
|
-
|
|
310
|
-
for (const stylePath of possibleStylePaths) {
|
|
311
|
-
if (fs.existsSync(path.join(process.cwd(), stylePath))) {
|
|
312
|
-
defaults.styles = stylePath;
|
|
313
|
-
break;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
if (skipPrompts) {
|
|
319
|
-
console.log(
|
|
320
|
-
chalk.gray('Using smart defaults based on project structure...')
|
|
321
|
-
);
|
|
322
|
-
return defaults;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
console.log(chalk.blue('\n📂 Configure installation paths:'));
|
|
326
|
-
console.log(
|
|
327
|
-
chalk.gray('Press enter to use the default value shown in parentheses\n')
|
|
328
|
-
);
|
|
329
|
-
|
|
330
|
-
const answers = await inquirer.prompt([
|
|
331
|
-
{
|
|
332
|
-
type: 'input',
|
|
333
|
-
name: 'utils',
|
|
334
|
-
message: 'Utils file path:',
|
|
335
|
-
default: defaults.utils,
|
|
336
|
-
validate: (input: string) => {
|
|
337
|
-
if (!input) return 'Path cannot be empty';
|
|
338
|
-
return true;
|
|
339
|
-
},
|
|
340
|
-
},
|
|
341
|
-
{
|
|
342
|
-
type: 'input',
|
|
343
|
-
name: 'components',
|
|
344
|
-
message: 'Components directory:',
|
|
345
|
-
default: defaults.components,
|
|
346
|
-
},
|
|
347
|
-
{
|
|
348
|
-
type: 'input',
|
|
349
|
-
name: 'primitives',
|
|
350
|
-
message: 'Primitives directory:',
|
|
351
|
-
default: defaults.primitives,
|
|
352
|
-
},
|
|
353
|
-
{
|
|
354
|
-
type: 'input',
|
|
355
|
-
name: 'blocks',
|
|
356
|
-
message: 'Blocks directory:',
|
|
357
|
-
default: defaults.blocks,
|
|
358
|
-
},
|
|
359
|
-
{
|
|
360
|
-
type: 'input',
|
|
361
|
-
name: 'hooks',
|
|
362
|
-
message: 'Hooks directory:',
|
|
363
|
-
default: defaults.hooks,
|
|
364
|
-
},
|
|
365
|
-
{
|
|
366
|
-
type: 'input',
|
|
367
|
-
name: 'maps',
|
|
368
|
-
message: 'Maps directory:',
|
|
369
|
-
default: defaults.maps,
|
|
370
|
-
},
|
|
371
|
-
{
|
|
372
|
-
type: 'input',
|
|
373
|
-
name: 'animations',
|
|
374
|
-
message: 'Animations directory:',
|
|
375
|
-
default: defaults.animations,
|
|
376
|
-
},
|
|
377
|
-
{
|
|
378
|
-
type: 'input',
|
|
379
|
-
name: 'styles',
|
|
380
|
-
message: 'Global styles file:',
|
|
381
|
-
default: defaults.styles,
|
|
382
|
-
},
|
|
383
|
-
{
|
|
384
|
-
type: 'input',
|
|
385
|
-
name: 'lib',
|
|
386
|
-
message: 'Lib directory:',
|
|
387
|
-
default: defaults.lib,
|
|
388
|
-
},
|
|
389
|
-
]);
|
|
390
|
-
|
|
391
|
-
return answers as PathConfig;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
async function installDependencies(): Promise<void> {
|
|
395
|
-
console.log(chalk.blue('📦 Installing dependencies...'));
|
|
396
|
-
|
|
397
|
-
const packageManager = detectPackageManager();
|
|
398
|
-
const execAsync = promisify(exec);
|
|
399
|
-
|
|
400
|
-
const dependencies = [
|
|
401
|
-
'clsx',
|
|
402
|
-
'tailwind-merge',
|
|
403
|
-
'framer-motion',
|
|
404
|
-
'lucide-react',
|
|
405
|
-
'next-themes',
|
|
406
|
-
'cmdk',
|
|
407
|
-
'@foundrykit/tailwind',
|
|
408
|
-
'@radix-ui/react-dialog',
|
|
409
|
-
'@radix-ui/react-dropdown-menu',
|
|
410
|
-
'@radix-ui/react-label',
|
|
411
|
-
'@radix-ui/react-popover',
|
|
412
|
-
'@radix-ui/react-select',
|
|
413
|
-
'@radix-ui/react-separator',
|
|
414
|
-
'@radix-ui/react-slot',
|
|
415
|
-
'@radix-ui/react-switch',
|
|
416
|
-
'@radix-ui/react-tabs',
|
|
417
|
-
'@radix-ui/react-tooltip',
|
|
418
|
-
];
|
|
419
|
-
|
|
420
|
-
const devDependencies = ['tailwindcss', 'autoprefixer', 'postcss'];
|
|
421
|
-
|
|
422
|
-
try {
|
|
423
|
-
// Install regular dependencies
|
|
424
|
-
const installCmd = packageManager === 'npm' ? 'install' : 'add';
|
|
425
|
-
await execAsync(
|
|
426
|
-
`${packageManager} ${installCmd} ${dependencies.join(' ')}`
|
|
427
|
-
);
|
|
428
|
-
|
|
429
|
-
// Install dev dependencies
|
|
430
|
-
const devFlag = packageManager === 'npm' ? '--save-dev' : '-D';
|
|
431
|
-
await execAsync(
|
|
432
|
-
`${packageManager} ${installCmd} ${devFlag} ${devDependencies.join(' ')}`
|
|
433
|
-
);
|
|
434
|
-
|
|
435
|
-
console.log(chalk.green('✅ Dependencies installed'));
|
|
436
|
-
} catch {
|
|
437
|
-
console.error(chalk.yellow('⚠️ Failed to install some dependencies'));
|
|
438
|
-
console.error(chalk.gray('You may need to install them manually'));
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
function detectPackageManager(): string {
|
|
443
|
-
if (fs.existsSync(path.join(process.cwd(), 'pnpm-lock.yaml'))) return 'pnpm';
|
|
444
|
-
if (fs.existsSync(path.join(process.cwd(), 'yarn.lock'))) return 'yarn';
|
|
445
|
-
if (fs.existsSync(path.join(process.cwd(), 'bun.lockb'))) return 'bun';
|
|
446
|
-
return 'npm';
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
async function setupTailwindV4(
|
|
450
|
-
pathConfig: PathConfig,
|
|
451
|
-
projectStructure: ProjectStructure,
|
|
452
|
-
skipPrompts?: boolean
|
|
453
|
-
): Promise<void> {
|
|
454
|
-
console.log(chalk.blue('🎨 Setting up Tailwind CSS v4...'));
|
|
455
|
-
|
|
456
|
-
// First check if layout already imports FoundryKit styles
|
|
457
|
-
const layoutPath = await findLayoutFile(projectStructure);
|
|
458
|
-
|
|
459
|
-
if (layoutPath) {
|
|
460
|
-
const layoutContent = await fs.readFile(layoutPath, 'utf-8');
|
|
461
|
-
|
|
462
|
-
// Check if already importing FoundryKit styles directly
|
|
463
|
-
if (layoutContent.includes('@foundrykit/tailwind/globals.css')) {
|
|
464
|
-
if (skipPrompts) {
|
|
465
|
-
console.log(
|
|
466
|
-
chalk.green(
|
|
467
|
-
'✅ Keeping existing import from @foundrykit/tailwind/globals.css'
|
|
468
|
-
)
|
|
469
|
-
);
|
|
470
|
-
return;
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
const { importPreference } = await inquirer.prompt([
|
|
474
|
-
{
|
|
475
|
-
type: 'list',
|
|
476
|
-
name: 'importPreference',
|
|
477
|
-
message:
|
|
478
|
-
'FoundryKit styles are already imported directly. How would you like to proceed?',
|
|
479
|
-
choices: [
|
|
480
|
-
{
|
|
481
|
-
name: 'Keep direct import from @foundrykit/tailwind/globals.css',
|
|
482
|
-
value: 'direct',
|
|
483
|
-
},
|
|
484
|
-
{
|
|
485
|
-
name: 'Switch to local globals.css file (recommended for customization)',
|
|
486
|
-
value: 'local',
|
|
487
|
-
},
|
|
488
|
-
],
|
|
489
|
-
default: 'direct',
|
|
490
|
-
},
|
|
491
|
-
]);
|
|
492
|
-
|
|
493
|
-
if (importPreference === 'direct') {
|
|
494
|
-
console.log(
|
|
495
|
-
chalk.green(
|
|
496
|
-
'✅ Keeping direct import from @foundrykit/tailwind/globals.css'
|
|
497
|
-
)
|
|
498
|
-
);
|
|
499
|
-
return;
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
// User wants to switch to local globals.css
|
|
503
|
-
await createOrUpdateGlobalsCss(pathConfig);
|
|
504
|
-
await updateLayoutImport(layoutPath, pathConfig);
|
|
505
|
-
return;
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
// Check if importing a local globals.css
|
|
509
|
-
const globalsCssImportMatch = layoutContent.match(
|
|
510
|
-
/import\s+['"]([^'"]*globals?\.css)['"]/
|
|
511
|
-
);
|
|
512
|
-
|
|
513
|
-
if (globalsCssImportMatch?.[1]) {
|
|
514
|
-
// Local globals.css is imported, update it
|
|
515
|
-
const importPath = globalsCssImportMatch[1];
|
|
516
|
-
const resolvedPath = resolveImportPath(layoutPath, importPath);
|
|
517
|
-
|
|
518
|
-
if (fs.existsSync(resolvedPath)) {
|
|
519
|
-
await updateExistingGlobalsCss(resolvedPath);
|
|
520
|
-
console.log(
|
|
521
|
-
chalk.green('✅ Updated existing globals.css with FoundryKit styles')
|
|
522
|
-
);
|
|
523
|
-
return;
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
// No existing setup found, use default preference or ask user
|
|
529
|
-
let setupPreference = 'local';
|
|
530
|
-
|
|
531
|
-
if (!skipPrompts) {
|
|
532
|
-
const answer = await inquirer.prompt([
|
|
533
|
-
{
|
|
534
|
-
type: 'list',
|
|
535
|
-
name: 'setupPreference',
|
|
536
|
-
message: 'How would you like to import FoundryKit styles?',
|
|
537
|
-
choices: [
|
|
538
|
-
{
|
|
539
|
-
name: 'Create/update a local globals.css file (recommended for customization)',
|
|
540
|
-
value: 'local',
|
|
541
|
-
},
|
|
542
|
-
{
|
|
543
|
-
name: 'Import directly from @foundrykit/tailwind/globals.css',
|
|
544
|
-
value: 'direct',
|
|
545
|
-
},
|
|
546
|
-
],
|
|
547
|
-
default: 'local',
|
|
548
|
-
},
|
|
549
|
-
]);
|
|
550
|
-
setupPreference = answer.setupPreference;
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
if (setupPreference === 'direct') {
|
|
554
|
-
await addDirectImportToLayout(layoutPath!);
|
|
555
|
-
} else {
|
|
556
|
-
await createOrUpdateGlobalsCss(pathConfig);
|
|
557
|
-
if (layoutPath) {
|
|
558
|
-
await updateLayoutImport(layoutPath, pathConfig);
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
console.log(chalk.green('✅ Tailwind CSS v4 configured'));
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
async function createOrUpdateGlobalsCss(pathConfig: PathConfig): Promise<void> {
|
|
566
|
-
const globalsCssPath = path.join(process.cwd(), pathConfig.styles);
|
|
567
|
-
|
|
568
|
-
// Check if file already exists
|
|
569
|
-
if (fs.existsSync(globalsCssPath)) {
|
|
570
|
-
await updateExistingGlobalsCss(globalsCssPath);
|
|
571
|
-
} else {
|
|
572
|
-
// Create new globals.css
|
|
573
|
-
const cssContent = `/* Import FoundryKit's Tailwind CSS v4 styles */
|
|
574
|
-
@import "@foundrykit/tailwind/globals.css";
|
|
575
|
-
|
|
576
|
-
/* Your custom styles below */
|
|
577
|
-
`;
|
|
578
|
-
|
|
579
|
-
await fs.ensureDir(path.dirname(globalsCssPath));
|
|
580
|
-
await fs.writeFile(globalsCssPath, cssContent);
|
|
581
|
-
console.log(chalk.green(`✅ Created ${pathConfig.styles}`));
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
async function updateExistingGlobalsCss(globalsCssPath: string): Promise<void> {
|
|
586
|
-
const content = await fs.readFile(globalsCssPath, 'utf-8');
|
|
587
|
-
|
|
588
|
-
// Check if already has FoundryKit import
|
|
589
|
-
if (content.includes('@foundrykit/tailwind/globals.css')) {
|
|
590
|
-
console.log(chalk.gray('globals.css already imports FoundryKit styles'));
|
|
591
|
-
return;
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
// Check if it has @import "tailwindcss"
|
|
595
|
-
if (content.includes('@import "tailwindcss"')) {
|
|
596
|
-
// Replace the tailwindcss import with FoundryKit import but keep all other content
|
|
597
|
-
const updatedContent = content.replace(
|
|
598
|
-
'@import "tailwindcss"',
|
|
599
|
-
`/* Import FoundryKit's Tailwind CSS v4 styles */\n@import "@foundrykit/tailwind/globals.css"`
|
|
600
|
-
);
|
|
601
|
-
|
|
602
|
-
await fs.writeFile(globalsCssPath, updatedContent);
|
|
603
|
-
console.log(chalk.green('✅ Updated globals.css with FoundryKit styles'));
|
|
604
|
-
} else {
|
|
605
|
-
// Just prepend the FoundryKit import
|
|
606
|
-
const updatedContent = `/* Import FoundryKit's Tailwind CSS v4 styles */
|
|
607
|
-
@import "@foundrykit/tailwind/globals.css";
|
|
608
|
-
|
|
609
|
-
/* Your custom styles below */
|
|
610
|
-
${content}`;
|
|
611
|
-
|
|
612
|
-
await fs.writeFile(globalsCssPath, updatedContent);
|
|
613
|
-
console.log(chalk.green('✅ Updated globals.css with FoundryKit styles'));
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
async function findLayoutFile(
|
|
618
|
-
projectStructure: ProjectStructure
|
|
619
|
-
): Promise<string | null> {
|
|
620
|
-
const possiblePaths = [];
|
|
621
|
-
|
|
622
|
-
if (projectStructure.appPath) {
|
|
623
|
-
const ext = projectStructure.isTypeScript ? '.tsx' : '.jsx';
|
|
624
|
-
possiblePaths.push(
|
|
625
|
-
path.join(projectStructure.appPath, `layout${ext}`),
|
|
626
|
-
path.join(projectStructure.appPath, `layout.js`)
|
|
627
|
-
);
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
// Also check standard paths
|
|
631
|
-
possiblePaths.push(
|
|
632
|
-
'app/layout.tsx',
|
|
633
|
-
'app/layout.jsx',
|
|
634
|
-
'app/layout.js',
|
|
635
|
-
'src/app/layout.tsx',
|
|
636
|
-
'src/app/layout.jsx',
|
|
637
|
-
'src/app/layout.js'
|
|
638
|
-
);
|
|
639
|
-
|
|
640
|
-
for (const layoutPath of possiblePaths) {
|
|
641
|
-
const fullPath = path.join(process.cwd(), layoutPath);
|
|
642
|
-
if (fs.existsSync(fullPath)) {
|
|
643
|
-
return fullPath;
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
return null;
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
async function updateLayoutImport(
|
|
651
|
-
layoutPath: string,
|
|
652
|
-
pathConfig: PathConfig
|
|
653
|
-
): Promise<void> {
|
|
654
|
-
try {
|
|
655
|
-
let content = await fs.readFile(layoutPath, 'utf-8');
|
|
656
|
-
|
|
657
|
-
// Calculate relative import path from layout to styles
|
|
658
|
-
const fromPath = path.dirname(layoutPath);
|
|
659
|
-
const toPath = path.join(process.cwd(), pathConfig.styles);
|
|
660
|
-
const relativePath = path.relative(fromPath, toPath).replace(/\\/g, '/');
|
|
661
|
-
const importPath = relativePath.startsWith('.')
|
|
662
|
-
? relativePath
|
|
663
|
-
: `./${relativePath}`;
|
|
664
|
-
|
|
665
|
-
// Check for existing global CSS imports
|
|
666
|
-
const globalImportRegex = /import\s+['"]([^'"]*globals?\.css)['"]/;
|
|
667
|
-
const match = content.match(globalImportRegex);
|
|
668
|
-
|
|
669
|
-
if (match) {
|
|
670
|
-
// Replace existing import
|
|
671
|
-
content = content.replace(globalImportRegex, `import '${importPath}'`);
|
|
672
|
-
} else if (!content.includes(importPath)) {
|
|
673
|
-
// Add new import after other imports
|
|
674
|
-
const importStatement = `import '${importPath}';\n`;
|
|
675
|
-
const importRegex = /^(import\s+.*?;\s*)+/m;
|
|
676
|
-
const importMatch = content.match(importRegex);
|
|
677
|
-
|
|
678
|
-
if (importMatch) {
|
|
679
|
-
const lastImportIndex = importMatch.index! + importMatch[0].length;
|
|
680
|
-
content =
|
|
681
|
-
content.slice(0, lastImportIndex) +
|
|
682
|
-
importStatement +
|
|
683
|
-
content.slice(lastImportIndex);
|
|
684
|
-
} else {
|
|
685
|
-
content = importStatement + content;
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
await fs.writeFile(layoutPath, content);
|
|
690
|
-
console.log(
|
|
691
|
-
chalk.gray(
|
|
692
|
-
`Updated ${path.relative(process.cwd(), layoutPath)} with CSS import`
|
|
693
|
-
)
|
|
694
|
-
);
|
|
695
|
-
} catch {
|
|
696
|
-
console.error(chalk.yellow('⚠️ Failed to update layout with CSS import'));
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
async function addDirectImportToLayout(layoutPath: string): Promise<void> {
|
|
701
|
-
try {
|
|
702
|
-
let content = await fs.readFile(layoutPath, 'utf-8');
|
|
703
|
-
const importStatement = `import '@foundrykit/tailwind/globals.css';\n`;
|
|
704
|
-
|
|
705
|
-
if (!content.includes('@foundrykit/tailwind/globals.css')) {
|
|
706
|
-
// Add import at the top of the file after any existing imports
|
|
707
|
-
const importRegex = /^(import\s+.*?;\s*)+/m;
|
|
708
|
-
const match = content.match(importRegex);
|
|
709
|
-
|
|
710
|
-
if (match) {
|
|
711
|
-
// Add after existing imports
|
|
712
|
-
const lastImportIndex = match.index! + match[0].length;
|
|
713
|
-
content =
|
|
714
|
-
content.slice(0, lastImportIndex) +
|
|
715
|
-
importStatement +
|
|
716
|
-
content.slice(lastImportIndex);
|
|
717
|
-
} else {
|
|
718
|
-
// Add at the very beginning
|
|
719
|
-
content = importStatement + content;
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
await fs.writeFile(layoutPath, content);
|
|
723
|
-
console.log(
|
|
724
|
-
chalk.green('✅ Added direct import of FoundryKit styles to layout')
|
|
725
|
-
);
|
|
726
|
-
}
|
|
727
|
-
} catch {
|
|
728
|
-
console.error(chalk.yellow('⚠️ Failed to add CSS import to layout'));
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
function resolveImportPath(fromFile: string, importPath: string): string {
|
|
733
|
-
if (importPath.startsWith('.')) {
|
|
734
|
-
// Relative import
|
|
735
|
-
return path.join(path.dirname(fromFile), importPath);
|
|
736
|
-
} else if (importPath.startsWith('@/')) {
|
|
737
|
-
// Alias import
|
|
738
|
-
return path.join(process.cwd(), importPath.replace('@/', 'src/'));
|
|
739
|
-
} else if (importPath.startsWith('/')) {
|
|
740
|
-
// Absolute import from project root
|
|
741
|
-
return path.join(process.cwd(), importPath);
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
// Default to relative from project root
|
|
745
|
-
return path.join(process.cwd(), importPath);
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
async function createDirectories(pathConfig: PathConfig): Promise<void> {
|
|
749
|
-
console.log(chalk.blue('📁 Creating component directories...'));
|
|
750
|
-
|
|
751
|
-
const dirs = [
|
|
752
|
-
pathConfig.primitives,
|
|
753
|
-
pathConfig.components,
|
|
754
|
-
pathConfig.blocks,
|
|
755
|
-
pathConfig.maps,
|
|
756
|
-
pathConfig.animations,
|
|
757
|
-
pathConfig.hooks,
|
|
758
|
-
pathConfig.lib,
|
|
759
|
-
];
|
|
760
|
-
|
|
761
|
-
for (const dir of dirs) {
|
|
762
|
-
const fullPath = path.join(process.cwd(), dir);
|
|
763
|
-
await fs.ensureDir(fullPath);
|
|
764
|
-
console.log(chalk.gray(`Created ${dir}`));
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
console.log(chalk.green('✅ Directories created'));
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
async function createExampleFiles(
|
|
771
|
-
pathConfig: PathConfig,
|
|
772
|
-
structure: ProjectStructure
|
|
773
|
-
): Promise<void> {
|
|
774
|
-
console.log(chalk.blue('📝 Creating example files...'));
|
|
775
|
-
|
|
776
|
-
// Create lib/utils.ts if it doesn't exist
|
|
777
|
-
const utilsPath = path.join(process.cwd(), pathConfig.utils);
|
|
778
|
-
const utilsContent = `import { type ClassValue, clsx } from 'clsx';
|
|
779
|
-
import { twMerge } from 'tailwind-merge';
|
|
780
|
-
|
|
781
|
-
export function cn(...inputs: ClassValue[]) {
|
|
782
|
-
return twMerge(clsx(inputs));
|
|
783
|
-
}
|
|
784
|
-
`;
|
|
785
|
-
|
|
786
|
-
await fs.ensureDir(path.dirname(utilsPath));
|
|
787
|
-
|
|
788
|
-
if (!fs.existsSync(utilsPath)) {
|
|
789
|
-
await fs.writeFile(utilsPath, utilsContent);
|
|
790
|
-
console.log(chalk.gray(`Created ${pathConfig.utils}`));
|
|
791
|
-
}
|
|
792
|
-
|
|
793
|
-
// Create providers.tsx for Next.js projects
|
|
794
|
-
const providersPath = path.join(
|
|
795
|
-
process.cwd(),
|
|
796
|
-
path.dirname(pathConfig.components),
|
|
797
|
-
`theme-provider${structure.isTypeScript ? '.tsx' : '.jsx'}`
|
|
798
|
-
);
|
|
799
|
-
|
|
800
|
-
const providersContent = `
|
|
801
|
-
'use client';
|
|
802
|
-
|
|
803
|
-
import type * as React from 'react';
|
|
804
|
-
import { ThemeProvider as NextThemesProvider } from 'next-themes';
|
|
805
|
-
|
|
806
|
-
export function ThemeProvider({ children }: { children: React.ReactNode }) {
|
|
807
|
-
return (
|
|
808
|
-
<NextThemesProvider
|
|
809
|
-
attribute='class'
|
|
810
|
-
defaultTheme='system'
|
|
811
|
-
enableSystem
|
|
812
|
-
disableTransitionOnChange
|
|
813
|
-
enableColorScheme
|
|
814
|
-
>
|
|
815
|
-
{children}
|
|
816
|
-
</NextThemesProvider>
|
|
817
|
-
);
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
`;
|
|
821
|
-
|
|
822
|
-
if (!fs.existsSync(providersPath)) {
|
|
823
|
-
await fs.writeFile(providersPath, providersContent);
|
|
824
|
-
console.log(
|
|
825
|
-
chalk.gray(
|
|
826
|
-
`Created theme-provider.${structure.isTypeScript ? 'tsx' : 'jsx'}`
|
|
827
|
-
)
|
|
828
|
-
);
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
console.log(chalk.green('✅ Example files created'));
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
async function updatePackageScripts(): Promise<void> {
|
|
835
|
-
console.log(chalk.blue('📝 Updating package.json scripts...'));
|
|
836
|
-
|
|
837
|
-
const packageJsonPath = path.join(process.cwd(), 'package.json');
|
|
838
|
-
const packageJson = await fs.readJson(packageJsonPath);
|
|
839
|
-
|
|
840
|
-
// Add foundrykit scripts
|
|
841
|
-
packageJson.scripts = {
|
|
842
|
-
...packageJson.scripts,
|
|
843
|
-
'foundrykit:add': 'pnpm dlx @foundrykit/cli add',
|
|
844
|
-
'foundrykit:update': 'pnpm dlx @foundrykit/cli update',
|
|
845
|
-
};
|
|
846
|
-
|
|
847
|
-
await fs.writeJson(packageJsonPath, packageJson, { spaces: 2 });
|
|
848
|
-
console.log(chalk.green('✅ Package scripts updated'));
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
async function createConfigFile(
|
|
852
|
-
options: InitOptions,
|
|
853
|
-
structure: ProjectStructure,
|
|
854
|
-
pathConfig: PathConfig
|
|
855
|
-
): Promise<void> {
|
|
856
|
-
console.log(chalk.blue('📝 Creating configuration file...'));
|
|
857
|
-
|
|
858
|
-
const configPath = path.join(process.cwd(), 'foundrykit.config.json');
|
|
859
|
-
|
|
860
|
-
if (fs.existsSync(configPath) && !options.force) {
|
|
861
|
-
console.log(chalk.yellow('⚠️ Configuration file already exists'));
|
|
862
|
-
return;
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
// Create configuration with custom paths
|
|
866
|
-
// Normalize paths - ensure they start with ./ if they're relative
|
|
867
|
-
const normalizePath = (p: string) => {
|
|
868
|
-
if (p.startsWith('./') || p.startsWith('../') || path.isAbsolute(p)) {
|
|
869
|
-
return p;
|
|
870
|
-
}
|
|
871
|
-
return `./${p}`;
|
|
872
|
-
};
|
|
873
|
-
|
|
874
|
-
const config = {
|
|
875
|
-
version: CLI_VERSION,
|
|
876
|
-
registry: DEFAULT_REGISTRY_URL,
|
|
877
|
-
paths: {
|
|
878
|
-
utils: normalizePath(pathConfig.utils),
|
|
879
|
-
primitives: normalizePath(pathConfig.primitives),
|
|
880
|
-
components: normalizePath(pathConfig.components),
|
|
881
|
-
blocks: normalizePath(pathConfig.blocks),
|
|
882
|
-
hooks: normalizePath(pathConfig.hooks),
|
|
883
|
-
maps: normalizePath(pathConfig.maps),
|
|
884
|
-
animations: normalizePath(pathConfig.animations),
|
|
885
|
-
},
|
|
886
|
-
packageManager: structure.packageManager,
|
|
887
|
-
typescript: structure.isTypeScript,
|
|
888
|
-
framework: structure.framework,
|
|
889
|
-
tailwind: {
|
|
890
|
-
css: normalizePath(pathConfig.styles),
|
|
891
|
-
},
|
|
892
|
-
aliases: {
|
|
893
|
-
'@': normalizePath(structure.baseDir.replace(/\/$/, '') || '.'),
|
|
894
|
-
'@/components': normalizePath(
|
|
895
|
-
path.dirname(pathConfig.components).replace(/\/$/, '')
|
|
896
|
-
),
|
|
897
|
-
'@/lib': normalizePath(pathConfig.lib.replace(/\/$/, '')),
|
|
898
|
-
'@/hooks': normalizePath(pathConfig.hooks.replace(/\/$/, '')),
|
|
899
|
-
},
|
|
900
|
-
};
|
|
901
|
-
|
|
902
|
-
await fs.writeJson(configPath, config, { spaces: 2 });
|
|
903
|
-
console.log(chalk.green('✅ Created foundrykit.config.json'));
|
|
904
|
-
}
|
|
905
|
-
|
|
906
|
-
async function installUtils(pathConfig: PathConfig): Promise<void> {
|
|
907
|
-
console.log(chalk.blue('📦 Installing utility functions...'));
|
|
908
|
-
|
|
909
|
-
const utilsPath = path.join(process.cwd(), pathConfig.utils);
|
|
910
|
-
const utilsContent = `import { type ClassValue, clsx } from 'clsx';
|
|
911
|
-
import { twMerge } from 'tailwind-merge';
|
|
912
|
-
|
|
913
|
-
export function cn(...inputs: ClassValue[]) {
|
|
914
|
-
return twMerge(clsx(inputs));
|
|
915
|
-
}
|
|
916
|
-
`;
|
|
917
|
-
|
|
918
|
-
// Ensure directory exists
|
|
919
|
-
const utilsDir = path.dirname(utilsPath);
|
|
920
|
-
await fs.ensureDir(utilsDir);
|
|
921
|
-
|
|
922
|
-
if (!fs.existsSync(utilsPath)) {
|
|
923
|
-
await fs.writeFile(utilsPath, utilsContent);
|
|
924
|
-
console.log(chalk.green('✅ Utility functions installed'));
|
|
925
|
-
} else {
|
|
926
|
-
console.log(chalk.gray('Utils file already exists, skipping...'));
|
|
927
|
-
}
|
|
928
|
-
}
|