prunelle 0.0.0-stage → 0.5.2
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/llms.txt +152 -0
- package/package.json +59 -4
- package/src/a11y/declaration.ts +335 -0
- package/src/a11y/index.ts +446 -0
- package/src/a11y/rgaa-map.ts +184 -0
- package/src/ambient.d.ts +6 -0
- package/src/attrs.ts +43 -0
- package/src/build/bundle.ts +657 -0
- package/src/build/carry.ts +57 -0
- package/src/build/client-entries.ts +107 -0
- package/src/build/client-plugin.ts +173 -0
- package/src/build/client-prune.ts +168 -0
- package/src/build/compile.ts +129 -0
- package/src/build/ecoindex.ts +229 -0
- package/src/build/files.ts +156 -0
- package/src/build/first-load.ts +164 -0
- package/src/build/graph.ts +247 -0
- package/src/build/index.ts +641 -0
- package/src/build/is-inside.ts +12 -0
- package/src/build/islands.ts +641 -0
- package/src/build/manifest.ts +325 -0
- package/src/build/output.ts +84 -0
- package/src/build/plugin-host.ts +278 -0
- package/src/build/precompress.ts +139 -0
- package/src/build/prerender.ts +232 -0
- package/src/build/render-rules.ts +205 -0
- package/src/build/report.ts +268 -0
- package/src/build/resolve.ts +52 -0
- package/src/build/routes.ts +342 -0
- package/src/build/server-entry.ts +38 -0
- package/src/build/static.ts +207 -0
- package/src/build/status-pages.ts +127 -0
- package/src/build/style-bundles.ts +526 -0
- package/src/cli/check-forms.ts +654 -0
- package/src/cli/check-links.ts +619 -0
- package/src/cli/check.ts +381 -0
- package/src/cli/commands.ts +345 -0
- package/src/cli/docs.ts +402 -0
- package/src/cli/index.ts +70 -0
- package/src/cli/inspect.ts +345 -0
- package/src/cli/mcp-tools.ts +480 -0
- package/src/cli/mcp.ts +205 -0
- package/src/cli/new.ts +41 -0
- package/src/cli/render.ts +261 -0
- package/src/cli/upgrade-names.ts +209 -0
- package/src/cli/upgrade.ts +354 -0
- package/src/compiler/analyze.ts +632 -0
- package/src/compiler/ast.ts +82 -0
- package/src/compiler/browser-globals.ts +127 -0
- package/src/compiler/cacheability.ts +592 -0
- package/src/compiler/compliance-rgaa.ts +502 -0
- package/src/compiler/compliance.ts +497 -0
- package/src/compiler/data-keys.ts +295 -0
- package/src/compiler/dev-source.ts +87 -0
- package/src/compiler/dom-attrs.ts +452 -0
- package/src/compiler/dom.ts +567 -0
- package/src/compiler/emit.ts +131 -0
- package/src/compiler/expr-context.ts +518 -0
- package/src/compiler/index.ts +8 -0
- package/src/compiler/interactivity.ts +366 -0
- package/src/compiler/mistakes.ts +499 -0
- package/src/compiler/node-env.ts +50 -0
- package/src/compiler/patch.ts +97 -0
- package/src/compiler/props.ts +511 -0
- package/src/compiler/scope.ts +607 -0
- package/src/compiler/server-only.ts +326 -0
- package/src/compiler/shared.ts +369 -0
- package/src/compiler/signal-reads.ts +242 -0
- package/src/compiler/slots.ts +227 -0
- package/src/compiler/ssr-helpers.ts +555 -0
- package/src/compiler/ssr-island.ts +90 -0
- package/src/compiler/ssr-prunelle-tags.ts +69 -0
- package/src/compiler/ssr.ts +526 -0
- package/src/context.ts +165 -0
- package/src/dev/child.ts +30 -0
- package/src/dev/error-log.ts +151 -0
- package/src/dev/index.ts +258 -0
- package/src/dev/modules.ts +68 -0
- package/src/dev/open-editor.ts +204 -0
- package/src/dev/protocol.ts +22 -0
- package/src/dev/queue.ts +79 -0
- package/src/dev/reload.ts +159 -0
- package/src/dev/supervisor.ts +204 -0
- package/src/dev/watchers.ts +251 -0
- package/src/dom/action.ts +164 -0
- package/src/dom/attrs.ts +84 -0
- package/src/dom/claim.ts +120 -0
- package/src/dom/extras.ts +562 -0
- package/src/dom/index.ts +289 -0
- package/src/dom/island.ts +285 -0
- package/src/dom/loop.ts +450 -0
- package/src/dom/revive.ts +36 -0
- package/src/index.ts +22 -0
- package/src/jsx-runtime.ts +566 -0
- package/src/plugins/config.ts +86 -0
- package/src/plugins/context.ts +66 -0
- package/src/plugins/index.ts +14 -0
- package/src/plugins/load.ts +70 -0
- package/src/plugins/order.ts +111 -0
- package/src/plugins/public.ts +15 -0
- package/src/plugins/requires.ts +47 -0
- package/src/plugins/services.ts +97 -0
- package/src/plugins/types.ts +261 -0
- package/src/reactivity/graph.ts +249 -0
- package/src/reactivity/index.ts +533 -0
- package/src/reactivity/selector.ts +51 -0
- package/src/reactivity/store.ts +208 -0
- package/src/server/action-protect.ts +198 -0
- package/src/server/action-registry.ts +78 -0
- package/src/server/action.ts +530 -0
- package/src/server/app-entry.ts +23 -0
- package/src/server/assets.ts +168 -0
- package/src/server/compress.ts +642 -0
- package/src/server/consent.ts +253 -0
- package/src/server/cookies.ts +139 -0
- package/src/server/document.ts +271 -0
- package/src/server/env.ts +33 -0
- package/src/server/errors.ts +391 -0
- package/src/server/form-schema.ts +343 -0
- package/src/server/health.ts +244 -0
- package/src/server/http.ts +538 -0
- package/src/server/index.ts +586 -0
- package/src/server/lifecycle.ts +75 -0
- package/src/server/loader.ts +123 -0
- package/src/server/page.ts +107 -0
- package/src/server/param-matchers.ts +112 -0
- package/src/server/plugin-host.ts +265 -0
- package/src/server/prerendered.ts +71 -0
- package/src/server/public.ts +19 -0
- package/src/server/rate-limit.ts +156 -0
- package/src/server/region.ts +96 -0
- package/src/server/request-body.ts +27 -0
- package/src/server/request-path.ts +73 -0
- package/src/server/request-scope.ts +22 -0
- package/src/server/route-cache.ts +423 -0
- package/src/server/route-table.ts +410 -0
- package/src/server/router.ts +261 -0
- package/src/server/routing.ts +472 -0
- package/src/server/security.ts +499 -0
- package/src/server/serve-handlers.ts +83 -0
- package/src/server/served-file.ts +128 -0
- package/src/server/standard-schema.ts +87 -0
- package/src/server/start.ts +143 -0
- package/src/server/static-dir.ts +220 -0
- package/src/server/stream.ts +211 -0
- package/src/ssr/context.ts +383 -0
- package/src/ssr/index.ts +596 -0
- package/src/ssr/navigation.ts +96 -0
- package/src/ssr/region.ts +183 -0
- package/src/style.ts +33 -0
- package/src/test/browser.ts +192 -0
- package/src/test/index.ts +191 -0
- package/src/ts-plugin/diagnostics.ts +378 -0
- package/src/ts-plugin/fixes.ts +364 -0
- package/src/ts-plugin/index.ts +194 -0
- package/src/unrenderable.ts +35 -0
- package/templates/_shared/AGENTS.md +10 -0
- package/templates/_shared/CLAUDE.md +1 -0
- package/templates/_shared/gitignore +3 -0
- package/templates/_shared/mcp.json +11 -0
- package/templates/_shared/public/robots.txt +2 -0
- package/templates/_shared/src/routes/legal.tsx +13 -0
- package/templates/_shared/tsconfig.json +25 -0
- package/templates/app/.env.example +4 -0
- package/templates/app/package.json +21 -0
- package/templates/app/prunelle.config.ts +11 -0
- package/templates/app/src/auth.ts +14 -0
- package/templates/app/src/routes/_layout.tsx +32 -0
- package/templates/app/src/routes/dashboard/_middleware.ts +3 -0
- package/templates/app/src/routes/dashboard/index.tsx +13 -0
- package/templates/app/src/routes/index.tsx +15 -0
- package/templates/app/src/routes/login.tsx +34 -0
- package/templates/app/src/styles/app.css +7 -0
- package/templates/app/tests/app.test.ts +32 -0
- package/templates/blog/content/posts/welcome.md +9 -0
- package/templates/blog/package.json +22 -0
- package/templates/blog/prunelle.config.ts +23 -0
- package/templates/blog/src/posts.ts +26 -0
- package/templates/blog/src/routes/_layout.tsx +20 -0
- package/templates/blog/src/routes/blog/[slug].tsx +31 -0
- package/templates/blog/src/routes/index.tsx +33 -0
- package/templates/blog/src/styles/app.css +10 -0
- package/templates/fullstack/package.json +19 -0
- package/templates/fullstack/prunelle.config.ts +6 -0
- package/templates/fullstack/src/actions/greet.ts +19 -0
- package/templates/fullstack/src/components/Counter.tsx +10 -0
- package/templates/fullstack/src/components/GreetForm.tsx +27 -0
- package/templates/fullstack/src/routes/_layout.tsx +14 -0
- package/templates/fullstack/src/routes/api/health.ts +5 -0
- package/templates/fullstack/src/routes/index.tsx +13 -0
- package/templates/fullstack/src/styles/app.css +29 -0
- package/templates/fullstack/tests/app.test.ts +37 -0
- package/templates/minimal/package.json +19 -0
- package/templates/minimal/prunelle.config.ts +6 -0
- package/templates/minimal/src/components/Counter.tsx +10 -0
- package/templates/minimal/src/routes/_layout.tsx +14 -0
- package/templates/minimal/src/routes/index.tsx +11 -0
- package/templates/minimal/src/styles/app.css +22 -0
- package/ts-plugin.cjs +4277 -0
- package/README.md +0 -3
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "__APP_NAME__",
|
|
3
|
+
"private": true,
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "prunelle dev",
|
|
7
|
+
"build": "prunelle build",
|
|
8
|
+
"start": "prunelle start",
|
|
9
|
+
"check": "prunelle check",
|
|
10
|
+
"test": "bun test"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"prunelle": "__PRUNELLE_VERSION__",
|
|
14
|
+
"@prunellejs/auth": "__PRUNELLE_VERSION__",
|
|
15
|
+
"@prunellejs/ui": "__PRUNELLE_VERSION__"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/bun": "latest",
|
|
19
|
+
"typescript": "^6.0.3"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { join } from 'node:path'
|
|
2
|
+
import { createAuth } from '@prunellejs/auth'
|
|
3
|
+
import { sqliteAuthStore } from '@prunellejs/auth/sqlite'
|
|
4
|
+
|
|
5
|
+
// Set AUTH_SECRET (at least 32 bytes) in production — see .env.example.
|
|
6
|
+
const defaultDb = import.meta.dir.startsWith('/$bunfs')
|
|
7
|
+
? './data/auth.sqlite'
|
|
8
|
+
: join(import.meta.dir, '../data/auth.sqlite')
|
|
9
|
+
|
|
10
|
+
export const auth = createAuth({
|
|
11
|
+
store: sqliteAuthStore(process.env.AUTH_DB || defaultDb),
|
|
12
|
+
secret: process.env.AUTH_SECRET || undefined,
|
|
13
|
+
defaultRedirect: '/dashboard',
|
|
14
|
+
})
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { LayoutProps } from 'prunelle'
|
|
2
|
+
import { Button, Cluster, Toaster } from '@prunellejs/ui'
|
|
3
|
+
import { Head } from 'prunelle'
|
|
4
|
+
import '../styles/app.css'
|
|
5
|
+
|
|
6
|
+
export default function Layout({ children, locals }: LayoutProps) {
|
|
7
|
+
const user = locals.user
|
|
8
|
+
return (
|
|
9
|
+
<>
|
|
10
|
+
<Head>
|
|
11
|
+
<title>__APP_NAME__</title>
|
|
12
|
+
</Head>
|
|
13
|
+
<div class="wrap">
|
|
14
|
+
<header data-layout="split" class="site-header">
|
|
15
|
+
<a href="/" class="site-brand">__APP_NAME__</a>
|
|
16
|
+
{user
|
|
17
|
+
? (
|
|
18
|
+
<Cluster>
|
|
19
|
+
<Button href="/dashboard" variant="ghost" size="sm">{user.email}</Button>
|
|
20
|
+
<form action="/auth/signout" method="post">
|
|
21
|
+
<Button type="submit" variant="outline" size="sm">Sign out</Button>
|
|
22
|
+
</form>
|
|
23
|
+
</Cluster>
|
|
24
|
+
)
|
|
25
|
+
: <Button href="/login" variant="outline" size="sm">Sign in</Button>}
|
|
26
|
+
</header>
|
|
27
|
+
<main>{children}</main>
|
|
28
|
+
</div>
|
|
29
|
+
<Toaster />
|
|
30
|
+
</>
|
|
31
|
+
)
|
|
32
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PageProps } from 'prunelle'
|
|
2
|
+
import { Card, CardBody, CardHeader } from '@prunellejs/ui'
|
|
3
|
+
|
|
4
|
+
export default async function DashboardPage({ locals }: PageProps) {
|
|
5
|
+
return (
|
|
6
|
+
<Card>
|
|
7
|
+
<CardHeader>Dashboard</CardHeader>
|
|
8
|
+
<CardBody>
|
|
9
|
+
<p class="m-0">Signed in as <strong>{locals.user?.email}</strong>.</p>
|
|
10
|
+
</CardBody>
|
|
11
|
+
</Card>
|
|
12
|
+
)
|
|
13
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Badge, Button, Cluster, Stack } from '@prunellejs/ui'
|
|
2
|
+
|
|
3
|
+
export default async function Home() {
|
|
4
|
+
return (
|
|
5
|
+
<Stack gap="md">
|
|
6
|
+
<Cluster><Badge tone="accent">Prunelle</Badge><Badge>SQLite Auth</Badge></Cluster>
|
|
7
|
+
<h1 class="page-title">Welcome to __APP_NAME__</h1>
|
|
8
|
+
<p class="page-lead">Zero-dependency Argon2id auth, @prunellejs/ui pure CSS grammar, and Bun speed.</p>
|
|
9
|
+
<Cluster>
|
|
10
|
+
<Button href="/login" tone="accent">Get started</Button>
|
|
11
|
+
<Button href="/dashboard" variant="outline">Dashboard</Button>
|
|
12
|
+
</Cluster>
|
|
13
|
+
</Stack>
|
|
14
|
+
)
|
|
15
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Button, Card, CardBody, CardHeader, Field, Grid, Stack } from '@prunellejs/ui'
|
|
2
|
+
|
|
3
|
+
export default function LoginPage() {
|
|
4
|
+
return (
|
|
5
|
+
<Grid min="md" gap="lg">
|
|
6
|
+
<Card>
|
|
7
|
+
<CardHeader>Sign in</CardHeader>
|
|
8
|
+
<CardBody>
|
|
9
|
+
<form action="/auth/signin" method="post">
|
|
10
|
+
<Stack gap="sm">
|
|
11
|
+
<input type="hidden" name="redirect" value="/dashboard" />
|
|
12
|
+
<Field id="in-email" label="Email" required><input id="in-email" name="email" type="email" required /></Field>
|
|
13
|
+
<Field id="in-pass" label="Password" required><input id="in-pass" name="password" type="password" required /></Field>
|
|
14
|
+
<Button type="submit" tone="accent">Sign in</Button>
|
|
15
|
+
</Stack>
|
|
16
|
+
</form>
|
|
17
|
+
</CardBody>
|
|
18
|
+
</Card>
|
|
19
|
+
<Card>
|
|
20
|
+
<CardHeader>Create account</CardHeader>
|
|
21
|
+
<CardBody>
|
|
22
|
+
<form action="/auth/signup" method="post">
|
|
23
|
+
<Stack gap="sm">
|
|
24
|
+
<input type="hidden" name="redirect" value="/dashboard" />
|
|
25
|
+
<Field id="up-email" label="Email" required><input id="up-email" name="email" type="email" required /></Field>
|
|
26
|
+
<Field id="up-pass" label="Password" hint="Min 12 characters" required><input id="up-pass" name="password" type="password" minlength="12" required /></Field>
|
|
27
|
+
<Button type="submit" tone="accent">Create account</Button>
|
|
28
|
+
</Stack>
|
|
29
|
+
</form>
|
|
30
|
+
</CardBody>
|
|
31
|
+
</Card>
|
|
32
|
+
</Grid>
|
|
33
|
+
)
|
|
34
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
body { margin: 0; background: var(--ui-paper); color: var(--ui-ink); font-family: var(--ui-font-body); }
|
|
2
|
+
.wrap { max-width: 52rem; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
|
|
3
|
+
.site-header { padding-bottom: 1.25rem; margin-bottom: 2rem; border-bottom: 1px solid var(--ui-line); }
|
|
4
|
+
.site-brand { font-family: var(--ui-font-display); font-size: 1.3rem; font-weight: 700; text-decoration: none; color: inherit; }
|
|
5
|
+
.page-title { margin: 0; font-family: var(--ui-font-display); }
|
|
6
|
+
.page-lead { margin: 0; color: var(--ui-muted); }
|
|
7
|
+
.m-0 { margin: 0; }
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { TestApp } from 'prunelle/test'
|
|
2
|
+
import { beforeAll, describe, expect, it } from 'bun:test'
|
|
3
|
+
import { resolve } from 'node:path'
|
|
4
|
+
import { testApp } from 'prunelle/test'
|
|
5
|
+
|
|
6
|
+
const root = resolve(import.meta.dir, '..')
|
|
7
|
+
process.env.AUTH_DB ??= ':memory:'
|
|
8
|
+
|
|
9
|
+
describe('__APP_NAME__', () => {
|
|
10
|
+
let app: TestApp
|
|
11
|
+
|
|
12
|
+
beforeAll(async () => {
|
|
13
|
+
app = await testApp({ root })
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('renders the home and login pages', async () => {
|
|
17
|
+
const home = await app.get('/')
|
|
18
|
+
expect(home.status).toBe(200)
|
|
19
|
+
expect(await home.text()).toContain('Welcome to __APP_NAME__')
|
|
20
|
+
|
|
21
|
+
const login = await app.get('/login')
|
|
22
|
+
expect(login.status).toBe(200)
|
|
23
|
+
expect(await login.text()).toContain('/auth/signin')
|
|
24
|
+
expect(app.errors).toEqual([])
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it('redirects unauthenticated requests from /dashboard to /login', async () => {
|
|
28
|
+
const res = await app.get('/dashboard')
|
|
29
|
+
expect(res.status).toBe(302)
|
|
30
|
+
expect(res.headers.get('location')).toBe('/login?next=%2Fdashboard')
|
|
31
|
+
})
|
|
32
|
+
})
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Welcome to __APP_NAME__
|
|
3
|
+
date: 2026-11-23
|
|
4
|
+
description: A zero-JS static Markdown blog built with Prunelle.
|
|
5
|
+
tags: [prunelle, bun]
|
|
6
|
+
---
|
|
7
|
+
## Fast by Default
|
|
8
|
+
|
|
9
|
+
This post is rendered at build time using Bun's native Zig Markdown engine and ships **0 KB** of client JavaScript.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "__APP_NAME__",
|
|
3
|
+
"private": true,
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "prunelle dev",
|
|
7
|
+
"build": "prunelle build",
|
|
8
|
+
"start": "prunelle start",
|
|
9
|
+
"check": "prunelle check",
|
|
10
|
+
"test": "bun test"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"prunelle": "__PRUNELLE_VERSION__",
|
|
14
|
+
"@prunellejs/content": "__PRUNELLE_VERSION__",
|
|
15
|
+
"@prunellejs/seo": "__PRUNELLE_VERSION__",
|
|
16
|
+
"@prunellejs/ui": "__PRUNELLE_VERSION__"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/bun": "latest",
|
|
20
|
+
"typescript": "^6.0.3"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { content } from '@prunellejs/content'
|
|
2
|
+
import { seo } from '@prunellejs/seo'
|
|
3
|
+
import { ui } from '@prunellejs/ui/plugin'
|
|
4
|
+
import { defineConfig } from 'prunelle/config'
|
|
5
|
+
import { posts } from './src/posts'
|
|
6
|
+
|
|
7
|
+
export default defineConfig({
|
|
8
|
+
lang: 'en',
|
|
9
|
+
plugins: [
|
|
10
|
+
ui({ grammar: 'editorial' }),
|
|
11
|
+
seo({ site: 'https://example.com', titleTemplate: '%s — __APP_NAME__', description: 'Articles & notes from __APP_NAME__', image: '/og.png' }),
|
|
12
|
+
content({
|
|
13
|
+
feeds: [{
|
|
14
|
+
path: '/rss.xml',
|
|
15
|
+
title: '__APP_NAME__',
|
|
16
|
+
description: 'Articles & notes',
|
|
17
|
+
site: 'https://example.com',
|
|
18
|
+
linkPrefix: '/blog',
|
|
19
|
+
collection: posts,
|
|
20
|
+
}],
|
|
21
|
+
}),
|
|
22
|
+
],
|
|
23
|
+
})
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from 'prunelle/server'
|
|
2
|
+
import { defineCollection } from '@prunellejs/content'
|
|
3
|
+
|
|
4
|
+
export interface PostMeta {
|
|
5
|
+
title: string
|
|
6
|
+
date: string
|
|
7
|
+
description?: string
|
|
8
|
+
tags?: string[]
|
|
9
|
+
draft?: boolean
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Any Standard Schema validator works here (Zod, Valibot, ArkType); this one keeps the template free of dependencies.
|
|
13
|
+
const postSchema: StandardSchemaV1<unknown, PostMeta> = {
|
|
14
|
+
'~standard': {
|
|
15
|
+
version: 1,
|
|
16
|
+
vendor: 'app',
|
|
17
|
+
validate(raw: unknown) {
|
|
18
|
+
const data = raw as Partial<PostMeta>
|
|
19
|
+
if (typeof data.title !== 'string' || typeof data.date !== 'string')
|
|
20
|
+
return { issues: [{ message: 'A post needs a title and a date', path: ['title'] }] }
|
|
21
|
+
return { value: data as PostMeta }
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const posts = defineCollection({ dir: 'content/posts', schema: postSchema })
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { PrunelleChild } from 'prunelle'
|
|
2
|
+
import { Head } from 'prunelle'
|
|
3
|
+
import '../styles/app.css'
|
|
4
|
+
|
|
5
|
+
export default function Layout({ children }: { children: PrunelleChild }) {
|
|
6
|
+
return (
|
|
7
|
+
<>
|
|
8
|
+
<Head>
|
|
9
|
+
<title>__APP_NAME__</title>
|
|
10
|
+
</Head>
|
|
11
|
+
<div class="wrap">
|
|
12
|
+
<header data-layout="split" class="site-header">
|
|
13
|
+
<a href="/" class="site-brand">__APP_NAME__</a>
|
|
14
|
+
<a href="/rss.xml" class="site-rss">RSS</a>
|
|
15
|
+
</header>
|
|
16
|
+
<main>{children}</main>
|
|
17
|
+
</div>
|
|
18
|
+
</>
|
|
19
|
+
)
|
|
20
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { RequestContext } from 'prunelle/server'
|
|
2
|
+
import { Button, Stack } from '@prunellejs/ui'
|
|
3
|
+
import { Head } from 'prunelle'
|
|
4
|
+
import { posts } from '../../posts'
|
|
5
|
+
|
|
6
|
+
export const prerender = true
|
|
7
|
+
export function paths() {
|
|
8
|
+
return posts.paths('/blog')
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export async function load(ctx: RequestContext) {
|
|
12
|
+
const post = posts.get(ctx.params.slug ?? '')
|
|
13
|
+
if (!post)
|
|
14
|
+
return new Response('Not found', { status: 404 })
|
|
15
|
+
return { post }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default function PostPage({ data }: { data: { post: NonNullable<ReturnType<typeof posts.get>> } }) {
|
|
19
|
+
const { post } = data
|
|
20
|
+
return (
|
|
21
|
+
<Stack gap="md">
|
|
22
|
+
<Head><title>{post.data.title}</title></Head>
|
|
23
|
+
<article>
|
|
24
|
+
<h1 class="post-title">{post.data.title}</h1>
|
|
25
|
+
<p class="post-meta">{post.data.date} · {post.readingMinutes} min read</p>
|
|
26
|
+
<div innerHTML={post.html} />
|
|
27
|
+
</article>
|
|
28
|
+
<div><Button href="/" variant="outline">← All posts</Button></div>
|
|
29
|
+
</Stack>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Badge, Card, CardBody, CardFooter, CardHeader, Cluster, Stack } from '@prunellejs/ui'
|
|
2
|
+
import { Head } from 'prunelle'
|
|
3
|
+
import { posts } from '../posts'
|
|
4
|
+
|
|
5
|
+
export const prerender = true
|
|
6
|
+
|
|
7
|
+
export default async function BlogIndex() {
|
|
8
|
+
const list = posts.all()
|
|
9
|
+
return (
|
|
10
|
+
<Stack gap="lg">
|
|
11
|
+
<Head>
|
|
12
|
+
<title>Articles</title>
|
|
13
|
+
</Head>
|
|
14
|
+
<h1 class="page-title">Articles</h1>
|
|
15
|
+
{list.map(post => (
|
|
16
|
+
<Card key={post.slug}>
|
|
17
|
+
<CardHeader>
|
|
18
|
+
<a href={`/blog/${post.slug}`} class="post-link">{post.data.title}</a>
|
|
19
|
+
</CardHeader>
|
|
20
|
+
<CardBody>
|
|
21
|
+
<p class="post-desc">{post.data.description ?? ''}</p>
|
|
22
|
+
</CardBody>
|
|
23
|
+
<CardFooter>
|
|
24
|
+
<Cluster>
|
|
25
|
+
<span>{post.data.date} · {post.readingMinutes} min read</span>
|
|
26
|
+
{(post.data.tags ?? []).map(tag => <Badge key={tag}>{tag}</Badge>)}
|
|
27
|
+
</Cluster>
|
|
28
|
+
</CardFooter>
|
|
29
|
+
</Card>
|
|
30
|
+
))}
|
|
31
|
+
</Stack>
|
|
32
|
+
)
|
|
33
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
body { margin: 0; background: var(--ui-paper); color: var(--ui-ink); font-family: var(--ui-font-body); }
|
|
2
|
+
.wrap { max-width: 46rem; margin: 0 auto; padding: 2rem 1.25rem 4rem; }
|
|
3
|
+
.site-header { padding-bottom: 1.25rem; margin-bottom: 2rem; border-bottom: 1px solid var(--ui-line); }
|
|
4
|
+
.site-brand { font-family: var(--ui-font-display); font-size: 1.35rem; font-weight: 700; text-decoration: none; color: inherit; }
|
|
5
|
+
.site-rss { font-size: 0.9rem; color: var(--ui-muted); }
|
|
6
|
+
.page-title { margin: 0; font-family: var(--ui-font-display); }
|
|
7
|
+
.post-link { color: inherit; text-decoration: none; }
|
|
8
|
+
.post-desc { margin: 0; color: var(--ui-muted); }
|
|
9
|
+
.post-title { font-family: var(--ui-font-display); margin-bottom: 0.25rem; }
|
|
10
|
+
.post-meta { color: var(--ui-muted); margin-top: 0; }
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "__APP_NAME__",
|
|
3
|
+
"private": true,
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "prunelle dev",
|
|
7
|
+
"build": "prunelle build",
|
|
8
|
+
"start": "prunelle start",
|
|
9
|
+
"check": "prunelle check",
|
|
10
|
+
"test": "bun test"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"prunelle": "__PRUNELLE_VERSION__"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@types/bun": "latest",
|
|
17
|
+
"typescript": "^6.0.3"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from 'prunelle/server'
|
|
2
|
+
import { action } from 'prunelle/server'
|
|
3
|
+
|
|
4
|
+
const nameSchema: StandardSchemaV1<{ name: string }> = {
|
|
5
|
+
'~standard': {
|
|
6
|
+
version: 1,
|
|
7
|
+
vendor: 'prunelle',
|
|
8
|
+
validate(raw: unknown) {
|
|
9
|
+
const name = String((raw as { name?: unknown })?.name ?? '').trim()
|
|
10
|
+
if (name.length < 2)
|
|
11
|
+
return { issues: [{ message: 'Enter at least 2 characters', path: ['name'] }] }
|
|
12
|
+
return { value: { name } }
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const greet = action(nameSchema, async ({ name }) => {
|
|
18
|
+
return { message: `Hello, ${name}!` }
|
|
19
|
+
})
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { signal } from 'prunelle'
|
|
2
|
+
import { greet } from '../actions/greet'
|
|
3
|
+
|
|
4
|
+
export function GreetForm() {
|
|
5
|
+
const name = signal('')
|
|
6
|
+
const reply = signal('')
|
|
7
|
+
|
|
8
|
+
async function onSubmit(e: SubmitEvent) {
|
|
9
|
+
e.preventDefault()
|
|
10
|
+
const res = await greet({ name: name.value })
|
|
11
|
+
reply.value = res.ok ? res.data.message : res.error
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<form class="greet-form" action={greet.url} method="post" onSubmit={onSubmit}>
|
|
16
|
+
<input
|
|
17
|
+
name="name"
|
|
18
|
+
aria-label="Your name"
|
|
19
|
+
placeholder="Your name"
|
|
20
|
+
value={name.value}
|
|
21
|
+
onInput={(e) => { name.value = (e.target as HTMLInputElement).value }}
|
|
22
|
+
/>
|
|
23
|
+
<button type="submit">Greet</button>
|
|
24
|
+
{reply.value && <span>{reply.value}</span>}
|
|
25
|
+
</form>
|
|
26
|
+
)
|
|
27
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PrunelleChild } from 'prunelle'
|
|
2
|
+
import { Head } from 'prunelle'
|
|
3
|
+
import '../styles/app.css'
|
|
4
|
+
|
|
5
|
+
export default function Layout({ children }: { children: PrunelleChild }) {
|
|
6
|
+
return (
|
|
7
|
+
<>
|
|
8
|
+
<Head>
|
|
9
|
+
<title>__APP_NAME__</title>
|
|
10
|
+
</Head>
|
|
11
|
+
<main>{children}</main>
|
|
12
|
+
</>
|
|
13
|
+
)
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Counter } from '../components/Counter'
|
|
2
|
+
import { GreetForm } from '../components/GreetForm'
|
|
3
|
+
|
|
4
|
+
export default async function Home() {
|
|
5
|
+
return (
|
|
6
|
+
<section>
|
|
7
|
+
<h1>Welcome to Prunelle</h1>
|
|
8
|
+
<p>Zero-directive islands, Standard-Schema actions, and Bun speed.</p>
|
|
9
|
+
<Counter initial={0} />
|
|
10
|
+
<GreetForm />
|
|
11
|
+
</section>
|
|
12
|
+
)
|
|
13
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
*, *::before, *::after { box-sizing: border-box; }
|
|
2
|
+
body {
|
|
3
|
+
margin: 0;
|
|
4
|
+
font-family: system-ui, -apple-system, sans-serif;
|
|
5
|
+
line-height: 1.6;
|
|
6
|
+
color: #111827;
|
|
7
|
+
background: #fafafa;
|
|
8
|
+
}
|
|
9
|
+
main {
|
|
10
|
+
max-width: 44rem;
|
|
11
|
+
margin: 4rem auto;
|
|
12
|
+
padding: 0 1.5rem;
|
|
13
|
+
}
|
|
14
|
+
button {
|
|
15
|
+
font: inherit;
|
|
16
|
+
padding: 0.5rem 1rem;
|
|
17
|
+
border-radius: 6px;
|
|
18
|
+
border: 1px solid #d1d5db;
|
|
19
|
+
background: #fff;
|
|
20
|
+
cursor: pointer;
|
|
21
|
+
}
|
|
22
|
+
button:hover { background: #f3f4f6; }
|
|
23
|
+
|
|
24
|
+
.greet-form {
|
|
25
|
+
margin-top: 1.5rem;
|
|
26
|
+
display: flex;
|
|
27
|
+
gap: 0.5rem;
|
|
28
|
+
align-items: center;
|
|
29
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ServerAction } from 'prunelle/server'
|
|
2
|
+
import type { TestApp } from 'prunelle/test'
|
|
3
|
+
import { beforeAll, describe, expect, it } from 'bun:test'
|
|
4
|
+
import { resolve } from 'node:path'
|
|
5
|
+
import { testApp } from 'prunelle/test'
|
|
6
|
+
|
|
7
|
+
const root = resolve(import.meta.dir, '..')
|
|
8
|
+
|
|
9
|
+
describe('__APP_NAME__', () => {
|
|
10
|
+
let app: TestApp
|
|
11
|
+
|
|
12
|
+
beforeAll(async () => {
|
|
13
|
+
app = await testApp({ root })
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('renders the home page and health endpoint', async () => {
|
|
17
|
+
const home = await app.get('/')
|
|
18
|
+
expect(home.status).toBe(200)
|
|
19
|
+
expect(await home.text()).toContain('Welcome to Prunelle')
|
|
20
|
+
|
|
21
|
+
const health = await app.get('/api/health')
|
|
22
|
+
expect(health.status).toBe(200)
|
|
23
|
+
expect(await health.json()).toEqual({ ok: true, runtime: 'bun' })
|
|
24
|
+
expect(app.errors).toEqual([])
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it('validates and runs the greet action', async () => {
|
|
28
|
+
const { greet } = await app.import('src/actions/greet.ts') as { greet: ServerAction<{ name: string }, { message: string }> }
|
|
29
|
+
|
|
30
|
+
const ok = await app.submit(greet, { name: 'Prunelle' })
|
|
31
|
+
expect(ok.status).toBe(200)
|
|
32
|
+
expect(await ok.json()).toEqual({ ok: true, data: { message: 'Hello, Prunelle!' } })
|
|
33
|
+
|
|
34
|
+
const invalid = await app.submit(greet, { name: 'a' })
|
|
35
|
+
expect(invalid.status).toBe(400)
|
|
36
|
+
})
|
|
37
|
+
})
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "__APP_NAME__",
|
|
3
|
+
"private": true,
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "prunelle dev",
|
|
7
|
+
"build": "prunelle build",
|
|
8
|
+
"start": "prunelle start",
|
|
9
|
+
"check": "prunelle check",
|
|
10
|
+
"test": "bun test"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"prunelle": "__PRUNELLE_VERSION__"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@types/bun": "latest",
|
|
17
|
+
"typescript": "^6.0.3"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PrunelleChild } from 'prunelle'
|
|
2
|
+
import { Head } from 'prunelle'
|
|
3
|
+
import '../styles/app.css'
|
|
4
|
+
|
|
5
|
+
export default function Layout({ children }: { children: PrunelleChild }) {
|
|
6
|
+
return (
|
|
7
|
+
<>
|
|
8
|
+
<Head>
|
|
9
|
+
<title>__APP_NAME__</title>
|
|
10
|
+
</Head>
|
|
11
|
+
<main>{children}</main>
|
|
12
|
+
</>
|
|
13
|
+
)
|
|
14
|
+
}
|