@fragments-sdk/cli 0.15.0 → 0.15.1

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.
Files changed (118) hide show
  1. package/dist/{ai-client-I6MDWNYA.js → ai-client-LSLQGOMM.js} +1 -2
  2. package/dist/bin.js +463 -71
  3. package/dist/bin.js.map +1 -1
  4. package/dist/chunk-5JF26E55.js +1255 -0
  5. package/dist/chunk-5JF26E55.js.map +1 -0
  6. package/dist/{chunk-XJQ5BIWI.js → chunk-6SQPP47U.js} +30 -314
  7. package/dist/chunk-6SQPP47U.js.map +1 -0
  8. package/dist/{chunk-65WSVDV5.js → chunk-HQ6A6DTV.js} +1386 -1097
  9. package/dist/chunk-HQ6A6DTV.js.map +1 -0
  10. package/dist/chunk-MHIBEEW4.js +511 -0
  11. package/dist/chunk-MHIBEEW4.js.map +1 -0
  12. package/dist/{chunk-CZD3AD4Q.js → chunk-ONUP6Z4W.js} +17 -6
  13. package/dist/chunk-ONUP6Z4W.js.map +1 -0
  14. package/dist/{codebase-scanner-VOTPXRYW.js → codebase-scanner-MQHUZC2G.js} +1 -2
  15. package/dist/{converter-JLINP7CJ.js → converter-7XM3Y6NJ.js} +1 -2
  16. package/dist/{converter-JLINP7CJ.js.map → converter-7XM3Y6NJ.js.map} +1 -1
  17. package/dist/core/index.js +0 -1
  18. package/dist/create-IH4R45GE.js +806 -0
  19. package/dist/create-IH4R45GE.js.map +1 -0
  20. package/dist/{generate-A4FP5426.js → generate-PVOLUAAC.js} +3 -4
  21. package/dist/{generate-A4FP5426.js.map → generate-PVOLUAAC.js.map} +1 -1
  22. package/dist/{govern-scan-UCBZR6D6.js → govern-scan-OYFZYOQW.js} +142 -9
  23. package/dist/govern-scan-OYFZYOQW.js.map +1 -0
  24. package/dist/index.d.ts +2 -22
  25. package/dist/index.js +8 -7
  26. package/dist/index.js.map +1 -1
  27. package/dist/{init-HGSM35XA.js → init-SSGUSP7Z.js} +3 -4
  28. package/dist/{init-HGSM35XA.js.map → init-SSGUSP7Z.js.map} +1 -1
  29. package/dist/{init-cloud-MQ6GRJAZ.js → init-cloud-3DNKPWFB.js} +29 -4
  30. package/dist/{init-cloud-MQ6GRJAZ.js.map → init-cloud-3DNKPWFB.js.map} +1 -1
  31. package/dist/mcp-bin.js +1 -2
  32. package/dist/mcp-bin.js.map +1 -1
  33. package/dist/node-37AUE74M.js +65 -0
  34. package/dist/push-contracts-WY32TFP6.js +84 -0
  35. package/dist/push-contracts-WY32TFP6.js.map +1 -0
  36. package/dist/{scan-VNNKACG2.js → scan-PKSYSTRR.js} +5 -5
  37. package/dist/{scan-generate-TWRHNU5M.js → scan-generate-VY27PIOX.js} +8 -9
  38. package/dist/scan-generate-VY27PIOX.js.map +1 -0
  39. package/dist/{scanner-7LAZYPWZ.js → scanner-4KZNOXAK.js} +1 -2
  40. package/dist/{service-FHQU7YS7.js → service-QJGWUIVL.js} +16 -9
  41. package/dist/{snapshot-KQEQ6XHL.js → snapshot-WIJMEIFT.js} +1 -2
  42. package/dist/{snapshot-KQEQ6XHL.js.map → snapshot-WIJMEIFT.js.map} +1 -1
  43. package/dist/{static-viewer-63PG6FWY.js → static-viewer-7QIBQZRC.js} +1 -2
  44. package/dist/{test-UQYUCZIS.js → test-64Z5BKBA.js} +2 -3
  45. package/dist/{test-UQYUCZIS.js.map → test-64Z5BKBA.js.map} +1 -1
  46. package/dist/token-normalizer-TEPOVBPV.js +312 -0
  47. package/dist/token-normalizer-TEPOVBPV.js.map +1 -0
  48. package/dist/token-parser-32KOIOFN.js +22 -0
  49. package/dist/token-parser-32KOIOFN.js.map +1 -0
  50. package/dist/{tokens-6GYKDV6U.js → tokens-NZWFQIAB.js} +7 -7
  51. package/dist/{tokens-generate-VTZV5EEW.js → tokens-generate-5JQSJ27E.js} +1 -2
  52. package/dist/{tokens-generate-VTZV5EEW.js.map → tokens-generate-5JQSJ27E.js.map} +1 -1
  53. package/dist/tokens-push-HY3KO36V.js +148 -0
  54. package/dist/tokens-push-HY3KO36V.js.map +1 -0
  55. package/package.json +5 -3
  56. package/src/bin.ts +90 -0
  57. package/src/commands/__fixtures__/shadcn-label-wrapper/src/components/ui/label.contract.json +1 -1
  58. package/src/commands/__fixtures__/shadcn-label-wrapper/src/components/ui/primitive.contract.json +1 -1
  59. package/src/commands/__tests__/build-freshness.test.ts +231 -0
  60. package/src/commands/__tests__/create.test.ts +71 -0
  61. package/src/commands/__tests__/drift-sync.test.ts +1 -1
  62. package/src/commands/__tests__/govern.test.ts +258 -0
  63. package/src/commands/__tests__/init.test.ts +1 -1
  64. package/src/commands/__tests__/scan-generate.test.ts +1 -1
  65. package/src/commands/build.ts +54 -1
  66. package/src/commands/context.ts +1 -1
  67. package/src/commands/create.ts +536 -0
  68. package/src/commands/doctor.ts +3 -2
  69. package/src/commands/govern-scan.ts +187 -8
  70. package/src/commands/govern.ts +65 -2
  71. package/src/commands/init-cloud.ts +32 -4
  72. package/src/commands/push-contracts.ts +112 -0
  73. package/src/commands/scan-generate.ts +1 -1
  74. package/src/commands/scan.ts +13 -0
  75. package/src/commands/sync.ts +2 -2
  76. package/src/commands/tokens-push.ts +199 -0
  77. package/src/core/__tests__/token-resolver.test.ts +1 -1
  78. package/src/core/component-extractor.test.ts +1 -1
  79. package/src/core/drift-verifier.ts +1 -1
  80. package/src/core/extractor-adapter.ts +1 -1
  81. package/src/index.ts +3 -3
  82. package/src/migrate/fragment-to-contract.ts +2 -2
  83. package/src/service/index.ts +8 -0
  84. package/src/service/tailwind-v4-parser.ts +314 -0
  85. package/src/service/token-parser.ts +56 -0
  86. package/src/setup.ts +10 -39
  87. package/src/theme/__tests__/component-contrast.test.ts +2 -2
  88. package/src/theme/__tests__/serializer.test.ts +1 -1
  89. package/src/theme/generator.ts +16 -1
  90. package/src/theme/schema.ts +8 -0
  91. package/src/theme/serializer.ts +13 -9
  92. package/src/theme/types.ts +8 -0
  93. package/src/validators.ts +1 -2
  94. package/dist/chunk-65WSVDV5.js.map +0 -1
  95. package/dist/chunk-7WHVW72L.js +0 -2664
  96. package/dist/chunk-7WHVW72L.js.map +0 -1
  97. package/dist/chunk-CZD3AD4Q.js.map +0 -1
  98. package/dist/chunk-MN3TJ3D5.js +0 -695
  99. package/dist/chunk-MN3TJ3D5.js.map +0 -1
  100. package/dist/chunk-XJQ5BIWI.js.map +0 -1
  101. package/dist/chunk-Z7EY4VHE.js +0 -50
  102. package/dist/govern-scan-UCBZR6D6.js.map +0 -1
  103. package/dist/sass.node-4XJK6YBF.js +0 -130708
  104. package/dist/sass.node-4XJK6YBF.js.map +0 -1
  105. package/dist/scan-generate-TWRHNU5M.js.map +0 -1
  106. package/src/build.ts +0 -736
  107. package/src/core/auto-props.ts +0 -464
  108. package/src/core/component-extractor.ts +0 -1121
  109. package/src/core/token-resolver.ts +0 -155
  110. package/src/viewer/preview-adapter.ts +0 -116
  111. /package/dist/{ai-client-I6MDWNYA.js.map → ai-client-LSLQGOMM.js.map} +0 -0
  112. /package/dist/{chunk-Z7EY4VHE.js.map → codebase-scanner-MQHUZC2G.js.map} +0 -0
  113. /package/dist/{codebase-scanner-VOTPXRYW.js.map → node-37AUE74M.js.map} +0 -0
  114. /package/dist/{scan-VNNKACG2.js.map → scan-PKSYSTRR.js.map} +0 -0
  115. /package/dist/{scanner-7LAZYPWZ.js.map → scanner-4KZNOXAK.js.map} +0 -0
  116. /package/dist/{service-FHQU7YS7.js.map → service-QJGWUIVL.js.map} +0 -0
  117. /package/dist/{static-viewer-63PG6FWY.js.map → static-viewer-7QIBQZRC.js.map} +0 -0
  118. /package/dist/{tokens-6GYKDV6U.js.map → tokens-NZWFQIAB.js.map} +0 -0
