Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
]
},
Expand All @@ -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."
}
]
},
Expand Down
3 changes: 3 additions & 0 deletions src/emit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
10 changes: 8 additions & 2 deletions src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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.'}
`
}
17 changes: 17 additions & 0 deletions test/generate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading