diff --git a/manifest.json b/manifest.json index ad07e0b..53b26eb 100644 --- a/manifest.json +++ b/manifest.json @@ -267,7 +267,7 @@ { "name": "TROKKY_CLAIM_SECRET", "generate": "hex24", - "why": "Lets the first person to open Studio claim the instance as its administrator. A one-time token you type once, not a password to remember. Without it the claim is open to whoever reaches the URL first." + "why": "Lets the first person to reach the instance claim it and become its administrator, from the Studio or with POST /api/auth/claim. A one-time token you type once, not a password to remember. Without it the claim is open to whoever reaches the URL first." } ] }, @@ -284,7 +284,7 @@ { "name": "TROKKY_CLAIM_SECRET", "generate": "hex24", - "why": "Lets the first person to open Studio claim the instance as its administrator. A one-time token you type once, not a password to remember. Without it the claim is open to whoever reaches the URL first." + "why": "Lets the first person to reach the instance claim it and become its administrator, from the Studio or with POST /api/auth/claim. A one-time token you type once, not a password to remember. Without it the claim is open to whoever reaches the URL first." } ] }, diff --git a/src/emit.ts b/src/emit.ts index 7e853df..987c379 100644 --- a/src/emit.ts +++ b/src/emit.ts @@ -92,6 +92,9 @@ import cloudflare from '@astrojs/cloudflare' export default defineConfig({ output: 'server', adapter: cloudflare(), + // The site keeps no per-visitor state. Left on, the adapter adds a SESSION KV namespace to the + // deploy that nothing reads; set a session driver here if a page ever needs Astro.session. + session: false, }) ` : `import { defineConfig } from 'astro/config' diff --git a/src/generate.ts b/src/generate.ts index e04d4aa..62947e8 100644 --- a/src/generate.ts +++ b/src/generate.ts @@ -73,9 +73,13 @@ export function generate(config: ProjectConfig, source: FileSource): FileTree { tree.set('.env.example', emit.envExample(config)) } - // A Studio-less project has nothing to copy Studio into. + // A Studio-less project has nothing to copy Studio into, and nothing to ignore for it. if (!hasStudio(config)) { tree.delete('scripts/copy-studio.mjs') + const ignore = tree.get('.gitignore') + if (typeof ignore === 'string') { + tree.set('.gitignore', ignore.replace('# Copied from @trokky/studio at build time; never hand-edited.\npublic/studio/\n', '')) + } } // Blank content has nothing to seed. Every other project reads its seed files: from disk on // Node, through the assets binding on Workers (bound for API-only projects too). @@ -164,7 +168,9 @@ minute between deploying and opening the link; it is not fine for an instance le ## Make it yours -${config.content === 'blank' ? '- `src/trokky/` — add your schemas; the Studio follows them.' : '- `src/trokky/schemas.ts` — the content model. The Studio follows it.\n- `src/trokky/structure.ts` — the Studio sidebar.'} +${config.content === 'blank' + ? `- \`src/trokky/\` — add your schemas; ${hasStudio(config) ? 'the Studio follows them' : 'the API validates against them'}.` + : `- \`src/trokky/schemas.ts\` — the content model. ${hasStudio(config) ? 'The Studio follows it.' : 'The API validates against it.'}\n- \`src/trokky/structure.ts\` — ${hasStudio(config) ? 'the Studio sidebar' : 'how content is arranged, including each singleton\'s document id, which the API enforces'}.`} ${hasFrontend(config) ? '- `src/pages/` and `src/layouts/` — the site.\n' : ''}${edge ? '- `wrangler.jsonc` — the Worker name and its resources.' : '- `trokky.config.ts` — storage, media and security.'} ` } diff --git a/test/generate.test.ts b/test/generate.test.ts index f9f3bfb..6aec292 100644 --- a/test/generate.test.ts +++ b/test/generate.test.ts @@ -107,6 +107,23 @@ describe('an API-only Worker', () => { expect(text(conference, 'wrangler.jsonc')).not.toContain('"assets"') }) + it('turns off Astro sessions on Workers, so the deploy creates no unused KV namespace', () => { + for (const content of ['magazine', 'conference'] as const) { + expect(text(build({ parts: 'full-site', content }), 'astro.config.mjs')).toContain('session: false') + } + }) + + it('does not talk about a Studio it does not have', () => { + for (const content of ['blank', 'magazine'] as const) { + const api = build({ parts: 'api', content }) + expect(text(api, 'README.md')).not.toMatch(/Studio follows|Studio sidebar/) + expect(text(api, '.gitignore')).not.toContain('public/studio/') + expect(text(api, '.dev.vars.example')).not.toContain('open Studio') + expect(text(build({ target: 'node', parts: 'api', content }), '.env.example')).not.toContain('open Studio') + } + expect(text(build({ parts: 'studio', content: 'magazine' }), '.gitignore')).toContain('public/studio/') + }) + it('depends on neither Studio nor Astro', () => { const pkg = JSON.parse(text(tree, 'package.json')) expect(pkg.dependencies['@trokky/studio']).toBeUndefined()