create-kerf 0.0.0-stage → 0.1.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 (128) hide show
  1. package/LICENSE +16 -0
  2. package/README.md +401 -2
  3. package/bin/create-kerf.mjs +121 -0
  4. package/package.json +37 -3
  5. package/scripts/tarballs.mjs +77 -0
  6. package/src/data.mjs +360 -0
  7. package/src/index.mjs +400 -0
  8. package/src/stack/pages.mjs +151 -0
  9. package/src/stack/schema.mjs +195 -0
  10. package/src/stack.mjs +293 -0
  11. package/src/templates.mjs +175 -0
  12. package/src/wizard.mjs +127 -0
  13. package/templates/admin/files/drizzle/.schema-hash +1 -0
  14. package/templates/admin/files/drizzle/0000_admin.sql +136 -0
  15. package/templates/admin/files/drizzle/meta/0000_snapshot.json +771 -0
  16. package/templates/admin/files/drizzle/meta/_journal.json +13 -0
  17. package/templates/admin/files/kerf.config.ts +31 -0
  18. package/templates/admin/files/public/favicon.svg +1 -0
  19. package/templates/admin/files/src/auth.server.ts +24 -0
  20. package/templates/admin/files/src/components/AuthPage.tsx +33 -0
  21. package/templates/admin/files/src/components/Failed.tsx +19 -0
  22. package/templates/admin/files/src/components/Logo.tsx +16 -0
  23. package/templates/admin/files/src/components/OrderDetail.tsx +93 -0
  24. package/templates/admin/files/src/components/OrdersFilters.tsx +44 -0
  25. package/templates/admin/files/src/components/OrdersTable.tsx +144 -0
  26. package/templates/admin/files/src/components/Overview.tsx +113 -0
  27. package/templates/admin/files/src/components/StatusBadge.tsx +12 -0
  28. package/templates/admin/files/src/db/schema.ts +68 -0
  29. package/templates/admin/files/src/lib/orders.ts +60 -0
  30. package/templates/admin/files/src/routes/404.tsx +20 -0
  31. package/templates/admin/files/src/routes/_error.tsx +20 -0
  32. package/templates/admin/files/src/routes/_layout.tsx +6 -0
  33. package/templates/admin/files/src/routes/admin/_layout.tsx +89 -0
  34. package/templates/admin/files/src/routes/admin/index.tsx +45 -0
  35. package/templates/admin/files/src/routes/admin/nested/_layout.tsx +35 -0
  36. package/templates/admin/files/src/routes/admin/nested/index.tsx +77 -0
  37. package/templates/admin/files/src/routes/admin/orders/[id].tsx +24 -0
  38. package/templates/admin/files/src/routes/admin/orders/index.tsx +28 -0
  39. package/templates/admin/files/src/routes/admin/per-row.tsx +81 -0
  40. package/templates/admin/files/src/routes/admin/slow.tsx +74 -0
  41. package/templates/admin/files/src/routes/index.tsx +13 -0
  42. package/templates/admin/files/src/routes/login.tsx +53 -0
  43. package/templates/admin/files/src/routes/signup.tsx +60 -0
  44. package/templates/admin/files/src/server/orders.ts +193 -0
  45. package/templates/admin/files/src/server/reports.ts +92 -0
  46. package/templates/admin/files/src/server/session.ts +45 -0
  47. package/templates/admin/files/src/theme.css +43 -0
  48. package/templates/admin/template.json +22 -0
  49. package/templates/catalog/files/drizzle/.schema-hash +1 -0
  50. package/templates/catalog/files/drizzle/0000_catalog.sql +47 -0
  51. package/templates/catalog/files/drizzle/meta/0000_snapshot.json +263 -0
  52. package/templates/catalog/files/drizzle/meta/_journal.json +13 -0
  53. package/templates/catalog/files/kerf.config.ts +30 -0
  54. package/templates/catalog/files/public/favicon.svg +1 -0
  55. package/templates/catalog/files/seed.sql +13 -0
  56. package/templates/catalog/files/src/components/AddToCart.tsx +22 -0
  57. package/templates/catalog/files/src/components/Aisles.tsx +31 -0
  58. package/templates/catalog/files/src/components/CartLines.tsx +96 -0
  59. package/templates/catalog/files/src/components/CartLink.tsx +29 -0
  60. package/templates/catalog/files/src/components/Failed.tsx +19 -0
  61. package/templates/catalog/files/src/components/Featured.tsx +19 -0
  62. package/templates/catalog/files/src/components/Filters.tsx +40 -0
  63. package/templates/catalog/files/src/components/Logo.tsx +16 -0
  64. package/templates/catalog/files/src/components/ProductArt.tsx +42 -0
  65. package/templates/catalog/files/src/components/ProductCard.tsx +42 -0
  66. package/templates/catalog/files/src/components/ProductList.tsx +65 -0
  67. package/templates/catalog/files/src/components/Related.tsx +19 -0
  68. package/templates/catalog/files/src/components/SiteFooter.tsx +9 -0
  69. package/templates/catalog/files/src/components/SiteHeader.tsx +16 -0
  70. package/templates/catalog/files/src/db/schema.ts +53 -0
  71. package/templates/catalog/files/src/lib/catalog.ts +35 -0
  72. package/templates/catalog/files/src/routes/404.tsx +18 -0
  73. package/templates/catalog/files/src/routes/_error.tsx +18 -0
  74. package/templates/catalog/files/src/routes/_layout.tsx +14 -0
  75. package/templates/catalog/files/src/routes/c/[slug].tsx +53 -0
  76. package/templates/catalog/files/src/routes/cart.tsx +29 -0
  77. package/templates/catalog/files/src/routes/index.tsx +84 -0
  78. package/templates/catalog/files/src/routes/p/[slug].tsx +67 -0
  79. package/templates/catalog/files/src/server/cart.ts +125 -0
  80. package/templates/catalog/files/src/server/catalog.ts +107 -0
  81. package/templates/catalog/files/src/theme.css +159 -0
  82. package/templates/catalog/template.json +20 -0
  83. package/templates/landing/files/.kerf/plugins.lock.json +42 -0
  84. package/templates/landing/files/assets/fonts/LICENSE-figtree.txt +93 -0
  85. package/templates/landing/files/assets/fonts/figtree.woff2 +0 -0
  86. package/templates/landing/files/assets/hero.webp +0 -0
  87. package/templates/landing/files/drizzle/.schema-hash +1 -0
  88. package/templates/landing/files/drizzle/0000_landing.sql +6 -0
  89. package/templates/landing/files/drizzle/meta/0000_snapshot.json +60 -0
  90. package/templates/landing/files/drizzle/meta/_journal.json +13 -0
  91. package/templates/landing/files/kerf.config.ts +44 -0
  92. package/templates/landing/files/public/favicon.svg +1 -0
  93. package/templates/landing/files/src/components/SiteFooter.tsx +24 -0
  94. package/templates/landing/files/src/components/SiteHeader.tsx +23 -0
  95. package/templates/landing/files/src/components/WaitlistForm.tsx +36 -0
  96. package/templates/landing/files/src/db/schema.ts +7 -0
  97. package/templates/landing/files/src/routes/404.tsx +24 -0
  98. package/templates/landing/files/src/routes/_error.tsx +24 -0
  99. package/templates/landing/files/src/routes/_layout.tsx +14 -0
  100. package/templates/landing/files/src/routes/index.tsx +130 -0
  101. package/templates/landing/files/src/routes/joined.tsx +30 -0
  102. package/templates/landing/files/src/routes/pricing.tsx +131 -0
  103. package/templates/landing/files/src/routes/privacy.tsx +56 -0
  104. package/templates/landing/files/src/server/waitlist.ts +13 -0
  105. package/templates/landing/files/src/theme.css +108 -0
  106. package/templates/landing/template.json +17 -0
  107. package/templates/todo/files/drizzle/.schema-hash +1 -0
  108. package/templates/todo/files/drizzle/0000_todo.sql +82 -0
  109. package/templates/todo/files/drizzle/meta/0000_snapshot.json +462 -0
  110. package/templates/todo/files/drizzle/meta/_journal.json +13 -0
  111. package/templates/todo/files/kerf.config.ts +30 -0
  112. package/templates/todo/files/public/favicon.svg +1 -0
  113. package/templates/todo/files/src/components/AuthPage.tsx +33 -0
  114. package/templates/todo/files/src/components/Logo.tsx +14 -0
  115. package/templates/todo/files/src/components/NewTodo.tsx +27 -0
  116. package/templates/todo/files/src/components/TodoList.tsx +101 -0
  117. package/templates/todo/files/src/db/schema.ts +18 -0
  118. package/templates/todo/files/src/lib/views.ts +13 -0
  119. package/templates/todo/files/src/routes/404.tsx +20 -0
  120. package/templates/todo/files/src/routes/_error.tsx +20 -0
  121. package/templates/todo/files/src/routes/_layout.tsx +6 -0
  122. package/templates/todo/files/src/routes/index.tsx +13 -0
  123. package/templates/todo/files/src/routes/login.tsx +53 -0
  124. package/templates/todo/files/src/routes/signup.tsx +57 -0
  125. package/templates/todo/files/src/routes/todos.tsx +87 -0
  126. package/templates/todo/files/src/server/todos.ts +98 -0
  127. package/templates/todo/files/src/theme.css +71 -0
  128. package/templates/todo/template.json +18 -0