@@ -0,0 +1,536 @@
1
+ /**
2
+ * fragments create - Scaffold a new project with Fragments UI and a custom theme
3
+ *
4
+ * Mirrors the shadcn model: configure on the web (usefragments.com/create),
5
+ * then `npx @fragments-sdk/cli create` bootstraps a project with that config.
6
+ */
7
+
8
+ import { execSync } from 'node:child_process';
9
+ import { existsSync, mkdirSync, writeFileSync, readFileSync, unlinkSync } from 'node:fs';
10
+ import { join, resolve } from 'node:path';
11
+ import pc from 'picocolors';
12
+ import { BRAND } from '../core/index.js';
13
+ import { decompressTheme } from '../theme/serializer.js';
14
+ import { generateCssTokens, generateScssTokens } from '../theme/generator.js';
15
+ import type { ThemeConfig } from '../theme/types.js';
16
+
17
+ // ============================================
18
+ // Types
19
+ // ============================================
20
+
21
+ export interface CreateOptions {
22
+ name?: string;
23
+ template?: 'nextjs' | 'vite';
24
+ packageManager?: 'npm' | 'pnpm' | 'yarn' | 'bun';
25
+ theme?: string;
26
+ preset?: string;
27
+ brand?: string;
28
+ scss?: boolean;
29
+ mcp?: boolean;
30
+ yes?: boolean;
31
+ noGit?: boolean;
32
+ }
33
+
34
+ export interface CreateResult {
35
+ success: boolean;
36
+ projectDir?: string;
37
+ error?: string;
38
+ }
39
+
40
+ // ============================================
41
+ // Package Manager Detection
42
+ // ============================================
43
+
44
+ function detectPackageManager(): 'npm' | 'pnpm' | 'yarn' | 'bun' {
45
+ const agent = process.env.npm_config_user_agent || '';
46
+ if (agent.startsWith('pnpm')) return 'pnpm';
47
+ if (agent.startsWith('yarn')) return 'yarn';
48
+ if (agent.startsWith('bun')) return 'bun';
49
+ return 'npm';
50
+ }
51
+
52
+ function getInstallCommand(pm: string): string {
53
+ return pm === 'yarn' ? 'yarn add' : `${pm} add`;
54
+ }
55
+
56
+ function getDevInstallCommand(pm: string): string {
57
+ return pm === 'yarn' ? 'yarn add -D' : `${pm} add -D`;
58
+ }
59
+
60
+ function getRunCommand(pm: string): string {
61
+ return pm === 'npm' ? 'npm run' : pm;
62
+ }
63
+
64
+ // ============================================
65
+ // Validation
66
+ // ============================================
67
+
68
+ function isValidProjectName(name: string): boolean {
69
+ return /^[a-z0-9][a-z0-9._-]*$/.test(name);
70
+ }
71
+
72
+ // ============================================
73
+ // Theme Resolution
74
+ // ============================================
75
+
76
+ const PRESET_API_URL = 'https://canny-otter-874.convex.site/api/theme-presets';
77
+
78
+ async function fetchPreset(presetId: string): Promise<ThemeConfig | null> {
79
+ try {
80
+ const res = await fetch(`${PRESET_API_URL}?id=${encodeURIComponent(presetId)}`);
81
+ if (!res.ok) return null;
82
+ const theme = await res.json();
83
+ if (!theme || !theme.name) return null;
84
+ return theme as ThemeConfig;
85
+ } catch {
86
+ return null;
87
+ }
88
+ }
89
+
90
+ async function resolveTheme(options: CreateOptions): Promise<ThemeConfig | null> {
91
+ if (options.preset) {
92
+ console.log(pc.dim(` Fetching theme preset ${options.preset}...`));
93
+ const theme = await fetchPreset(options.preset);
94
+ if (!theme) {
95
+ console.error(pc.red(`Error: Could not fetch preset "${options.preset}". It may have expired or the ID is invalid.`));
96
+ return null;
97
+ }
98
+ return theme;
99
+ }
100
+
101
+ if (options.theme) {
102
+ const decoded = decompressTheme(options.theme);
103
+ if (!decoded) {
104
+ console.error(pc.red('Error: Could not decode theme string. Make sure you copied it from usefragments.com/create'));
105
+ return null;
106
+ }
107
+ return decoded;
108
+ }
109
+
110
+ if (options.brand) {
111
+ return {
112
+ name: 'custom',
113
+ colors: {
114
+ accent: options.brand,
115
+ },
116
+ };
117
+ }
118
+
119
+ return {
120
+ name: 'default',
121
+ colors: {
122
+ accent: '#6366f1',
123
+ },
124
+ };
125
+ }
126
+
127
+ // ============================================
128
+ // Templates
129
+ // ============================================
130
+
131
+ export function generateNextjsLayout(themePath: string): string {
132
+ return `import type { Metadata } from 'next';
133
+ import '@fragments-sdk/ui/styles';
134
+ import '${themePath}';
135
+ import { Providers } from './providers';
136
+
137
+ export const metadata: Metadata = {
138
+ title: 'My App',
139
+ description: 'Built with Fragments UI',
140
+ };
141
+
142
+ export default function RootLayout({
143
+ children,
144
+ }: {
145
+ children: React.ReactNode;
146
+ }) {
147
+ return (
148
+ <html lang="en" suppressHydrationWarning>
149
+ <body>
150
+ <Providers>{children}</Providers>
151
+ </body>
152
+ </html>
153
+ );
154
+ }
155
+ `;
156
+ }
157
+
158
+ export function generateNextjsProviders(): string {
159
+ return `'use client';
160
+
161
+ import type { ReactNode } from 'react';
162
+ import { ThemeProvider, TooltipProvider, ToastProvider } from '@fragments-sdk/ui';
163
+
164
+ export function Providers({ children }: { children: ReactNode }) {
165
+ return (
166
+ <ThemeProvider defaultMode="system">
167
+ <TooltipProvider>
168
+ <ToastProvider>{children}</ToastProvider>
169
+ </TooltipProvider>
170
+ </ThemeProvider>
171
+ );
172
+ }
173
+ `;
174
+ }
175
+
176
+ export function generateNextjsPage(): string {
177
+ return `'use client';
178
+
179
+ import { Button, Card, Stack, Text, Input } from '@fragments-sdk/ui';
180
+
181
+ export default function Home() {
182
+ return (
183
+ <main style={{ minHeight: '100vh', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
184
+ <Card style={{ maxWidth: 480, width: '100%' }}>
185
+ <Card.Header>
186
+ <Card.Title>Welcome to Fragments</Card.Title>
187
+ <Card.Description>Your app is ready. Start building something great.</Card.Description>
188
+ </Card.Header>
189
+ <Card.Body>
190
+ <Stack gap={3}>
191
+ <Input placeholder="Enter something..." />
192
+ <Stack direction="row" gap={2}>
193
+ <Button>Get Started</Button>
194
+ <Button variant="secondary">Learn More</Button>
195
+ </Stack>
196
+ </Stack>
197
+ </Card.Body>
198
+ </Card>
199
+ </main>
200
+ );
201
+ }
202
+ `;
203
+ }
204
+
205
+ function generateViteMain(themePath: string): string {
206
+ return `import { StrictMode } from 'react';
207
+ import { createRoot } from 'react-dom/client';
208
+ import { ThemeProvider, TooltipProvider, ToastProvider } from '@fragments-sdk/ui';
209
+ import '@fragments-sdk/ui/styles';
210
+ import '${themePath}';
211
+ import App from './App';
212
+
213
+ createRoot(document.getElementById('root')!).render(
214
+ <StrictMode>
215
+ <ThemeProvider defaultMode="system">
216
+ <TooltipProvider>
217
+ <ToastProvider>
218
+ <App />
219
+ </ToastProvider>
220
+ </TooltipProvider>
221
+ </ThemeProvider>
222
+ </StrictMode>,
223
+ );
224
+ `;
225
+ }
226
+
227
+ function generateViteApp(): string {
228
+ return `import { Button, Card, Stack, Text, Input } from '@fragments-sdk/ui';
229
+
230
+ function App() {
231
+ return (
232
+ <main style={{ minHeight: '100vh', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
233
+ <Card style={{ maxWidth: 480, width: '100%' }}>
234
+ <Card.Header>
235
+ <Card.Title>Welcome to Fragments</Card.Title>
236
+ <Card.Description>Your app is ready. Start building something great.</Card.Description>
237
+ </Card.Header>
238
+ <Card.Body>
239
+ <Stack gap={3}>
240
+ <Input placeholder="Enter something..." />
241
+ <Stack direction="row" gap={2}>
242
+ <Button>Get Started</Button>
243
+ <Button variant="secondary">Learn More</Button>
244
+ </Stack>
245
+ </Stack>
246
+ </Card.Body>
247
+ </Card>
248
+ </main>
249
+ );
250
+ }
251
+
252
+ export default App;
253
+ `;
254
+ }
255
+
256
+ // ============================================
257
+ // Scaffolding
258
+ // ============================================
259
+
260
+ async function promptIfMissing(options: CreateOptions): Promise<CreateOptions> {
261
+ const resolved = { ...options };
262
+
263
+ if (!resolved.name) {
264
+ if (resolved.yes) {
265
+ resolved.name = 'my-app';
266
+ } else {
267
+ try {
268
+ const { input } = await import('@inquirer/prompts');
269
+ resolved.name = await input({
270
+ message: 'Project name:',
271
+ default: 'my-app',
272
+ validate: (val) => isValidProjectName(val) || 'Use lowercase letters, numbers, hyphens, dots, underscores',
273
+ });
274
+ } catch {
275
+ resolved.name = 'my-app';
276
+ }
277
+ }
278
+ }
279
+
280
+ if (!resolved.template && !resolved.yes) {
281
+ try {
282
+ const { select } = await import('@inquirer/prompts');
283
+ resolved.template = await select({
284
+ message: 'Framework:',
285
+ choices: [
286
+ { name: 'Next.js (App Router)', value: 'nextjs' as const },
287
+ { name: 'Vite + React', value: 'vite' as const },
288
+ ],
289
+ default: 'nextjs',
290
+ });
291
+ } catch {
292
+ resolved.template = 'nextjs';
293
+ }
294
+ }
295
+
296
+ resolved.template = resolved.template || 'nextjs';
297
+ resolved.packageManager = resolved.packageManager || detectPackageManager();
298
+
299
+ return resolved;
300
+ }
301
+
302
+ function scaffoldFramework(name: string, template: string, pm: string): void {
303
+ console.log(pc.cyan(`\nScaffolding ${template === 'nextjs' ? 'Next.js' : 'Vite + React'} project...\n`));
304
+
305
+ if (template === 'nextjs') {
306
+ const cmd = `npx create-next-app@latest ${name} --ts --app --src-dir --no-tailwind --no-eslint --import-alias "@/*" --yes`;
307
+ execSync(cmd, { stdio: 'inherit' });
308
+ } else {
309
+ // Vite
310
+ if (pm === 'bun') {
311
+ execSync(`bun create vite ${name} --template react-ts`, { stdio: 'inherit' });
312
+ } else {
313
+ execSync(`npm create vite@latest ${name} -- --template react-ts`, { stdio: 'inherit' });
314
+ }
315
+ }
316
+ }
317
+
318
+ function installDeps(projectDir: string, pm: string, scss: boolean): void {
319
+ console.log(pc.cyan('\nInstalling Fragments UI...\n'));
320
+
321
+ const install = getInstallCommand(pm);
322
+ execSync(`${install} @fragments-sdk/ui`, { cwd: projectDir, stdio: 'inherit' });
323
+
324
+ if (scss) {
325
+ const devInstall = getDevInstallCommand(pm);
326
+ execSync(`${devInstall} sass`, { cwd: projectDir, stdio: 'inherit' });
327
+ }
328
+ }
329
+
330
+ function writeThemeFile(projectDir: string, theme: ThemeConfig, scss: boolean, template: string): string {
331
+ const stylesDir = join(projectDir, 'src', 'styles');
332
+ mkdirSync(stylesDir, { recursive: true });
333
+
334
+ const ext = scss ? 'scss' : 'css';
335
+ const content = scss ? generateScssTokens(theme) : generateCssTokens(theme);
336
+ const filePath = join(stylesDir, `theme.${ext}`);
337
+ writeFileSync(filePath, content, 'utf-8');
338
+
339
+ // Next.js layout is at src/app/layout.tsx → relative path is ../styles/theme.ext
340
+ // Vite main is at src/main.tsx → relative path is ./styles/theme.ext
341
+ if (template === 'nextjs') {
342
+ return `../styles/theme.${ext}`;
343
+ }
344
+ return `./styles/theme.${ext}`;
345
+ }
346
+
347
+ export function addNextTranspilePackages(projectDir: string): void {
348
+ const configCandidates = ['next.config.ts', 'next.config.mjs', 'next.config.js'];
349
+
350
+ for (const configFile of configCandidates) {
351
+ const fullPath = join(projectDir, configFile);
352
+ if (!existsSync(fullPath)) continue;
353
+
354
+ const content = readFileSync(fullPath, 'utf-8');
355
+
356
+ if (content.includes('transpilePackages') && content.includes('@fragments-sdk/ui')) {
357
+ return;
358
+ }
359
+
360
+ if (content.includes('transpilePackages')) {
361
+ return;
362
+ }
363
+
364
+ const patterns = [
365
+ {
366
+ search: /const\s+\w+\s*(?::\s*\w+)?\s*=\s*\{/,
367
+ replacement: (match: string) => `${match}\n transpilePackages: ['@fragments-sdk/ui'],`,
368
+ },
369
+ {
370
+ search: /module\.exports\s*=\s*\{/,
371
+ replacement: (match: string) => `${match}\n transpilePackages: ['@fragments-sdk/ui'],`,
372
+ },
373
+ {
374
+ search: /export\s+default\s*\{/,
375
+ replacement: (match: string) => `${match}\n transpilePackages: ['@fragments-sdk/ui'],`,
376
+ },
377
+ ];
378
+
379
+ for (const pattern of patterns) {
380
+ if (!pattern.search.test(content)) continue;
381
+
382
+ writeFileSync(
383
+ fullPath,
384
+ content.replace(pattern.search, pattern.replacement),
385
+ 'utf-8',
386
+ );
387
+ return;
388
+ }
389
+
390
+ return;
391
+ }
392
+ }
393
+
394
+ function rewriteAppFiles(projectDir: string, template: string, themePath: string): void {
395
+ if (template === 'nextjs') {
396
+ // Rewrite layout.tsx
397
+ const layoutPath = join(projectDir, 'src', 'app', 'layout.tsx');
398
+ writeFileSync(layoutPath, generateNextjsLayout(themePath), 'utf-8');
399
+
400
+ const providersPath = join(projectDir, 'src', 'app', 'providers.tsx');
401
+ writeFileSync(providersPath, generateNextjsProviders(), 'utf-8');
402
+
403
+ // Rewrite page.tsx
404
+ const pagePath = join(projectDir, 'src', 'app', 'page.tsx');
405
+ writeFileSync(pagePath, generateNextjsPage(), 'utf-8');
406
+
407
+ // Remove default page.module.css if it exists
408
+ const moduleCssPath = join(projectDir, 'src', 'app', 'page.module.css');
409
+ try {
410
+ unlinkSync(moduleCssPath);
411
+ } catch { /* doesn't exist, that's fine */ }
412
+
413
+ // Remove globals.css if it exists (we use our own theme)
414
+ const globalsCssPath = join(projectDir, 'src', 'app', 'globals.css');
415
+ try {
416
+ unlinkSync(globalsCssPath);
417
+ } catch { /* doesn't exist */ }
418
+
419
+ addNextTranspilePackages(projectDir);
420
+ } else {
421
+ // Vite: rewrite main.tsx and App.tsx
422
+ const mainPath = join(projectDir, 'src', 'main.tsx');
423
+ writeFileSync(mainPath, generateViteMain(themePath), 'utf-8');
424
+
425
+ const appPath = join(projectDir, 'src', 'App.tsx');
426
+ writeFileSync(appPath, generateViteApp(), 'utf-8');
427
+
428
+ // Clean up default Vite files
429
+ for (const file of ['src/App.css', 'src/index.css']) {
430
+ try {
431
+ unlinkSync(join(projectDir, file));
432
+ } catch { /* doesn't exist */ }
433
+ }
434
+ }
435
+ }
436
+
437
+ function initGit(projectDir: string): void {
438
+ try {
439
+ // create-next-app already inits git, so check first
440
+ if (!existsSync(join(projectDir, '.git'))) {
441
+ execSync('git init', { cwd: projectDir, stdio: 'ignore' });
442
+ execSync('git add -A', { cwd: projectDir, stdio: 'ignore' });
443
+ execSync('git commit -m "Initial commit with Fragments UI"', { cwd: projectDir, stdio: 'ignore' });
444
+ }
445
+ } catch {
446
+ // Git not available — skip silently
447
+ }
448
+ }
449
+
450
+ function configureMcp(projectDir: string): void {
451
+ const mcpConfig = {
452
+ mcpServers: {
453
+ fragments: {
454
+ command: 'npx',
455
+ args: ['-y', '@fragments-sdk/cli', 'mcp'],
456
+ },
457
+ },
458
+ };
459
+
460
+ const mcpDir = join(projectDir, '.mcp');
461
+ mkdirSync(mcpDir, { recursive: true });
462
+ writeFileSync(join(mcpDir, 'config.json'), JSON.stringify(mcpConfig, null, 2), 'utf-8');
463
+ }
464
+
465
+ // ============================================
466
+ // Main
467
+ // ============================================
468
+
469
+ export async function create(options: CreateOptions): Promise<CreateResult> {
470
+ console.log(pc.cyan(`\n${BRAND.name} Create\n`));
471
+
472
+ // 1. Gather inputs
473
+ const resolved = await promptIfMissing(options);
474
+ const name = resolved.name!;
475
+ const template = resolved.template!;
476
+ const pm = resolved.packageManager!;
477
+
478
+ // 2. Validate
479
+ if (!isValidProjectName(name)) {
480
+ return { success: false, error: `Invalid project name: ${name}. Use lowercase letters, numbers, hyphens, dots, underscores.` };
481
+ }
482
+
483
+ const projectDir = resolve(process.cwd(), name);
484
+ if (existsSync(projectDir)) {
485
+ return { success: false, error: `Directory "${name}" already exists.` };
486
+ }
487
+
488
+ // 3. Resolve theme
489
+ const theme = await resolveTheme(resolved);
490
+ if (!theme) {
491
+ return { success: false, error: 'Invalid theme configuration.' };
492
+ }
493
+
494
+ // 4. Scaffold framework
495
+ scaffoldFramework(name, template, pm);
496
+
497
+ if (!existsSync(projectDir)) {
498
+ return { success: false, error: 'Framework scaffolding failed — project directory was not created.' };
499
+ }
500
+
501
+ // 5. Install deps
502
+ installDeps(projectDir, pm, !!resolved.scss);
503
+
504
+ // 6. Write theme tokens
505
+ const themePath = writeThemeFile(projectDir, theme, !!resolved.scss, template);
506
+
507
+ // 7. Rewrite app files with providers + theme import
508
+ rewriteAppFiles(projectDir, template, themePath);
509
+
510
+ // 8. MCP config
511
+ if (resolved.mcp) {
512
+ configureMcp(projectDir);
513
+ console.log(pc.dim(' Configured MCP server for AI tooling'));
514
+ }
515
+
516
+ // 9. Git init
517
+ if (!resolved.noGit) {
518
+ initGit(projectDir);
519
+ }
520
+
521
+ // 10. Success message
522
+ const run = getRunCommand(pm);
523
+ console.log('');
524
+ console.log(pc.green(' Project created successfully!'));
525
+ console.log('');
526
+ console.log(` ${pc.cyan('cd')} ${name}`);
527
+ console.log(` ${pc.cyan(run)} dev`);
528
+ console.log('');
529
+
530
+ if (theme.name !== 'default') {
531
+ console.log(pc.dim(` Theme "${theme.name}" applied with full token set.`));
532
+ console.log(pc.dim(` Edit src/styles/theme.${resolved.scss ? 'scss' : 'css'} to customize.\n`));
533
+ }
534
+
535
+ return { success: true, projectDir };
536
+ }
@@ -13,6 +13,7 @@ import { readFile, access } from 'node:fs/promises';
13
13
  import { join, resolve } from 'node:path';
14
14
  import pc from 'picocolors';
15
15
  import { BRAND } from '../core/index.js';
16
+ import { NEUTRAL_PALETTES } from '@fragments-sdk/viewer/docs-data';
16
17
 
17
18
  // ============================================
18
19
  // Types
@@ -43,10 +44,10 @@ export interface DoctorResult {
43
44
  }
44
45
 
45
46
  // ============================================
46
- // Valid seed values (match _seeds.scss)
47
+ // Valid seed values derived from canonical sources
47
48
  // ============================================
48
49
 
49
- const VALID_NEUTRALS = ['stone', 'ice', 'earth', 'sand', 'fire'];
50
+ const VALID_NEUTRALS = NEUTRAL_PALETTES.map((p) => p.name);
50
51
  const VALID_DENSITIES = ['compact', 'default', 'relaxed'];
51
52
  const VALID_RADII = ['sharp', 'subtle', 'default', 'rounded', 'pill'];
52
53