create-swift-rust 0.7.0 → 0.8.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.
Files changed (31) hide show
  1. package/dist/index.js +1030 -39
  2. package/dist/index.js.map +1 -1
  3. package/package.json +1 -1
  4. package/templates/default/src/app/about/page.tsx +6 -6
  5. package/templates/default/src/app/about/team/page.tsx +6 -6
  6. package/templates/default/src/app/blog/[slug]/page.tsx +24 -16
  7. package/templates/default/src/app/blog/page.tsx +36 -18
  8. package/templates/default/src/app/blog/tag/[tag]/page.tsx +8 -8
  9. package/templates/default/src/app/contact/page.tsx +8 -8
  10. package/templates/default/src/app/dashboard/analytics/page.tsx +12 -12
  11. package/templates/default/src/app/dashboard/loading.tsx +8 -8
  12. package/templates/default/src/app/dashboard/page.tsx +36 -27
  13. package/templates/default/src/app/dashboard/posts/[id]/not-found.tsx +2 -2
  14. package/templates/default/src/app/dashboard/posts/[id]/page.tsx +5 -5
  15. package/templates/default/src/app/dashboard/posts/new/page.tsx +15 -10
  16. package/templates/default/src/app/dashboard/posts/page.tsx +7 -7
  17. package/templates/default/src/app/dashboard/settings/page.tsx +39 -17
  18. package/templates/default/src/app/error.tsx +2 -2
  19. package/templates/default/src/app/fonts/page.tsx +39 -39
  20. package/templates/default/src/app/images/page.tsx +53 -15
  21. package/templates/default/src/app/layout.tsx +1 -1
  22. package/templates/default/src/app/loading.tsx +5 -5
  23. package/templates/default/src/app/not-found.tsx +2 -2
  24. package/templates/default/src/app/page.tsx +114 -72
  25. package/templates/default/src/app/videos/page.tsx +22 -22
  26. package/templates/default/src/components/font-studio.tsx +37 -37
  27. package/templates/default/src/components/footer.tsx +5 -5
  28. package/templates/default/src/components/logo.tsx +2 -2
  29. package/templates/default/src/components/nav.tsx +28 -10
  30. package/templates/default/src/components/sidebar.tsx +10 -10
  31. package/templates/default/tsconfig.json +0 -2
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import { basename, dirname, join, resolve } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import * as p from "@clack/prompts";
7
7
  import pc from "picocolors";