package/src/index.mjs ADDED
@@ -0,0 +1,400 @@
1
+ // `--template` lays a real app over all that (templates.mjs). A short AGENTS.md is written here; the full one needs the
2
+ // installed kerf, so bin/create-kerf.mjs runs `kerf agents-md` right after the install. Everything else (.kerf/, the slot
3
+ // modules) is generated by `kerf` itself on the first `kerf dev` or `kerf check`, so a scaffold never goes stale against
4
+ // the CLI.
5
+
6
+ import { randomBytes } from 'node:crypto'
7
+ import { existsSync, mkdirSync, readdirSync, writeFileSync } from 'node:fs'
8
+ import { basename, dirname, join } from 'node:path'
9
+ import { customAuth } from './data.mjs'
10
+ import {
11
+ classes,
12
+ context,
13
+ loginPage,
14
+ sharedAuthTables,
15
+ stackDeps,
16
+ stackFiles,
17
+ TAILWIND_CSS,
18
+ TAILWIND_VITE,
19
+ tailwindPackages,
20
+ todosPage,
21
+ VERSION,
22
+ } from './stack.mjs'
23
+ import { agentsFile, loadTemplate, withTemplate } from './templates.mjs'
24
+
25
+ /** What `--ui` takes. */
26
+ export const UI = ['veneer', 'headless', 'tailwind', 'none']
27
+ /** What `--db` takes. */
28
+ export const DB = ['sqlite', 'postgres', 'mysql', 'none']
29
+ /** What `--layer` takes. */
30
+ export const LAYERS = ['drizzle', 'prisma', 'native']
31
+ /** What `--runtime` takes. */
32
+ export const RUNTIMES = ['node', 'bun', 'deno']
33
+ /** What `--config` takes. */
34
+ export const CONFIGS = ['ts', 'json', 'yaml']
35
+ export { TEMPLATES, withTemplate } from './templates.mjs'
36
+
37
+ const json = (v) => JSON.stringify(v, null, 2) + '\n'
38
+ const title = (name) => name.replace(/[-_]+/g, ' ').replace(/\b\w/g, (c) => c.toUpperCase())
39
+
40
+ /** `kerf.config.ts`, `.json` or `.yaml`: one schema, so the same app in each. */
41
+ const LAYER_PLUGIN = {
42
+ prisma: { pkg: '@kerf-js/db/plugin-prisma', name: 'prisma' },
43
+ native: { pkg: '@kerf-js/db/plugin-native', name: 'native' },
44
+ }
45
+
46
+ const appPlugins = ({ ui, layer }) => [
47
+ ...(ui === 'veneer' ? [{ pkg: '@kerf-js/veneer', name: 'veneer' }] : []),
48
+ ...(LAYER_PLUGIN[layer] ? [LAYER_PLUGIN[layer]] : []),
49
+ ]
50
+
51
+ /** What each plugin a scaffold picks declares. `kerf check` fails a scaffold where these fall behind the plugin. */
52
+ const GRANTS = {
53
+ '@kerf-js/veneer': [
54
+ 'fs.read:node_modules/@kerf-js/veneer-core/**',
55
+ 'fs.write:$TMPDIR/veneer-seed-*',
56
+ 'spawn:node',
57
+ ],
58
+ '@kerf-js/db/plugin-prisma': ['fs.read:prisma/**', 'fs.write:prisma/migrations/**', 'spawn:node'],
59
+ '@kerf-js/db/plugin-native': ['fs.read:migrations/**', 'fs.write:migrations/**'],
60
+ }
61
+
62
+ /** Choosing a plugin here is approving it. There's no install yet, so `kerf plugins approve --all` pins the code later. */
63
+ function pluginLock(options) {
64
+ const plugins = Object.fromEntries(
65
+ appPlugins(options).map((p) => [
66
+ p.pkg,
67
+ { version: null, integrity: null, permissions: GRANTS[p.pkg], provides: [], undeclared: [] },
68
+ ]),
69
+ )
70
+ return Object.keys(plugins).length
71
+ ? { '.kerf/plugins.lock.json': json({ version: 1, plugins }) }
72
+ : {}
73
+ }
74
+
75
+ function configFile(format, { ui, label, runtime, layer, veneer }) {
76
+ const plugins = appPlugins({ ui, layer })
77
+ const entry = (p) => (p.pkg === '@kerf-js/veneer' && veneer ? [p.pkg, veneer] : p.pkg)
78
+ const site = { name: label, title: `%s · ${label}`, description: 'Made with kerf.' }
79
+ if (format === 'json') {
80
+ const config = {
81
+ $schema: './.kerf/config.schema.json',
82
+ site,
83
+ ...(plugins.length && { plugins: plugins.map(entry) }),
84
+ ...(runtime !== 'node' && { runtime }),
85
+ }
86
+ return { 'kerf.config.json': json(config) }
87
+ }
88
+ if (format === 'yaml') {
89
+ return {
90
+ 'kerf.config.yaml':
91
+ `# yaml-language-server: $schema=./.kerf/config.schema.json\nsite:\n` +
92
+ Object.entries(site)
93
+ .map(([k, v]) => ` ${k}: ${JSON.stringify(v)}\n`)
94
+ .join('') +
95
+ (plugins.length
96
+ ? `plugins:\n${plugins.map((p) => ` - ${JSON.stringify(entry(p))}\n`).join('')}`
97
+ : '') +
98
+ (runtime !== 'node' ? `runtime: ${runtime}\n` : ''),
99
+ }
100
+ }
101
+ return {
102
+ 'kerf.config.ts':
103
+ `import { defineConfig } from '@kerf-js/core/config'\n` +
104
+ plugins.map((p) => `import { ${p.name} } from '${p.pkg}/plugin'\n`).join('') +
105
+ `\nexport default defineConfig({\n` +
106
+ ` site: { name: ${JSON.stringify(label)}, title: ${JSON.stringify(site.title)}, description: 'Made with kerf.' },\n` +
107
+ (plugins.length
108
+ ? ` plugins: [${plugins.map((p) => `${p.name}(${p.pkg === '@kerf-js/veneer' && veneer ? JSON.stringify(veneer) : ''})`).join(', ')}],\n`
109
+ : '') +
110
+ (runtime !== 'node' ? ` runtime: '${runtime}',\n` : '') +
111
+ `})\n`,
112
+ }
113
+ }
114
+
115
+ /**
116
+ * The files for an app, as `{ path: text }`.
117
+ * @param {{ ui?: string, name?: string, version?: string, db?: string, layer?: string, auth?: boolean | 'custom', runtime?: string, config?: string, secret?: string, template?: string, pm?: string }} [options]
118
+ */
119
+ export function template(options = {}) {
120
+ const {
121
+ ui = 'veneer',
122
+ name = 'kerf-app',
123
+ version = VERSION,
124
+ db = 'none',
125
+ layer = 'drizzle',
126
+ auth = false,
127
+ runtime = 'node',
128
+ config = 'ts',
129
+ secret = randomBytes(32).toString('base64'),
130
+ template: chosen,
131
+ } = withTemplate(options)
132
+ if (!UI.includes(ui)) throw new Error(`--ui must be one of ${UI.join(', ')} (got "${ui}")`)
133
+ if (!DB.includes(db)) throw new Error(`--db must be one of ${DB.join(', ')} (got "${db}")`)
134
+ if (!RUNTIMES.includes(runtime))
135
+ throw new Error(`--runtime must be one of ${RUNTIMES.join(', ')} (got "${runtime}")`)
136
+ if (!CONFIGS.includes(config))
137
+ throw new Error(`--config must be one of ${CONFIGS.join(', ')} (got "${config}")`)
138
+ if (!LAYERS.includes(layer))
139
+ throw new Error(`--layer must be one of ${LAYERS.join(', ')} (got "${layer}")`)
140
+ if (auth && db === 'none')
141
+ throw new Error('--auth keeps users in a database: add --db sqlite, postgres or mysql')
142
+ const overlay = chosen && loadTemplate(chosen)
143
+ const label = title(name)
144
+ const stack = stackDeps({ db, auth: auth === true, layer, version })
145
+ const deps = { '@kerf-js/core': version, '@kerf-js/start': version }
146
+ if (ui === 'veneer') deps['@kerf-js/veneer'] = version
147
+ if (ui === 'headless') deps['@kerf-js/veneer-core'] = version
148
+ if (ui === 'tailwind') Object.assign(stack.dev, tailwindPackages)
149
+ for (const [dep, wanted] of Object.entries(overlay?.dependencies ?? {}))
150
+ deps[dep] = dep.startsWith('@kerf-js/') ? version : wanted
151
+
152
+ const files = baseFiles({
153
+ name,
154
+ version,
155
+ db,
156
+ layer,
157
+ ui,
158
+ config,
159
+ label,
160
+ runtime,
161
+ overlay,
162
+ stack,
163
+ deps,
164
+ auth,
165
+ })
166
+ Object.assign(files, pluginLock({ ui, layer }))
167
+ if (options.pm === 'pnpm')
168
+ files['pnpm-workspace.yaml'] = pnpmSettings(db !== 'none' && layer === 'prisma')
169
+ if (ui !== 'veneer') files['src/app.css'] = css(ui)
170
+ if (ui === 'tailwind') files['vite.config.ts'] = TAILWIND_VITE
171
+ if (db !== 'none') {
172
+ Object.assign(files, stackFiles({ db, auth: auth === true, name, secret, layer }))
173
+ if (!overlay) files['src/routes/todos/index.tsx'] = todosPage(ui)
174
+ if (auth === true) files['src/routes/login.tsx'] = loginPage(ui)
175
+ if (auth === 'custom')
176
+ Object.assign(files, {
177
+ 'src/auth.server.ts': customAuth,
178
+ 'src/context.server.ts': context(true),
179
+ })
180
+ }
181
+ if (overlay) {
182
+ for (const path of Object.keys(files))
183
+ if (/^src\/(routes\/(about\.tsx|todos\/)|server\/todos\.ts)/.test(path)) delete files[path]
184
+ if (auth) files['src/db/auth.ts'] = sharedAuthTables()
185
+ Object.assign(files, overlay.files)
186
+ }
187
+ return files
188
+ }
189
+
190
+ // pnpm 11 and later stop an install at a dependency's build script that nobody has allowed or refused. None is needed:
191
+ // esbuild ships its binary as an optional package, and the app's own postinstall runs `prisma generate`.
192
+ const pnpmSettings = (prisma) =>
193
+ `allowBuilds:\n esbuild: false\n${prisma ? " '@prisma/engines': false\n prisma: false\n" : ''}`
194
+
195
+ function baseFiles({
196
+ name,
197
+ version,
198
+ db,
199
+ layer,
200
+ ui,
201
+ config,
202
+ label,
203
+ runtime,
204
+ overlay,
205
+ stack,
206
+ deps,
207
+ auth,
208
+ }) {
209
+ return {
210
+ 'package.json': json({
211
+ name,
212
+ private: true,
213
+ type: 'module',
214
+ scripts: {
215
+ dev: 'kerf dev',
216
+ build: 'kerf build',
217
+ check: 'kerf check',
218
+ typecheck: 'kerf tsc',
219
+ start: 'kerf start',
220
+ ...(db !== 'none' && { 'db:generate': 'kerf db generate' }),
221
+ ...(db !== 'none' && layer === 'prisma' && { postinstall: 'prisma generate' }),
222
+ },
223
+ dependencies: { ...deps, ...stack.deps },
224
+ devDependencies: { '@kerf-js/cli': version, typescript: '7.0.2', ...stack.dev },
225
+ }),
226
+ ...configFile(config, {
227
+ ui,
228
+ label,
229
+ runtime,
230
+ layer: db === 'none' ? 'drizzle' : layer,
231
+ veneer: overlay?.veneer,
232
+ }),
233
+ 'tsconfig.json': json({
234
+ compilerOptions: {
235
+ target: 'es2022',
236
+ module: 'esnext',
237
+ moduleResolution: 'bundler',
238
+ strict: true,
239
+ noEmit: true,
240
+ skipLibCheck: true,
241
+ jsx: 'preserve',
242
+ jsxImportSource: '@kerf-js/core',
243
+ lib: ['es2023', 'dom', 'dom.iterable'],
244
+ paths: { '#/*': ['./src/*'] },
245
+ types: db === 'none' ? ['@kerf-js/core/client'] : ['@kerf-js/core/client', 'node'],
246
+ plugins: [{ name: '@kerf-js/cli/ts-plugin' }],
247
+ },
248
+ include: ['src', ...(config === 'ts' ? ['kerf.config.ts'] : []), '.kerf/*.d.ts'],
249
+ }),
250
+ // VS Code's own tsserver only looks for plugins where it's told, and TypeScript 7 ships no tsserver to select instead.
251
+ '.vscode/settings.json': json({ 'typescript.tsserver.pluginPaths': ['.'] }),
252
+ '.gitignore': `node_modules/\n.kerf/*\n!.kerf/plugins.lock.json\n.output/\ndist/\n${db === 'none' ? '' : '.env\n.data/\n'}${layer === 'prisma' ? 'src/generated/\n' : ''}`,
253
+ 'src/routes/_layout.tsx': layout(ui, { db, auth }),
254
+ 'src/routes/index.tsx': home(ui, label),
255
+ 'AGENTS.md': agentsFile({ ui, db, layer, shipped: overlay?.pages, auth }),
256
+ 'src/routes/about.tsx': `export const meta = { title: 'About', description: 'What this app is.' }\n\nexport default function About() {\n return <h1>About</h1>\n}\n`,
257
+ }
258
+ }
259
+
260
+ /** Write the app into `dir` (which must be missing or empty). */
261
+ export function scaffold(dir, options = {}) {
262
+ if (existsSync(dir) && readdirSync(dir).length) throw new Error(`${dir} is not empty`)
263
+ const files = template({
264
+ name: basename(dir)
265
+ .toLowerCase()
266
+ .replace(/[^a-z0-9-_.]/g, '-'),
267
+ ...options,
268
+ })
269
+ for (const [rel, text] of Object.entries(files)) {
270
+ mkdirSync(dirname(join(dir, rel)), { recursive: true })
271
+ writeFileSync(join(dir, rel), text)
272
+ }
273
+ return { dir, files: Object.keys(files) }
274
+ }
275
+
276
+ function layout(ui, options) {
277
+ const text = shell(ui, options)
278
+ return ui === 'tailwind'
279
+ ? text.replace('<nav>', '<nav class="flex gap-4 p-4">').replace('<main>', '<main class="p-4">')
280
+ : text
281
+ }
282
+
283
+ function shell(ui, { db, auth: which }) {
284
+ const auth = which === true
285
+ const imports =
286
+ ui === 'veneer'
287
+ ? ''
288
+ : (ui === 'headless' ? `import '@kerf-js/veneer-core/styles/veneer.css'\n` : '') +
289
+ `import '../app.css'\n`
290
+ const links = db === 'none' ? '' : `\n <Link href="/todos">Todos</Link>`
291
+ const signOut =
292
+ ui === 'veneer'
293
+ ? '<Button emphasis="ghost" size="sm" onClick={() => signOut()}>Sign out</Button>'
294
+ : '<button type="button" onClick={() => signOut()}>Sign out</button>'
295
+ if (!auth) {
296
+ return `${imports}import { Link, type RouteProps } from '@kerf-js/start'
297
+
298
+ export default function Root(props: RouteProps) {
299
+ return (
300
+ <>
301
+ <nav>
302
+ <Link href="/">Home</Link>
303
+ <Link href="/about">About</Link>${links}
304
+ </nav>
305
+ <main>{props.children}</main>
306
+ </>
307
+ )
308
+ }
309
+ `
310
+ }
311
+ return `${imports}${ui === 'veneer' ? "import { Button } from '@kerf-js/veneer'\n" : ''}import { Link, type LoadArgs, type RouteProps } from '@kerf-js/start'
312
+ import { me, signOut } from '#/server/session'
313
+
314
+ export const load = ({ ctx }: LoadArgs) => me.fetch()
315
+
316
+ export default function Root(props: RouteProps<typeof load>) {
317
+ return (
318
+ <>
319
+ <nav>
320
+ <Link href="/">Home</Link>
321
+ <Link href="/about">About</Link>${links}
322
+ {props.data ? ${signOut} : <Link href="/login">Sign in</Link>}
323
+ </nav>
324
+ <main>{props.children}</main>
325
+ </>
326
+ )
327
+ }
328
+ `
329
+ }
330
+
331
+ function home(ui, label) {
332
+ if (ui === 'veneer') {
333
+ return `import type { Meta } from '@kerf-js/start'
334
+ import { state } from '@kerf-js/core'
335
+ import { Badge, Button, Card } from '@kerf-js/veneer'
336
+
337
+ export const meta: Meta = { title: { absolute: ${JSON.stringify(label)} }, description: ${JSON.stringify(`${label}, made with kerf.`)} }
338
+
339
+ export default function Home() {
340
+ const count = state(0)
341
+ return (
342
+ <Card eyebrow="kerf + veneer" title=${JSON.stringify(`Welcome to ${label}`)}>
343
+ <p>
344
+ Clicked <Badge>{count.value}</Badge> times.
345
+ </p>
346
+ <Button onClick={() => count.value++}>Click</Button>
347
+ </Card>
348
+ )
349
+ }
350
+ `
351
+ }
352
+ return `import type { Meta } from '@kerf-js/start'
353
+ import { state } from '@kerf-js/core'
354
+
355
+ export const meta: Meta = { title: { absolute: ${JSON.stringify(label)} }, description: ${JSON.stringify(`${label}, made with kerf.`)} }
356
+
357
+ export default function Home() {
358
+ const count = state(0)
359
+ return (
360
+ <section class=${JSON.stringify(classes(ui, 'card'))}>
361
+ <h1${named(ui, 'title')}>Welcome to ${label}</h1>
362
+ <button${named(ui, 'button')} type="button" onClick={() => count.value++}>
363
+ Clicked {count.value} times
364
+ </button>
365
+ </section>
366
+ )
367
+ }
368
+ `
369
+ }
370
+
371
+ const named = (ui, part) => (classes(ui, part) ? ` class="${classes(ui, part)}"` : '')
372
+
373
+ function css(ui) {
374
+ if (ui === 'tailwind') return TAILWIND_CSS
375
+ // headless rides veneer's tokens (veneer-core's veneer.css, the fluid title size included); none brings its own.
376
+ const v =
377
+ ui === 'headless'
378
+ ? {
379
+ bg: 'var(--veneer-color-page)',
380
+ fg: 'var(--veneer-color-text)',
381
+ accent: 'var(--veneer-color-accent-solid)',
382
+ radius: 'var(--veneer-radius-surface)',
383
+ title: 'var(--veneer-text-title-size)',
384
+ }
385
+ : {
386
+ bg: 'Canvas',
387
+ fg: 'CanvasText',
388
+ accent: 'LinkText',
389
+ radius: '8px',
390
+ title: 'clamp(1.5rem, 1.2rem + 2cqi, 2.5rem)',
391
+ }
392
+ return `:root { color-scheme: light dark; }
393
+ body { margin: 0; font-family: system-ui, sans-serif; background: ${v.bg}; color: ${v.fg}; }
394
+ nav { display: flex; gap: 1rem; padding: 1rem; }
395
+ main { padding: 1rem; max-inline-size: 60rem; margin-inline: auto; }
396
+ .card { container-type: inline-size; padding: 1.5rem; border-radius: ${v.radius}; border: 1px solid color-mix(in oklab, currentColor 15%, transparent); }
397
+ .card h1 { font-size: ${v.title}; }
398
+ button { font: inherit; padding: 0.5rem 1rem; border-radius: ${v.radius}; border: 1px solid ${v.accent}; background: none; color: inherit; }
399
+ `
400
+ }
@@ -0,0 +1,151 @@
1
+ // Tailwind: the same files `kerf add tailwind` writes (packages/cli/src/tailwind.mjs, held equal by a test).
2
+ /** What `--ui tailwind` adds, pinned. */
3
+ export const tailwindPackages = { tailwindcss: '4.3.3', '@tailwindcss/vite': '4.3.3' }
4
+ /** `vite.config.ts` for `--ui tailwind`. */
5
+ export const TAILWIND_VITE = `import tailwindcss from '@tailwindcss/vite'
6
+
7
+ export default { plugins: [tailwindcss()] }
8
+ `
9
+ /** The stylesheet for `--ui tailwind`. */
10
+ export const TAILWIND_CSS = `@import "tailwindcss";
11
+ `
12
+ const tw = {
13
+ card: 'mx-auto max-w-2xl space-y-4 rounded-lg border border-current/15 p-6',
14
+ title: 'text-2xl font-semibold',
15
+ button: 'rounded-md border border-current/30 px-3 py-1.5 hover:bg-current/5',
16
+ input: 'rounded-md border border-current/30 px-3 py-1.5',
17
+ }
18
+ /** The class of a scaffold element: Tailwind's utilities, or the plain CSS in src/app.css. */
19
+ export const classes = (ui, part) => (ui === 'tailwind' ? tw[part] : part === 'card' ? 'card' : '')
20
+ const attr = (ui, part) => (ui === 'tailwind' ? ` class="${tw[part]}"` : '')
21
+
22
+ /** The page's controls in each UI kit: veneer's components, or plain elements with the same roles and names. */
23
+ export const controls = (ui) =>
24
+ ui === 'veneer'
25
+ ? {
26
+ imports: `import { Alert, Button, Card, Checkbox, Input } from '@kerf-js/veneer'\n`,
27
+ card: (title, body) => `<Card title=${JSON.stringify(title)}>${body}</Card>`,
28
+ input: (label, box, type = 'text') =>
29
+ `<Input label=${JSON.stringify(label)} type="${type}" value={${box}.value} onInput={e => (${box}.value = e.currentTarget.value)} />`,
30
+ submit: (label, pending) => `<Button type="submit" loading={${pending}}>${label}</Button>`,
31
+ button: (label, onClick, extra = '') =>
32
+ `<Button emphasis="ghost" ${extra}onClick={${onClick}}>${label}</Button>`,
33
+ error: (box) => `{${box}.value && <Alert tone="critical" live>{${box}.value}</Alert>}`,
34
+ row: `<Checkbox checked={t.done} onChange={() => toggleTodo({ id: t.id })}>{t.title}</Checkbox>
35
+ <Button emphasis="ghost" tone="neutral" size="sm" icon="x" aria-label={\`Delete \${t.title}\`} onClick={() => deleteTodo({ id: t.id })} />`,
36
+ }
37
+ : {
38
+ imports: '',
39
+ card: (title, body) =>
40
+ `<section class="${classes(ui, 'card')}"><h1${attr(ui, 'title')}>${title}</h1>${body}</section>`,
41
+ input: (label, box, type = 'text') =>
42
+ `<label>${label} <input${attr(ui, 'input')} type="${type}" value={${box}.value} onInput={e => (${box}.value = e.currentTarget.value)} /></label>`,
43
+ submit: (label, pending) =>
44
+ `<button${attr(ui, 'button')} type="submit" disabled={${pending}}>${label}</button>`,
45
+ button: (label, onClick, extra = '') =>
46
+ `<button${attr(ui, 'button')} type="button" ${extra}onClick={${onClick}}>${label}</button>`,
47
+ error: (box) => `{${box}.value && <p role="alert">{${box}.value}</p>}`,
48
+ row: `<label>
49
+ <input type="checkbox" checked={t.done} onChange={() => toggleTodo({ id: t.id })} /> {t.title}
50
+ </label>
51
+ <button type="button" aria-label={\`Delete \${t.title}\`} onClick={() => deleteTodo({ id: t.id })}>×</button>`,
52
+ }
53
+
54
+ /** `/todos`: the list on the server functions, written for this `--ui`. */
55
+ export function todosPage(ui) {
56
+ const c = controls(ui)
57
+ return `import type { Meta } from '@kerf-js/start'
58
+ import { Boundary, state } from '@kerf-js/core'
59
+ ${c.imports}import { addTodo, deleteTodo, listTodos, toggleTodo } from '#/server/todos'
60
+
61
+ export const meta: Meta = { title: 'Todos', description: 'Your todo list: add, tick off and delete.' }
62
+
63
+ // The query is made in here, inside the Boundary, so the Boundary sees it: it shows \`pending\` until the list arrives.
64
+ function TodoList() {
65
+ const todos = listTodos()
66
+ return (
67
+ <ul class="todos">
68
+ {(todos.value ?? []).map(t => (
69
+ <li key={t.id} class={t.done ? 'done' : 'open'}>
70
+ ${c.row}
71
+ </li>
72
+ ))}
73
+ </ul>
74
+ )
75
+ }
76
+
77
+ export default function Todos() {
78
+ const title = state('')
79
+ const problem = state('')
80
+ const add = async (e: SubmitEvent) => {
81
+ e.preventDefault()
82
+ const text = title.value.trim()
83
+ if (!text) return
84
+ title.value = ''
85
+ problem.value = ''
86
+ await addTodo({ title: text }).catch((err: Error) => (problem.value = err.message))
87
+ }
88
+ return (
89
+ ${c.card(
90
+ 'Todos',
91
+ `
92
+ <form onSubmit={add}>
93
+ ${c.input('New todo', 'title')}
94
+ ${c.submit('Add', 'addTodo.pending.value')}
95
+ </form>
96
+ ${c.error('problem')}
97
+ <Boundary pending={<p>Loading…</p>}>
98
+ <TodoList />
99
+ </Boundary>
100
+ `,
101
+ )}
102
+ )
103
+ }
104
+ `
105
+ }
106
+
107
+ /** `/login`: sign in and sign up, written for this `--ui`. */
108
+ export function loginPage(ui) {
109
+ const c = controls(ui)
110
+ return `import { redirect, type LoadArgs, type Meta } from '@kerf-js/start'
111
+ import { state } from '@kerf-js/core'
112
+ ${c.imports}import { signIn, signUp } from '#/server/session'
113
+
114
+ export const load = ({ ctx }: LoadArgs) => {
115
+ if (ctx.user) redirect('/todos')
116
+ }
117
+
118
+ export const meta: Meta = { title: 'Sign in', description: 'Sign in, or make an account.' }
119
+
120
+ export default function Login() {
121
+ const creating = state(false)
122
+ const name = state('')
123
+ const email = state('')
124
+ const password = state('')
125
+ const problem = state('')
126
+ const submit = async (e: SubmitEvent) => {
127
+ e.preventDefault()
128
+ problem.value = ''
129
+ const done = creating.value
130
+ ? signUp({ name: name.value, email: email.value, password: password.value })
131
+ : signIn({ email: email.value, password: password.value })
132
+ await done.catch((err: Error) => (problem.value = err.message))
133
+ }
134
+ return (
135
+ ${c.card(
136
+ 'Sign in',
137
+ `
138
+ <form onSubmit={submit}>
139
+ {creating.value && ${c.input('Name', 'name')}}
140
+ ${c.input('Email', 'email', 'email')}
141
+ ${c.input('Password', 'password', 'password')}
142
+ ${c.submit(`{creating.value ? 'Create account' : 'Sign in'}`, 'signIn.pending.value || signUp.pending.value')}
143
+ </form>
144
+ ${c.error('problem')}
145
+ ${c.button(`{creating.value ? 'I have an account' : 'Create an account'}`, '() => (creating.value = !creating.value)')}
146
+ `,
147
+ )}
148
+ )
149
+ }
150
+ `
151
+ }