@kayjs/kay 2.0.0-beta.3 → 2.0.0-beta.4

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 (91) hide show
  1. package/llms.txt +42 -0
  2. package/package.json +24 -13
  3. package/src/build/bundle.ts +11 -51
  4. package/src/build/client-plugin.ts +108 -0
  5. package/src/build/compile.ts +4 -2
  6. package/src/build/graph.ts +16 -3
  7. package/src/build/index.ts +23 -15
  8. package/src/build/islands.ts +28 -30
  9. package/src/build/manifest.ts +6 -3
  10. package/src/build/report.ts +82 -13
  11. package/src/build/resolve.ts +6 -7
  12. package/src/build/routes.ts +12 -21
  13. package/src/build/server-entry.ts +1 -1
  14. package/src/cli/check.ts +49 -43
  15. package/src/cli/commands.ts +224 -0
  16. package/src/cli/index.ts +46 -302
  17. package/src/cli/new.ts +15 -509
  18. package/src/cli/upgrade-plugins.ts +168 -0
  19. package/src/cli/upgrade.ts +220 -0
  20. package/src/compiler/analyze.ts +319 -565
  21. package/src/compiler/ast.ts +39 -0
  22. package/src/compiler/data-keys.ts +233 -0
  23. package/src/compiler/dom.ts +18 -15
  24. package/src/compiler/interactivity.ts +174 -0
  25. package/src/compiler/mistakes.ts +19 -1
  26. package/src/compiler/server-only.ts +4 -1
  27. package/src/compiler/shared.ts +1 -1
  28. package/src/compiler/ssr.ts +28 -28
  29. package/src/context.ts +1 -1
  30. package/src/dev/index.ts +15 -23
  31. package/src/dom/extras.ts +43 -12
  32. package/src/dom/index.ts +25 -1
  33. package/src/index.ts +0 -13
  34. package/src/jsx-runtime.ts +1 -1
  35. package/src/plugins/context.ts +8 -6
  36. package/src/plugins/index.ts +2 -2
  37. package/src/plugins/load.ts +25 -2
  38. package/src/plugins/public.ts +6 -0
  39. package/src/plugins/services.ts +15 -3
  40. package/src/plugins/types.ts +7 -11
  41. package/src/server/action-registry.ts +10 -4
  42. package/src/server/action.ts +8 -2
  43. package/src/server/document.ts +13 -1
  44. package/src/server/errors.ts +7 -5
  45. package/src/server/index.ts +9 -10
  46. package/src/server/lifecycle.ts +22 -0
  47. package/src/server/plugin-host.ts +6 -8
  48. package/src/server/public.ts +15 -0
  49. package/src/server/request-scope.ts +22 -0
  50. package/src/server/stream.ts +4 -3
  51. package/src/ssr/context.ts +25 -0
  52. package/src/ssr/index.ts +10 -7
  53. package/src/test/browser.ts +180 -0
  54. package/src/test/index.ts +4 -1
  55. package/templates/_shared/AGENTS.md +5 -0
  56. package/templates/_shared/CLAUDE.md +1 -0
  57. package/templates/_shared/public/robots.txt +2 -0
  58. package/templates/_shared/tsconfig.json +19 -0
  59. package/templates/app/.env.example +4 -0
  60. package/templates/app/kay.config.ts +11 -0
  61. package/templates/app/package.json +20 -0
  62. package/templates/app/src/auth.ts +14 -0
  63. package/templates/app/src/routes/_layout.tsx +32 -0
  64. package/templates/app/src/routes/dashboard/_middleware.ts +3 -0
  65. package/templates/app/src/routes/dashboard/index.tsx +13 -0
  66. package/templates/app/src/routes/index.tsx +15 -0
  67. package/templates/app/src/routes/login.tsx +34 -0
  68. package/templates/app/src/styles/app.css +7 -0
  69. package/templates/blog/content/posts/welcome.md +9 -0
  70. package/templates/blog/kay.config.ts +23 -0
  71. package/templates/blog/package.json +21 -0
  72. package/templates/blog/src/posts.ts +26 -0
  73. package/templates/blog/src/routes/_layout.tsx +20 -0
  74. package/templates/blog/src/routes/blog/[slug].tsx +31 -0
  75. package/templates/blog/src/routes/index.tsx +29 -0
  76. package/templates/blog/src/styles/app.css +10 -0
  77. package/templates/fullstack/kay.config.ts +6 -0
  78. package/templates/fullstack/package.json +18 -0
  79. package/templates/fullstack/src/actions/greet.ts +19 -0
  80. package/templates/fullstack/src/components/Counter.tsx +10 -0
  81. package/templates/fullstack/src/components/GreetForm.tsx +26 -0
  82. package/templates/fullstack/src/routes/_layout.tsx +14 -0
  83. package/templates/fullstack/src/routes/api/health.ts +5 -0
  84. package/templates/fullstack/src/routes/index.tsx +13 -0
  85. package/templates/fullstack/src/styles/app.css +29 -0
  86. package/templates/minimal/kay.config.ts +6 -0
  87. package/templates/minimal/package.json +18 -0
  88. package/templates/minimal/src/components/Counter.tsx +10 -0
  89. package/templates/minimal/src/routes/_layout.tsx +14 -0
  90. package/templates/minimal/src/routes/index.tsx +11 -0
  91. package/templates/minimal/src/styles/app.css +22 -0
