@ultimat3/cli 31.37.0 → 31.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/package.json +29 -29
  2. package/src/cmd-planned.ts +5 -28
  3. package/src/generate-sign-in-runtime.ts +70 -0
  4. package/src/generate-sign-in.ts +19 -6
  5. package/src/generate-write.ts +12 -0
  6. package/src/island-plugin-path.ts +35 -0
  7. package/src/island-realtime.ts +11 -8
  8. package/src/island-runtime.ts +4 -1
  9. package/src/new-shapes.ts +10 -1
  10. package/src/templates/shapes/agent-actions.ts +224 -0
  11. package/src/templates/shapes/agent-job.ts +171 -0
  12. package/src/templates/shapes/agent-model.ts +271 -0
  13. package/src/templates/shapes/agent-prompt.ts +254 -0
  14. package/src/templates/shapes/agent-scripted.ts +56 -0
  15. package/src/templates/shapes/agent.ts +138 -0
  16. package/src/templates/shapes/content-admin-es.ts +95 -0
  17. package/src/templates/shapes/content-pages.ts +221 -0
  18. package/src/templates/shapes/content-site.ts +343 -0
  19. package/src/templates/shapes/content.ts +133 -0
  20. package/src/templates/shapes/index.ts +10 -0
  21. package/src/templates/shapes/offline-e2e.ts +123 -0
  22. package/src/templates/shapes/offline-form.ts +334 -0
  23. package/src/templates/shapes/offline.ts +118 -0
  24. package/src/templates/shapes/realtime-mutator.ts +136 -0
  25. package/src/templates/shapes/realtime-nodes.ts +203 -0
  26. package/src/templates/shapes/realtime-slice.ts +166 -0
  27. package/src/templates/shapes/realtime.ts +162 -0
  28. package/src/templates/shapes/saas-billing-tests.ts +135 -0
  29. package/src/templates/shapes/saas-billing.ts +137 -0
  30. package/src/templates/shapes/saas-receiver.ts +136 -0
  31. package/src/templates/shapes/saas.ts +112 -0
  32. package/src/templates/sign-in-oidc.ts +2 -4
  33. package/src/templates/sign-in-runtime.ts +172 -0
  34. package/src/templates/sign-in-shared.ts +5 -36
  35. package/wiki/Building-Your-Own-Base.md +339 -0
  36. package/wiki/CLI-Reference.md +1 -14
  37. package/wiki/Caching-And-Invalidation.md +1 -1
  38. package/wiki/Entities-And-Migrations.md +2 -2
  39. package/wiki/Known-Gaps.md +8 -2
  40. package/wiki/MCP-And-AI.md +3 -3
  41. package/wiki/Money.md +1 -1
  42. package/wiki/Shapes.md +18 -9
  43. package/wiki/Troubleshooting.md +1 -1
  44. package/wiki/Upgrading.md +1 -1
