@murumets-ee/create 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.
package/dist/index.js ADDED
@@ -0,0 +1,2039 @@
1
+ import{a as e,b as m,c,d as l,e as w}from"./chunk-YJOFTYN5.js";import{join as v}from"path";import{join as s}from"path";async function y(t,n){await e(s(t,"lib/auth.ts"),`import { getToolkitApp } from './app'
2
+ import { getAuth } from '@murumets-ee/auth'
3
+
4
+ await getToolkitApp()
5
+
6
+ export const auth = getAuth()
7
+ `),await e(s(t,"lib/auth-client.ts"),`import { createClient } from '@murumets-ee/auth/client'
8
+
9
+ export const authClient = createClient()
10
+ `),await e(s(t,"app/api/auth/[...all]/route.ts"),`import { toNextJsHandler } from 'better-auth/next-js'
11
+ import { auth } from '../../../../lib/auth'
12
+
13
+ export const { GET, POST } = toNextJsHandler(auth)
14
+ `),await e(s(t,"app/[locale]/auth/layout.tsx"),`import { AuthProviders } from './providers'
15
+ import type { ReactNode } from 'react'
16
+
17
+ export default function AuthLayout({ children }: { children: ReactNode }) {
18
+ return (
19
+ <AuthProviders>
20
+ <div className="flex min-h-[calc(100vh-3rem)] items-center justify-center px-4">
21
+ {children}
22
+ </div>
23
+ </AuthProviders>
24
+ )
25
+ }
26
+ `),await e(s(t,"app/[locale]/auth/providers.tsx"),`'use client'
27
+
28
+ import { AuthUIProvider } from '@murumets-ee/auth-ui'
29
+ import { authClient } from '@/lib/auth-client'
30
+ import Link from 'next/link'
31
+ import { useRouter } from 'next/navigation'
32
+ import { useLocale } from 'next-intl'
33
+ import type { ReactNode } from 'react'
34
+
35
+ export function AuthProviders({ children }: { children: ReactNode }) {
36
+ const router = useRouter()
37
+ const locale = useLocale()
38
+
39
+ return (
40
+ <AuthUIProvider
41
+ authClient={authClient as never}
42
+ basePath="/auth"
43
+ redirectTo="/"
44
+ Link={Link}
45
+ navigate={(url) => router.push(url)}
46
+ resetPasswordUrl={\`/\${locale}/auth/reset-password\`}
47
+ >
48
+ {children}
49
+ </AuthUIProvider>
50
+ )
51
+ }
52
+ `),await e(s(t,"app/[locale]/auth/sign-in/page.tsx"),`import { SignInForm } from '@murumets-ee/auth-ui'
53
+
54
+ export default function SignInPage() {
55
+ return <SignInForm />
56
+ }
57
+ `),await e(s(t,"app/[locale]/auth/sign-up/page.tsx"),`import { SignUpForm } from '@murumets-ee/auth-ui'
58
+
59
+ export default function SignUpPage() {
60
+ return <SignUpForm />
61
+ }
62
+ `),await e(s(t,"app/[locale]/auth/forgot-password/page.tsx"),`import { ForgotPasswordForm } from '@murumets-ee/auth-ui'
63
+
64
+ export default function ForgotPasswordPage() {
65
+ return <ForgotPasswordForm />
66
+ }
67
+ `),await e(s(t,"app/[locale]/auth/reset-password/page.tsx"),`import { Suspense } from 'react'
68
+ import { ResetPasswordContent } from './content'
69
+
70
+ export default function ResetPasswordPage() {
71
+ return (
72
+ <Suspense>
73
+ <ResetPasswordContent />
74
+ </Suspense>
75
+ )
76
+ }
77
+ `),await e(s(t,"app/[locale]/auth/reset-password/content.tsx"),`'use client'
78
+
79
+ import { useSearchParams } from 'next/navigation'
80
+ import { ResetPasswordForm } from '@murumets-ee/auth-ui'
81
+
82
+ export function ResetPasswordContent() {
83
+ const searchParams = useSearchParams()
84
+ const token = searchParams.get('token')
85
+
86
+ if (!token) {
87
+ return (
88
+ <div className="text-center">
89
+ <h1 className="text-2xl font-bold text-zinc-900 dark:text-zinc-50">
90
+ Invalid or expired link
91
+ </h1>
92
+ <p className="mt-2 text-zinc-500">
93
+ Please request a new password reset.
94
+ </p>
95
+ </div>
96
+ )
97
+ }
98
+
99
+ return <ResetPasswordForm token={token} />
100
+ }
101
+ `),await e(s(t,"app/[locale]/setup/page.tsx"),`import { redirect } from 'next/navigation'
102
+ import { sql } from 'drizzle-orm'
103
+ import { getToolkitApp } from '@/lib/app'
104
+ import { SetupForm } from './form'
105
+
106
+ export default async function SetupPage() {
107
+ const app = await getToolkitApp()
108
+ const result = await app.db.readOnly.execute<{ count: string }>(
109
+ sql\`SELECT COUNT(*)::text as count FROM "user"\`,
110
+ )
111
+
112
+ if (Number(result[0]?.count) > 0) {
113
+ redirect('/')
114
+ }
115
+
116
+ return (
117
+ <div className="max-w-md mx-auto p-8">
118
+ <h1 className="text-2xl font-bold mb-2">Create Admin</h1>
119
+ <p className="text-sm text-zinc-500 dark:text-zinc-400 mb-6">
120
+ No users found. Create the first admin account.
121
+ </p>
122
+ <SetupForm />
123
+ </div>
124
+ )
125
+ }
126
+ `),await e(s(t,"app/[locale]/setup/form.tsx"),`'use client'
127
+
128
+ import { useState } from 'react'
129
+ import { createFirstAdmin } from './actions'
130
+
131
+ export function SetupForm() {
132
+ const [result, setResult] = useState<{ ok?: boolean; error?: string; email?: string } | null>(null)
133
+ const [loading, setLoading] = useState(false)
134
+
135
+ async function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
136
+ e.preventDefault()
137
+ setLoading(true)
138
+ setResult(null)
139
+ const res = await createFirstAdmin(new FormData(e.currentTarget))
140
+ setResult(res)
141
+ setLoading(false)
142
+ }
143
+
144
+ if (result?.ok) {
145
+ return (
146
+ <div className="space-y-2">
147
+ <p className="text-green-600 dark:text-green-400">Admin created: {result.email}</p>
148
+ <a href="/auth/sign-in" className="text-blue-600 dark:text-blue-400 hover:underline">
149
+ Sign in &rarr;
150
+ </a>
151
+ </div>
152
+ )
153
+ }
154
+
155
+ return (
156
+ <form onSubmit={handleSubmit} className="flex flex-col gap-4">
157
+ <label className="text-sm font-medium">
158
+ Name
159
+ <input
160
+ name="name"
161
+ required
162
+ className="mt-1 block w-full px-3 py-2 bg-zinc-100 dark:bg-zinc-900 border border-zinc-300 dark:border-zinc-700 rounded-md text-sm focus:outline-none focus:ring-1 focus:ring-blue-500"
163
+ />
164
+ </label>
165
+ <label className="text-sm font-medium">
166
+ Email
167
+ <input
168
+ name="email"
169
+ type="email"
170
+ required
171
+ className="mt-1 block w-full px-3 py-2 bg-zinc-100 dark:bg-zinc-900 border border-zinc-300 dark:border-zinc-700 rounded-md text-sm focus:outline-none focus:ring-1 focus:ring-blue-500"
172
+ />
173
+ </label>
174
+ <label className="text-sm font-medium">
175
+ Password (min 8 chars)
176
+ <input
177
+ name="password"
178
+ type="password"
179
+ required
180
+ minLength={8}
181
+ className="mt-1 block w-full px-3 py-2 bg-zinc-100 dark:bg-zinc-900 border border-zinc-300 dark:border-zinc-700 rounded-md text-sm focus:outline-none focus:ring-1 focus:ring-blue-500"
182
+ />
183
+ </label>
184
+
185
+ {result?.error && <p className="text-red-600 dark:text-red-400 text-sm">{result.error}</p>}
186
+
187
+ <button
188
+ type="submit"
189
+ disabled={loading}
190
+ className="px-4 py-2 text-sm rounded-md bg-blue-600 text-white hover:bg-blue-500 disabled:opacity-50 transition-colors"
191
+ >
192
+ {loading ? 'Creating...' : 'Create Admin'}
193
+ </button>
194
+ </form>
195
+ )
196
+ }
197
+ `),await e(s(t,"app/[locale]/setup/actions.ts"),`'use server'
198
+
199
+ import { sql } from 'drizzle-orm'
200
+ import { getToolkitApp } from '@/lib/app'
201
+ import { getAuth } from '@murumets-ee/auth'
202
+
203
+ /**
204
+ * Create the first admin user. Locked down:
205
+ * - Advisory lock prevents race conditions (two simultaneous requests)
206
+ * - User count check inside the lock ensures only one admin can be created
207
+ * - Once any user exists, this action permanently refuses
208
+ */
209
+ export async function createFirstAdmin(formData: FormData) {
210
+ const email = formData.get('email') as string
211
+ const password = formData.get('password') as string
212
+ const name = formData.get('name') as string
213
+
214
+ if (!email || !password || !name) {
215
+ return { error: 'All fields are required' }
216
+ }
217
+
218
+ if (password.length < 8) {
219
+ return { error: 'Password must be at least 8 characters' }
220
+ }
221
+
222
+ const app = await getToolkitApp()
223
+
224
+ // Acquire advisory lock + check atomically in a transaction
225
+ const canCreate = await app.db.readWrite.transaction(async (tx) => {
226
+ // Advisory lock 1 = "setup lock". Blocks concurrent setup attempts.
227
+ await tx.execute(sql\`SELECT pg_advisory_xact_lock(1)\`)
228
+
229
+ const result = await tx.execute<{ count: string }>(
230
+ sql\`SELECT COUNT(*)::text as count FROM "user"\`,
231
+ )
232
+ return Number(result[0]?.count) === 0
233
+ })
234
+
235
+ if (!canCreate) {
236
+ return { error: 'Admin user already exists. Setup is complete.' }
237
+ }
238
+
239
+ const auth = getAuth()
240
+
241
+ const adminUser = await auth.api.signUpEmail({
242
+ body: { email, password, name },
243
+ })
244
+
245
+ await app.db.readWrite.execute(
246
+ sql\`UPDATE "user" SET role = 'admin' WHERE id = \${adminUser.user.id}\`,
247
+ )
248
+
249
+ return { ok: true, email: adminUser.user.email }
250
+ }
251
+ `)}import{join as d}from"path";async function k(t,n){let{name:r}=n;await e(d(t,".env.example"),`DATABASE_URL=postgresql://${r}:${r}_dev_password@localhost:5432/${r}_dev
252
+ BETTER_AUTH_SECRET=dev-secret-change-me-in-production-min-32-chars
253
+ BETTER_AUTH_URL=http://localhost:3000
254
+ LOG_LEVEL=debug
255
+ NEXT_PUBLIC_APP_URL=http://localhost:3000
256
+ QUEUE_WORKER=true
257
+ RESEND_API_KEY=
258
+ RESEND_WEBHOOK_SECRET=
259
+ MAIL_FROM=noreply@example.com
260
+ CSAT_SECRET=
261
+ `),await e(d(t,".npmrc"),`@murumets-ee:registry=https://npm.pkg.github.com
262
+ //npm.pkg.github.com/:_authToken=\${GITHUB_TOKEN}
263
+ `),await w(d(t,".gitignore"),`
264
+ # Toolkit generated files
265
+ generated/
266
+
267
+ # Environment
268
+ .env*
269
+ !.env.example
270
+ `),await e(d(t,"docker-compose.yml"),`services:
271
+ postgres:
272
+ image: postgres:17-alpine
273
+ container_name: ${r}-postgres
274
+ restart: unless-stopped
275
+ environment:
276
+ POSTGRES_USER: ${r}
277
+ POSTGRES_PASSWORD: ${r}_dev_password
278
+ POSTGRES_DB: ${r}_dev
279
+ ports:
280
+ - "5432:5432"
281
+ volumes:
282
+ - postgres_data:/var/lib/postgresql/data
283
+ healthcheck:
284
+ test: ["CMD-SHELL", "pg_isready -U ${r} -d ${r}_dev"]
285
+ interval: 10s
286
+ timeout: 5s
287
+ retries: 5
288
+
289
+ volumes:
290
+ postgres_data:
291
+ name: ${r}_postgres_data
292
+ `)}import{join as x}from"path";async function A(t,n){await e(x(t,"entities/index.ts"),`export { Article } from './article'
293
+ export { Category } from './category'
294
+ `),await e(x(t,"entities/article.ts"),`import { behavior, defineEntity, field } from '@murumets-ee/entity'
295
+
296
+ export const Article = defineEntity({
297
+ name: 'article',
298
+ fields: {
299
+ title: field.text({ required: true, maxLength: 200, indexed: true, translatable: true }),
300
+ slug: field.slug({ from: 'title', unique: true }),
301
+ excerpt: field.text({ maxLength: 500, translatable: true }),
302
+ body: field.richtext(),
303
+ viewCount: field.number({ default: 0, integer: true }),
304
+ featured: field.boolean({ default: false }),
305
+ publishDate: field.date(),
306
+ contentType: field.select({ options: ['news', 'tutorial', 'announcement'], default: 'news' }),
307
+ category: field.reference({ entity: 'category', required: false }),
308
+ tags: field.reference({ entity: 'category', cardinality: 'many' }),
309
+ coverImage: field.media({ accept: ['image/*'] }),
310
+ },
311
+ behaviors: [
312
+ behavior.publishable(),
313
+ behavior.auditable(),
314
+ behavior.sluggable('title'),
315
+ behavior.revisionable(),
316
+ ],
317
+ scope: 'global',
318
+ access: {
319
+ view: 'public',
320
+ create: 'group.editor',
321
+ update: 'group.editor',
322
+ delete: 'group.admin',
323
+ },
324
+ })
325
+ `),await e(x(t,"entities/category.ts"),`import { defineEntity, field } from '@murumets-ee/entity'
326
+
327
+ export const Category = defineEntity({
328
+ name: 'category',
329
+ fields: {
330
+ name: field.text({ required: true, maxLength: 100, indexed: true, translatable: true }),
331
+ slug: field.slug({ from: 'name', unique: true }),
332
+ description: field.text({ maxLength: 500, translatable: true }),
333
+ },
334
+ scope: 'global',
335
+ access: {
336
+ view: 'public',
337
+ create: 'group.editor',
338
+ update: 'group.editor',
339
+ delete: 'group.admin',
340
+ },
341
+ })
342
+ `)}import{join as T}from"path";async function N(t,n){await e(T(t,"i18n/routing.ts"),`import { defineRouting } from 'next-intl/routing'
343
+
344
+ export const routing = defineRouting({
345
+ locales: ['en'],
346
+ defaultLocale: 'en',
347
+ })
348
+ `),await e(T(t,"i18n/request.ts"),`import { getRequestConfig } from 'next-intl/server'
349
+ import { hasLocale } from 'next-intl'
350
+ import { routing } from './routing'
351
+ import { getAuthMessages } from '@murumets-ee/auth-ui/i18n'
352
+
353
+ export default getRequestConfig(async ({ requestLocale }) => {
354
+ const requested = await requestLocale
355
+ const locale = hasLocale(routing.locales, requested)
356
+ ? requested
357
+ : routing.defaultLocale
358
+
359
+ const authMessages = await getAuthMessages(locale)
360
+
361
+ return {
362
+ locale,
363
+ messages: {
364
+ ...authMessages,
365
+ },
366
+ }
367
+ })
368
+ `)}import{mkdir as z}from"fs/promises";import{join as a}from"path";var i={myorgCore:"0.1.0",myorgDb:"0.1.0",myorgEntity:"0.1.0",myorgLogging:"0.1.0",myorgAuth:"0.1.0",myorgAuthUi:"0.1.0",betterAuth:"1.4.0",drizzleOrm:"0.45.1",nextIntl:"4.8.2",nextThemes:"0.4.6",lucideReact:"0.563.0",postgres:"3.4.5",reactHookForm:"7.71.1",hookformResolvers:"5.2.2",zod:"3.24.1",drizzleKit:"0.27.2",tsx:"4.19.2",babelReactCompiler:"1.0.0"};async function E(t,n,r){await L(t,n),r?.("Workspace root created"),r?.("Creating admin app..."),await $(t,n),r?.("Admin app created"),r?.("Creating web app..."),await M(t,n),r?.("Web app created"),await _(t,n),r?.("Shared config package created")}async function L(t,n){let{name:r}=n;await z(t,{recursive:!0}),await e(a(t,"pnpm-workspace.yaml"),`packages:
369
+ - 'packages/*'
370
+ - 'apps/*'
371
+
372
+ ignoredBuiltDependencies:
373
+ - sharp
374
+ - unrs-resolver
375
+ `),await e(a(t,"package.json"),`${JSON.stringify({name:`@${r}/monorepo`,version:"0.0.0",private:!0,type:"module",scripts:{dev:"turbo dev",build:"turbo build","db:generate":"tsx --env-file=.env packages/config/scripts/generate-schema.ts","db:migrate:generate":"drizzle-kit generate --config packages/config/drizzle.config.ts","db:migrate":"tsx --env-file=.env packages/config/scripts/migrate.ts","db:reset":"tsx --env-file=.env packages/config/scripts/reset-db.ts"},devDependencies:{turbo:"^2.3.3",typescript:"^5.7.3",tsx:`^${i.tsx}`,"drizzle-kit":`^${i.drizzleKit}`}},null,2)}
376
+ `),await e(a(t,".gitignore"),`# dependencies
377
+ node_modules/
378
+
379
+ # build
380
+ dist/
381
+ .next/
382
+ .turbo/
383
+
384
+ # env
385
+ .env*
386
+ !.env.example
387
+
388
+ # toolkit generated
389
+ generated/
390
+
391
+ # IDE
392
+ .vscode/
393
+ .idea/
394
+
395
+ # OS
396
+ .DS_Store
397
+ Thumbs.db
398
+
399
+ # logs
400
+ *.log
401
+
402
+ # migrations meta
403
+ migrations/
404
+
405
+ # turbo
406
+ .turbo/
407
+ `),await e(a(t,".env.example"),`DATABASE_URL=postgresql://${r}:${r}_dev_password@localhost:5432/${r}_dev
408
+ BETTER_AUTH_SECRET=dev-secret-change-me-in-production-min-32-chars
409
+ BETTER_AUTH_URL=http://localhost:3000
410
+ LOG_LEVEL=debug
411
+ NEXT_PUBLIC_APP_URL=http://localhost:3000
412
+ QUEUE_WORKER=true
413
+ RESEND_API_KEY=
414
+ RESEND_WEBHOOK_SECRET=
415
+ MAIL_FROM=noreply@example.com
416
+ CSAT_SECRET=
417
+ `),await e(a(t,".npmrc"),`@murumets-ee:registry=https://npm.pkg.github.com
418
+ //npm.pkg.github.com/:_authToken=\${GITHUB_TOKEN}
419
+ `),await e(a(t,"docker-compose.yml"),`services:
420
+ postgres:
421
+ image: postgres:17-alpine
422
+ container_name: ${r}-postgres
423
+ restart: unless-stopped
424
+ environment:
425
+ POSTGRES_USER: ${r}
426
+ POSTGRES_PASSWORD: ${r}_dev_password
427
+ POSTGRES_DB: ${r}_dev
428
+ ports:
429
+ - "5432:5432"
430
+ volumes:
431
+ - postgres_data:/var/lib/postgresql/data
432
+ healthcheck:
433
+ test: ["CMD-SHELL", "pg_isready -U ${r} -d ${r}_dev"]
434
+ interval: 10s
435
+ timeout: 5s
436
+ retries: 5
437
+
438
+ volumes:
439
+ postgres_data:
440
+ name: ${r}_postgres_data
441
+ `)}async function _(t,n){let{name:r}=n,o=a(t,"packages/config");await e(a(o,"package.json"),`${JSON.stringify({name:`@${r}/config`,version:"0.1.0",private:!0,type:"module",exports:{".":"./toolkit.config.ts","./entities":"./entities/index.ts","./entities/*":"./entities/*","./app":"./lib/app.ts","./auth":"./lib/auth.ts","./auth-client":"./lib/auth-client.ts"},dependencies:{"@murumets-ee/core":`^${i.myorgCore}`,"@murumets-ee/db":`^${i.myorgDb}`,"@murumets-ee/entity":`^${i.myorgEntity}`,"@murumets-ee/logging":`^${i.myorgLogging}`,"@murumets-ee/auth":`^${i.myorgAuth}`,"better-auth":`^${i.betterAuth}`,"drizzle-orm":`^${i.drizzleOrm}`,postgres:`^${i.postgres}`,zod:`^${i.zod}`}},null,2)}
442
+ `),await e(a(o,"tsconfig.json"),`${JSON.stringify({compilerOptions:{target:"ES2022",module:"ESNext",moduleResolution:"Bundler",strict:!0,esModuleInterop:!0,skipLibCheck:!0,resolveJsonModule:!0},include:["**/*.ts"]},null,2)}
443
+ `),await e(a(o,"toolkit.config.ts"),`import { auth } from '@murumets-ee/auth/plugin'
444
+ import { content } from '@murumets-ee/content/plugin'
445
+ import { defineConfig } from '@murumets-ee/core'
446
+ import { mail, ResendMailProvider } from '@murumets-ee/mail'
447
+ import { media } from '@murumets-ee/media/plugin'
448
+ import { queue } from '@murumets-ee/queue/plugin'
449
+ import { settings } from '@murumets-ee/settings/plugin'
450
+ import { storage } from '@murumets-ee/storage/plugin'
451
+ import { taxonomy } from '@murumets-ee/taxonomy/plugin'
452
+ import { ticketing } from '@murumets-ee/ticketing/plugin'
453
+ import { Article, Category } from './entities'
454
+ import * as authSchema from './generated/auth-schema'
455
+
456
+ if (!process.env.DATABASE_URL) {
457
+ throw new Error('DATABASE_URL environment variable is required')
458
+ }
459
+
460
+ export default defineConfig({
461
+ db: {
462
+ url: process.env.DATABASE_URL,
463
+ poolMin: 2,
464
+ poolMax: 10,
465
+ },
466
+ logging: {
467
+ level: (process.env.LOG_LEVEL || 'info') as 'debug' | 'info' | 'warn' | 'error',
468
+ name: '${r}',
469
+ },
470
+ entities: [Category, Article],
471
+ plugins: [
472
+ auth({ providers: ['email'], schema: authSchema }),
473
+ content({
474
+ locales: [{ code: 'en', label: 'English' }],
475
+ defaultLocale: 'en',
476
+ }),
477
+ settings(),
478
+ storage(),
479
+ media(),
480
+ taxonomy(),
481
+ queue(),
482
+ mail({
483
+ provider: process.env.RESEND_API_KEY
484
+ ? new ResendMailProvider({ apiKey: process.env.RESEND_API_KEY })
485
+ : undefined,
486
+ defaultFrom: process.env.MAIL_FROM ?? 'noreply@example.com',
487
+ webhookSecret: process.env.RESEND_WEBHOOK_SECRET,
488
+ }),
489
+ ticketing({
490
+ csatSecret: process.env.CSAT_SECRET,
491
+ }),
492
+ ],
493
+ projectRoot: import.meta.dirname,
494
+ })
495
+ `),await e(a(o,"auth.config.ts"),`import { betterAuth } from 'better-auth'
496
+ import { drizzleAdapter } from 'better-auth/adapters/drizzle'
497
+ import { admin } from 'better-auth/plugins'
498
+ import { organization } from 'better-auth/plugins/organization'
499
+ import { drizzle } from 'drizzle-orm/postgres-js'
500
+ import postgres from 'postgres'
501
+
502
+ const sql = postgres(process.env.DATABASE_URL!)
503
+ const db = drizzle(sql)
504
+
505
+ export const auth = betterAuth({
506
+ database: drizzleAdapter(db, { provider: 'pg' }),
507
+ emailAndPassword: { enabled: true },
508
+ plugins: [
509
+ admin(),
510
+ organization(),
511
+ ],
512
+ })
513
+ `),await e(a(o,"drizzle.config.ts"),`import type { Config } from 'drizzle-kit'
514
+
515
+ if (!process.env.DATABASE_URL) {
516
+ throw new Error('DATABASE_URL environment variable is required')
517
+ }
518
+
519
+ export default {
520
+ schema: ['./generated/schema.ts', './generated/auth-schema.ts'],
521
+ out: './migrations',
522
+ dialect: 'postgresql',
523
+ dbCredentials: {
524
+ url: process.env.DATABASE_URL,
525
+ },
526
+ } satisfies Config
527
+ `),await e(a(o,"entities/index.ts"),`export { Article } from './article'
528
+ export { Category } from './category'
529
+ `),await e(a(o,"entities/article.ts"),`import { behavior, defineEntity, field } from '@murumets-ee/entity'
530
+
531
+ export const Article = defineEntity({
532
+ name: 'article',
533
+ fields: {
534
+ title: field.text({ required: true, maxLength: 200, indexed: true, translatable: true }),
535
+ slug: field.slug({ from: 'title', unique: true }),
536
+ excerpt: field.text({ maxLength: 500, translatable: true }),
537
+ body: field.richtext(),
538
+ viewCount: field.number({ default: 0, integer: true }),
539
+ featured: field.boolean({ default: false }),
540
+ publishDate: field.date(),
541
+ contentType: field.select({ options: ['news', 'tutorial', 'announcement'], default: 'news' }),
542
+ category: field.reference({ entity: 'category', required: false }),
543
+ tags: field.reference({ entity: 'category', cardinality: 'many' }),
544
+ coverImage: field.media({ accept: ['image/*'] }),
545
+ },
546
+ behaviors: [
547
+ behavior.publishable(),
548
+ behavior.auditable(),
549
+ behavior.sluggable('title'),
550
+ behavior.revisionable(),
551
+ ],
552
+ scope: 'global',
553
+ access: {
554
+ view: 'public',
555
+ create: 'group.editor',
556
+ update: 'group.editor',
557
+ delete: 'group.admin',
558
+ },
559
+ })
560
+ `),await e(a(o,"entities/category.ts"),`import { defineEntity, field } from '@murumets-ee/entity'
561
+
562
+ export const Category = defineEntity({
563
+ name: 'category',
564
+ fields: {
565
+ name: field.text({ required: true, maxLength: 100, indexed: true, translatable: true }),
566
+ slug: field.slug({ from: 'name', unique: true }),
567
+ description: field.text({ maxLength: 500, translatable: true }),
568
+ },
569
+ scope: 'global',
570
+ access: {
571
+ view: 'public',
572
+ create: 'group.editor',
573
+ update: 'group.editor',
574
+ delete: 'group.admin',
575
+ },
576
+ })
577
+ `),await e(a(o,"lib/app.ts"),`import { createApp, setApp, type ToolkitApp } from '@murumets-ee/core'
578
+ import config from '../toolkit.config'
579
+
580
+ let appInstance: ToolkitApp | null = null
581
+
582
+ export async function getToolkitApp(): Promise<ToolkitApp> {
583
+ if (!appInstance) {
584
+ console.log('Initializing toolkit app...')
585
+ appInstance = await createApp(config)
586
+ setApp(appInstance)
587
+ console.log('Toolkit app initialized')
588
+ }
589
+ return appInstance
590
+ }
591
+ `),await e(a(o,"lib/auth.ts"),`import { getToolkitApp } from './app'
592
+ import { getAuth } from '@murumets-ee/auth'
593
+
594
+ await getToolkitApp()
595
+
596
+ export const auth = getAuth()
597
+ `),await e(a(o,"lib/auth-client.ts"),`import { createClient } from '@murumets-ee/auth/client'
598
+
599
+ export const authClient = createClient()
600
+ `),await e(a(o,"generated/auth-schema.ts"),`// This file is generated by better-auth CLI.
601
+ // Run: npx @better-auth/cli generate --config auth.config.ts -y
602
+ export {}
603
+ `),await e(a(o,"scripts/generate-schema.ts"),`/**
604
+ * Generate Drizzle schemas from entity definitions
605
+ */
606
+
607
+ import { mkdir, writeFile } from 'node:fs/promises'
608
+ import { join } from 'node:path'
609
+ import { generateSchemaCode, generateTranslationSchemaCode } from '@murumets-ee/entity'
610
+ import config from '../toolkit.config'
611
+
612
+ async function generateSchemas() {
613
+ console.log('Generating Drizzle schemas from entity definitions...')
614
+
615
+ const schemaDir = join(import.meta.dirname, '..', 'generated')
616
+ await mkdir(schemaDir, { recursive: true })
617
+
618
+ const imports: string[] = []
619
+ const schemas: string[] = []
620
+ let hasTranslations = false
621
+
622
+ for (const entity of config.entities) {
623
+ console.log(\` - Generating schema for \${entity.name}\`)
624
+
625
+ const schemaCode = generateSchemaCode(entity)
626
+ schemas.push(\`\\n// \${entity.name} table\`)
627
+ schemas.push(schemaCode)
628
+
629
+ const translationCode = generateTranslationSchemaCode(entity)
630
+ if (translationCode) {
631
+ hasTranslations = true
632
+ schemas.push(\`\\n// \${entity.name} translations\`)
633
+ schemas.push(translationCode)
634
+ }
635
+ }
636
+
637
+ const pgCoreImports = hasTranslations
638
+ ? \`import { pgTable, varchar, text, boolean, timestamp, integer, jsonb, uuid, unique } from 'drizzle-orm/pg-core'\\n\`
639
+ : \`import { pgTable, varchar, text, boolean, timestamp, integer, jsonb, uuid } from 'drizzle-orm/pg-core'\\n\`
640
+ imports.push(pgCoreImports)
641
+
642
+ const schemaFile = join(schemaDir, 'schema.ts')
643
+ await writeFile(schemaFile, [...imports, ...schemas].join('\\n'))
644
+
645
+ console.log(\`\\nSchemas written to: \${schemaFile}\`)
646
+ console.log('Run \\\`pnpm db:migrate:generate\\\` to create migrations')
647
+ }
648
+
649
+ generateSchemas().catch(console.error)
650
+ `),await e(a(o,"scripts/migrate.ts"),`/**
651
+ * Run pending migrations
652
+ */
653
+
654
+ import { createDbClient, runMigrations } from '@murumets-ee/db'
655
+
656
+ async function migrate() {
657
+ console.log('Running migrations...')
658
+
659
+ try {
660
+ if (!process.env.DATABASE_URL) {
661
+ throw new Error('DATABASE_URL environment variable is required')
662
+ }
663
+
664
+ const db = createDbClient({ url: process.env.DATABASE_URL })
665
+ await runMigrations(db, import.meta.dirname + '/..')
666
+
667
+ console.log('Migrations completed successfully')
668
+ process.exit(0)
669
+ } catch (error) {
670
+ console.error('Migration failed:', error)
671
+ process.exit(1)
672
+ }
673
+ }
674
+
675
+ migrate()
676
+ `),await e(a(o,"scripts/reset-db.ts"),`/**
677
+ * Reset database (DROP all tables)
678
+ * WARNING: Only for development
679
+ */
680
+
681
+ import postgres from 'postgres'
682
+
683
+ async function resetDb() {
684
+ const DATABASE_URL = process.env.DATABASE_URL
685
+
686
+ if (!DATABASE_URL) {
687
+ throw new Error('DATABASE_URL not set')
688
+ }
689
+
690
+ console.warn('WARNING: This will DROP ALL TABLES')
691
+ console.log('Database:', DATABASE_URL.split('@')[1])
692
+
693
+ const sql = postgres(DATABASE_URL)
694
+
695
+ try {
696
+ await sql\`
697
+ DROP SCHEMA public CASCADE;
698
+ CREATE SCHEMA public;
699
+ GRANT ALL ON SCHEMA public TO PUBLIC;
700
+ \`
701
+
702
+ console.log('Database reset complete')
703
+ } finally {
704
+ await sql.end()
705
+ }
706
+ }
707
+
708
+ resetDb().catch(console.error)
709
+ `)}async function $(t,n){let{name:r}=n,o=a(t,"apps/admin");await z(a(t,"apps"),{recursive:!0}),l(`pnpm create next-app@${"16"} ${o} --typescript --tailwind --no-eslint --app --no-src-dir --turbopack --react-compiler --skip-install --import-alias "@/*"`),await c(o,["app/page.tsx","app/page.module.css","app/fonts","README.md","pnpm-workspace.yaml"]),await m(a(o,"package.json"),{dependencies:{[`@${r}/config`]:"workspace:*","@murumets-ee/auth-ui":`^${i.myorgAuthUi}`,"better-auth":`^${i.betterAuth}`,"next-intl":`^${i.nextIntl}`,"next-themes":`^${i.nextThemes}`,"lucide-react":`^${i.lucideReact}`,"react-hook-form":`^${i.reactHookForm}`,"@hookform/resolvers":`^${i.hookformResolvers}`,zod:`^${i.zod}`},devDependencies:{"babel-plugin-react-compiler":i.babelReactCompiler}});let{appendToFile:h}=await import("./utils-5ZPYHNWB.js");await h(a(o,".gitignore"),`
710
+ # Environment
711
+ .env*
712
+ !.env.example
713
+ `),await e(a(o,"next.config.ts"),`import type { NextConfig } from 'next'
714
+ import createNextIntlPlugin from 'next-intl/plugin'
715
+
716
+ const withNextIntl = createNextIntlPlugin('./i18n/request.ts')
717
+
718
+ const nextConfig: NextConfig = {
719
+ reactCompiler: true,
720
+ transpilePackages: [
721
+ '@${r}/config',
722
+ '@murumets-ee/core',
723
+ '@murumets-ee/entity',
724
+ '@murumets-ee/db',
725
+ '@murumets-ee/logging',
726
+ '@murumets-ee/auth-ui',
727
+ ],
728
+ serverExternalPackages: ['drizzle-orm', 'postgres'],
729
+ experimental: {
730
+ serverActions: {
731
+ bodySizeLimit: '2mb',
732
+ },
733
+ },
734
+ }
735
+
736
+ export default withNextIntl(nextConfig)
737
+ `),await e(a(o,"proxy.ts"),`import { NextRequest, NextResponse } from 'next/server'
738
+ import createMiddleware from 'next-intl/middleware'
739
+ import { routing } from './i18n/routing'
740
+
741
+ const intlMiddleware = createMiddleware(routing)
742
+
743
+ const protectedPaths = ['/setup']
744
+
745
+ export function proxy(request: NextRequest) {
746
+ const { pathname } = request.nextUrl
747
+
748
+ const localePattern = new RegExp(\`^/(\${routing.locales.join('|')})\`)
749
+ const pathWithoutLocale = pathname.replace(localePattern, '') || '/'
750
+
751
+ if (protectedPaths.some((p) => pathWithoutLocale.startsWith(p))) {
752
+ const session = request.cookies.get('better-auth.session_token')
753
+ if (!session) {
754
+ const locale = pathname.match(localePattern)?.[1] || routing.defaultLocale
755
+ return NextResponse.redirect(new URL(\`/\${locale}/auth/sign-in\`, request.url))
756
+ }
757
+ }
758
+
759
+ return intlMiddleware(request)
760
+ }
761
+
762
+ export const config = {
763
+ matcher: '/((?!api|_next|_vercel|.*\\\\..*).*)',
764
+ }
765
+ `),await e(a(o,"i18n/routing.ts"),`import { defineRouting } from 'next-intl/routing'
766
+
767
+ export const routing = defineRouting({
768
+ locales: ['en'],
769
+ defaultLocale: 'en',
770
+ })
771
+ `),await e(a(o,"i18n/request.ts"),`import { getRequestConfig } from 'next-intl/server'
772
+ import { hasLocale } from 'next-intl'
773
+ import { routing } from './routing'
774
+ import { getAuthMessages } from '@murumets-ee/auth-ui/i18n'
775
+
776
+ export default getRequestConfig(async ({ requestLocale }) => {
777
+ const requested = await requestLocale
778
+ const locale = hasLocale(routing.locales, requested)
779
+ ? requested
780
+ : routing.defaultLocale
781
+
782
+ const authMessages = await getAuthMessages(locale)
783
+
784
+ return {
785
+ locale,
786
+ messages: {
787
+ ...authMessages,
788
+ },
789
+ }
790
+ })
791
+ `),await e(a(o,"app/globals.css"),`@import "tailwindcss";
792
+ @source "../node_modules/@murumets-ee/auth-ui/dist";
793
+
794
+ @custom-variant dark (&:where(.dark, .dark *));
795
+
796
+ :root {
797
+ --background: #ffffff;
798
+ --foreground: #171717;
799
+ }
800
+
801
+ @theme inline {
802
+ --color-background: var(--background);
803
+ --color-foreground: var(--foreground);
804
+ --font-sans: var(--font-geist-sans);
805
+ --font-mono: var(--font-geist-mono);
806
+ }
807
+
808
+ .dark {
809
+ --background: #0a0a0a;
810
+ --foreground: #ededed;
811
+ }
812
+
813
+ body {
814
+ background: var(--background);
815
+ color: var(--foreground);
816
+ font-family: Arial, Helvetica, sans-serif;
817
+ }
818
+ `),await e(a(o,"app/theme-provider.tsx"),`'use client'
819
+
820
+ import { ThemeProvider as NextThemesProvider } from 'next-themes'
821
+ import type { ReactNode } from 'react'
822
+
823
+ export function ThemeProvider({ children }: { children: ReactNode }) {
824
+ return (
825
+ <NextThemesProvider
826
+ attribute="class"
827
+ defaultTheme="system"
828
+ enableSystem
829
+ disableTransitionOnChange
830
+ >
831
+ {children}
832
+ </NextThemesProvider>
833
+ )
834
+ }
835
+ `),await e(a(o,"app/theme-toggle.tsx"),`'use client'
836
+
837
+ import { useTheme } from 'next-themes'
838
+ import { useState, useEffect } from 'react'
839
+ import { Sun, Moon } from 'lucide-react'
840
+
841
+ export function ThemeToggle() {
842
+ const [mounted, setMounted] = useState(false)
843
+ const { resolvedTheme, setTheme } = useTheme()
844
+
845
+ useEffect(() => { setMounted(true) }, [])
846
+
847
+ if (!mounted) {
848
+ return <div className="h-8 w-8" />
849
+ }
850
+
851
+ return (
852
+ <button
853
+ type="button"
854
+ onClick={() => setTheme(resolvedTheme === 'dark' ? 'light' : 'dark')}
855
+ className="rounded-md p-1.5 text-zinc-400 transition-colors hover:bg-zinc-100 hover:text-zinc-600 dark:hover:bg-zinc-800 dark:hover:text-zinc-200 cursor-pointer"
856
+ aria-label={resolvedTheme === 'dark' ? 'Switch to light mode' : 'Switch to dark mode'}
857
+ >
858
+ {resolvedTheme === 'dark' ? <Sun className="h-5 w-5" /> : <Moon className="h-5 w-5" />}
859
+ </button>
860
+ )
861
+ }
862
+ `),await e(a(o,"app/nav-header.tsx"),`'use client'
863
+
864
+ import Link from 'next/link'
865
+ import { usePathname } from 'next/navigation'
866
+ import { ThemeToggle } from './theme-toggle'
867
+
868
+ const links = [
869
+ { href: '/', label: 'Home' },
870
+ { href: '/auth/sign-in', label: 'Sign In' },
871
+ { href: '/setup', label: 'Setup' },
872
+ ]
873
+
874
+ export function NavHeader() {
875
+ const pathname = usePathname()
876
+
877
+ function isActive(href: string) {
878
+ return href === '/' ? pathname === '/' : pathname.startsWith(href)
879
+ }
880
+
881
+ const linkClass = (href: string) =>
882
+ \`px-3 py-1.5 rounded-md text-sm transition-colors \${
883
+ isActive(href)
884
+ ? 'bg-zinc-200 text-zinc-900 dark:bg-zinc-800 dark:text-zinc-50'
885
+ : 'text-zinc-500 hover:text-zinc-700 hover:bg-zinc-100 dark:text-zinc-400 dark:hover:text-zinc-200 dark:hover:bg-zinc-800/50'
886
+ }\`
887
+
888
+ return (
889
+ <header className="sticky top-0 z-50 backdrop-blur-md border-b bg-white/80 border-zinc-200 dark:bg-zinc-950/80 dark:border-zinc-800">
890
+ <nav className="max-w-6xl mx-auto flex items-center gap-1 px-4 h-12">
891
+ <span className="font-semibold text-sm text-zinc-700 dark:text-zinc-300 mr-3 select-none">
892
+ ${r} Admin
893
+ </span>
894
+ {links.map(({ href, label }) => (
895
+ <Link key={href} href={href} className={linkClass(href)}>
896
+ {label}
897
+ </Link>
898
+ ))}
899
+ <div className="ml-auto">
900
+ <ThemeToggle />
901
+ </div>
902
+ </nav>
903
+ </header>
904
+ )
905
+ }
906
+ `),await e(a(o,"app/layout.tsx"),`import './globals.css'
907
+
908
+ export default function RootLayout({ children }: { children: React.ReactNode }) {
909
+ return children
910
+ }
911
+ `),await e(a(o,"app/[locale]/layout.tsx"),`import type { Metadata } from 'next'
912
+ import { Geist, Geist_Mono } from 'next/font/google'
913
+ import { NextIntlClientProvider } from 'next-intl'
914
+ import { getMessages } from 'next-intl/server'
915
+ import { notFound } from 'next/navigation'
916
+ import { routing } from '@/i18n/routing'
917
+ import { ThemeProvider } from '../theme-provider'
918
+ import { NavHeader } from '../nav-header'
919
+
920
+ const geistSans = Geist({
921
+ variable: '--font-geist-sans',
922
+ subsets: ['latin'],
923
+ })
924
+
925
+ const geistMono = Geist_Mono({
926
+ variable: '--font-geist-mono',
927
+ subsets: ['latin'],
928
+ })
929
+
930
+ export const metadata: Metadata = {
931
+ title: '${r} Admin',
932
+ description: 'Built with Lumi CMS Toolkit',
933
+ }
934
+
935
+ export default async function LocaleLayout({
936
+ children,
937
+ params,
938
+ }: {
939
+ children: React.ReactNode
940
+ params: Promise<{ locale: string }>
941
+ }) {
942
+ const { locale } = await params
943
+ if (!routing.locales.includes(locale as any)) notFound()
944
+
945
+ const messages = await getMessages()
946
+
947
+ return (
948
+ <html lang={locale} suppressHydrationWarning>
949
+ <body className={\`\${geistSans.variable} \${geistMono.variable} antialiased\`}>
950
+ <ThemeProvider>
951
+ <NextIntlClientProvider locale={locale} messages={messages}>
952
+ <NavHeader />
953
+ {children}
954
+ </NextIntlClientProvider>
955
+ </ThemeProvider>
956
+ </body>
957
+ </html>
958
+ )
959
+ }
960
+ `),await e(a(o,"app/[locale]/page.tsx"),`import { createQueryClient } from '@murumets-ee/core/clients'
961
+ import { Article, Category } from '@${r}/config/entities'
962
+ import { getToolkitApp } from '@${r}/config/app'
963
+
964
+ export default async function HomePage() {
965
+ await getToolkitApp()
966
+ const articles = createQueryClient(Article)
967
+ const categories = createQueryClient(Category)
968
+
969
+ const [articleList, categoryList] = await Promise.all([
970
+ articles.findMany({ limit: 10 }),
971
+ categories.findMany({}),
972
+ ])
973
+
974
+ return (
975
+ <div className="min-h-screen p-8">
976
+ <div className="max-w-4xl mx-auto">
977
+ <h1 className="text-4xl font-bold mb-8">Welcome to ${r}</h1>
978
+
979
+ <section className="mb-12">
980
+ <h2 className="text-2xl font-semibold mb-4">
981
+ Categories ({categoryList.length})
982
+ </h2>
983
+ <div className="grid gap-4 md:grid-cols-2">
984
+ {categoryList.map((cat) => (
985
+ <div
986
+ key={cat.id}
987
+ className="border border-zinc-200 dark:border-zinc-800 rounded-lg p-4"
988
+ >
989
+ <h3 className="font-semibold text-lg">{cat.name}</h3>
990
+ <p className="text-sm text-zinc-600 dark:text-zinc-400">
991
+ {cat.description}
992
+ </p>
993
+ </div>
994
+ ))}
995
+ </div>
996
+ </section>
997
+
998
+ <section>
999
+ <h2 className="text-2xl font-semibold mb-4">
1000
+ Articles ({articleList.length})
1001
+ </h2>
1002
+ {articleList.length === 0 ? (
1003
+ <p className="text-zinc-500">No published articles yet.</p>
1004
+ ) : (
1005
+ <div className="space-y-4">
1006
+ {articleList.map((article) => (
1007
+ <div
1008
+ key={article.id}
1009
+ className="border border-zinc-200 dark:border-zinc-800 rounded-lg p-6"
1010
+ >
1011
+ <h3 className="text-xl font-bold">{article.title}</h3>
1012
+ <p className="text-zinc-600 dark:text-zinc-400 mt-2">
1013
+ {article.excerpt}
1014
+ </p>
1015
+ </div>
1016
+ ))}
1017
+ </div>
1018
+ )}
1019
+ </section>
1020
+ </div>
1021
+ </div>
1022
+ )
1023
+ }
1024
+ `),await e(a(o,"app/api/auth/[...all]/route.ts"),`import { toNextJsHandler } from 'better-auth/next-js'
1025
+ import { auth } from '@${r}/config/auth'
1026
+
1027
+ export const { GET, POST } = toNextJsHandler(auth)
1028
+ `),await e(a(o,"app/[locale]/auth/layout.tsx"),`import { AuthProviders } from './providers'
1029
+ import type { ReactNode } from 'react'
1030
+
1031
+ export default function AuthLayout({ children }: { children: ReactNode }) {
1032
+ return (
1033
+ <AuthProviders>
1034
+ <div className="flex min-h-[calc(100vh-3rem)] items-center justify-center px-4">
1035
+ {children}
1036
+ </div>
1037
+ </AuthProviders>
1038
+ )
1039
+ }
1040
+ `),await e(a(o,"app/[locale]/auth/providers.tsx"),`'use client'
1041
+
1042
+ import { AuthUIProvider } from '@murumets-ee/auth-ui'
1043
+ import { authClient } from '@${r}/config/auth-client'
1044
+ import Link from 'next/link'
1045
+ import { useRouter } from 'next/navigation'
1046
+ import { useLocale } from 'next-intl'
1047
+ import type { ReactNode } from 'react'
1048
+
1049
+ export function AuthProviders({ children }: { children: ReactNode }) {
1050
+ const router = useRouter()
1051
+ const locale = useLocale()
1052
+
1053
+ return (
1054
+ <AuthUIProvider
1055
+ authClient={authClient as never}
1056
+ basePath="/auth"
1057
+ redirectTo="/"
1058
+ Link={Link}
1059
+ navigate={(url) => router.push(url)}
1060
+ resetPasswordUrl={\`/\${locale}/auth/reset-password\`}
1061
+ >
1062
+ {children}
1063
+ </AuthUIProvider>
1064
+ )
1065
+ }
1066
+ `),await e(a(o,"app/[locale]/auth/sign-in/page.tsx"),`import { SignInForm } from '@murumets-ee/auth-ui'
1067
+
1068
+ export default function SignInPage() {
1069
+ return <SignInForm />
1070
+ }
1071
+ `),await e(a(o,"app/[locale]/auth/sign-up/page.tsx"),`import { SignUpForm } from '@murumets-ee/auth-ui'
1072
+
1073
+ export default function SignUpPage() {
1074
+ return <SignUpForm />
1075
+ }
1076
+ `),await e(a(o,"app/[locale]/auth/forgot-password/page.tsx"),`import { ForgotPasswordForm } from '@murumets-ee/auth-ui'
1077
+
1078
+ export default function ForgotPasswordPage() {
1079
+ return <ForgotPasswordForm />
1080
+ }
1081
+ `),await e(a(o,"app/[locale]/auth/reset-password/page.tsx"),`import { Suspense } from 'react'
1082
+ import { ResetPasswordContent } from './content'
1083
+
1084
+ export default function ResetPasswordPage() {
1085
+ return (
1086
+ <Suspense>
1087
+ <ResetPasswordContent />
1088
+ </Suspense>
1089
+ )
1090
+ }
1091
+ `),await e(a(o,"app/[locale]/auth/reset-password/content.tsx"),`'use client'
1092
+
1093
+ import { useSearchParams } from 'next/navigation'
1094
+ import { ResetPasswordForm } from '@murumets-ee/auth-ui'
1095
+
1096
+ export function ResetPasswordContent() {
1097
+ const searchParams = useSearchParams()
1098
+ const token = searchParams.get('token')
1099
+
1100
+ if (!token) {
1101
+ return (
1102
+ <div className="text-center">
1103
+ <h1 className="text-2xl font-bold text-zinc-900 dark:text-zinc-50">
1104
+ Invalid or expired link
1105
+ </h1>
1106
+ <p className="mt-2 text-zinc-500">
1107
+ Please request a new password reset.
1108
+ </p>
1109
+ </div>
1110
+ )
1111
+ }
1112
+
1113
+ return <ResetPasswordForm token={token} />
1114
+ }
1115
+ `),await e(a(o,"app/[locale]/setup/page.tsx"),`import { redirect } from 'next/navigation'
1116
+ import { sql } from 'drizzle-orm'
1117
+ import { getToolkitApp } from '@${r}/config/app'
1118
+ import { SetupForm } from './form'
1119
+
1120
+ export default async function SetupPage() {
1121
+ const app = await getToolkitApp()
1122
+ const result = await app.db.readOnly.execute<{ count: string }>(
1123
+ sql\`SELECT COUNT(*)::text as count FROM "user"\`,
1124
+ )
1125
+
1126
+ if (Number(result[0]?.count) > 0) {
1127
+ redirect('/')
1128
+ }
1129
+
1130
+ return (
1131
+ <div className="max-w-md mx-auto p-8">
1132
+ <h1 className="text-2xl font-bold mb-2">Create Admin</h1>
1133
+ <p className="text-sm text-zinc-500 dark:text-zinc-400 mb-6">
1134
+ No users found. Create the first admin account.
1135
+ </p>
1136
+ <SetupForm />
1137
+ </div>
1138
+ )
1139
+ }
1140
+ `),await e(a(o,"app/[locale]/setup/form.tsx"),`'use client'
1141
+
1142
+ import { useState } from 'react'
1143
+ import { createFirstAdmin } from './actions'
1144
+
1145
+ export function SetupForm() {
1146
+ const [result, setResult] = useState<{ ok?: boolean; error?: string; email?: string } | null>(null)
1147
+ const [loading, setLoading] = useState(false)
1148
+
1149
+ async function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
1150
+ e.preventDefault()
1151
+ setLoading(true)
1152
+ setResult(null)
1153
+ const res = await createFirstAdmin(new FormData(e.currentTarget))
1154
+ setResult(res)
1155
+ setLoading(false)
1156
+ }
1157
+
1158
+ if (result?.ok) {
1159
+ return (
1160
+ <div className="space-y-2">
1161
+ <p className="text-green-600 dark:text-green-400">Admin created: {result.email}</p>
1162
+ <a href="/auth/sign-in" className="text-blue-600 dark:text-blue-400 hover:underline">
1163
+ Sign in &rarr;
1164
+ </a>
1165
+ </div>
1166
+ )
1167
+ }
1168
+
1169
+ return (
1170
+ <form onSubmit={handleSubmit} className="flex flex-col gap-4">
1171
+ <label className="text-sm font-medium">
1172
+ Name
1173
+ <input
1174
+ name="name"
1175
+ required
1176
+ className="mt-1 block w-full px-3 py-2 bg-zinc-100 dark:bg-zinc-900 border border-zinc-300 dark:border-zinc-700 rounded-md text-sm focus:outline-none focus:ring-1 focus:ring-blue-500"
1177
+ />
1178
+ </label>
1179
+ <label className="text-sm font-medium">
1180
+ Email
1181
+ <input
1182
+ name="email"
1183
+ type="email"
1184
+ required
1185
+ className="mt-1 block w-full px-3 py-2 bg-zinc-100 dark:bg-zinc-900 border border-zinc-300 dark:border-zinc-700 rounded-md text-sm focus:outline-none focus:ring-1 focus:ring-blue-500"
1186
+ />
1187
+ </label>
1188
+ <label className="text-sm font-medium">
1189
+ Password (min 8 chars)
1190
+ <input
1191
+ name="password"
1192
+ type="password"
1193
+ required
1194
+ minLength={8}
1195
+ className="mt-1 block w-full px-3 py-2 bg-zinc-100 dark:bg-zinc-900 border border-zinc-300 dark:border-zinc-700 rounded-md text-sm focus:outline-none focus:ring-1 focus:ring-blue-500"
1196
+ />
1197
+ </label>
1198
+
1199
+ {result?.error && <p className="text-red-600 dark:text-red-400 text-sm">{result.error}</p>}
1200
+
1201
+ <button
1202
+ type="submit"
1203
+ disabled={loading}
1204
+ className="px-4 py-2 text-sm rounded-md bg-blue-600 text-white hover:bg-blue-500 disabled:opacity-50 transition-colors"
1205
+ >
1206
+ {loading ? 'Creating...' : 'Create Admin'}
1207
+ </button>
1208
+ </form>
1209
+ )
1210
+ }
1211
+ `),await e(a(o,"app/[locale]/setup/actions.ts"),`'use server'
1212
+
1213
+ import { sql } from 'drizzle-orm'
1214
+ import { getToolkitApp } from '@${r}/config/app'
1215
+ import { getAuth } from '@murumets-ee/auth'
1216
+
1217
+ export async function createFirstAdmin(formData: FormData) {
1218
+ const email = formData.get('email') as string
1219
+ const password = formData.get('password') as string
1220
+ const name = formData.get('name') as string
1221
+
1222
+ if (!email || !password || !name) {
1223
+ return { error: 'All fields are required' }
1224
+ }
1225
+
1226
+ if (password.length < 8) {
1227
+ return { error: 'Password must be at least 8 characters' }
1228
+ }
1229
+
1230
+ const app = await getToolkitApp()
1231
+
1232
+ const canCreate = await app.db.readWrite.transaction(async (tx) => {
1233
+ await tx.execute(sql\`SELECT pg_advisory_xact_lock(1)\`)
1234
+
1235
+ const result = await tx.execute<{ count: string }>(
1236
+ sql\`SELECT COUNT(*)::text as count FROM "user"\`,
1237
+ )
1238
+ return Number(result[0]?.count) === 0
1239
+ })
1240
+
1241
+ if (!canCreate) {
1242
+ return { error: 'Admin user already exists. Setup is complete.' }
1243
+ }
1244
+
1245
+ const auth = getAuth()
1246
+
1247
+ const adminUser = await auth.api.signUpEmail({
1248
+ body: { email, password, name },
1249
+ })
1250
+
1251
+ await app.db.readWrite.execute(
1252
+ sql\`UPDATE "user" SET role = 'admin' WHERE id = \${adminUser.user.id}\`,
1253
+ )
1254
+
1255
+ return { ok: true, email: adminUser.user.email }
1256
+ }
1257
+ `)}async function M(t,n){let{name:r}=n,o=a(t,"apps/web");l(`pnpm create next-app@${"16"} ${o} --typescript --tailwind --no-eslint --app --no-src-dir --turbopack --react-compiler --skip-install --import-alias "@/*"`),await c(o,["app/page.tsx","app/page.module.css","app/fonts","README.md","pnpm-workspace.yaml"]),await m(a(o,"package.json"),{dependencies:{[`@${r}/config`]:"workspace:*","@murumets-ee/core":`^${i.myorgCore}`,"@murumets-ee/auth-ui":`^${i.myorgAuthUi}`,"next-intl":`^${i.nextIntl}`,"next-themes":`^${i.nextThemes}`,"lucide-react":`^${i.lucideReact}`},devDependencies:{"babel-plugin-react-compiler":i.babelReactCompiler}});let{appendToFile:h}=await import("./utils-5ZPYHNWB.js");await h(a(o,".gitignore"),`
1258
+ # Environment
1259
+ .env*
1260
+ !.env.example
1261
+ `),await e(a(o,"next.config.ts"),`import type { NextConfig } from 'next'
1262
+ import createNextIntlPlugin from 'next-intl/plugin'
1263
+
1264
+ const withNextIntl = createNextIntlPlugin('./i18n/request.ts')
1265
+
1266
+ const nextConfig: NextConfig = {
1267
+ reactCompiler: true,
1268
+ transpilePackages: [
1269
+ '@${r}/config',
1270
+ '@murumets-ee/core',
1271
+ '@murumets-ee/entity',
1272
+ '@murumets-ee/db',
1273
+ '@murumets-ee/logging',
1274
+ '@murumets-ee/auth-ui',
1275
+ ],
1276
+ serverExternalPackages: ['drizzle-orm', 'postgres'],
1277
+ }
1278
+
1279
+ export default withNextIntl(nextConfig)
1280
+ `),await e(a(o,"proxy.ts"),`import createMiddleware from 'next-intl/middleware'
1281
+ import { routing } from './i18n/routing'
1282
+
1283
+ export default createMiddleware(routing)
1284
+
1285
+ export const config = {
1286
+ matcher: '/((?!api|_next|_vercel|.*\\\\..*).*)',
1287
+ }
1288
+ `),await e(a(o,"i18n/routing.ts"),`import { defineRouting } from 'next-intl/routing'
1289
+
1290
+ export const routing = defineRouting({
1291
+ locales: ['en'],
1292
+ defaultLocale: 'en',
1293
+ })
1294
+ `),await e(a(o,"i18n/request.ts"),`import { getRequestConfig } from 'next-intl/server'
1295
+ import { hasLocale } from 'next-intl'
1296
+ import { routing } from './routing'
1297
+ import { getAuthMessages } from '@murumets-ee/auth-ui/i18n'
1298
+
1299
+ export default getRequestConfig(async ({ requestLocale }) => {
1300
+ const requested = await requestLocale
1301
+ const locale = hasLocale(routing.locales, requested)
1302
+ ? requested
1303
+ : routing.defaultLocale
1304
+
1305
+ const authMessages = await getAuthMessages(locale)
1306
+
1307
+ return {
1308
+ locale,
1309
+ messages: {
1310
+ ...authMessages,
1311
+ },
1312
+ }
1313
+ })
1314
+ `),await e(a(o,"app/globals.css"),`@import "tailwindcss";
1315
+ @source "../node_modules/@murumets-ee/auth-ui/dist";
1316
+
1317
+ @custom-variant dark (&:where(.dark, .dark *));
1318
+
1319
+ :root {
1320
+ --background: #ffffff;
1321
+ --foreground: #171717;
1322
+ }
1323
+
1324
+ @theme inline {
1325
+ --color-background: var(--background);
1326
+ --color-foreground: var(--foreground);
1327
+ --font-sans: var(--font-geist-sans);
1328
+ --font-mono: var(--font-geist-mono);
1329
+ }
1330
+
1331
+ .dark {
1332
+ --background: #0a0a0a;
1333
+ --foreground: #ededed;
1334
+ }
1335
+
1336
+ body {
1337
+ background: var(--background);
1338
+ color: var(--foreground);
1339
+ font-family: Arial, Helvetica, sans-serif;
1340
+ }
1341
+ `),await e(a(o,"app/theme-provider.tsx"),`'use client'
1342
+
1343
+ import { ThemeProvider as NextThemesProvider } from 'next-themes'
1344
+ import type { ReactNode } from 'react'
1345
+
1346
+ export function ThemeProvider({ children }: { children: ReactNode }) {
1347
+ return (
1348
+ <NextThemesProvider
1349
+ attribute="class"
1350
+ defaultTheme="system"
1351
+ enableSystem
1352
+ disableTransitionOnChange
1353
+ >
1354
+ {children}
1355
+ </NextThemesProvider>
1356
+ )
1357
+ }
1358
+ `),await e(a(o,"app/theme-toggle.tsx"),`'use client'
1359
+
1360
+ import { useTheme } from 'next-themes'
1361
+ import { useState, useEffect } from 'react'
1362
+ import { Sun, Moon } from 'lucide-react'
1363
+
1364
+ export function ThemeToggle() {
1365
+ const [mounted, setMounted] = useState(false)
1366
+ const { resolvedTheme, setTheme } = useTheme()
1367
+
1368
+ useEffect(() => { setMounted(true) }, [])
1369
+
1370
+ if (!mounted) {
1371
+ return <div className="h-8 w-8" />
1372
+ }
1373
+
1374
+ return (
1375
+ <button
1376
+ type="button"
1377
+ onClick={() => setTheme(resolvedTheme === 'dark' ? 'light' : 'dark')}
1378
+ className="rounded-md p-1.5 text-zinc-400 transition-colors hover:bg-zinc-100 hover:text-zinc-600 dark:hover:bg-zinc-800 dark:hover:text-zinc-200 cursor-pointer"
1379
+ aria-label={resolvedTheme === 'dark' ? 'Switch to light mode' : 'Switch to dark mode'}
1380
+ >
1381
+ {resolvedTheme === 'dark' ? <Sun className="h-5 w-5" /> : <Moon className="h-5 w-5" />}
1382
+ </button>
1383
+ )
1384
+ }
1385
+ `),await e(a(o,"app/nav-header.tsx"),`'use client'
1386
+
1387
+ import Link from 'next/link'
1388
+ import { usePathname } from 'next/navigation'
1389
+ import { ThemeToggle } from './theme-toggle'
1390
+
1391
+ const links = [
1392
+ { href: '/', label: 'Home' },
1393
+ ]
1394
+
1395
+ export function NavHeader() {
1396
+ const pathname = usePathname()
1397
+
1398
+ function isActive(href: string) {
1399
+ return href === '/' ? pathname === '/' : pathname.startsWith(href)
1400
+ }
1401
+
1402
+ const linkClass = (href: string) =>
1403
+ \`px-3 py-1.5 rounded-md text-sm transition-colors \${
1404
+ isActive(href)
1405
+ ? 'bg-zinc-200 text-zinc-900 dark:bg-zinc-800 dark:text-zinc-50'
1406
+ : 'text-zinc-500 hover:text-zinc-700 hover:bg-zinc-100 dark:text-zinc-400 dark:hover:text-zinc-200 dark:hover:bg-zinc-800/50'
1407
+ }\`
1408
+
1409
+ return (
1410
+ <header className="sticky top-0 z-50 backdrop-blur-md border-b bg-white/80 border-zinc-200 dark:bg-zinc-950/80 dark:border-zinc-800">
1411
+ <nav className="max-w-6xl mx-auto flex items-center gap-1 px-4 h-12">
1412
+ <span className="font-semibold text-sm text-zinc-700 dark:text-zinc-300 mr-3 select-none">
1413
+ ${r}
1414
+ </span>
1415
+ {links.map(({ href, label }) => (
1416
+ <Link key={href} href={href} className={linkClass(href)}>
1417
+ {label}
1418
+ </Link>
1419
+ ))}
1420
+ <div className="ml-auto">
1421
+ <ThemeToggle />
1422
+ </div>
1423
+ </nav>
1424
+ </header>
1425
+ )
1426
+ }
1427
+ `),await e(a(o,"app/layout.tsx"),`import './globals.css'
1428
+
1429
+ export default function RootLayout({ children }: { children: React.ReactNode }) {
1430
+ return children
1431
+ }
1432
+ `),await e(a(o,"app/[locale]/layout.tsx"),`import type { Metadata } from 'next'
1433
+ import { Geist, Geist_Mono } from 'next/font/google'
1434
+ import { NextIntlClientProvider } from 'next-intl'
1435
+ import { getMessages } from 'next-intl/server'
1436
+ import { notFound } from 'next/navigation'
1437
+ import { routing } from '@/i18n/routing'
1438
+ import { ThemeProvider } from '../theme-provider'
1439
+ import { NavHeader } from '../nav-header'
1440
+
1441
+ const geistSans = Geist({
1442
+ variable: '--font-geist-sans',
1443
+ subsets: ['latin'],
1444
+ })
1445
+
1446
+ const geistMono = Geist_Mono({
1447
+ variable: '--font-geist-mono',
1448
+ subsets: ['latin'],
1449
+ })
1450
+
1451
+ export const metadata: Metadata = {
1452
+ title: '${r}',
1453
+ description: 'Built with Lumi CMS Toolkit',
1454
+ }
1455
+
1456
+ export default async function LocaleLayout({
1457
+ children,
1458
+ params,
1459
+ }: {
1460
+ children: React.ReactNode
1461
+ params: Promise<{ locale: string }>
1462
+ }) {
1463
+ const { locale } = await params
1464
+ if (!routing.locales.includes(locale as any)) notFound()
1465
+
1466
+ const messages = await getMessages()
1467
+
1468
+ return (
1469
+ <html lang={locale} suppressHydrationWarning>
1470
+ <body className={\`\${geistSans.variable} \${geistMono.variable} antialiased\`}>
1471
+ <ThemeProvider>
1472
+ <NextIntlClientProvider locale={locale} messages={messages}>
1473
+ <NavHeader />
1474
+ {children}
1475
+ </NextIntlClientProvider>
1476
+ </ThemeProvider>
1477
+ </body>
1478
+ </html>
1479
+ )
1480
+ }
1481
+ `),await e(a(o,"app/[locale]/page.tsx"),`import { createQueryClient } from '@murumets-ee/core/clients'
1482
+ import { Article, Category } from '@${r}/config/entities'
1483
+ import { getToolkitApp } from '@${r}/config/app'
1484
+
1485
+ export default async function HomePage() {
1486
+ await getToolkitApp()
1487
+ const articles = createQueryClient(Article)
1488
+ const categories = createQueryClient(Category)
1489
+
1490
+ const [articleList, categoryList] = await Promise.all([
1491
+ articles.findMany({ limit: 10 }),
1492
+ categories.findMany({}),
1493
+ ])
1494
+
1495
+ return (
1496
+ <div className="min-h-screen p-8">
1497
+ <div className="max-w-4xl mx-auto">
1498
+ <h1 className="text-4xl font-bold mb-8">Welcome to ${r}</h1>
1499
+
1500
+ <section className="mb-12">
1501
+ <h2 className="text-2xl font-semibold mb-4">
1502
+ Categories ({categoryList.length})
1503
+ </h2>
1504
+ <div className="grid gap-4 md:grid-cols-2">
1505
+ {categoryList.map((cat) => (
1506
+ <div
1507
+ key={cat.id}
1508
+ className="border border-zinc-200 dark:border-zinc-800 rounded-lg p-4"
1509
+ >
1510
+ <h3 className="font-semibold text-lg">{cat.name}</h3>
1511
+ <p className="text-sm text-zinc-600 dark:text-zinc-400">
1512
+ {cat.description}
1513
+ </p>
1514
+ </div>
1515
+ ))}
1516
+ </div>
1517
+ </section>
1518
+
1519
+ <section>
1520
+ <h2 className="text-2xl font-semibold mb-4">
1521
+ Articles ({articleList.length})
1522
+ </h2>
1523
+ {articleList.length === 0 ? (
1524
+ <p className="text-zinc-500">No published articles yet.</p>
1525
+ ) : (
1526
+ <div className="space-y-4">
1527
+ {articleList.map((article) => (
1528
+ <div
1529
+ key={article.id}
1530
+ className="border border-zinc-200 dark:border-zinc-800 rounded-lg p-6"
1531
+ >
1532
+ <h3 className="text-xl font-bold">{article.title}</h3>
1533
+ <p className="text-zinc-600 dark:text-zinc-400 mt-2">
1534
+ {article.excerpt}
1535
+ </p>
1536
+ </div>
1537
+ ))}
1538
+ </div>
1539
+ )}
1540
+ </section>
1541
+ </div>
1542
+ </div>
1543
+ )
1544
+ }
1545
+ `)}import{join as u}from"path";async function S(t,n){let{name:r}=n;await e(u(t,"next.config.ts"),`import type { NextConfig } from 'next'
1546
+ import createNextIntlPlugin from 'next-intl/plugin'
1547
+
1548
+ const withNextIntl = createNextIntlPlugin('./i18n/request.ts')
1549
+
1550
+ const nextConfig: NextConfig = {
1551
+ reactCompiler: true,
1552
+ transpilePackages: ['@murumets-ee/core', '@murumets-ee/entity', '@murumets-ee/db', '@murumets-ee/logging', '@murumets-ee/auth-ui'],
1553
+ serverExternalPackages: ['drizzle-orm', 'postgres'],
1554
+ experimental: {
1555
+ serverActions: {
1556
+ bodySizeLimit: '2mb',
1557
+ },
1558
+ },
1559
+ }
1560
+
1561
+ export default withNextIntl(nextConfig)
1562
+ `),await e(u(t,"proxy.ts"),`import { NextRequest, NextResponse } from 'next/server'
1563
+ import createMiddleware from 'next-intl/middleware'
1564
+ import { routing } from './i18n/routing'
1565
+
1566
+ const intlMiddleware = createMiddleware(routing)
1567
+
1568
+ const protectedPaths = ['/setup']
1569
+
1570
+ export function proxy(request: NextRequest) {
1571
+ const { pathname } = request.nextUrl
1572
+
1573
+ // Strip locale prefix to check actual path
1574
+ const localePattern = new RegExp(\`^/(\${routing.locales.join('|')})\`)
1575
+ const pathWithoutLocale = pathname.replace(localePattern, '') || '/'
1576
+
1577
+ // Auth check for protected paths
1578
+ if (protectedPaths.some((p) => pathWithoutLocale.startsWith(p))) {
1579
+ const session = request.cookies.get('better-auth.session_token')
1580
+ if (!session) {
1581
+ const locale = pathname.match(localePattern)?.[1] || routing.defaultLocale
1582
+ return NextResponse.redirect(new URL(\`/\${locale}/auth/sign-in\`, request.url))
1583
+ }
1584
+ }
1585
+
1586
+ // Locale routing
1587
+ return intlMiddleware(request)
1588
+ }
1589
+
1590
+ export const config = {
1591
+ matcher: '/((?!api|_next|_vercel|.*\\\\..*).*)',
1592
+ }
1593
+ `),await e(u(t,"app/layout.tsx"),`import './globals.css'
1594
+
1595
+ export default function RootLayout({ children }: { children: React.ReactNode }) {
1596
+ return children
1597
+ }
1598
+ `),await e(u(t,"app/[locale]/layout.tsx"),`import type { Metadata } from 'next'
1599
+ import { Geist, Geist_Mono } from 'next/font/google'
1600
+ import { NextIntlClientProvider } from 'next-intl'
1601
+ import { getMessages } from 'next-intl/server'
1602
+ import { notFound } from 'next/navigation'
1603
+ import { routing } from '@/i18n/routing'
1604
+ import { ThemeProvider } from '../theme-provider'
1605
+ import { NavHeader } from '../nav-header'
1606
+
1607
+ const geistSans = Geist({
1608
+ variable: '--font-geist-sans',
1609
+ subsets: ['latin'],
1610
+ })
1611
+
1612
+ const geistMono = Geist_Mono({
1613
+ variable: '--font-geist-mono',
1614
+ subsets: ['latin'],
1615
+ })
1616
+
1617
+ export const metadata: Metadata = {
1618
+ title: '${r}',
1619
+ description: 'Built with Lumi CMS Toolkit',
1620
+ }
1621
+
1622
+ export default async function LocaleLayout({
1623
+ children,
1624
+ params,
1625
+ }: {
1626
+ children: React.ReactNode
1627
+ params: Promise<{ locale: string }>
1628
+ }) {
1629
+ const { locale } = await params
1630
+ if (!routing.locales.includes(locale as any)) notFound()
1631
+
1632
+ const messages = await getMessages()
1633
+
1634
+ return (
1635
+ <html lang={locale} suppressHydrationWarning>
1636
+ <body className={\`\${geistSans.variable} \${geistMono.variable} antialiased\`}>
1637
+ <ThemeProvider>
1638
+ <NextIntlClientProvider locale={locale} messages={messages}>
1639
+ <NavHeader />
1640
+ {children}
1641
+ </NextIntlClientProvider>
1642
+ </ThemeProvider>
1643
+ </body>
1644
+ </html>
1645
+ )
1646
+ }
1647
+ `),await e(u(t,"app/[locale]/page.tsx"),`import { createQueryClient } from '@murumets-ee/core/clients'
1648
+ import { Article, Category } from '@/entities'
1649
+ import { getToolkitApp } from '@/lib/app'
1650
+
1651
+ export default async function HomePage() {
1652
+ await getToolkitApp()
1653
+ const articles = createQueryClient(Article)
1654
+ const categories = createQueryClient(Category)
1655
+
1656
+ const [articleList, categoryList] = await Promise.all([
1657
+ articles.findMany({ limit: 10 }),
1658
+ categories.findMany({}),
1659
+ ])
1660
+
1661
+ return (
1662
+ <div className="min-h-screen p-8">
1663
+ <div className="max-w-4xl mx-auto">
1664
+ <h1 className="text-4xl font-bold mb-8">Welcome to ${r}</h1>
1665
+
1666
+ <section className="mb-12">
1667
+ <h2 className="text-2xl font-semibold mb-4">
1668
+ Categories ({categoryList.length})
1669
+ </h2>
1670
+ <div className="grid gap-4 md:grid-cols-2">
1671
+ {categoryList.map((cat) => (
1672
+ <div
1673
+ key={cat.id}
1674
+ className="border border-zinc-200 dark:border-zinc-800 rounded-lg p-4"
1675
+ >
1676
+ <h3 className="font-semibold text-lg">{cat.name}</h3>
1677
+ <p className="text-sm text-zinc-600 dark:text-zinc-400">
1678
+ {cat.description}
1679
+ </p>
1680
+ </div>
1681
+ ))}
1682
+ </div>
1683
+ </section>
1684
+
1685
+ <section>
1686
+ <h2 className="text-2xl font-semibold mb-4">
1687
+ Articles ({articleList.length})
1688
+ </h2>
1689
+ {articleList.length === 0 ? (
1690
+ <p className="text-zinc-500">No published articles yet.</p>
1691
+ ) : (
1692
+ <div className="space-y-4">
1693
+ {articleList.map((article) => (
1694
+ <div
1695
+ key={article.id}
1696
+ className="border border-zinc-200 dark:border-zinc-800 rounded-lg p-6"
1697
+ >
1698
+ <h3 className="text-xl font-bold">{article.title}</h3>
1699
+ <p className="text-zinc-600 dark:text-zinc-400 mt-2">
1700
+ {article.excerpt}
1701
+ </p>
1702
+ </div>
1703
+ ))}
1704
+ </div>
1705
+ )}
1706
+ </section>
1707
+ </div>
1708
+ </div>
1709
+ )
1710
+ }
1711
+ `)}import{join as b}from"path";async function P(t,n){await e(b(t,"scripts/generate-schema.ts"),`/**
1712
+ * Generate Drizzle schemas from entity definitions
1713
+ * This script reads entity definitions and outputs Drizzle schema files
1714
+ */
1715
+
1716
+ import { mkdir, writeFile } from 'node:fs/promises'
1717
+ import { join } from 'node:path'
1718
+ import { generateSchemaCode, generateTranslationSchemaCode } from '@murumets-ee/entity'
1719
+ import config from '../toolkit.config'
1720
+
1721
+ async function generateSchemas() {
1722
+ console.log('Generating Drizzle schemas from entity definitions...')
1723
+
1724
+ const schemaDir = join(import.meta.dirname, '..', 'generated')
1725
+ await mkdir(schemaDir, { recursive: true })
1726
+
1727
+ const imports: string[] = []
1728
+ const schemas: string[] = []
1729
+ let hasTranslations = false
1730
+
1731
+ for (const entity of config.entities) {
1732
+ console.log(\` - Generating schema for \${entity.name}\`)
1733
+
1734
+ // Generate main table (returns TypeScript code string)
1735
+ const schemaCode = generateSchemaCode(entity)
1736
+ schemas.push(\`\\n// \${entity.name} table\`)
1737
+ schemas.push(schemaCode)
1738
+
1739
+ // Generate translation table if needed (returns TypeScript code string or null)
1740
+ const translationCode = generateTranslationSchemaCode(entity)
1741
+ if (translationCode) {
1742
+ hasTranslations = true
1743
+ schemas.push(\`\\n// \${entity.name} translations\`)
1744
+ schemas.push(translationCode)
1745
+ }
1746
+ }
1747
+
1748
+ // Add imports (include unique() if translation tables exist)
1749
+ const pgCoreImports = hasTranslations
1750
+ ? \`import { pgTable, varchar, text, boolean, timestamp, integer, jsonb, uuid, unique } from 'drizzle-orm/pg-core'\\n\`
1751
+ : \`import { pgTable, varchar, text, boolean, timestamp, integer, jsonb, uuid } from 'drizzle-orm/pg-core'\\n\`
1752
+ imports.push(pgCoreImports)
1753
+
1754
+ const schemaFile = join(schemaDir, 'schema.ts')
1755
+ await writeFile(schemaFile, [...imports, ...schemas].join('\\n'))
1756
+
1757
+ console.log(\`\\nSchemas written to: \${schemaFile}\`)
1758
+ console.log('Run \\\`pnpm db:migrate:generate\\\` to create migrations')
1759
+ }
1760
+
1761
+ generateSchemas().catch(console.error)
1762
+ `),await e(b(t,"scripts/migrate.ts"),`/**
1763
+ * Run pending migrations
1764
+ * Applies both toolkit migrations (.toolkit/) and project migrations
1765
+ */
1766
+
1767
+ import { createDbClient, runMigrations } from '@murumets-ee/db'
1768
+
1769
+ async function migrate() {
1770
+ console.log('Running migrations...')
1771
+
1772
+ try {
1773
+ if (!process.env.DATABASE_URL) {
1774
+ throw new Error('DATABASE_URL environment variable is required')
1775
+ }
1776
+
1777
+ const db = createDbClient({ url: process.env.DATABASE_URL })
1778
+ await runMigrations(db, import.meta.dirname + '/..')
1779
+
1780
+ console.log('Migrations completed successfully')
1781
+ process.exit(0)
1782
+ } catch (error) {
1783
+ console.error('Migration failed:', error)
1784
+ process.exit(1)
1785
+ }
1786
+ }
1787
+
1788
+ migrate()
1789
+ `),await e(b(t,"scripts/reset-db.ts"),`/**
1790
+ * Reset database (DROP all tables)
1791
+ * WARNING: Only for development
1792
+ */
1793
+
1794
+ import postgres from 'postgres'
1795
+
1796
+ async function resetDb() {
1797
+ const DATABASE_URL = process.env.DATABASE_URL
1798
+
1799
+ if (!DATABASE_URL) {
1800
+ throw new Error('DATABASE_URL not set')
1801
+ }
1802
+
1803
+ console.warn('WARNING: This will DROP ALL TABLES')
1804
+ console.log('Database:', DATABASE_URL.split('@')[1])
1805
+
1806
+ const sql = postgres(DATABASE_URL)
1807
+
1808
+ try {
1809
+ // Drop all tables (cascade to handle foreign keys)
1810
+ await sql\`
1811
+ DROP SCHEMA public CASCADE;
1812
+ CREATE SCHEMA public;
1813
+ GRANT ALL ON SCHEMA public TO PUBLIC;
1814
+ \`
1815
+
1816
+ console.log('Database reset complete')
1817
+ } finally {
1818
+ await sql.end()
1819
+ }
1820
+ }
1821
+
1822
+ resetDb().catch(console.error)
1823
+ `)}import{join as f}from"path";async function R(t,n){let{name:r}=n;await e(f(t,"app/globals.css"),`@import "tailwindcss";
1824
+ @source "../node_modules/@murumets-ee/auth-ui/dist";
1825
+
1826
+ @custom-variant dark (&:where(.dark, .dark *));
1827
+
1828
+ :root {
1829
+ --background: #ffffff;
1830
+ --foreground: #171717;
1831
+ }
1832
+
1833
+ @theme inline {
1834
+ --color-background: var(--background);
1835
+ --color-foreground: var(--foreground);
1836
+ --font-sans: var(--font-geist-sans);
1837
+ --font-mono: var(--font-geist-mono);
1838
+ }
1839
+
1840
+ .dark {
1841
+ --background: #0a0a0a;
1842
+ --foreground: #ededed;
1843
+ }
1844
+
1845
+ body {
1846
+ background: var(--background);
1847
+ color: var(--foreground);
1848
+ font-family: Arial, Helvetica, sans-serif;
1849
+ }
1850
+ `),await e(f(t,"app/theme-provider.tsx"),`'use client'
1851
+
1852
+ import { ThemeProvider as NextThemesProvider } from 'next-themes'
1853
+ import type { ReactNode } from 'react'
1854
+
1855
+ export function ThemeProvider({ children }: { children: ReactNode }) {
1856
+ return (
1857
+ <NextThemesProvider
1858
+ attribute="class"
1859
+ defaultTheme="system"
1860
+ enableSystem
1861
+ disableTransitionOnChange
1862
+ >
1863
+ {children}
1864
+ </NextThemesProvider>
1865
+ )
1866
+ }
1867
+ `),await e(f(t,"app/theme-toggle.tsx"),`'use client'
1868
+
1869
+ import { useTheme } from 'next-themes'
1870
+ import { useState, useEffect } from 'react'
1871
+ import { Sun, Moon } from 'lucide-react'
1872
+
1873
+ export function ThemeToggle() {
1874
+ const [mounted, setMounted] = useState(false)
1875
+ const { resolvedTheme, setTheme } = useTheme()
1876
+
1877
+ useEffect(() => { setMounted(true) }, [])
1878
+
1879
+ if (!mounted) {
1880
+ return <div className="h-8 w-8" />
1881
+ }
1882
+
1883
+ return (
1884
+ <button
1885
+ type="button"
1886
+ onClick={() => setTheme(resolvedTheme === 'dark' ? 'light' : 'dark')}
1887
+ className="rounded-md p-1.5 text-zinc-400 transition-colors hover:bg-zinc-100 hover:text-zinc-600 dark:hover:bg-zinc-800 dark:hover:text-zinc-200 cursor-pointer"
1888
+ aria-label={resolvedTheme === 'dark' ? 'Switch to light mode' : 'Switch to dark mode'}
1889
+ >
1890
+ {resolvedTheme === 'dark' ? <Sun className="h-5 w-5" /> : <Moon className="h-5 w-5" />}
1891
+ </button>
1892
+ )
1893
+ }
1894
+ `),await e(f(t,"app/nav-header.tsx"),`'use client'
1895
+
1896
+ import Link from 'next/link'
1897
+ import { usePathname } from 'next/navigation'
1898
+ import { ThemeToggle } from './theme-toggle'
1899
+
1900
+ const links = [
1901
+ { href: '/', label: 'Home' },
1902
+ { href: '/auth/sign-in', label: 'Sign In' },
1903
+ { href: '/setup', label: 'Setup' },
1904
+ ]
1905
+
1906
+ export function NavHeader() {
1907
+ const pathname = usePathname()
1908
+
1909
+ function isActive(href: string) {
1910
+ return href === '/' ? pathname === '/' : pathname.startsWith(href)
1911
+ }
1912
+
1913
+ const linkClass = (href: string) =>
1914
+ \`px-3 py-1.5 rounded-md text-sm transition-colors \${
1915
+ isActive(href)
1916
+ ? 'bg-zinc-200 text-zinc-900 dark:bg-zinc-800 dark:text-zinc-50'
1917
+ : 'text-zinc-500 hover:text-zinc-700 hover:bg-zinc-100 dark:text-zinc-400 dark:hover:text-zinc-200 dark:hover:bg-zinc-800/50'
1918
+ }\`
1919
+
1920
+ return (
1921
+ <header className="sticky top-0 z-50 backdrop-blur-md border-b bg-white/80 border-zinc-200 dark:bg-zinc-950/80 dark:border-zinc-800">
1922
+ <nav className="max-w-6xl mx-auto flex items-center gap-1 px-4 h-12">
1923
+ <span className="font-semibold text-sm text-zinc-700 dark:text-zinc-300 mr-3 select-none">
1924
+ ${r}
1925
+ </span>
1926
+ {links.map(({ href, label }) => (
1927
+ <Link key={href} href={href} className={linkClass(href)}>
1928
+ {label}
1929
+ </Link>
1930
+ ))}
1931
+ <div className="ml-auto">
1932
+ <ThemeToggle />
1933
+ </div>
1934
+ </nav>
1935
+ </header>
1936
+ )
1937
+ }
1938
+ `)}import{join as p}from"path";async function C(t,n){let{name:r}=n;await e(p(t,"toolkit.config.ts"),`import { auth } from '@murumets-ee/auth/plugin'
1939
+ import { content } from '@murumets-ee/content/plugin'
1940
+ import { defineConfig } from '@murumets-ee/core'
1941
+ import { mail, ResendMailProvider } from '@murumets-ee/mail'
1942
+ import { media } from '@murumets-ee/media/plugin'
1943
+ import { queue } from '@murumets-ee/queue/plugin'
1944
+ import { settings } from '@murumets-ee/settings/plugin'
1945
+ import { storage } from '@murumets-ee/storage/plugin'
1946
+ import { taxonomy } from '@murumets-ee/taxonomy/plugin'
1947
+ import { ticketing } from '@murumets-ee/ticketing/plugin'
1948
+ import { Article, Category } from './entities'
1949
+ import * as authSchema from './generated/auth-schema'
1950
+
1951
+ if (!process.env.DATABASE_URL) {
1952
+ throw new Error('DATABASE_URL environment variable is required')
1953
+ }
1954
+
1955
+ export default defineConfig({
1956
+ db: {
1957
+ url: process.env.DATABASE_URL,
1958
+ poolMin: 2,
1959
+ poolMax: 10,
1960
+ },
1961
+ logging: {
1962
+ level: (process.env.LOG_LEVEL || 'info') as 'debug' | 'info' | 'warn' | 'error',
1963
+ name: '${r}',
1964
+ },
1965
+ entities: [Category, Article],
1966
+ plugins: [
1967
+ auth({ providers: ['email'], schema: authSchema }),
1968
+ content({
1969
+ locales: [{ code: 'en', label: 'English' }],
1970
+ defaultLocale: 'en',
1971
+ }),
1972
+ settings(),
1973
+ storage(),
1974
+ media(),
1975
+ taxonomy(),
1976
+ queue(),
1977
+ mail({
1978
+ provider: process.env.RESEND_API_KEY
1979
+ ? new ResendMailProvider({ apiKey: process.env.RESEND_API_KEY })
1980
+ : undefined,
1981
+ defaultFrom: process.env.MAIL_FROM ?? 'noreply@example.com',
1982
+ webhookSecret: process.env.RESEND_WEBHOOK_SECRET,
1983
+ }),
1984
+ ticketing({
1985
+ csatSecret: process.env.CSAT_SECRET,
1986
+ }),
1987
+ ],
1988
+ projectRoot: import.meta.dirname,
1989
+ })
1990
+ `),await e(p(t,"lib/app.ts"),`import { createApp, setApp, type ToolkitApp } from '@murumets-ee/core'
1991
+ import config from '../toolkit.config'
1992
+
1993
+ let appInstance: ToolkitApp | null = null
1994
+
1995
+ export async function getToolkitApp(): Promise<ToolkitApp> {
1996
+ if (!appInstance) {
1997
+ console.log('Initializing toolkit app...')
1998
+ appInstance = await createApp(config)
1999
+ setApp(appInstance)
2000
+ console.log('Toolkit app initialized')
2001
+ }
2002
+ return appInstance
2003
+ }
2004
+ `),await e(p(t,"drizzle.config.ts"),`import type { Config } from 'drizzle-kit'
2005
+
2006
+ if (!process.env.DATABASE_URL) {
2007
+ throw new Error('DATABASE_URL environment variable is required')
2008
+ }
2009
+
2010
+ export default {
2011
+ schema: ['./generated/schema.ts', './generated/auth-schema.ts'],
2012
+ out: './migrations',
2013
+ dialect: 'postgresql',
2014
+ dbCredentials: {
2015
+ url: process.env.DATABASE_URL,
2016
+ },
2017
+ } satisfies Config
2018
+ `),await e(p(t,"auth.config.ts"),`import { betterAuth } from 'better-auth'
2019
+ import { drizzleAdapter } from 'better-auth/adapters/drizzle'
2020
+ import { admin } from 'better-auth/plugins'
2021
+ import { organization } from 'better-auth/plugins/organization'
2022
+ import { drizzle } from 'drizzle-orm/postgres-js'
2023
+ import postgres from 'postgres'
2024
+
2025
+ const sql = postgres(process.env.DATABASE_URL!)
2026
+ const db = drizzle(sql)
2027
+
2028
+ export const auth = betterAuth({
2029
+ database: drizzleAdapter(db, { provider: 'pg' }),
2030
+ emailAndPassword: { enabled: true },
2031
+ plugins: [
2032
+ admin(),
2033
+ organization(),
2034
+ ],
2035
+ })
2036
+ `),await e(p(t,"generated/auth-schema.ts"),`// This file is generated by better-auth CLI.
2037
+ // Run: npx @better-auth/cli generate --config auth.config.ts -y
2038
+ export {}
2039
+ `)}async function q(t,n){t.mode==="single"?await O(t,n):await U(t,n)}async function O(t,n){let r=v(process.cwd(),t.name);n?.("Creating Next.js app..."),l(`pnpm create next-app@${"16"} ${t.name} --typescript --tailwind --no-eslint --app --no-src-dir --turbopack --react-compiler --skip-install --import-alias "@/*"`),await c(r,["app/page.tsx","app/page.module.css","app/fonts","README.md"]),await m(v(r,"package.json"),{dependencies:{"@murumets-ee/core":`^${i.myorgCore}`,"@murumets-ee/db":`^${i.myorgDb}`,"@murumets-ee/entity":`^${i.myorgEntity}`,"@murumets-ee/logging":`^${i.myorgLogging}`,"@murumets-ee/auth":`^${i.myorgAuth}`,"@murumets-ee/auth-ui":`^${i.myorgAuthUi}`,"better-auth":`^${i.betterAuth}`,"drizzle-orm":`^${i.drizzleOrm}`,"next-intl":`^${i.nextIntl}`,"next-themes":`^${i.nextThemes}`,"lucide-react":`^${i.lucideReact}`,postgres:`^${i.postgres}`,"react-hook-form":`^${i.reactHookForm}`,"@hookform/resolvers":`^${i.hookformResolvers}`,zod:`^${i.zod}`},devDependencies:{"drizzle-kit":`^${i.drizzleKit}`,tsx:`^${i.tsx}`,"babel-plugin-react-compiler":i.babelReactCompiler},scripts:{"db:generate":"tsx --env-file=.env scripts/generate-schema.ts","db:migrate:generate":"drizzle-kit generate","db:migrate":"tsx --env-file=.env scripts/migrate.ts","db:reset":"tsx --env-file=.env scripts/reset-db.ts"}}),n?.("Adding toolkit files..."),await k(r,t),await A(r,t),await C(r,t),await y(r,t),await N(r,t),await S(r,t),await R(r,t),await P(r,t),t.installDeps&&(n?.("Installing dependencies..."),l("pnpm install",{cwd:r}))}async function U(t,n){let r=v(process.cwd(),t.name);n?.("Creating workspace..."),await E(r,t,n),t.installDeps&&(n?.("Installing dependencies..."),l("pnpm install",{cwd:r}))}export{q as scaffold};