package/src/cli/new.ts CHANGED
@@ -1,7 +1,9 @@
1
- // `kay new <name> [--template minimal|fullstack|blog|app] [--force]` project scaffolder.
1
+ // `kay new <name> [--template minimal|fullstack|blog|app] [--force]` project scaffolder: copies `templates/_shared` and `templates/<template>`.
2
2
 
3
- import { existsSync, mkdirSync, readdirSync, writeFileSync } from 'node:fs'
3
+ import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'
4
4
  import { basename, dirname, join, resolve } from 'node:path'
5
+ import pkg from '../../package.json' with { type: 'json' }
6
+ import { relPosix, walkAllFiles } from '../build/files'
5
7
 
6
8
  export type ScaffoldTemplate = 'minimal' | 'fullstack' | 'blog' | 'app'
7
9
 
@@ -11,522 +13,26 @@ export interface ScaffoldOptions {
11
13
  kayVersion?: string | undefined
12
14
  }
13
15
 
16
+ const TEMPLATES_DIR = join(import.meta.dir, '../../templates')
17
+
14
18
  export function scaffoldProject(targetDir: string, options: ScaffoldOptions = {}): { root: string, files: string[] } {
15
19
  const root = resolve(targetDir)
16
20
  const name = basename(root).toLowerCase().replace(/[^a-z0-9-_]/g, '-') || 'kay-app'
17
21
  const template: ScaffoldTemplate = options.template ?? 'minimal'
18
- const kayVersion = options.kayVersion ?? '^2.0.0-beta.3'
22
+ const kayVersion = options.kayVersion ?? `^${pkg.version}`
19
23
 
20
24
  if (existsSync(root) && readdirSync(root).length > 0 && !options.force)
21
25
  throw new Error(`kay new: directory "${root}" is not empty (pass --force to overwrite)`)
22
26
 
23
- const kayDep = kayVersion.startsWith('npm:') || kayVersion.startsWith('file:') || kayVersion.startsWith('link:')
24
- ? kayVersion
25
- : `npm:@kayjs/kay@${kayVersion}`
26
- const deps: Record<string, string> = { kay: kayDep }
27
- if (template === 'blog') {
28
- deps['@kayjs/content'] = kayVersion
29
- deps['@kayjs/seo'] = kayVersion
30
- deps['@kayjs/ui'] = kayVersion
31
- }
32
- else if (template === 'app') {
33
- deps['@kayjs/auth'] = kayVersion
34
- deps['@kayjs/ui'] = kayVersion
35
- }
36
-
37
- const files: Record<string, string> = {
38
- 'package.json': `${JSON.stringify({
39
- name,
40
- private: true,
41
- type: 'module',
42
- scripts: {
43
- dev: 'kay dev',
44
- build: 'kay build',
45
- start: 'kay start',
46
- check: 'kay check',
47
- },
48
- dependencies: deps,
49
- devDependencies: {
50
- '@types/bun': 'latest',
51
- 'typescript': '^5.8.0',
52
- },
53
- }, null, 2)}\n`,
54
-
55
- 'tsconfig.json': `${JSON.stringify({
56
- compilerOptions: {
57
- target: 'ESNext',
58
- module: 'ESNext',
59
- moduleResolution: 'bundler',
60
- jsx: 'react-jsx',
61
- jsxImportSource: 'kay',
62
- strict: true,
63
- noEmit: true,
64
- skipLibCheck: true,
65
- types: ['bun'],
66
- },
67
- include: ['src', 'kay.config.ts'],
68
- }, null, 2)}\n`,
69
-
70
- 'kay.config.ts': `import { defineConfig } from 'kay/server'
71
-
72
- export default defineConfig({
73
- lang: 'en',
74
- plugins: [],
75
- })
76
- `,
77
-
78
- 'public/robots.txt': `User-agent: *\nAllow: /\n`,
79
-
80
- 'src/styles/app.css': `*, *::before, *::after { box-sizing: border-box; }
81
- body {
82
- margin: 0;
83
- font-family: system-ui, -apple-system, sans-serif;
84
- line-height: 1.6;
85
- color: #111827;
86
- background: #fafafa;
87
- }
88
- main {
89
- max-width: 44rem;
90
- margin: 4rem auto;
91
- padding: 0 1.5rem;
92
- }
93
- button {
94
- font: inherit;
95
- padding: 0.5rem 1rem;
96
- border-radius: 6px;
97
- border: 1px solid #d1d5db;
98
- background: #fff;
99
- cursor: pointer;
100
- }
101
- button:hover { background: #f3f4f6; }
102
- `,
103
-
104
- 'src/routes/_layout.tsx': `import type { KayChild } from 'kay'
105
- import { Head } from 'kay'
106
- import '../styles/app.css'
107
-
108
- export default function Layout({ children }: { children: KayChild }) {
109
- return (
110
- <>
111
- <Head>
112
- <title>${name}</title>
113
- </Head>
114
- <main>{children}</main>
115
- </>
116
- )
117
- }
118
- `,
119
-
120
- 'src/components/Counter.tsx': `import { signal } from 'kay'
121
-
122
- export function Counter({ initial = 0 }: { initial?: number }) {
123
- const count = signal(initial)
124
- return (
125
- <button type="button" onClick={() => count.value++}>
126
- Count: {count.value}
127
- </button>
128
- )
129
- }
130
- `,
131
-
132
- 'src/routes/index.tsx': `import { Counter } from '../components/Counter'
133
-
134
- export default async function Home() {
135
- return (
136
- <section>
137
- <h1>Welcome to Kay</h1>
138
- <p>Zero-directive islands, native TSX, and Bun speed.</p>
139
- <Counter initial={0} />
140
- </section>
141
- )
142
- }
143
- `,
144
- }
145
-
146
- if (template === 'fullstack') {
147
- files['src/routes/api/health.ts'] = `import type { RequestContext } from 'kay/server'
148
-
149
- export function GET(ctx: RequestContext) {
150
- return ctx.json({ ok: true, runtime: 'bun' })
151
- }
152
- `
153
- files['src/actions/greet.ts'] = `import type { StandardSchemaV1 } from 'kay/server'
154
- import { action } from 'kay/server'
155
-
156
- const nameSchema: StandardSchemaV1<{ name: string }> = {
157
- '~standard': {
158
- version: 1,
159
- vendor: 'kay',
160
- validate(raw: unknown) {
161
- const name = String((raw as { name?: unknown })?.name ?? '').trim()
162
- if (name.length < 2)
163
- return { issues: [{ message: 'Enter at least 2 characters', path: ['name'] }] }
164
- return { value: { name } }
165
- },
166
- },
167
- }
168
-
169
- export const greet = action(nameSchema, async ({ name }) => {
170
- return { message: \`Hello, \${name}!\` }
171
- })
172
- `
173
- files['src/styles/app.css'] += `
174
- .greet-form {
175
- margin-top: 1.5rem;
176
- display: flex;
177
- gap: 0.5rem;
178
- align-items: center;
179
- }
180
- `
181
- files['src/components/GreetForm.tsx'] = `import { signal } from 'kay'
182
- import { greet } from '../actions/greet'
183
-
184
- export function GreetForm() {
185
- const name = signal('')
186
- const reply = signal('')
187
-
188
- async function onSubmit(e: SubmitEvent) {
189
- e.preventDefault()
190
- const res = await greet({ name: name.value })
191
- reply.value = res.ok ? res.data.message : res.error
192
- }
193
-
194
- return (
195
- <form class="greet-form" action={greet.url} method="post" onSubmit={onSubmit}>
196
- <input
197
- name="name"
198
- placeholder="Your name"
199
- value={name.value}
200
- onInput={(e) => { name.value = (e.target as HTMLInputElement).value }}
201
- />
202
- <button type="submit">Greet</button>
203
- {reply.value && <span>{reply.value}</span>}
204
- </form>
205
- )
206
- }
207
- `
208
- files['src/routes/index.tsx'] = `import { Counter } from '../components/Counter'
209
- import { GreetForm } from '../components/GreetForm'
210
-
211
- export default async function Home() {
212
- return (
213
- <section>
214
- <h1>Welcome to Kay</h1>
215
- <p>Zero-directive islands, Standard-Schema actions, and Bun speed.</p>
216
- <Counter initial={0} />
217
- <GreetForm />
218
- </section>
219
- )
220
- }
221
- `
222
- }
223
-
224
- else if (template === 'blog') {
225
- delete files['src/components/Counter.tsx']
226
-
227
- files['src/styles/app.css'] = `body { margin: 0; background: var(--ui-paper); color: var(--ui-ink); font-family: var(--ui-font-body); }
228
- .wrap { max-width: 46rem; margin: 0 auto; padding: 2rem 1.25rem 4rem; }
229
- .site-header { padding-bottom: 1.25rem; margin-bottom: 2rem; border-bottom: 1px solid var(--ui-line); }
230
- .site-brand { font-family: var(--ui-font-display); font-size: 1.35rem; font-weight: 700; text-decoration: none; color: inherit; }
231
- .site-rss { font-size: 0.9rem; color: var(--ui-muted); }
232
- .page-title { margin: 0; font-family: var(--ui-font-display); }
233
- .post-link { color: inherit; text-decoration: none; }
234
- .post-desc { margin: 0; color: var(--ui-muted); }
235
- .post-title { font-family: var(--ui-font-display); margin-bottom: 0.25rem; }
236
- .post-meta { color: var(--ui-muted); margin-top: 0; }
237
- `
238
-
239
- files['content/posts/welcome.md'] = `---
240
- title: Welcome to ${name}
241
- date: 2026-11-23
242
- description: A zero-JS static Markdown blog built with Kay v2.
243
- tags: [kay, bun]
244
- ---
245
- ## Fast by Default
246
-
247
- This post is rendered at build time using Bun's native Zig Markdown engine and ships **0 KB** of client JavaScript.
248
- `
249
- files['src/posts.ts'] = `import { existsSync } from 'node:fs'
250
- import { join } from 'node:path'
251
- import { defineCollection } from '@kayjs/content'
252
-
253
- export interface PostMeta {
254
- title: string
255
- date: string
256
- description?: string
257
- tags?: string[]
258
- draft?: boolean
259
- }
260
-
261
- const postsDir = existsSync(join(import.meta.dir, '../content/posts'))
262
- ? join(import.meta.dir, '../content/posts')
263
- : join(import.meta.dir, '../../content/posts')
264
-
265
- export const posts = defineCollection<PostMeta>({ dir: postsDir })
266
- `
267
- files['kay.config.ts'] = `import { contentPlugin } from '@kayjs/content'
268
- import { seo } from '@kayjs/seo'
269
- import { ui } from '@kayjs/ui/plugin'
270
- import { defineConfig } from 'kay/server'
271
- import { posts } from './src/posts'
272
-
273
- export default defineConfig({
274
- lang: 'en',
275
- plugins: [
276
- ui({ grammar: 'editorial' }),
277
- seo({ site: 'https://example.com', titleTemplate: '%s — ${name}' }),
278
- contentPlugin({
279
- feeds: [{
280
- path: '/rss.xml',
281
- title: '${name}',
282
- description: 'Articles & notes',
283
- site: 'https://example.com',
284
- linkPrefix: '/blog',
285
- collection: posts,
286
- }],
287
- }),
288
- ],
289
- })
290
- `
291
- files['src/routes/_layout.tsx'] = `import type { KayChild } from 'kay'
292
- import { Head } from 'kay'
293
- import '../styles/app.css'
294
-
295
- export default function Layout({ children }: { children: KayChild }) {
296
- return (
297
- <>
298
- <Head>
299
- <title>${name}</title>
300
- </Head>
301
- <div class="wrap">
302
- <header data-layout="split" class="site-header">
303
- <a href="/" class="site-brand">${name}</a>
304
- <a href="/rss.xml" class="site-rss">RSS</a>
305
- </header>
306
- <main>{children}</main>
307
- </div>
308
- </>
309
- )
310
- }
311
- `
312
- files['src/routes/index.tsx'] = `import { Badge, Card, CardBody, CardFooter, CardHeader, Cluster, Stack } from '@kayjs/ui'
313
- import { posts } from '../posts'
314
-
315
- export const prerender = true
316
-
317
- export default async function BlogIndex() {
318
- const list = posts.all()
319
- return (
320
- <Stack gap="lg">
321
- <h1 class="page-title">Articles</h1>
322
- {list.map(post => (
323
- <Card key={post.slug}>
324
- <CardHeader>
325
- <a href={\`/blog/\${post.slug}\`} class="post-link">{post.data.title}</a>
326
- </CardHeader>
327
- <CardBody>
328
- <p class="post-desc">{post.data.description ?? ''}</p>
329
- </CardBody>
330
- <CardFooter>
331
- <Cluster>
332
- <span>{post.data.date} · {post.readingMinutes} min read</span>
333
- {(post.data.tags ?? []).map(tag => <Badge key={tag}>{tag}</Badge>)}
334
- </Cluster>
335
- </CardFooter>
336
- </Card>
337
- ))}
338
- </Stack>
339
- )
340
- }
341
- `
342
- files['src/routes/blog/[slug].tsx'] = `import type { RequestContext } from 'kay/server'
343
- import { Button, Stack } from '@kayjs/ui'
344
- import { Head } from 'kay'
345
- import { posts } from '../../posts'
346
-
347
- export const prerender = true
348
- export function paths() {
349
- return posts.paths('/blog')
350
- }
351
-
352
- export async function load(ctx: RequestContext) {
353
- const post = posts.get(ctx.params.slug ?? '')
354
- if (!post)
355
- return new Response('Not found', { status: 404 })
356
- return { post }
357
- }
358
-
359
- export default function PostPage({ data }: { data: { post: NonNullable<ReturnType<typeof posts.get>> } }) {
360
- const { post } = data
361
- return (
362
- <Stack gap="md">
363
- <Head><title>{post.data.title}</title></Head>
364
- <article>
365
- <h1 class="post-title">{post.data.title}</h1>
366
- <p class="post-meta">{post.data.date} · {post.readingMinutes} min read</p>
367
- <div innerHTML={post.html} />
368
- </article>
369
- <div><Button href="/" variant="outline">← All posts</Button></div>
370
- </Stack>
371
- )
372
- }
373
- `
374
- }
375
- else if (template === 'app') {
376
- delete files['src/components/Counter.tsx']
377
-
378
- files['src/styles/app.css'] = `body { margin: 0; background: var(--ui-paper); color: var(--ui-ink); font-family: var(--ui-font-body); }
379
- .wrap { max-width: 52rem; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
380
- .site-header { padding-bottom: 1.25rem; margin-bottom: 2rem; border-bottom: 1px solid var(--ui-line); }
381
- .site-brand { font-family: var(--ui-font-display); font-size: 1.3rem; font-weight: 700; text-decoration: none; color: inherit; }
382
- .page-title { margin: 0; font-family: var(--ui-font-display); }
383
- .page-lead { margin: 0; color: var(--ui-muted); }
384
- .m-0 { margin: 0; }
385
- `
386
-
387
- files['src/auth.ts'] = `import { join } from 'node:path'
388
- import { createAuth } from '@kayjs/auth'
389
- import { sqliteAuthStore } from '@kayjs/auth/sqlite'
390
-
391
- // Set AUTH_SECRET (at least 32 bytes) in production — see .env.example.
392
- const defaultDb = import.meta.dir.startsWith('/$bunfs')
393
- ? './data/auth.sqlite'
394
- : join(import.meta.dir, '../data/auth.sqlite')
395
-
396
- export const auth = createAuth({
397
- store: sqliteAuthStore(process.env.AUTH_DB || defaultDb),
398
- secret: process.env.AUTH_SECRET || undefined,
399
- defaultRedirect: '/dashboard',
400
- })
401
- `
402
- files['.env.example'] = `# Generate a 32+ byte secret for production, e.g.:
403
- # openssl rand -base64 32
404
- AUTH_SECRET=
405
- AUTH_DB=./data/auth.sqlite
406
- `
407
- files['kay.config.ts'] = `import { ui } from '@kayjs/ui/plugin'
408
- import { defineConfig } from 'kay/server'
409
- import { auth } from './src/auth'
410
-
411
- export default defineConfig({
412
- lang: 'en',
413
- plugins: [
414
- ui({ grammar: 'editorial' }),
415
- auth.plugin,
416
- ],
417
- })
418
- `
419
- files['src/routes/_layout.tsx'] = `import type { LayoutProps } from 'kay'
420
- import { Button, Cluster, Toaster } from '@kayjs/ui'
421
- import { Head } from 'kay'
422
- import '../styles/app.css'
423
-
424
- export default function Layout({ children, locals }: LayoutProps) {
425
- const user = locals.user
426
- return (
427
- <>
428
- <Head>
429
- <title>${name}</title>
430
- </Head>
431
- <div class="wrap">
432
- <header data-layout="split" class="site-header">
433
- <a href="/" class="site-brand">${name}</a>
434
- {user
435
- ? (
436
- <Cluster>
437
- <Button href="/dashboard" variant="ghost" size="sm">{user.email}</Button>
438
- <form action="/auth/signout" method="post">
439
- <Button type="submit" variant="outline" size="sm">Sign out</Button>
440
- </form>
441
- </Cluster>
442
- )
443
- : <Button href="/login" variant="outline" size="sm">Sign in</Button>}
444
- </header>
445
- <main>{children}</main>
446
- </div>
447
- <Toaster />
448
- </>
449
- )
450
- }
451
- `
452
- files['src/routes/index.tsx'] = `import { Badge, Button, Cluster, Stack } from '@kayjs/ui'
453
-
454
- export default async function Home() {
455
- return (
456
- <Stack gap="md">
457
- <Cluster><Badge tone="accent">Kay v2</Badge><Badge>SQLite Auth</Badge></Cluster>
458
- <h1 class="page-title">Welcome to ${name}</h1>
459
- <p class="page-lead">Zero-dependency Argon2id auth, @kayjs/ui pure CSS grammar, and Bun speed.</p>
460
- <Cluster>
461
- <Button href="/login" tone="accent">Get started</Button>
462
- <Button href="/dashboard" variant="outline">Dashboard</Button>
463
- </Cluster>
464
- </Stack>
465
- )
466
- }
467
- `
468
- files['src/routes/login.tsx'] = `import { Button, Card, CardBody, CardHeader, Field, Grid, Stack } from '@kayjs/ui'
469
-
470
- export default function LoginPage() {
471
- return (
472
- <Grid min="md" gap="lg">
473
- <Card>
474
- <CardHeader>Sign in</CardHeader>
475
- <CardBody>
476
- <form action="/auth/signin" method="post">
477
- <Stack gap="sm">
478
- <input type="hidden" name="redirect" value="/dashboard" />
479
- <Field id="in-email" label="Email" required><input id="in-email" name="email" type="email" required /></Field>
480
- <Field id="in-pass" label="Password" required><input id="in-pass" name="password" type="password" required /></Field>
481
- <Button type="submit" tone="accent">Sign in</Button>
482
- </Stack>
483
- </form>
484
- </CardBody>
485
- </Card>
486
- <Card>
487
- <CardHeader>Create account</CardHeader>
488
- <CardBody>
489
- <form action="/auth/signup" method="post">
490
- <Stack gap="sm">
491
- <input type="hidden" name="redirect" value="/dashboard" />
492
- <Field id="up-email" label="Email" required><input id="up-email" name="email" type="email" required /></Field>
493
- <Field id="up-pass" label="Password" hint="Min 12 characters" required><input id="up-pass" name="password" type="password" minlength="12" required /></Field>
494
- <Button type="submit" tone="accent">Create account</Button>
495
- </Stack>
496
- </form>
497
- </CardBody>
498
- </Card>
499
- </Grid>
500
- )
501
- }
502
- `
503
- files['src/routes/dashboard/_middleware.ts'] = `import { auth } from '../../auth'
504
-
505
- export default auth.guard({ redirectTo: '/login' })
506
- `
507
- files['src/routes/dashboard/index.tsx'] = `import type { PageProps } from 'kay'
508
- import { Card, CardBody, CardHeader } from '@kayjs/ui'
509
-
510
- export default async function DashboardPage({ locals }: PageProps) {
511
- return (
512
- <Card>
513
- <CardHeader>Dashboard</CardHeader>
514
- <CardBody>
515
- <p class="m-0">Signed in as <strong>{locals.user?.email}</strong>.</p>
516
- </CardBody>
517
- </Card>
518
- )
519
- }
520
- `
521
- }
522
-
523
27
  const written: string[] = []
524
- for (const [rel, content] of Object.entries(files)) {
525
- const abs = join(root, rel)
526
- mkdirSync(dirname(abs), { recursive: true })
527
- writeFileSync(abs, content)
528
- written.push(rel)
28
+ for (const dir of [join(TEMPLATES_DIR, '_shared'), join(TEMPLATES_DIR, template)]) {
29
+ for (const abs of walkAllFiles(dir)) {
30
+ const rel = relPosix(dir, abs)
31
+ const text = readFileSync(abs, 'utf8').replaceAll('__APP_NAME__', name).replaceAll('__KAY_VERSION__', kayVersion)
32
+ mkdirSync(dirname(join(root, rel)), { recursive: true })
33
+ writeFileSync(join(root, rel), text)
34
+ written.push(rel)
35
+ }
529
36
  }
530
-
531
37
  return { root, files: written }
532
38
  }