@@ -0,0 +1,221 @@
1
+ // The `content` shape's source: markdown files under `apps/web/content/<locale>/`, and the one
2
+ // reader every `site/` route reads them through. Files, not rows — a page is written by committing
3
+ // a file, and `x build --target static` renders each one per locale. No table, no migration.
4
+
5
+ import type { GeneratedFile, NameSet } from '../naming';
6
+
7
+ /** The second locale the shape routes beside `en`: one is a site, two prove the hreflang cluster. */
8
+ export const CONTENT_LOCALES = ['en', 'es'] as const;
9
+
10
+ const reader =
11
+ (): string => `// The site's pages, read from \`apps/web/content/<locale>/<slug>.md\`. A file's \`#\` line is its
12
+ // title and its first paragraph its description. Build-time only: every route that calls this is
13
+ // \`render: 'static'\`, so a visitor's request never reads a file and the site needs no database.
14
+
15
+ import { assertCoded, renderFixShellArg, retryMemo } from '@ultimat3/core';
16
+ import { parseMarkdown } from '@ultimat3/ui';
17
+
18
+ /** One page in one locale. \`body\` is the markdown under the title, rendered by \`Markdown\`. */
19
+ export interface ContentPage {
20
+ readonly locale: string;
21
+ readonly slug: string;
22
+ readonly title: string;
23
+ readonly lead: string;
24
+ readonly body: string;
25
+ }
26
+
27
+ const ROOT = new URL('../content/', import.meta.url);
28
+ const SLUG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
29
+ const TITLE = /^# +(\\S.*)$/;
30
+
31
+ type Block = ReturnType<typeof parseMarkdown>[number];
32
+ type Inline = Extract<Block, { kind: 'paragraph' }>['children'][number];
33
+
34
+ /** An inline run as the plain text a \`<meta name="description">\` carries. */
35
+ const plain = (inlines: readonly Inline[]): string =>
36
+ inlines
37
+ .map((inline) => {
38
+ if (inline.kind === 'text' || inline.kind === 'code') return inline.text;
39
+ if (inline.kind === 'image') return inline.alt;
40
+ if (inline.kind === 'break') return ' ';
41
+ return plain(inline.children);
42
+ })
43
+ .join('');
44
+
45
+ /** One file, read. Refused, naming the file, when it cannot say what it is. */
46
+ export function readPage(locale: string, slug: string, markdown: string): ContentPage {
47
+ const file = \`apps/web/content/\${locale}/\${slug}.md\`;
48
+ assertCoded(
49
+ SLUG.test(slug),
50
+ 'X_INVARIANT',
51
+ \`\${file}: a file name is the page's URL, so it is lowercase words joined by hyphens\`,
52
+ \`mv \${renderFixShellArg(file, '<file>')} apps/web/content/\${locale}/<lowercase-slug>.md\`,
53
+ );
54
+ const [first = '', ...rest] = markdown.split('\\n');
55
+ const title = TITLE.exec(first.trim())?.[1]?.trim();
56
+ assertCoded(
57
+ title !== undefined,
58
+ 'X_INVARIANT',
59
+ \`\${file} does not open with a "# Title" line, so the page has no title\`,
60
+ \`edit \${file}: make its first line "# <the page title>"\`,
61
+ );
62
+ const body = rest.join('\\n').trim();
63
+ const blocks = parseMarkdown(body);
64
+ assertCoded(
65
+ !blocks.some((block) => block.kind === 'heading' && block.level === 1),
66
+ 'X_INVARIANT',
67
+ \`\${file} has a second "#" heading, and a page has one h1\`,
68
+ \`edit \${file}: turn every "#" heading after the first line into "##"\`,
69
+ );
70
+ const lead = blocks.find((block) => block.kind === 'paragraph');
71
+ assertCoded(
72
+ lead !== undefined,
73
+ 'X_INVARIANT',
74
+ \`\${file} has no paragraph under its title, so the page has no description\`,
75
+ \`edit \${file}: add one sentence under the title saying what the page is\`,
76
+ );
77
+ return { locale, slug, title, lead: plain(lead.children).trim(), body };
78
+ }
79
+
80
+ async function load(): Promise<readonly ContentPage[]> {
81
+ const root = Bun.fileURLToPath(ROOT);
82
+ const paths = await Array.fromAsync(new Bun.Glob('*/*.md').scan({ cwd: root }));
83
+ return await Promise.all(
84
+ paths.sort().map(async (path) => {
85
+ const [locale = '', name = ''] = path.split('/');
86
+ return readPage(
87
+ locale,
88
+ name.slice(0, -'.md'.length),
89
+ await Bun.file(\`\${root}/\${path}\`).text(),
90
+ );
91
+ }),
92
+ );
93
+ }
94
+
95
+ /** Every page in every locale, read on the first call and shared by every route after it. */
96
+ const corpus = retryMemo(load);
97
+
98
+ /** The pages of one locale, in file-name order. */
99
+ export async function contentPages(locale: string): Promise<readonly ContentPage[]> {
100
+ return (await corpus.get()).filter((page) => page.locale === locale);
101
+ }
102
+
103
+ /** One page, or the 404 a static route answers for a path it never built. */
104
+ export async function contentPage(locale: string, slug: string): Promise<ContentPage> {
105
+ const page = (await contentPages(locale)).find((candidate) => candidate.slug === slug);
106
+ assertCoded(
107
+ page !== undefined,
108
+ 'X_NOT_FOUND',
109
+ \`no page apps/web/content/\${locale}/\${slug}.md\`,
110
+ \`ls apps/web/content/\${locale} # every page is a file here; translate the default locale's into it\`,
111
+ );
112
+ return page;
113
+ }
114
+ `;
115
+
116
+ const readerTest = (
117
+ app: NameSet,
118
+ ): string => `// The reader: what a file becomes, every file it refuses, and that every locale has every page —
119
+ // a page missing in one locale is a 404 in that language that nothing else would notice.
120
+ import '@${app.kebab}/i18n';
121
+ import { routedLocales } from '@ultimat3/i18n';
122
+ import { expect, unitTest } from '@ultimat3/testing';
123
+ import { contentPage, contentPages, readPage } from './content';
124
+
125
+ const coded = (code: string) => expect.objectContaining({ code });
126
+
127
+ unitTest('a file is its title, its lead as plain text, and the body under the title', () => {
128
+ const page = readPage('en', 'hello', '# Hello\\n\\nThe **first** [line](/x), \`code\`.\\n\\n## A');
129
+ expect(page.title).toBe('Hello');
130
+ expect(page.lead).toBe('The first line, code.');
131
+ expect(page.body.startsWith('The **first**')).toBe(true);
132
+ });
133
+
134
+ unitTest('a file that cannot say what it is is refused, naming the file', () => {
135
+ expect(() => readPage('en', 'Bad Name', '# T\\n\\nLead.')).toThrow(coded('X_INVARIANT'));
136
+ expect(() => readPage('en', 'untitled', 'Lead only.')).toThrow(coded('X_INVARIANT'));
137
+ expect(() => readPage('en', 'twice', '# One\\n\\nLead.\\n\\n# Two')).toThrow(coded('X_INVARIANT'));
138
+ expect(() => readPage('en', 'bare', '# Title\\n\\n## Only a heading')).toThrow(
139
+ coded('X_INVARIANT'),
140
+ );
141
+ });
142
+
143
+ unitTest('every routed locale has the same pages as the default one', async () => {
144
+ const [fallback = 'en', ...others] = routedLocales();
145
+ const slugs = async (locale: string) => (await contentPages(locale)).map((page) => page.slug);
146
+ const expected = await slugs(fallback);
147
+ expect(expected.length).toBeGreaterThan(0);
148
+ expect(others.length).toBeGreaterThan(0);
149
+ for (const locale of others)
150
+ expect({ locale, slugs: await slugs(locale) }).toEqual({ locale, slugs: expected });
151
+ });
152
+
153
+ unitTest('one page by locale and slug, and X_NOT_FOUND for a path no file builds', async () => {
154
+ const [first] = await contentPages('en');
155
+ expect((await contentPage('en', first?.slug ?? '')).title).toBe(first?.title ?? '');
156
+ await expect(contentPage('en', 'no-such-page')).rejects.toThrow(coded('X_NOT_FOUND'));
157
+ });
158
+ `;
159
+
160
+ const GETTING_STARTED_EN = `# Getting started
161
+
162
+ Every page on this site is a markdown file, rendered once per language when the site is built.
163
+
164
+ ## Write a page
165
+
166
+ 1. Add a file under \`apps/web/content/en/\`. Its name is the page's address, its first line is the
167
+ title, and its first paragraph is the description a search result shows.
168
+ 2. Add the same file, translated, under every other locale folder.
169
+ 3. Run \`bun run verify\`. The build renders the page in every language, and refuses one that is
170
+ missing in any of them.
171
+
172
+ ## What ships
173
+
174
+ No JavaScript, on any page. The sitemap lists each page once per language, and every copy links
175
+ to the others.
176
+ `;
177
+
178
+ const GETTING_STARTED_ES = `# Primeros pasos
179
+
180
+ Cada página de este sitio es un archivo markdown, generado una vez por idioma al construir el sitio.
181
+
182
+ ## Escribir una página
183
+
184
+ 1. Añade un archivo en \`apps/web/content/en/\`. Su nombre es la dirección de la página, su primera
185
+ línea es el título y su primer párrafo es la descripción que muestra un buscador.
186
+ 2. Añade el mismo archivo, traducido, en la carpeta de cada otro idioma.
187
+ 3. Ejecuta \`bun run verify\`. La compilación genera la página en cada idioma y rechaza la que
188
+ falte en alguno.
189
+
190
+ ## Qué se publica
191
+
192
+ Nada de JavaScript, en ninguna página. El mapa del sitio lista cada página una vez por idioma, y
193
+ cada copia enlaza a las demás.
194
+ `;
195
+
196
+ const ABOUT_EN = `# About
197
+
198
+ What this site is, and who keeps it. Replace this file with your own words.
199
+
200
+ It is built from files with no database behind it, so any static host can serve it.
201
+ `;
202
+
203
+ const ABOUT_ES = `# Acerca de
204
+
205
+ Qué es este sitio y quién lo mantiene. Sustituye este archivo por tus propias palabras.
206
+
207
+ Se construye a partir de archivos sin base de datos detrás, así que cualquier alojamiento estático
208
+ puede servirlo.
209
+ `;
210
+
211
+ /** The reader, its test, and two pages in each locale. */
212
+ export function contentPageFiles(app: NameSet): readonly GeneratedFile[] {
213
+ return [
214
+ { path: 'apps/web/shared/content.ts', contents: reader() },
215
+ { path: 'apps/web/shared/content.test.ts', contents: readerTest(app) },
216
+ { path: 'apps/web/content/en/getting-started.md', contents: GETTING_STARTED_EN },
217
+ { path: 'apps/web/content/en/about.md', contents: ABOUT_EN },
218
+ { path: 'apps/web/content/es/getting-started.md', contents: GETTING_STARTED_ES },
219
+ { path: 'apps/web/content/es/about.md', contents: ABOUT_ES },
220
+ ];
221
+ }
@@ -0,0 +1,343 @@
1
+ // The `content` shape's `site/`: the front page at `/` listing every page, and one page per
2
+ // markdown file at `/<slug>`, both `render: 'static'` with zero JavaScript, each built once per
3
+ // routed locale (`/es/<slug>`) inside one frame that links the other languages.
4
+
5
+ import type { GeneratedFile, NameSet } from '../naming';
6
+
7
+ const frame = (
8
+ app: NameSet,
9
+ ): string => `// The chrome every page wears: the site's name home, the page in each language, and the body.
10
+ // Server-rendered links only — a language switch is a link to the other copy, never a script.
11
+
12
+ // The app's catalogs declare which locales are routed: imported here, by the one module that reads
13
+ // them, so the frame links every language whoever loads it first — a page, or this file's test alone.
14
+ import '@${app.kebab}/i18n';
15
+ import { routedLocales } from '@ultimat3/i18n';
16
+ import { LocaleSwitcher } from '@ultimat3/ui';
17
+ import type { JSX } from 'solid-js';
18
+ import styles from './site-frame.module.scss';
19
+
20
+ /** A proper noun, the same in every language — never a catalog string. */
21
+ export const SITE_NAME = '${app.pascal}';
22
+
23
+ export function SiteFrame(props: {
24
+ /** The locale this copy renders in. */
25
+ readonly locale: string;
26
+ /** Where the site's name links: the front page in this locale. */
27
+ readonly home: string;
28
+ /** This page's path, unprefixed: the switcher links it in every routed locale. */
29
+ readonly path: string;
30
+ readonly children: JSX.Element;
31
+ }): JSX.Element {
32
+ return (
33
+ <div class={styles.frame}>
34
+ <header class={styles.header}>
35
+ <a class={styles.brand} href={props.home}>
36
+ {SITE_NAME}
37
+ </a>
38
+ <LocaleSwitcher locales={routedLocales()} value={props.locale} path={props.path} />
39
+ </header>
40
+ <main class={styles.main}>{props.children}</main>
41
+ </div>
42
+ );
43
+ }
44
+ `;
45
+
46
+ const frameTest =
47
+ (): string => `// The frame: the site's name links home, and every routed locale is one link to this page.
48
+ import { expect, renderView, unitTest } from '@ultimat3/testing';
49
+ import { SITE_NAME, SiteFrame } from './site-frame';
50
+
51
+ unitTest('the name links home, and each language links this page in it', async () => {
52
+ const view = await renderView(SiteFrame, {
53
+ locale: 'en',
54
+ home: '/',
55
+ path: '/about',
56
+ children: 'body',
57
+ });
58
+ const hrefs = [...view.html.matchAll(/href="([^"]*)"/g)].map((match) => match[1]);
59
+ expect(hrefs).toEqual(['/', '/about', '/es/about']);
60
+ expect(view.text).toContain(SITE_NAME);
61
+ expect(view.text).toContain('body');
62
+ });
63
+ `;
64
+
65
+ const frameStyle = (): string => `@use '@ultimat3/ui/tokens' as tokens;
66
+
67
+ .frame {
68
+ background: tokens.role('bg');
69
+ color: tokens.role('fg');
70
+ }
71
+
72
+ .header {
73
+ display: flex;
74
+ align-items: center;
75
+ justify-content: space-between;
76
+ gap: tokens.space(4);
77
+ padding: tokens.space(4) tokens.space(8);
78
+ border-bottom: 1px solid tokens.role('line');
79
+ }
80
+
81
+ .brand {
82
+ font-weight: tokens.weight('medium');
83
+ color: tokens.role('fg-strong');
84
+ text-decoration: none;
85
+ }
86
+
87
+ .main {
88
+ display: grid;
89
+ gap: tokens.space(4);
90
+ padding: tokens.space(8);
91
+ }
92
+ `;
93
+
94
+ /** What both pages declare: built once per locale at `x build --target static`, no script. */
95
+ const STATIC_HEAD = ` render: 'static',
96
+ hydrate: 'never',
97
+ budget: { js: '0kb' },`;
98
+
99
+ const indexPage = (
100
+ app: NameSet,
101
+ ): string => `// The front page: what the site is, and every page it holds in this locale. Zero JavaScript.
102
+
103
+ import { useT } from '@${app.kebab}/i18n';
104
+ import { currentLocale, localizedPath } from '@ultimat3/i18n';
105
+ import { defineRoute } from '@ultimat3/render';
106
+ import { ld } from '@ultimat3/seo';
107
+ import type { JSX } from 'solid-js';
108
+ import { For } from 'solid-js';
109
+ import { contentPages } from '../shared/content';
110
+ import { SITE_NAME, SiteFrame } from '../shared/site-frame';
111
+ import styles from './page.module.scss';
112
+
113
+ export const config = defineRoute({
114
+ ${STATIC_HEAD}
115
+ offline: 'precache',
116
+ load: async () => {
117
+ const locale = currentLocale();
118
+ const pages = await contentPages(locale);
119
+ return {
120
+ locale,
121
+ home: localizedPath('/', locale),
122
+ pages: pages.map((page) => ({ ...page, href: localizedPath(\`/\${page.slug}\`, locale) })),
123
+ };
124
+ },
125
+ meta: ({ t, url }) => ({
126
+ title: t('site.content.title', { name: SITE_NAME }),
127
+ description: t('site.content.description'),
128
+ canonical: url,
129
+ ld: [ld.WebSite({ name: SITE_NAME, url })],
130
+ }),
131
+ });
132
+
133
+ export type FrontPage = Awaited<ReturnType<NonNullable<typeof config.load>>>;
134
+
135
+ export function Page(props: { readonly data: FrontPage }): JSX.Element {
136
+ const t = useT();
137
+ return (
138
+ <SiteFrame locale={props.data.locale} home={props.data.home} path="/">
139
+ <h1>{t('site.content.headline')}</h1>
140
+ <p class={styles.lede}>{t('site.content.lede')}</p>
141
+ <h2>{t('site.content.pages')}</h2>
142
+ <ul class={styles.list}>
143
+ <For each={props.data.pages}>
144
+ {(page) => (
145
+ <li class={styles.item}>
146
+ <a href={page.href}>{page.title}</a>
147
+ <p>{page.lead}</p>
148
+ </li>
149
+ )}
150
+ </For>
151
+ </ul>
152
+ </SiteFrame>
153
+ );
154
+ }
155
+ `;
156
+
157
+ const indexTest = (
158
+ app: NameSet,
159
+ ): string => `// The front page: what it links in each locale, its zero-JS contract and its metadata.
160
+ import { useT } from '@${app.kebab}/i18n';
161
+ import { ctxOf, runWithContext } from '@ultimat3/core';
162
+ import { expect, renderRoute, unitTest } from '@ultimat3/testing';
163
+ import * as page from './page';
164
+
165
+ const url = 'https://example.test/';
166
+ const pageLinks = (html: string): string[] =>
167
+ [...html.matchAll(/<li[^>]*><a href="([^"]*)"/g)].map((match) => match[1] ?? '');
168
+
169
+ unitTest('it lists every page of its locale under one h1, with no missing string', async () => {
170
+ const t = useT();
171
+ const view = await renderRoute(page, { url });
172
+ expect(view.html.match(/<h1\\b/g)).toHaveLength(1);
173
+ expect(view.text).toContain(t('site.content.headline'));
174
+ expect(pageLinks(view.html)).toEqual(['/about', '/getting-started']);
175
+ expect(view.text).not.toContain('⟦');
176
+ });
177
+
178
+ unitTest('the Spanish copy links the Spanish pages, in Spanish', async () => {
179
+ const view = await runWithContext(ctxOf({ locale: 'es' }), () => renderRoute(page, { url }));
180
+ expect(pageLinks(view.html)).toEqual(['/es/about', '/es/getting-started']);
181
+ expect(view.data.home).toBe('/es/');
182
+ expect(view.text).not.toContain('⟦');
183
+ expect(view.text).not.toContain(useT()('site.content.headline'));
184
+ });
185
+
186
+ unitTest('it is static, ships zero JavaScript, and says what the site is', async () => {
187
+ const t = useT();
188
+ const view = await renderRoute(page, { url });
189
+ expect(page.config.render).toBe('static');
190
+ expect(page.config.hydrate).toBe('never');
191
+ expect(page.config.budget.js).toBe('0kb');
192
+ expect(view.islands).toEqual([]);
193
+ expect(view.meta.description).toBe(t('site.content.description'));
194
+ expect(view.meta.ld).toHaveLength(1);
195
+ });
196
+ `;
197
+
198
+ const indexStyle = (): string => `@use '@ultimat3/ui/tokens' as tokens;
199
+
200
+ .lede {
201
+ color: tokens.role('fg-muted');
202
+ }
203
+
204
+ .list {
205
+ display: grid;
206
+ gap: tokens.space(3);
207
+ padding: 0;
208
+ list-style: none;
209
+ }
210
+
211
+ .item {
212
+ display: grid;
213
+ gap: tokens.space(1);
214
+ color: tokens.role('fg-muted');
215
+ }
216
+ `;
217
+
218
+ const contentRoute = (
219
+ app: NameSet,
220
+ ): string => `// One page per markdown file: \`apps/web/content/en/about.md\` is \`/about\`, its Spanish copy
221
+ // \`/es/about\`. Static, 0 KB: the body is markdown rendered on the server, through \`Markdown\`.
222
+
223
+ import { useT } from '@${app.kebab}/i18n';
224
+ import { currentLocale, localizedPath, routedLocales } from '@ultimat3/i18n';
225
+ import { defineRoute } from '@ultimat3/render';
226
+ import { ld } from '@ultimat3/seo';
227
+ import { Markdown } from '@ultimat3/ui';
228
+ import type { JSX } from 'solid-js';
229
+ import { contentPage, contentPages } from '../../shared/content';
230
+ import { SiteFrame } from '../../shared/site-frame';
231
+
232
+ export const config = defineRoute({
233
+ ${STATIC_HEAD}
234
+ // \`runtime\`: a dynamic route has no one URL to precache; each page is cached once visited.
235
+ offline: 'runtime',
236
+ // The default locale's files name the pages; every other locale renders the same slugs, and one
237
+ // missing there stops the build with X_NOT_FOUND naming the file.
238
+ prerender: async () =>
239
+ (await contentPages(routedLocales()[0] ?? currentLocale())).map((page) => page.slug),
240
+ load: async ({ params }) => {
241
+ const locale = currentLocale();
242
+ const page = await contentPage(locale, params.page ?? '');
243
+ return { ...page, home: localizedPath('/', locale) };
244
+ },
245
+ meta: ({ data, t, url }) => ({
246
+ title: data.title,
247
+ description: data.lead,
248
+ canonical: url,
249
+ ld: [
250
+ ld.BreadcrumbList({
251
+ items: [
252
+ { name: t('site.content.home'), url: data.home },
253
+ { name: data.title, url },
254
+ ],
255
+ }),
256
+ ],
257
+ }),
258
+ });
259
+
260
+ export type ContentRoute = Awaited<ReturnType<NonNullable<typeof config.load>>>;
261
+
262
+ export function Page(props: { readonly data: ContentRoute }): JSX.Element {
263
+ const t = useT();
264
+ return (
265
+ <SiteFrame locale={props.data.locale} home={props.data.home} path={\`/\${props.data.slug}\`}>
266
+ <article>
267
+ <h1>{props.data.title}</h1>
268
+ <Markdown text={props.data.body} baseLevel={1} />
269
+ </article>
270
+ <a href={props.data.home}>{t('site.content.back')}</a>
271
+ </SiteFrame>
272
+ );
273
+ }
274
+ `;
275
+
276
+ const contentRouteTest = (
277
+ app: NameSet,
278
+ ): string => `// One page: which slugs the build renders, what a file becomes, its Spanish copy, and the 404.
279
+ import { useT } from '@${app.kebab}/i18n';
280
+ import { ctxOf, runWithContext } from '@ultimat3/core';
281
+ import { expect, renderRoute, unitTest } from '@ultimat3/testing';
282
+ import * as page from './page';
283
+
284
+ const url = 'https://example.test/about';
285
+
286
+ unitTest('the build renders one page per file of the default locale', async () => {
287
+ expect(await page.config.prerender?.()).toEqual(['about', 'getting-started']);
288
+ });
289
+
290
+ unitTest('a file renders its title once, its body, and the way back', async () => {
291
+ const view = await renderRoute(page, { url, params: { page: 'getting-started' } });
292
+ expect(view.html.match(/<h1\\b/g)).toHaveLength(1);
293
+ expect(view.html).toContain('<h2');
294
+ expect(view.meta.title).toBe(view.data.title);
295
+ expect(view.meta.description).toBe(view.data.lead);
296
+ expect(view.text).toContain(useT()('site.content.back'));
297
+ expect(view.text).not.toContain('⟦');
298
+ });
299
+
300
+ unitTest('the Spanish copy reads the Spanish file', async () => {
301
+ const english = await renderRoute(page, { url, params: { page: 'about' } });
302
+ const spanish = await runWithContext(ctxOf({ locale: 'es' }), () =>
303
+ renderRoute(page, { url, params: { page: 'about' } }),
304
+ );
305
+ expect(spanish.data.locale).toBe('es');
306
+ expect(spanish.data.home).toBe('/es/');
307
+ expect(spanish.data.title).not.toBe(english.data.title);
308
+ expect(spanish.text).not.toContain('⟦');
309
+ });
310
+
311
+ unitTest('it is static with zero JavaScript, and a slug no file has is X_NOT_FOUND', async () => {
312
+ expect(page.config.render).toBe('static');
313
+ expect(page.config.budget.js).toBe('0kb');
314
+ await expect(renderRoute(page, { url, params: { page: 'gone' } })).rejects.toThrow(
315
+ expect.objectContaining({ code: 'X_NOT_FOUND' }),
316
+ );
317
+ });
318
+ `;
319
+
320
+ const contentRouteE2e =
321
+ (): string => `// A built page in a real browser, in the second locale: the document a static host serves.
322
+ import { e2eTest, expect } from '@ultimat3/testing';
323
+
324
+ e2eTest('/es/about loads in a browser and names itself', async ({ page }) => {
325
+ await page.goto('/es/about');
326
+ expect(await page.title()).not.toBe('');
327
+ });
328
+ `;
329
+
330
+ /** The frame, the two routes, their tests and styles. */
331
+ export function contentSiteFiles(app: NameSet): readonly GeneratedFile[] {
332
+ return [
333
+ { path: 'apps/web/shared/site-frame.tsx', contents: frame(app) },
334
+ { path: 'apps/web/shared/site-frame.test.ts', contents: frameTest() },
335
+ { path: 'apps/web/shared/site-frame.module.scss', contents: frameStyle() },
336
+ { path: 'apps/web/site/page.tsx', contents: indexPage(app) },
337
+ { path: 'apps/web/site/page.test.ts', contents: indexTest(app) },
338
+ { path: 'apps/web/site/page.module.scss', contents: indexStyle() },
339
+ { path: 'apps/web/site/[page]/page.tsx', contents: contentRoute(app) },
340
+ { path: 'apps/web/site/[page]/page.test.ts', contents: contentRouteTest(app) },
341
+ { path: 'apps/web/site/[page]/page.e2e.test.ts', contents: contentRouteE2e() },
342
+ ];
343
+ }