8
- /** Locate the bundled template dir, both from src/ (dev) and dist/ (published). */
8
+ /** Locate the bundled full-demo template (src/ in dev, dist/ when published). */
9
9
  function templateDir() {
10
10
  const here = dirname(fileURLToPath(import.meta.url));
11
11
  for (const candidate of [
@@ -17,10 +17,16 @@ function templateDir() {
17
17
  }
18
18
  return resolve(here, "..", "templates", "default");
19
19
  }
20
- /**
21
- * Copy the full-demo template into `target`, restoring underscore-prefixed
22
- * dotfiles and substituting the project name placeholder.
23
- */
20
+ async function writeVscodeConfig(target) {
21
+ await mkdir(join(target, ".vscode"), { recursive: true });
22
+ await writeFile(join(target, ".vscode", "settings.json"), `${JSON.stringify({
23
+ "css.lint.unknownAtRules": "ignore",
24
+ "scss.lint.unknownAtRules": "ignore",
25
+ "less.lint.unknownAtRules": "ignore",
26
+ }, null, 2)}\n`);
27
+ await writeFile(join(target, ".vscode", "extensions.json"), `${JSON.stringify({ recommendations: ["bradlc.vscode-tailwindcss", "biomejs.biome"] }, null, 2)}\n`);
28
+ }
29
+ /** Copy the full-demo template into `target` (restores dotfiles, substitutes name). */
24
30
  async function copyTemplate(target, projectName) {
25
31
  const src = templateDir();
26
32
  if (!existsSync(src)) {
@@ -28,18 +34,15 @@ async function copyTemplate(target, projectName) {
28
34
  }
29
35
  await mkdir(target, { recursive: true });
30
36
  await cp(src, target, { recursive: true });
31
- // Restore real dotfile names (npm mangles dotfiles inside packages).
32
- const dotfiles = [
37
+ for (const [from, to] of [
33
38
  ["_gitignore", ".gitignore"],
34
39
  ["_env.example", ".env.example"],
35
40
  ["_env.local", ".env.local"],
36
- ];
37
- for (const [from, to] of dotfiles) {
41
+ ]) {
38
42
  const fromPath = join(target, from);
39
43
  if (existsSync(fromPath))
40
44
  await rename(fromPath, join(target, to));
41
45
  }
42
- // Substitute the project name in package.json + README.
43
46
  const displayName = projectName === "." ? basename(resolve(target)) : projectName;
44
47
  for (const file of ["package.json", "README.md"]) {
45
48
  const path = join(target, file);
@@ -48,6 +51,7 @@ async function copyTemplate(target, projectName) {
48
51
  const contents = await readFile(path, "utf8");
49
52
  await writeFile(path, contents.split("__PROJECT_NAME__").join(displayName));
50
53
  }
54
+ await writeVscodeConfig(target);
51
55
  }
52
56
  async function pathExists(path) {
53
57
  try {
@@ -73,16 +77,33 @@ function normalizeProjectName(name) {
73
77
  return ".";
74
78
  return t.replace(/\/+$/, "");
75
79
  }
80
+ function isValidAlias(alias) {
81
+ return /^[a-zA-Z@][a-zA-Z0-9_/*-]*$/.test(alias);
82
+ }
76
83
  const HELP = `
77
84
  ${pc.bold("create-swift-rust")} - scaffold a new swift-rust project
78
85
 
79
86
  ${pc.bold("Usage")}
80
87
  ${pc.cyan("bun create swift-rust@latest")} [project-name] [options]
81
88
 
82
- Scaffolds the full-demo starter: blog, dashboard, API routes, and the
83
- Image / PDF / Video / Font components — TypeScript, Tailwind, Biome, src/app.
84
-
85
89
  ${pc.bold("Options")}
90
+ ${pc.yellow("--full")} Scaffold the full demo (default; opinionated)
91
+ ${pc.yellow("--minimal")} Scaffold a minimal app (configurable below)
92
+ ${pc.yellow("--ts, --typescript")} Use TypeScript (default)
93
+ ${pc.yellow("--js, --javascript")} Use JavaScript
94
+ ${pc.yellow("--tailwind")} Install Tailwind CSS
95
+ ${pc.yellow("--no-tailwind")} Skip Tailwind CSS
96
+ ${pc.yellow("--shadcn")} Install shadcn-style UI components (default)
97
+ ${pc.yellow("--no-shadcn")} Skip shadcn UI components
98
+ ${pc.yellow("--src-dir")} Use a src/ directory (src/app) (default)
99
+ ${pc.yellow("--no-src-dir")} Use top-level app/
100
+ ${pc.yellow("--biome")} Use Biome for linting (default)
101
+ ${pc.yellow("--eslint")} Use ESLint for linting
102
+ ${pc.yellow("--import-alias <prefix>")} Set import alias (default "@/*")
103
+ ${pc.yellow("--ssr")} Server-side rendering
104
+ ${pc.yellow("--ssr-wasm")} SSR with WASM hydration (default)
105
+ ${pc.yellow("--ssr-htmx")} SSR with HTMX
106
+ ${pc.yellow("--wasm")} Full WASM SPA
86
107
  ${pc.yellow("--install")} Run bun install after scaffolding
87
108
  ${pc.yellow("--no-install")} Skip bun install (default)
88
109
  ${pc.yellow("--yes, -y")} Skip prompts, use defaults
@@ -90,8 +111,8 @@ ${pc.bold("Options")}
90
111
 
91
112
  ${pc.bold("Examples")}
92
113
  ${pc.cyan("bun create swift-rust@latest")}
93
- ${pc.cyan("bun create swift-rust@latest my-app --install")}
94
- ${pc.cyan("bun create swift-rust@latest ./")}
114
+ ${pc.cyan("bun create swift-rust@latest my-app --ts --tailwind --src-dir")}
115
+ ${pc.cyan("bun create swift-rust@latest ./ --tailwind --eslint")}
95
116
  `;
96
117
  function parseFlags(args) {
97
118
  const flags = {};
@@ -103,6 +124,12 @@ function parseFlags(args) {
103
124
  flags.language = "ts";
104
125
  else if (a === "--js" || a === "--javascript")
105
126
  flags.language = "js";
127
+ else if (a === "--full" || a === "--full-demo")
128
+ flags.template = "full";
129
+ else if (a === "--minimal")
130
+ flags.template = "minimal";
131
+ else if (a === "--template")
132
+ flags.template = args[++i];
106
133
  else if (a === "--tailwind")
107
134
  flags.tailwind = true;
108
135
  else if (a === "--no-tailwind")
@@ -144,6 +171,24 @@ function parseFlags(args) {
144
171
  }
145
172
  return flags;
146
173
  }
174
+ const RENDERER_OPTIONS = [
175
+ {
176
+ value: "ssr-wasm",
177
+ label: "SSR + WASM hydration",
178
+ hint: "Default. Server-rendered HTML, WASM-hydrated interactive islands.",
179
+ },
180
+ { value: "ssr", label: "SSR only", hint: "Server-rendered HTML, no client JavaScript at all." },
181
+ {
182
+ value: "ssr-htmx",
183
+ label: "SSR + HTMX",
184
+ hint: "Progressive enhancement with HTMX-style interactions.",
185
+ },
186
+ {
187
+ value: "wasm",
188
+ label: "Full WASM SPA",
189
+ hint: "Single-page app compiled entirely to WebAssembly.",
190
+ },
191
+ ];
147
192
  async function askQuestions(flags, positional) {
148
193
  const yesMode = flags.yes === true;
149
194
  const projectName = positional ??
@@ -165,8 +210,190 @@ async function askQuestions(flags, positional) {
165
210
  p.cancel("Aborted.");
166
211
  return null;
167
212
  }
168
- // The scaffold is the full-demo template (TypeScript + src/ + Tailwind +
169
- // Biome). The only remaining choice is whether to install dependencies.
213
+ // Template selection. The full demo is opinionated (TS + Tailwind + Biome +
214
+ // src/app), so picking it skips the configuration prompts.
215
+ let templateAnswer;
216
+ if (flags.template) {
217
+ templateAnswer = flags.template;
218
+ }
219
+ else if (yesMode) {
220
+ templateAnswer = "full";
221
+ }
222
+ else {
223
+ templateAnswer = (await p.select({
224
+ message: "Which template would you like?",
225
+ options: [
226
+ {
227
+ value: "full",
228
+ label: "Full demo",
229
+ hint: "blog, dashboard, API, Image/PDF/Video/Font — TS + Tailwind + Biome",
230
+ },
231
+ { value: "minimal", label: "Minimal", hint: "a clean starter you configure below" },
232
+ ],
233
+ initialValue: "full",
234
+ }));
235
+ }
236
+ if (p.isCancel(templateAnswer)) {
237
+ p.cancel("Aborted.");
238
+ return null;
239
+ }
240
+ const template = templateAnswer;
241
+ const askInstall = async () => {
242
+ const a = typeof flags.install === "boolean"
243
+ ? flags.install
244
+ : yesMode
245
+ ? false
246
+ : ((await p.confirm({
247
+ message: "Would you like to install dependencies with `bun install`?",
248
+ initialValue: true,
249
+ })) ?? false);
250
+ if (p.isCancel(a)) {
251
+ p.cancel("Aborted.");
252
+ return null;
253
+ }
254
+ return a === true;
255
+ };
256
+ if (template === "full") {
257
+ const install = await askInstall();
258
+ if (install === null)
259
+ return null;
260
+ return {
261
+ projectName: normalizeProjectName(String(projectName)),
262
+ template: "full",
263
+ language: "ts",
264
+ renderer: "ssr-wasm",
265
+ linter: "biome",
266
+ tailwind: true,
267
+ srcDir: true,
268
+ importAlias: "@/*",
269
+ useShadcn: false,
270
+ install,
271
+ };
272
+ }
273
+ let languageAnswer;
274
+ if (flags.language) {
275
+ languageAnswer = flags.language;
276
+ }
277
+ else if (yesMode) {
278
+ languageAnswer = "ts";
279
+ }
280
+ else {
281
+ const languageOptions = [
282
+ { value: "ts", label: "TypeScript", hint: "Type-safe, recommended" },
283
+ { value: "js", label: "JavaScript", hint: "No type checking" },
284
+ ];
285
+ const result = await p.select({
286
+ message: "Which language would you like to use?",
287
+ options: languageOptions,
288
+ initialValue: "ts",
289
+ });
290
+ languageAnswer = result;
291
+ }
292
+ if (p.isCancel(languageAnswer)) {
293
+ p.cancel("Aborted.");
294
+ return null;
295
+ }
296
+ const language = languageAnswer;
297
+ let renderer = flags.renderer ?? "ssr-wasm";
298
+ if (!flags.renderer && !yesMode) {
299
+ const r = (await p.select({
300
+ message: "Which rendering mode do you want?",
301
+ options: RENDERER_OPTIONS,
302
+ initialValue: "ssr-wasm",
303
+ }));
304
+ if (p.isCancel(r)) {
305
+ p.cancel("Aborted.");
306
+ return null;
307
+ }
308
+ renderer = r;
309
+ }
310
+ let linterAnswer;
311
+ if (flags.linter) {
312
+ linterAnswer = flags.linter;
313
+ }
314
+ else if (yesMode) {
315
+ linterAnswer = "biome";
316
+ }
317
+ else {
318
+ const linterOptions = [
319
+ { value: "biome", label: "Biome", hint: "Fast Rust-based all-in-one tool (recommended)" },
320
+ { value: "eslint", label: "ESLint", hint: "The classic, more configurable" },
321
+ ];
322
+ const result = await p.select({
323
+ message: "Which linter would you like to use?",
324
+ options: linterOptions,
325
+ initialValue: "biome",
326
+ });
327
+ linterAnswer = result;
328
+ }
329
+ if (p.isCancel(linterAnswer)) {
330
+ p.cancel("Aborted.");
331
+ return null;
332
+ }
333
+ const linter = linterAnswer;
334
+ const tailwindAnswer = typeof flags.tailwind === "boolean"
335
+ ? flags.tailwind
336
+ : yesMode
337
+ ? false
338
+ : ((await p.confirm({
339
+ message: "Would you like to use Tailwind CSS?",
340
+ initialValue: true,
341
+ })) ?? false);
342
+ if (p.isCancel(tailwindAnswer)) {
343
+ p.cancel("Aborted.");
344
+ return null;
345
+ }
346
+ const tailwind = tailwindAnswer === true;
347
+ const useShadcnAnswer = typeof flags.useShadcn === "boolean"
348
+ ? flags.useShadcn
349
+ : yesMode
350
+ ? true
351
+ : ((await p.confirm({
352
+ message: "Would you like to use shadcn-style UI components?",
353
+ initialValue: true,
354
+ })) ?? false);
355
+ if (p.isCancel(useShadcnAnswer)) {
356
+ p.cancel("Aborted.");
357
+ return null;
358
+ }
359
+ const useShadcn = useShadcnAnswer === true;
360
+ const srcDirAnswer = typeof flags.srcDir === "boolean"
361
+ ? flags.srcDir
362
+ : yesMode
363
+ ? true
364
+ : ((await p.confirm({
365
+ message: "Would you like to use a `src/` directory for your app code?",
366
+ initialValue: true,
367
+ })) ?? true);
368
+ if (p.isCancel(srcDirAnswer)) {
369
+ p.cancel("Aborted.");
370
+ return null;
371
+ }
372
+ const srcDir = srcDirAnswer === true;
373
+ const importAliasAnswer = flags.importAlias ??
374
+ (yesMode
375
+ ? "@/*"
376
+ : (await p.text({
377
+ message: "Would you like to customize the import alias?",
378
+ placeholder: "@/*",
379
+ defaultValue: "@/*",
380
+ validate: (v) => {
381
+ if (!v)
382
+ return "Import alias is required";
383
+ if (!isValidAlias(v))
384
+ return "Invalid alias. Use letters, numbers, @, /, *, -, _.";
385
+ return undefined;
386
+ },
387
+ })));
388
+ if (p.isCancel(importAliasAnswer)) {
389
+ p.cancel("Aborted.");
390
+ return null;
391
+ }
392
+ const importAlias = importAliasAnswer;
393
+ if (!importAlias) {
394
+ p.cancel("Aborted.");
395
+ return null;
396
+ }
170
397
  const installAnswer = typeof flags.install === "boolean"
171
398
  ? flags.install
172
399
  : yesMode
@@ -179,24 +406,757 @@ async function askQuestions(flags, positional) {
179
406
  p.cancel("Aborted.");
180
407
  return null;
181
408
  }
409
+ const install = installAnswer === true;
182
410
  return {
183
411
  projectName: normalizeProjectName(String(projectName)),
184
- language: "ts",
185
- renderer: "ssr-wasm",
186
- linter: "biome",
187
- tailwind: true,
188
- srcDir: true,
189
- importAlias: "@/*",
190
- useShadcn: false,
191
- install: installAnswer === true,
412
+ template: "minimal",
413
+ language,
414
+ renderer,
415
+ linter,
416
+ tailwind,
417
+ srcDir,
418
+ importAlias,
419
+ useShadcn,
420
+ install,
421
+ };
422
+ }
423
+ async function writeProjectFiles(target, answers) {
424
+ const { projectName: rawName, language, renderer, linter, tailwind, srcDir, importAlias, useShadcn, } = answers;
425
+ // When scaffolding into the current directory ("."), name the package after
426
+ // the directory itself (like create-next-app), since "." is not a valid name.
427
+ const projectName = rawName === "." ? basename(resolve(target)) : rawName;
428
+ const appDir = join(target, srcDir ? "src/app" : "app");
429
+ const componentsDir = join(target, srcDir ? "src/components" : "components");
430
+ const libDir = join(target, srcDir ? "src/lib" : "lib");
431
+ const uiDir = join(componentsDir, "ui");
432
+ await mkdir(target, { recursive: true });
433
+ await mkdir(appDir, { recursive: true });
434
+ await mkdir(componentsDir, { recursive: true });
435
+ await mkdir(libDir, { recursive: true });
436
+ await mkdir(join(target, "public"), { recursive: true });
437
+ if (useShadcn) {
438
+ await mkdir(uiDir, { recursive: true });
439
+ }
440
+ const fileExt = (lang) => (lang === "ts" ? "ts" : "js");
441
+ const componentExt = (lang) => (lang === "ts" ? "tsx" : "jsx");
442
+ const pkg = {
443
+ name: projectName,
444
+ version: "0.1.0",
445
+ private: true,
446
+ type: "module",
447
+ scripts: {
448
+ dev: "swift-rust dev",
449
+ build: "swift-rust build",
450
+ start: "swift-rust start",
451
+ lint: linter === "biome" ? "biome check ." : "eslint .",
452
+ test: "bun test",
453
+ ...(language === "ts" ? { typecheck: "tsc --noEmit" } : {}),
454
+ format: linter === "biome" ? "biome format --write ." : "prettier --write .",
455
+ },
456
+ dependencies: {
457
+ "swift-rust": "^1.0.0",
458
+ react: "^19.0.0",
459
+ "react-dom": "^19.0.0",
460
+ ...(useShadcn
461
+ ? {
462
+ clsx: "^2.1.1",
463
+ "tailwind-merge": "^2.5.5",
464
+ "class-variance-authority": "^0.7.1",
465
+ "lucide-react": "^0.460.0",
466
+ "tw-animate-css": "^1.0.0",
467
+ }
468
+ : {}),
469
+ },
470
+ devDependencies: {
471
+ ...(language === "ts"
472
+ ? { typescript: "^6.0.0", "@types/react": "^19.0.0", "@types/react-dom": "^19.0.0" }
473
+ : {}),
474
+ ...(linter === "biome" ? { "@biomejs/biome": "^2.4.16" } : { eslint: "^9.0.0" }),
475
+ ...(tailwind
476
+ ? { tailwindcss: "^4.0.0", "@tailwindcss/postcss": "^4.0.0", postcss: "^8.4.0" }
477
+ : {}),
478
+ ...(useShadcn ? { shadcn: "^4.0.0" } : {}),
479
+ },
192
480
  };
481
+ await writeFile(join(target, "package.json"), `${JSON.stringify(pkg, null, 2)}\n`);
482
+ const config = {
483
+ rendering: renderer,
484
+ image: { domains: [], formats: ["image/avif", "image/webp"] },
485
+ font: { subsets: ["latin"], display: "swap" },
486
+ pdf: { defaultPageSize: "A4" },
487
+ };
488
+ await writeFile(join(target, "swift-rust.config.json"), `${JSON.stringify(config, null, 2)}\n`);
489
+ if (language === "ts") {
490
+ const tsconfig = {
491
+ extends: "swift-rust/tsconfig.base.json",
492
+ compilerOptions: {
493
+ jsx: "preserve",
494
+ paths: { [importAlias]: [srcDir ? "./src/*" : "./*"] },
495
+ },
496
+ include: srcDir
497
+ ? ["src/**/*", "globals.d.ts", ".swift-rust/types/**/*"]
498
+ : ["app/**/*", "components/**/*", "lib/**/*", "globals.d.ts", ".swift-rust/types/**/*"],
499
+ exclude: ["node_modules", "dist", ".swift-rust", ".turbo"],
500
+ };
501
+ await writeFile(join(target, "tsconfig.json"), `${JSON.stringify(tsconfig, null, 2)}\n`);
502
+ }
503
+ else {
504
+ const jsconfig = {
505
+ compilerOptions: {
506
+ paths: { [importAlias]: [srcDir ? "./src/*" : "./*"] },
507
+ },
508
+ include: srcDir ? ["src/**/*"] : ["app/**/*", "components/**/*", "lib/**/*"],
509
+ };
510
+ await writeFile(join(target, "jsconfig.json"), `${JSON.stringify(jsconfig, null, 2)}\n`);
511
+ }
512
+ const gitignore = [
513
+ "node_modules/",
514
+ ".swift-rust/",
515
+ ".vercel/",
516
+ "dist/",
517
+ ".turbo/",
518
+ "target/",
519
+ "*.log",
520
+ ".DS_Store",
521
+ "",
522
+ "# env files — ignore everything except the example",
523
+ ".env",
524
+ ".env.*",
525
+ "!.env.example",
526
+ ].join("\n");
527
+ await writeFile(join(target, ".gitignore"), `${gitignore}\n`);
528
+ const vercelConfig = {
529
+ $schema: "https://openapi.vercel.sh/vercel.json",
530
+ buildCommand: "bun run build",
531
+ installCommand: "bun install --frozen-lockfile",
532
+ outputDirectory: ".vercel/output",
533
+ framework: null,
534
+ trailingSlash: false,
535
+ cleanUrls: true,
536
+ headers: [
537
+ {
538
+ source: "/_swift-rust/static/(.*)",
539
+ headers: [{ key: "Cache-Control", value: "public, max-age=31536000, immutable" }],
540
+ },
541
+ {
542
+ source: "/fonts/(.*)",
543
+ headers: [{ key: "Cache-Control", value: "public, max-age=31536000, immutable" }],
544
+ },
545
+ ],
546
+ };
547
+ await writeFile(join(target, "vercel.json"), `${JSON.stringify(vercelConfig, null, 2)}\n`);
548
+ if (tailwind) {
549
+ const postcss = `const config = {
550
+ plugins: {
551
+ "@tailwindcss/postcss": {},
552
+ },
553
+ };
554
+
555
+ export default config;
556
+ `;
557
+ await writeFile(join(target, "postcss.config.mjs"), postcss);
558
+ const shadcnVars = useShadcn
559
+ ? `
560
+
561
+ /* shadcn design tokens (https://ui.shadcn.com/docs/theming) */
562
+ :root {
563
+ --ui-bg: #ffffff;
564
+ --ui-fg: #09090b;
565
+ --ui-card: #ffffff;
566
+ --ui-card-fg: #09090b;
567
+ --ui-popover: #ffffff;
568
+ --ui-popover-fg: #09090b;
569
+ --ui-primary: #18181b;
570
+ --ui-primary-fg: #fafafa;
571
+ --ui-secondary: #f4f4f5;
572
+ --ui-secondary-fg: #18181b;
573
+ --ui-muted: #f4f4f5;
574
+ --ui-muted-fg: #71717a;
575
+ --ui-accent: #f4f4f5;
576
+ --ui-accent-fg: #18181b;
577
+ --ui-destructive: #ef4444;
578
+ --ui-destructive-fg: #fafafa;
579
+ --ui-border: #e4e4e7;
580
+ --ui-input: #e4e4e7;
581
+ --ui-ring: #18181b;
582
+ --ui-radius: 0.5rem;
583
+ }
584
+
585
+ .dark {
586
+ --ui-bg: #09090b;
587
+ --ui-fg: #fafafa;
588
+ --ui-card: #09090b;
589
+ --ui-card-fg: #fafafa;
590
+ --ui-popover: #09090b;
591
+ --ui-popover-fg: #fafafa;
592
+ --ui-primary: #fafafa;
593
+ --ui-primary-fg: #18181b;
594
+ --ui-secondary: #27272a;
595
+ --ui-secondary-fg: #fafafa;
596
+ --ui-muted: #27272a;
597
+ --ui-muted-fg: #a1a1aa;
598
+ --ui-accent: #27272a;
599
+ --ui-accent-fg: #fafafa;
600
+ --ui-destructive: #7f1d1d;
601
+ --ui-destructive-fg: #fafafa;
602
+ --ui-border: #27272a;
603
+ --ui-input: #27272a;
604
+ --ui-ring: #d4d4d8;
605
+ }
606
+
607
+ @media (prefers-color-scheme: dark) {
608
+ :root:not(.light) {
609
+ --ui-bg: #09090b;
610
+ --ui-fg: #fafafa;
611
+ --ui-card: #09090b;
612
+ --ui-card-fg: #fafafa;
613
+ --ui-popover: #09090b;
614
+ --ui-popover-fg: #fafafa;
615
+ --ui-primary: #fafafa;
616
+ --ui-primary-fg: #18181b;
617
+ --ui-secondary: #27272a;
618
+ --ui-secondary-fg: #fafafa;
619
+ --ui-muted: #27272a;
620
+ --ui-muted-fg: #a1a1aa;
621
+ --ui-accent: #27272a;
622
+ --ui-accent-fg: #fafafa;
623
+ --ui-destructive: #7f1d1d;
624
+ --ui-destructive-fg: #fafafa;
625
+ --ui-border: #27272a;
626
+ --ui-input: #27272a;
627
+ --ui-ring: #d4d4d8;
628
+ }
629
+ }
630
+
631
+ @theme inline {
632
+ --color-background: var(--ui-bg);
633
+ --color-foreground: var(--ui-fg);
634
+ --color-card: var(--ui-card);
635
+ --color-card-foreground: var(--ui-card-fg);
636
+ --color-popover: var(--ui-popover);
637
+ --color-popover-foreground: var(--ui-popover-fg);
638
+ --color-primary: var(--ui-primary);
639
+ --color-primary-foreground: var(--ui-primary-fg);
640
+ --color-secondary: var(--ui-secondary);
641
+ --color-secondary-foreground: var(--ui-secondary-fg);
642
+ --color-muted: var(--ui-muted);
643
+ --color-muted-foreground: var(--ui-muted-fg);
644
+ --color-accent: var(--ui-accent);
645
+ --color-accent-foreground: var(--ui-accent-fg);
646
+ --color-destructive: var(--ui-destructive);
647
+ --color-destructive-foreground: var(--ui-destructive-fg);
648
+ --color-border: var(--ui-border);
649
+ --color-input: var(--ui-input);
650
+ --color-ring: var(--ui-ring);
651
+ --radius: var(--ui-radius);
652
+ }
653
+ `
654
+ : "";
655
+ const css = `@import "tailwindcss";
656
+ ${useShadcn ? '@import "tw-animate-css";' : ""}
657
+
658
+ @theme {
659
+ --color-bg: #ffffff;
660
+ --color-fg: #09090b;
661
+ --color-accent: ${useShadcn ? "#f97316" : "#0070f3"};
662
+ --font-sans: var(--font-geist-sans), system-ui, sans-serif;
663
+ --font-mono: var(--font-geist-mono), ui-monospace, monospace;
664
+ }
665
+
666
+ @variant dark (&:where(.dark, .dark *));
667
+
668
+ @media (prefers-color-scheme: dark) {
669
+ :root:not(.light) {
670
+ --color-bg: #09090b;
671
+ --color-fg: #fafafa;
672
+ }
673
+ }
674
+
675
+ body {
676
+ background: var(--color-bg);
677
+ color: var(--color-fg);
678
+ font-family: var(--font-sans);
679
+ }
680
+ ${shadcnVars}`;
681
+ await writeFile(join(appDir, `globals.${fileExt(language)}`), language === "ts" ? `import "./globals.css";\n` : `import "./globals.css";\n`);
682
+ await writeFile(join(appDir, "globals.css"), css);
683
+ }
684
+ const layoutImports = `import type { ReactNode } from "react";
685
+ import { Geist, Geist_Mono } from "swift-rust/font/google";
686
+ ${tailwind ? `import "./globals.css";\n` : ""}
687
+ const geistSans = Geist({ subsets: ["latin"], display: "swap", variable: true });
688
+ const geistMono = Geist_Mono({ subsets: ["latin"], display: "swap", variable: true });
689
+
690
+ export const metadata = {
691
+ title: {
692
+ template: "%s | ${projectName}",
693
+ default: "${projectName}",
694
+ },
695
+ description: "Built with swift-rust — the React framework powered with Rust + Bun. 10x faster than Next.js.",
696
+ };
697
+
698
+ export default function RootLayout({ children }: { children: ReactNode }) {
699
+ return (
700
+ <html
701
+ lang="en"
702
+ className={\`\${geistSans.variable} \${geistMono.variable} h-full antialiased\`}
703
+ >
704
+ <head>
705
+ <link rel="preconnect" href="https://fonts.googleapis.com" />
706
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="anonymous" />
707
+ </head>
708
+ <body className="${tailwind ? "min-h-full flex flex-col" : ""}">${tailwind ? "{children}" : "\\n {children}\\n "}</body>
709
+ </html>
710
+ );
711
+ }
712
+ `;
713
+ await writeFile(join(appDir, `layout.${componentExt(language)}`), layoutImports);
714
+ const homePage = tailwind
715
+ ? useShadcn
716
+ ? `import { buttonVariants } from "@/components/ui/button";
717
+ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
718
+ import { Badge } from "@/components/ui/badge";
719
+
720
+ export default function Home() {
721
+ return (
722
+ <main className="min-h-screen flex items-center justify-center px-6 py-12">
723
+ <Card className="max-w-2xl w-full">
724
+ <CardHeader>
725
+ <Badge variant="secondary" className="w-fit mb-2">Welcome</Badge>
726
+ <CardTitle className="text-3xl sm:text-5xl">${projectName}</CardTitle>
727
+ <CardDescription>
728
+ Get started by editing <code>${srcDir ? "src/app/" : "app/"}page.${componentExt(language)}</code>.
729
+ </CardDescription>
730
+ </CardHeader>
731
+ <CardContent className="flex gap-2">
732
+ <a
733
+ href="https://swift-rust.dev/docs"
734
+ className={buttonVariants({ variant: "default" })}
735
+ >
736
+ Read the docs →
737
+ </a>
738
+ <a
739
+ href="https://github.com/swift-rust/swift-rust"
740
+ className={buttonVariants({ variant: "outline" })}
741
+ >
742
+ GitHub
743
+ </a>
744
+ </CardContent>
745
+ </Card>
746
+ </main>
747
+ );
748
+ }
749
+ `
750
+ : `export default function Home() {
751
+ return (
752
+ <main className="min-h-screen flex items-center justify-center px-6">
753
+ <div className="max-w-2xl text-center">
754
+ <div className="inline-block mb-4 px-3 py-1 text-xs font-medium rounded-full bg-accent/10 text-accent">
755
+ Welcome
756
+ </div>
757
+ <h1 className="text-5xl sm:text-7xl font-bold tracking-tight mb-6">
758
+ ${projectName}
759
+ </h1>
760
+ <p className="text-lg text-fg-secondary mb-8">
761
+ Get started by editing <code>${srcDir ? "src/app/" : "app/"}page.${componentExt(language)}</code>.
762
+ </p>
763
+ <a
764
+ href="https://swift-rust.dev/docs"
765
+ className="inline-flex items-center gap-2 px-5 py-2.5 rounded-lg bg-fg text-bg font-medium text-sm hover:opacity-90 transition-opacity"
766
+ >
767
+ Read the docs →
768
+ </a>
769
+ </div>
770
+ </main>
771
+ );
772
+ }
773
+ `
774
+ : `export default function Home() {
775
+ return (
776
+ <main style={{ minHeight: "100vh", display: "flex", alignItems: "center", justifyContent: "center", padding: "2rem" }}>
777
+ <div style={{ maxWidth: "32rem", textAlign: "center" }}>
778
+ <h1>${projectName}</h1>
779
+ <p>Get started by editing <code>${srcDir ? "src/app/" : "app/"}page.${componentExt(language)}</code>.</p>
780
+ <a href="https://swift-rust.dev/docs">Read the docs →</a>
781
+ </div>
782
+ </main>
783
+ );
784
+ }
785
+ `;
786
+ await writeFile(join(appDir, `page.${componentExt(language)}`), homePage);
787
+ const notFoundPage = tailwind
788
+ ? `export const metadata = { title: "Not found" };
789
+
790
+ export default function NotFound() {
791
+ return (
792
+ <main className="min-h-screen flex items-center justify-center px-6">
793
+ <div className="text-center">
794
+ <h1 className="text-6xl font-bold mb-4">404</h1>
795
+ <p className="text-fg-secondary">Page not found</p>
796
+ <a href="/" className="text-accent mt-6 inline-block">← Go home</a>
797
+ </div>
798
+ </main>
799
+ );
800
+ }
801
+ `
802
+ : `export default function NotFound() {
803
+ return (
804
+ <main>
805
+ <h1>404</h1>
806
+ <p>Page not found</p>
807
+ <a href="/">← Go home</a>
808
+ </main>
809
+ );
810
+ }
811
+ `;
812
+ await writeFile(join(appDir, `not-found.${componentExt(language)}`), notFoundPage);
813
+ if (linter === "biome") {
814
+ const biome = {
815
+ $schema: "https://biomejs.dev/schemas/2.4.16/schema.json",
816
+ vcs: { enabled: true, clientKind: "git", useIgnoreFile: true },
817
+ files: {
818
+ includes: ["**", "!.swift-rust", "!node_modules", "!dist", "!.turbo"],
819
+ },
820
+ formatter: { enabled: true, indentStyle: "space", indentWidth: 2 },
821
+ assist: { actions: { source: { organizeImports: "on" } } },
822
+ linter: {
823
+ enabled: true,
824
+ rules: { recommended: true, a11y: { noSvgWithoutTitle: "off" } },
825
+ },
826
+ javascript: { formatter: { quoteStyle: "double", semicolons: "always" } },
827
+ };
828
+ await writeFile(join(target, "biome.json"), `${JSON.stringify(biome, null, 2)}\n`);
829
+ }
830
+ else {
831
+ const eslint = `import swiftRust from "eslint-config-swift-rust";
832
+
833
+ export default [
834
+ ...swiftRust,
835
+ {
836
+ ignores: [".swift-rust/**", "node_modules/**", "dist/**", ".turbo/**"],
837
+ },
838
+ ];
839
+ `;
840
+ await writeFile(join(target, "eslint.config.mjs"), eslint);
841
+ }
842
+ const readme = `# ${projectName}
843
+
844
+ Built with [swift-rust](https://swift-rust.dev) — the React framework powered with Rust + Bun. 10x faster than Next.js.
845
+
846
+ ## Scripts
847
+
848
+ - \`bun run dev\` — start the dev server
849
+ - \`bun run build\` — build for production
850
+ - \`bun run start\` — start the production server
851
+ - \`bun run lint\` — run the linter
852
+ - \`bun run typecheck\` — run TypeScript checks (if TS)
853
+ - \`bun run test\` — run tests
854
+ - \`bun run format\` — format the code
855
+
856
+ ## Project structure
857
+
858
+ ${srcDir
859
+ ? `\`\`\`\nsrc/\n app/\n layout.${componentExt(language)}\n page.${componentExt(language)}\n not-found.${componentExt(language)}\n components/\n lib/\n\`\`\``
860
+ : `\`\`\`\napp/\n layout.${componentExt(language)}\n page.${componentExt(language)}\n not-found.${componentExt(language)}\ncomponents/\nlib/\n\`\`\``}
861
+
862
+ ## Learn more
863
+
864
+ - [Documentation](https://swift-rust.dev/docs)
865
+ - [Examples](https://github.com/swift-rust/swift-rust/tree/main/examples)
866
+ - [Discord](https://discord.gg/swift-rust)
867
+
868
+ ## Deploy to Vercel
869
+
870
+ The fastest way to deploy is to push to GitHub and import the repo on Vercel:
871
+
872
+ \`\`\`bash
873
+ git init && git add -A && git commit -m "init"
874
+ git remote add origin https://github.com/you/${projectName}.git
875
+ git push -u origin main
876
+ \`\`\`
877
+
878
+ Then on [vercel.com/new](https://vercel.com/new), import the repo. No configuration needed — \`vercel.json\` is included. Your site will be live at \`https://${projectName}.vercel.app\`.
879
+
880
+ For custom domains and ISR / serverless functions, see the [deploy guide](https://swift-rust.dev/docs/guides/deploying).
881
+ `;
882
+ await writeFile(join(target, "README.md"), readme);
883
+ const envExample = `# Example environment variables. Copy values you need into .env.local.
884
+ # .env.local is git-ignored; .env.example is committed.
885
+ # SWIFT_RUST_RUNTIME=/path/to/bun
886
+ `;
887
+ await writeFile(join(target, ".env.example"), envExample);
888
+ // Local env file (git-ignored) so the app works out of the box.
889
+ const envLocal = `# Local environment variables (git-ignored). Not committed.
890
+ # SWIFT_RUST_RUNTIME=/path/to/bun
891
+ `;
892
+ await writeFile(join(target, ".env.local"), envLocal);
893
+ const favicon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><rect width="32" height="32" rx="7" fill="#0a0a0a"/><g stroke="#ffffff" stroke-width="1.9" stroke-linecap="round" fill="none"><circle cx="16" cy="16" r="6.4"/><path d="M16 4.4v2.6M16 25v2.6M4.4 16h2.6M25 16h2.6M7.9 7.9l1.8 1.8M22.3 22.3l1.8 1.8M7.9 24.1l1.8-1.8M22.3 9.7l1.8-1.8"/></g><path d="M17.8 9.3 L11.6 17 H15.2 L14.2 22.8 L20.4 15 H16.8 Z" fill="#fb923c"/></svg>
894
+ `;
895
+ // Metadata icons live in the app directory (Next.js style): swift-rust
896
+ // serves app/favicon.* from the site root and auto-links them in <head>.
897
+ await writeFile(join(appDir, "favicon.svg"), favicon);
898
+ // 32x32 favicon.ico (PNG-encoded) matching favicon.svg, so browsers that
899
+ // request /favicon.ico get a real icon instead of a 404.
900
+ const faviconIco = "AAABAAEAICAAAAEAIAAZBQAAFgAAAIlQTkcNChoKAAAADUlIRFIAAAAgAAAAIAgGAAAAc3p69AAAAAZiS0dEAP8A/wD/oL2nkwAABM5JREFUWIXFl19sU2UYxn/f6cbsoTsFoqywPw5BMzodpGNxhUIINMREgssEg5ELI7tUs/HnYiExRI1wwRKWXRBiMGEmphqykKl3JYOOBLMy3U7nthDI6LqRzii6ullit75eYJtNtnWWoU/yJc15z/s8z/f2y/ueTzEDNpttdTKZfB94FXgeWM7SYBK4BXyraVrLxMTET6mASv2wWq0HgAtKqfwlEp0TIvI78E48Hr+UNmC1Wg8opb6caegJQ0TkjXg8fknZbLbV09PTt7PZeU1NDQCXL1/OxkRM07QNStf1j4ET2TCMjIwAUFRUlE06wEc5wN5ss3Nzc7NNTWGvBqx/XJZsISIbNMA2V1DTNPr6+vD7/RiGMSdBR0cHHR0dc8YMw8Dv99PX14emaXO+o5TKnzsCJJNJotEobreb9vb2WSaUUpSXl9Pa2srFixdxOp2PiLe3t+N2u4lGoySTyflkQNd1mW85HA7p6uoSEZGWlhax2+1y7NgxiUQiMhPJ+2EJh8Ny5MgRsdvt0tLSIiIiXV1d4nA45uXXdV2Urusyv72Hu2lsbOTKlSscP34cj8dDMpmku7ubUCjEyulfeHlljDWvf4hSis7OTs6cOcPu3bs5deoUsVhsIfqFK5BadrtdOjs7RUSkp6dHqqurRdd1KXo6X26frJL3dj0rbrdbTNMUEZFAICCGYWTk1XVd5j0DM1FXV4fH46G3t5c9e/Zgmia5FsXnh9bz7Ko8+qNxent78Xq9hEIhtm/fzuHDhxdDTca/QCnFwMAAhYWFbNu2DdM0AWh6rZg69zMAlJzsZfzBNACbN2/m+vXrRCIRnE4nIgvSk7ECGzdupLi4mJs3b6bF33StSouP/PZnWhygp6eH7u5uSkpKKCsry0Q/20BNTQ2RSITR0VFGR0fx+XyUlpYCpMWrSpbTXFuSzilasYzx0y7GT7u4deIl1hq56XdLS0vx+Xxpvkgkkp4fi65AqoSaplGQn0vroefIy3k0LTEtvP3FEPdiiXTjyVR+WMQZcDqdBINBgsEgO3funBXrb3yRQvsyABouD/PZdz8DEAgEqKyspLKyksHBwQUNZKzAwMAAw8PDbNmyhU2bNqWfG09ZWGs8FPf9cD8t7nK5cLlchMPhjOKLMiAiNDc3o5Ti/Pnz2GwPR0e5w4pSYN77g/q2YQBsNhvnzp1DKcXZs2czigOLb0SBQEBEREzTlK1bt8q7u0rk3ifV8sLaFaLrung8HgmFQiIicvXq1UU3on/Vio8ePcqOHTsQEcbaPuD7X62MWdZQUVGBy+VCKcW1a9doamrC6/U+fiv+5zAyDEMaGhokHA5Lcmxw1kC6e/eu1NfXi2EYSzeM/H4/brebYDDIvn37Zu2mrKyMdevWATA0NDTrwKXGcVVVFTdu3MDr9c5bgHkNaJqGaZpEo1Fqa2vnLKXP5wPg4MGDj8QMw6CtrQ2Hw0FFRcW83wTKarXGsr0LjI2NAVBQUJBNOkBMU0rdyTZ7CXBHA77JNjuRSJBIJB7HwNf/58Vk3GKxbEhdzfYrpb7iv72a7Y/H420WgKmpqf6cnJwflVKvAHlPWHxcRN6Kx+NtAJbU06mpqf68vLwLIvIAyP97LVsi0QmgD/jUYrEcmpyc7E4F/gIrAoFO2P2bCQAAAABJRU5ErkJggg==";
901
+ await writeFile(join(appDir, "favicon.ico"), Buffer.from(faviconIco, "base64"));
902
+ if (useShadcn) {
903
+ await scaffoldShadcn({ target, uiDir, libDir, componentExt: componentExt(language), srcDir });
904
+ }
905
+ await writeVscodeConfig(target);
906
+ }
907
+ async function scaffoldShadcn(options) {
908
+ const { target, uiDir, libDir, componentExt, srcDir } = options;
909
+ const utilsContent = `import { clsx, type ClassValue } from "clsx";
910
+ import { twMerge } from "tailwind-merge";
911
+
912
+ export function cn(...inputs: ClassValue[]) {
913
+ return twMerge(clsx(inputs));
914
+ }
915
+ `;
916
+ const buttonContent = `import * as React from "react";
917
+ import { cva, type VariantProps } from "class-variance-authority";
918
+ import { cn } from "@/lib/utils";
919
+
920
+ const buttonVariants = cva(
921
+ "inline-flex items-center justify-center gap-2 rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--ui-ring)] focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
922
+ {
923
+ variants: {
924
+ variant: {
925
+ default: "bg-[var(--ui-primary)] text-[var(--ui-primary-fg)] hover:opacity-90",
926
+ destructive: "bg-[var(--ui-destructive)] text-white hover:opacity-90",
927
+ outline:
928
+ "border border-[var(--ui-border)] bg-[var(--ui-bg)] hover:bg-[var(--ui-accent)] hover:text-[var(--ui-accent-fg)]",
929
+ secondary: "bg-[var(--ui-secondary)] text-[var(--ui-secondary-fg)] hover:opacity-90",
930
+ ghost: "hover:bg-[var(--ui-accent)] hover:text-[var(--ui-accent-fg)]",
931
+ link: "text-[var(--ui-primary)] underline-offset-4 hover:underline",
932
+ },
933
+ size: {
934
+ default: "h-9 px-4 py-2",
935
+ sm: "h-8 rounded-md px-3 text-xs",
936
+ lg: "h-10 rounded-md px-8",
937
+ icon: "h-9 w-9",
938
+ },
939
+ },
940
+ defaultVariants: {
941
+ variant: "default",
942
+ size: "default",
943
+ },
944
+ },
945
+ );
946
+
947
+ export interface ButtonProps
948
+ extends React.ButtonHTMLAttributes<HTMLButtonElement>,
949
+ VariantProps<typeof buttonVariants> {}
950
+
951
+ export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
952
+ ({ className, variant, size, ...props }, ref) => (
953
+ <button ref={ref} className={cn(buttonVariants({ variant, size, className }))} {...props} />
954
+ ),
955
+ );
956
+ Button.displayName = "Button";
957
+
958
+ export { buttonVariants };
959
+ `;
960
+ const cardContent = `import * as React from "react";
961
+ import { cn } from "@/lib/utils";
962
+
963
+ export const Card = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
964
+ ({ className, ...props }, ref) => (
965
+ <div
966
+ ref={ref}
967
+ className={cn(
968
+ "rounded-xl border border-[var(--ui-border)] bg-[var(--ui-card)] text-[var(--ui-card-fg)] shadow-sm",
969
+ className,
970
+ )}
971
+ {...props}
972
+ />
973
+ ),
974
+ );
975
+ Card.displayName = "Card";
976
+
977
+ export const CardHeader = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
978
+ ({ className, ...props }, ref) => (
979
+ <div ref={ref} className={cn("flex flex-col space-y-1.5 p-6", className)} {...props} />
980
+ ),
981
+ );
982
+ CardHeader.displayName = "CardHeader";
983
+
984
+ export const CardTitle = React.forwardRef<
985
+ HTMLDivElement,
986
+ React.HTMLAttributes<HTMLDivElement>
987
+ >(({ className, ...props }, ref) => (
988
+ <div
989
+ ref={ref}
990
+ className={cn("font-semibold leading-none tracking-tight", className)}
991
+ {...props}
992
+ />
993
+ ));
994
+ CardTitle.displayName = "CardTitle";
995
+
996
+ export const CardDescription = React.forwardRef<
997
+ HTMLDivElement,
998
+ React.HTMLAttributes<HTMLDivElement>
999
+ >(({ className, ...props }, ref) => (
1000
+ <div
1001
+ ref={ref}
1002
+ className={cn("text-sm text-[var(--ui-muted-fg)]", className)}
1003
+ {...props}
1004
+ />
1005
+ ));
1006
+ CardDescription.displayName = "CardDescription";
1007
+
1008
+ export const CardContent = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
1009
+ ({ className, ...props }, ref) => (
1010
+ <div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
1011
+ ),
1012
+ );
1013
+ CardContent.displayName = "CardContent";
1014
+
1015
+ export const CardFooter = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
1016
+ ({ className, ...props }, ref) => (
1017
+ <div ref={ref} className={cn("flex items-center p-6 pt-0", className)} {...props} />
1018
+ ),
1019
+ );
1020
+ CardFooter.displayName = "CardFooter";
1021
+ `;
1022
+ const inputContent = `import * as React from "react";
1023
+ import { cn } from "@/lib/utils";
1024
+
1025
+ export type InputProps = React.InputHTMLAttributes<HTMLInputElement>;
1026
+
1027
+ export const Input = React.forwardRef<HTMLInputElement, InputProps>(
1028
+ ({ className, type, ...props }, ref) => (
1029
+ <input
1030
+ type={type}
1031
+ ref={ref}
1032
+ className={cn(
1033
+ "flex h-9 w-full rounded-md border border-[var(--ui-border)] bg-transparent px-3 py-1 text-sm shadow-sm transition-colors",
1034
+ "file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-[var(--ui-fg)]",
1035
+ "placeholder:text-[var(--ui-muted-fg)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--ui-ring)] focus-visible:ring-offset-1",
1036
+ "disabled:cursor-not-allowed disabled:opacity-50",
1037
+ className,
1038
+ )}
1039
+ {...props}
1040
+ />
1041
+ ),
1042
+ );
1043
+ Input.displayName = "Input";
1044
+ `;
1045
+ const labelContent = `import * as React from "react";
1046
+ import { cn } from "@/lib/utils";
1047
+
1048
+ export const Label = React.forwardRef<
1049
+ HTMLLabelElement,
1050
+ React.LabelHTMLAttributes<HTMLLabelElement>
1051
+ >(({ className, ...props }, ref) => (
1052
+ <label
1053
+ ref={ref}
1054
+ className={cn(
1055
+ "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",
1056
+ className,
1057
+ )}
1058
+ {...props}
1059
+ />
1060
+ ));
1061
+ Label.displayName = "Label";
1062
+ `;
1063
+ const badgeContent = `import * as React from "react";
1064
+ import { cva, type VariantProps } from "class-variance-authority";
1065
+ import { cn } from "@/lib/utils";
1066
+
1067
+ const badgeVariants = cva(
1068
+ "inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-[var(--ui-ring)] focus:ring-offset-2",
1069
+ {
1070
+ variants: {
1071
+ variant: {
1072
+ default:
1073
+ "border-transparent bg-[var(--ui-primary)] text-[var(--ui-primary-fg)] hover:opacity-90",
1074
+ secondary:
1075
+ "border-transparent bg-[var(--ui-secondary)] text-[var(--ui-secondary-fg)] hover:opacity-90",
1076
+ destructive:
1077
+ "border-transparent bg-[var(--ui-destructive)] text-white hover:opacity-90",
1078
+ outline: "text-[var(--ui-fg)] border-[var(--ui-border)]",
1079
+ },
1080
+ },
1081
+ defaultVariants: {
1082
+ variant: "default",
1083
+ },
1084
+ },
1085
+ );
1086
+
1087
+ export interface BadgeProps
1088
+ extends React.HTMLAttributes<HTMLDivElement>,
1089
+ VariantProps<typeof badgeVariants> {}
1090
+
1091
+ export function Badge({ className, variant, ...props }: BadgeProps) {
1092
+ return <div className={cn(badgeVariants({ variant }), className)} {...props} />;
1093
+ }
1094
+
1095
+ export { badgeVariants };
1096
+ `;
1097
+ const componentsJson = `{
1098
+ "$schema": "https://ui.shadcn.com/schema.json",
1099
+ "style": "new-york",
1100
+ "rsc": true,
1101
+ "tsx": ${componentExt === "tsx"},
1102
+ "tailwind": {
1103
+ "config": "",
1104
+ "css": "${srcDir ? "src/app/globals.css" : "app/globals.css"}",
1105
+ "baseColor": "zinc",
1106
+ "cssVariables": true,
1107
+ "prefix": ""
1108
+ },
1109
+ "aliases": {
1110
+ "components": "@/components",
1111
+ "utils": "@/lib/utils",
1112
+ "ui": "@/components/ui",
1113
+ "lib": "@/lib",
1114
+ "hooks": "@/hooks"
1115
+ },
1116
+ "iconLibrary": "lucide"
1117
+ }
1118
+ `;
1119
+ await writeFile(join(libDir, "utils.ts"), utilsContent);
1120
+ await writeFile(join(uiDir, `button.${componentExt}`), buttonContent);
1121
+ await writeFile(join(uiDir, `card.${componentExt}`), cardContent);
1122
+ await writeFile(join(uiDir, `input.${componentExt}`), inputContent);
1123
+ await writeFile(join(uiDir, `label.${componentExt}`), labelContent);
1124
+ await writeFile(join(uiDir, `badge.${componentExt}`), badgeContent);
1125
+ await writeFile(join(target, "components.json"), `${componentsJson}\n`);
193
1126
  }
194
1127
  async function runInstall(target) {
195
1128
  const { spawn } = await import("node:child_process");
196
- await new Promise((resolvePromise, reject) => {
197
- const child = spawn("bun", ["install"], { cwd: target, stdio: "inherit" });
198
- child.on("error", reject);
199
- child.on("close", (code) => code === 0 ? resolvePromise() : reject(new Error(`bun install exited with code ${code}`)));
1129
+ return new Promise((resolve, reject) => {
1130
+ const proc = spawn("bun", ["install"], { cwd: target, stdio: "inherit" });
1131
+ proc.on("exit", (code) => {
1132
+ if (code === 0)
1133
+ resolve();
1134
+ else
1135
+ reject(new Error(`bun install exited with code ${code}`));
1136
+ });
1137
+ proc.on("error", reject);
1138
+ });
1139
+ }
1140
+ const SHADCN_DEFAULT_COMPONENTS = ["button", "card", "input", "label", "badge"];
1141
+ async function runShadcnAdd(target, components) {
1142
+ const { spawn } = await import("node:child_process");
1143
+ return new Promise((resolve) => {
1144
+ const args = [
1145
+ "--bun",
1146
+ "shadcn@latest",
1147
+ "add",
1148
+ ...components,
1149
+ "--yes",
1150
+ "--overwrite",
1151
+ "--cwd",
1152
+ target,
1153
+ "--silent",
1154
+ ];
1155
+ const proc = spawn("bunx", args, { cwd: target, stdio: "pipe" });
1156
+ proc.on("exit", (code) => {
1157
+ resolve(code === 0);
1158
+ });
1159
+ proc.on("error", () => resolve(false));
200
1160
  });
201
1161
  }
202
1162
  async function main() {
@@ -218,7 +1178,7 @@ async function main() {
218
1178
  const answers = await askQuestions(flags, positional);
219
1179
  if (!answers)
220
1180
  process.exit(1);
221
- const { projectName, install } = answers;
1181
+ const { projectName, tailwind, linter, srcDir, install } = answers;
222
1182
  const target = resolve(process.cwd(), projectName);
223
1183
  if (projectName === ".") {
224
1184
  if ((await listDir(target)).length > 0) {
@@ -248,14 +1208,27 @@ async function main() {
248
1208
  process.exit(1);
249
1209
  }
250
1210
  }
251
- const summary = [
252
- `${pc.cyan("•")} Project: ${pc.bold(projectName === "." ? resolve(target) : projectName)}`,
253
- `${pc.cyan("•")} Template: Full demo (blog, dashboard, API, Image/PDF/Video/Font)`,
254
- `${pc.cyan("•")} Language: TypeScript`,
255
- `${pc.cyan("•")} Styling: Tailwind CSS`,
256
- `${pc.cyan("•")} Linter: Biome`,
257
- `${pc.cyan("•")} Install: ${install ? "Yes" : "No"}`,
258
- ].join("\n");
1211
+ const summary = (answers.template === "full"
1212
+ ? [
1213
+ `${pc.cyan("•")} Project: ${pc.bold(projectName === "." ? resolve(target) : projectName)}`,
1214
+ `${pc.cyan("•")} Template: Full demo (blog, dashboard, API, Image/PDF/Video/Font)`,
1215
+ `${pc.cyan("•")} Language: TypeScript`,
1216
+ `${pc.cyan("•")} Styling: Tailwind CSS`,
1217
+ `${pc.cyan("•")} Linter: Biome`,
1218
+ `${pc.cyan("•")} Install: ${install ? "Yes" : "No"}`,
1219
+ ]
1220
+ : [
1221
+ `${pc.cyan("•")} Project: ${pc.bold(projectName === "." ? resolve(target) : projectName)}`,
1222
+ `${pc.cyan("•")} Template: Minimal`,
1223
+ `${pc.cyan("•")} Language: ${answers.language === "ts" ? "TypeScript" : "JavaScript"}`,
1224
+ `${pc.cyan("•")} Renderer: ${answers.renderer}`,
1225
+ `${pc.cyan("•")} Linter: ${linter === "biome" ? "Biome" : "ESLint"}`,
1226
+ `${pc.cyan("•")} Tailwind: ${tailwind ? "Yes" : "No"}`,
1227
+ `${pc.cyan("•")} shadcn UI: ${answers.useShadcn ? "Yes" : "No"}`,
1228
+ `${pc.cyan("•")} src/ dir: ${srcDir ? "Yes (src/app/)" : "No"}`,
1229
+ `${pc.cyan("•")} Import as: ${answers.importAlias}`,
1230
+ `${pc.cyan("•")} Install: ${install ? "Yes" : "No"}`,
1231
+ ]).join("\n");
259
1232
  if (quiet) {
260
1233
  console.log(`Configuration:\n${summary}`);
261
1234
  }
@@ -272,18 +1245,36 @@ async function main() {
272
1245
  }
273
1246
  console.log(`Scaffolding ${pc.cyan(projectName === "." ? "." : projectName)}…`);
274
1247
  try {
275
- await copyTemplate(target, projectName);
1248
+ if (answers.template === "full") {
1249
+ await copyTemplate(target, projectName);
1250
+ }
1251
+ else {
1252
+ await writeProjectFiles(target, answers);
1253
+ }
276
1254
  console.log(`✓ Scaffolded project into ${pc.green(target)}`);
1255
+ let installSucceeded = false;
277
1256
  if (install) {
278
1257
  console.log("Running bun install…");
279
1258
  try {
280
1259
  await runInstall(target);
281
1260
  console.log("✓ Installed dependencies");
1261
+ installSucceeded = true;
282
1262
  }
283
1263
  catch (_err) {
284
1264
  console.error("Failed to install dependencies. Run `bun install` manually.");
285
1265
  }
286
1266
  }
1267
+ if (answers.useShadcn && installSucceeded) {
1268
+ console.log("Fetching canonical shadcn components…");
1269
+ const ok = await runShadcnAdd(target, SHADCN_DEFAULT_COMPONENTS);
1270
+ if (ok) {
1271
+ console.log(`✓ Added ${SHADCN_DEFAULT_COMPONENTS.length} shadcn components from the registry`);
1272
+ }
1273
+ else {
1274
+ const cwdArg = projectName === "." ? "." : `./${projectName}`;
1275
+ console.log(`${pc.yellow("!")} Could not fetch shadcn components from the registry. Using bundled shadcn-style components as a fallback. You can retry later with: ${pc.cyan(`bunx --bun shadcn@latest add ${SHADCN_DEFAULT_COMPONENTS.join(" ")} --cwd ${cwdArg}`)}`);
1276
+ }
1277
+ }
287
1278
  const next = projectName === "." ? "bun run dev" : `cd ${projectName}\nbun run dev`;
288
1279
  console.log(`\n${pc.green("Done!")} Next steps:\n${pc.cyan(next)}`);
289
1280
  }