create-meith 0.17.2 → 0.18.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/src/scaffold.ts CHANGED
@@ -1,11 +1,78 @@
1
+ export type ScaffoldTarget = 'self-host' | 'vercel'
2
+
1
3
  export interface ScaffoldOptions {
2
4
  readonly name: string
3
5
  readonly version: string
4
6
  readonly repositoryUrl: string
7
+ readonly target?: ScaffoldTarget
8
+ readonly templateRepositoryUrl?: string
5
9
  }
6
10
 
7
11
  export const DEFAULT_REPOSITORY_URL = 'https://github.com/meith-dev/meith'
8
12
 
13
+ export const DEFAULT_TEMPLATE_REPOSITORY_URL = 'https://github.com/meith-dev/vercel-template'
14
+
15
+ export const NEXT_VERSION = '16.3.1'
16
+
17
+ export const AT_ROOT_FLAG = '--at-root'
18
+
19
+ export const MATERIALIZED_AT_ROOT = [
20
+ 'app',
21
+ 'src',
22
+ 'public',
23
+ 'next.config.mjs',
24
+ 'postcss.config.mjs',
25
+ 'components.json',
26
+ 'instrumentation.ts',
27
+ 'proxy.ts',
28
+ 'tsconfig.json',
29
+ 'next-env.d.ts',
30
+ ]
31
+
32
+ export const VERCEL_BUILD_COMMAND = `community migrate && forum-web build ${AT_ROOT_FLAG}`
33
+
34
+ export const TICK_PATH = '/api/system/tick'
35
+
36
+ export const TICK_SCHEDULE = '* * * * *'
37
+
38
+ export const MATERIALIZED_PUBLIC = [
39
+ 'placeholder-logo.png',
40
+ 'placeholder-logo.svg',
41
+ 'placeholder-user.jpg',
42
+ 'placeholder.jpg',
43
+ 'placeholder.svg',
44
+ 'sw.js',
45
+ ]
46
+
47
+ const AT_ROOT_IGNORE_PATHS = MATERIALIZED_AT_ROOT.flatMap((entry) =>
48
+ entry === 'public' ? MATERIALIZED_PUBLIC.map((file) => `/public/${file}`) : [`/${entry}`],
49
+ ).join('\n')
50
+
51
+ const AT_ROOT_IGNORES = `# What \`forum-web ${AT_ROOT_FLAG}\` writes into this directory: @meith/web's own
52
+ # Next app, materialized here rather than into .meith/app so that the build
53
+ # artefact lands at ./.next, where Vercel's Next.js builder reads it. Every
54
+ # path here belongs to the framework and is rewritten on every build.
55
+ #
56
+ # public/ is listed file by file rather than as a directory, because that one
57
+ # is shared: forum-web decides what it owns per file, so this board's own
58
+ # public/ads.txt, public/.well-known/... or domain-verification file sits
59
+ # beside the framework's and is tracked normally.
60
+ #
61
+ # app/ and src/ are ignored WHOLESALE, and that has a consequence worth
62
+ # knowing before you go looking for it: a file you add under either is left
63
+ # alone by the build and still never committed, so it works locally and is
64
+ # simply absent from the deploy, which builds from what git has. Extend the
65
+ # board with a plugin or a theme instead — the forum loads those from
66
+ # community.config.ts, and they are yours to commit. forum-web prints a
67
+ # warning naming any file of yours it finds there.
68
+ #
69
+ # For the rest, a build refuses rather than overwriting a file it did not
70
+ # write, and names it. The two exceptions are tsconfig.json and
71
+ # next-env.d.ts: forum-web generates those from scratch every run rather than
72
+ # copying them, so it cannot tell one of yours from a stale one of its own
73
+ # and replaces them without asking.
74
+ ${AT_ROOT_IGNORE_PATHS}`
75
+
9
76
  const NAME_PATTERN = /^[a-z0-9][a-z0-9._-]{0,213}$/
10
77
 
11
78
  export function validateName(name: string): string | null {
@@ -20,8 +87,317 @@ export function validateName(name: string): string | null {
20
87
  return null
21
88
  }
22
89
 
90
+ const ENV_REQUIRED_HEADING = `# ─── Required ────────────────────────────────────────────────────────────────`
91
+
92
+ const ENV_OPTIONAL_HEADING = `# ─── Optional ────────────────────────────────────────────────────────────────`
93
+
94
+ const ENV_DATABASE_URL_PROSE = `# Your Postgres connection string.
95
+ #
96
+ # If it is a managed database that offers a TRANSACTION-MODE POOLER string, use
97
+ # that rather than the direct one — Neon, Supabase and their kind hand out both,
98
+ # and on the direct string a board works in testing and starts refusing
99
+ # connections under the first real traffic, with an error that names the
100
+ # database rather than the cause. Your own Postgres, with a fixed number of
101
+ # processes in front of it, does not need one.`
102
+
103
+ const ENV_DIRECT_DATABASE_URL_PROSE = `# The other half of that pair: the DIRECT (non-pooler) string, used only by
104
+ # \`community migrate\` and \`community backup\`. Migrations hold a session-level
105
+ # advisory lock so that two deploys landing together queue instead of both
106
+ # applying the same migration, and a transaction-mode pooler cannot hold that
107
+ # lock: it takes the connection back the moment the lock statement ends, which
108
+ # leaves the lock on a backend another client gets. Set both and each gets the
109
+ # connection it needs; set only DATABASE_URL and migrations use it too, which is
110
+ # right for a Postgres you run yourself.`
111
+
112
+ const ENV_AUTH_SECRET_PROSE = `# Session and token signing. No default, deliberately: a shipped default is a
113
+ # board every reader of the source can sign a session for.
114
+ #
115
+ # node -e "console.log(require('crypto').randomBytes(32).toString('base64url'))"`
116
+
117
+ const ENV_TICK_SECRET_PROSE = `# The shared secret the tick caller presents to GET /api/system/tick. Generate
118
+ # it the same way. Without it the tick is unauthenticated, and the tick is how
119
+ # bans expire and digests send.`
120
+
121
+ const ENV_DATA_SOURCE_PROSE = `# fixture = deterministic in-memory sample data, no database needed. This is
122
+ # what \`npm run build\` uses, and what a checkout with no database falls back to.`
123
+
124
+ const ENV_APP_URL_PROSE = `# Absolute, no trailing slash. Used in mail, feeds and canonical URLs — every
125
+ # place a relative URL cannot work because there is no request to be relative to.
126
+ #
127
+ # Optional: leave it blank and the installer asks, prefilled from the address you
128
+ # load /install at, and stores the answer on the board where the settings screen
129
+ # can change it without a redeploy. Set it here and it wins outright.`
130
+
131
+ const ENV_SMTP_MAIL_BLOCK = `# Mail. Leave these alone and the installer asks for mail on first run, storing
132
+ # it on the board — a settings screen with a test button, no redeploy. Set
133
+ # MAIL_DRIVER here instead and the environment wins outright, which is what you
134
+ # want if the credential must not live in the database.
135
+ #
136
+ # The default sends NOTHING: each message goes to the server log, so password
137
+ # reset fails silently until mail is configured one way or the other.
138
+ # MAIL_DRIVER=smtp
139
+ # MAIL_SMTP_HOST=smtp.example.com
140
+ # MAIL_SMTP_PORT=465
141
+ # MAIL_SMTP_SECURITY=tls # tls (465) | starttls (587) | none
142
+ # MAIL_SMTP_USERNAME=
143
+ # MAIL_SMTP_PASSWORD=
144
+ # MAIL_FROM=noreply@yourdomain.com`
145
+
146
+ function selfHostEnvExample(name: string): string {
147
+ return `# ${name} — environment.
148
+ #
149
+ # Copy to .env.local for development. On the server this is \`.env\` beside the
150
+ # compose file; nothing here belongs in git.
151
+
152
+ ${ENV_REQUIRED_HEADING}
153
+
154
+ ${ENV_DATABASE_URL_PROSE}
155
+ DATABASE_URL=
156
+
157
+ ${ENV_DIRECT_DATABASE_URL_PROSE}
158
+ # DIRECT_DATABASE_URL=
159
+
160
+ ${ENV_AUTH_SECRET_PROSE}
161
+ AUTH_SECRET=
162
+
163
+ ${ENV_TICK_SECRET_PROSE}
164
+ TICK_SECRET=
165
+
166
+ ${ENV_OPTIONAL_HEADING}
167
+
168
+ ${ENV_DATA_SOURCE_PROSE}
169
+ DATA_SOURCE=postgres
170
+
171
+ ${ENV_APP_URL_PROSE}
172
+ APP_URL=
173
+
174
+ ${ENV_SMTP_MAIL_BLOCK}
175
+
176
+ `
177
+ }
178
+
179
+ function vercelEnvExample(name: string): string {
180
+ return `# ${name} — environment, on Vercel.
181
+ #
182
+ # Nothing on Vercel reads this file. The platform holds each of these as a
183
+ # project environment variable, and the Deploy Button in README.md asks for the
184
+ # ones it cannot provision itself. This is the reference for what they mean —
185
+ # and the file to copy to .env.local to run the same board on your own machine.
186
+
187
+ # ─── Drivers ─────────────────────────────────────────────────────────────────
188
+
189
+ # An instance is created for a request, may be frozen between requests, and is
190
+ # destroyed without warning; it has a writable /tmp nothing else can read and no
191
+ # background process of its own. Every driver below therefore keeps its state
192
+ # somewhere outside the instance, and these five values are not a default to
193
+ # tune — they are the one combination the board supports on functions.
194
+ #
195
+ # DATA_SOURCE=fixture is a read-only sample board with no write side.
196
+ # QUEUE_DRIVER=memory loses every queued job when the instance goes away, which
197
+ # is after almost every request, and the board already refuses it in production.
198
+ # CACHE_DRIVER=next and memory cache inside the process, so each instance serves
199
+ # its own stale copy for up to a minute. FILESTORE_DRIVER=local writes to a disk
200
+ # no other instance can read and that is discarded with the instance — on Vercel
201
+ # the board refuses it outright rather than losing uploads quietly.
202
+ #
203
+ # CACHE_DRIVER and FILESTORE_DRIVER are asked for at deploy time. The other
204
+ # three derive themselves: a DATABASE_URL means postgres for the data source and
205
+ # the queue, and a RESEND_API_KEY with a MAIL_FROM beside it means mail over the
206
+ # provider's HTTPS API. Setting one here overrides the derivation, which is what
207
+ # this file is for when you copy it to .env.local.
208
+ #
209
+ # The two that stay explicit stay that way on purpose: each turns on an external
210
+ # service the board then depends on for every request, and neither is switched on
211
+ # by a variable that merely happens to be present. The board caches in Redis and
212
+ # puts uploads in an object store because you said so.
213
+ #
214
+ # What happens if you leave one blank differs, and the difference is the reason
215
+ # the form asks for both. Leave FILESTORE_DRIVER blank and the board refuses to
216
+ # boot at all: the default is local, and local on this platform means uploads
217
+ # written to a disk that is about to disappear. Leave CACHE_DRIVER blank and
218
+ # nothing complains — the board falls back to caching inside each instance and
219
+ # serves whatever that instance last saw, for up to a minute, however many
220
+ # instances there are. That one degrades quietly, which is exactly why it is
221
+ # worth typing rather than leaving to a default.
222
+ DATA_SOURCE=postgres
223
+ QUEUE_DRIVER=postgres
224
+ CACHE_DRIVER=redis
225
+ FILESTORE_DRIVER=blob
226
+ MAIL_DRIVER=http
227
+
228
+ ${ENV_REQUIRED_HEADING}
229
+
230
+ ${ENV_DATABASE_URL_PROSE}
231
+ DATABASE_URL=
232
+
233
+ ${ENV_DIRECT_DATABASE_URL_PROSE}
234
+ #
235
+ # On Vercel this is not optional. DATABASE_URL here is the pooler string, the
236
+ # build runs \`community migrate\` against it, and /install takes the second of
237
+ # those two session locks on first run. Neon publishes the direct string as
238
+ # DATABASE_URL_UNPOOLED; copy that value into this variable.
239
+ DIRECT_DATABASE_URL=
240
+
241
+ # The shared cache — a Redis or Valkey endpoint, \`rediss://\` for TLS. Redis
242
+ # holds cache entries and nothing else: losing it costs the board a warm cache,
243
+ # not data, and signs nobody out. A store provisioned with the board publishes
244
+ # its own connection variable; copy that value into this one.
245
+ REDIS_URL=
246
+
247
+ ${ENV_AUTH_SECRET_PROSE}
248
+ AUTH_SECRET=
249
+
250
+ ${ENV_TICK_SECRET_PROSE}
251
+ #
252
+ # Vercel Cron sends \`Authorization: Bearer <CRON_SECRET>\` and cannot be told to
253
+ # send any other name, so CRON_SECRET is the one to set here. The board accepts
254
+ # either name, and both when both are set. Whichever you use, 32 characters is
255
+ # the floor — stricter than the 16 Vercel's own cron documentation suggests, so
256
+ # a secret generated by following those instructions is rejected here.
257
+ CRON_SECRET=
258
+ # TICK_SECRET=
259
+
260
+ # Uploads, in the Vercel Blob store the Deploy Button provisions. The store
261
+ # publishes this variable into the project by itself, so there is nothing to
262
+ # type and nothing to mistype — but the board still needs FILESTORE_DRIVER=blob
263
+ # above before it will use it. Every object is written with private access: an
264
+ # object URL is not a public link, and member content is served by the board,
265
+ # which is where permissions are checked.
266
+ #
267
+ # An upload is held whole in the instance's memory on the way in and on the way
268
+ # out, so the function's memory limit, not the store, is what caps a file.
269
+ BLOB_READ_WRITE_TOKEN=
270
+
271
+ # Uploads in an S3-compatible bucket instead — AWS, R2, MinIO, Spaces. This is
272
+ # the portable option, and the one every other deployment of this board uses:
273
+ # a bucket is a thing you hold, and it is not the only way to get the objects
274
+ # out of it. Set FILESTORE_DRIVER=s3 above and the first four below; boot fails
275
+ # naming any that are missing. S3_ENDPOINT is for anything that is not AWS and
276
+ # switches the client to path-style addressing; set S3_REGION=auto for R2.
277
+ # S3_PUBLIC_BASE_URL is the host objects are *served* from when that is not the
278
+ # API endpoint.
279
+ # S3_BUCKET=
280
+ # S3_REGION=
281
+ # S3_ACCESS_KEY_ID=
282
+ # S3_SECRET_ACCESS_KEY=
283
+ # S3_ENDPOINT=
284
+ # S3_PUBLIC_BASE_URL=
285
+
286
+ # Mail over the provider's own HTTPS API, on 443 — the one outbound path a
287
+ # function can rely on. SMTP on port 25 is blocked by serverless egress and the
288
+ # board refuses it on Vercel; 587 with STARTTLS may work, but an API does not
289
+ # depend on the platform's egress rules staying as they are.
290
+ #
291
+ # MAIL_FROM is yours to decide and the one mail value the button asks for: it
292
+ # must be an address at a domain the provider has verified for you, and no
293
+ # default is right. Send from an unverified sender and the provider rejects
294
+ # every message.
295
+ MAIL_FROM=
296
+
297
+ # Add the Resend integration to the project from Vercel's marketplace and it
298
+ # publishes its key under this name, which the board reads: with RESEND_API_KEY
299
+ # set, and MAIL_FROM beside it, the board sends over Resend's HTTPS API and
300
+ # needs neither of the two variables below. The mail driver itself is a plain
301
+ # JSON-over-HTTPS sender and is not Resend-specific — this is one injected name
302
+ # bridged to the generic pair, not a provider baked into the board.
303
+ RESEND_API_KEY=
304
+
305
+ # Any other provider with the same shape — a bearer token and an endpoint that
306
+ # accepts {from, to, subject, text, html, reply_to}. Set BOTH, plus
307
+ # MAIL_DRIVER=http above; they do not turn the driver on by themselves, and only
308
+ # RESEND_API_KEY implies it.
309
+ #
310
+ # Setting just one of them stands the Resend bridge down completely, on purpose:
311
+ # the board will not hand a key issued for Resend to an endpoint you chose, nor
312
+ # aim your token at Resend. Boot fails naming the half you left out. Delete
313
+ # RESEND_API_KEY once you have moved off Resend.
314
+ # MAIL_HTTP_ENDPOINT=
315
+ # MAIL_HTTP_TOKEN=
316
+
317
+ ${ENV_OPTIONAL_HEADING}
318
+
319
+ ${ENV_APP_URL_PROSE}
320
+ APP_URL=
321
+
322
+ `
323
+ }
324
+
325
+ function envExample(name: string, target: ScaffoldTarget): string {
326
+ return target === 'vercel' ? vercelEnvExample(name) : selfHostEnvExample(name)
327
+ }
328
+
329
+ const SELF_HOST_DEPLOY_KIT = [
330
+ '.dockerignore',
331
+ '.github/workflows/build.yml',
332
+ 'Dockerfile',
333
+ 'docker-compose.yml',
334
+ 'docker-entrypoint.sh',
335
+ 'docker-healthcheck.sh',
336
+ ] as const
337
+
338
+ const VERCEL_TYPED_DRIVERS = ['CACHE_DRIVER=redis', 'FILESTORE_DRIVER=blob'] as const
339
+
340
+ const VERCEL_DERIVED_DRIVERS = [
341
+ 'DATA_SOURCE=postgres',
342
+ 'QUEUE_DRIVER=postgres',
343
+ 'MAIL_DRIVER=http',
344
+ ] as const
345
+
346
+ export const VERCEL_PROMPTED_ENV = [
347
+ 'CACHE_DRIVER',
348
+ 'FILESTORE_DRIVER',
349
+ 'DIRECT_DATABASE_URL',
350
+ 'REDIS_URL',
351
+ 'AUTH_SECRET',
352
+ 'CRON_SECRET',
353
+ 'MAIL_FROM',
354
+ ] as const
355
+
356
+ export const VERCEL_MARKETPLACE_STORES = [
357
+ { type: 'integration', integrationSlug: 'neon', productSlug: 'neon', protocol: 'storage' },
358
+ {
359
+ type: 'integration',
360
+ integrationSlug: 'upstash',
361
+ productSlug: 'upstash-kv',
362
+ protocol: 'storage',
363
+ },
364
+ { type: 'blob' },
365
+ ] as const
366
+
367
+ export function deployButtonUrl(templateRepositoryUrl: string): string {
368
+ const params = new URLSearchParams([
369
+ ['repository-url', templateRepositoryUrl],
370
+ ['project-name', 'meith-board'],
371
+ ['repository-name', 'meith-board'],
372
+ ['env', VERCEL_PROMPTED_ENV.join(',')],
373
+ [
374
+ 'envDescription',
375
+ 'Two driver values, two secrets to generate, the direct database URL, the cache URL, and the verified address the board sends from.',
376
+ ],
377
+ ['envLink', `${templateRepositoryUrl}/blob/main/.env.example`],
378
+ ['stores', JSON.stringify(VERCEL_MARKETPLACE_STORES)],
379
+ ['skippable-integrations', '1'],
380
+ ])
381
+
382
+ return `https://vercel.com/new/clone?${params.toString()}`
383
+ }
384
+
385
+ function vercelJson(): string {
386
+ return `${JSON.stringify(
387
+ {
388
+ framework: 'nextjs',
389
+ buildCommand: VERCEL_BUILD_COMMAND,
390
+ crons: [{ path: TICK_PATH, schedule: TICK_SCHEDULE }],
391
+ },
392
+ null,
393
+ 2,
394
+ )}\n`
395
+ }
396
+
23
397
  export function scaffold(options: ScaffoldOptions): ReadonlyMap<string, string> {
24
398
  const { name, version, repositoryUrl } = options
399
+ const target = options.target ?? 'self-host'
400
+ const atRootFlag = target === 'vercel' ? ` ${AT_ROOT_FLAG}` : ''
25
401
  const files = new Map<string, string>()
26
402
 
27
403
  files.set(
@@ -33,15 +409,16 @@ export function scaffold(options: ScaffoldOptions): ReadonlyMap<string, string>
33
409
  private: true,
34
410
  type: 'module',
35
411
  scripts: {
36
- dev: 'forum-web dev',
37
- build: 'forum-web build',
38
- start: 'forum-web start',
412
+ dev: `forum-web dev${atRootFlag}`,
413
+ build: `forum-web build${atRootFlag}`,
414
+ start: `forum-web start${atRootFlag}`,
39
415
  community: 'community',
40
416
  },
41
417
  dependencies: {
42
418
  '@meith/web': version,
43
419
  '@meith/cli': version,
44
420
  '@meith/theme-default': version,
421
+ next: NEXT_VERSION,
45
422
  },
46
423
  engines: { node: '>=22' },
47
424
  },
@@ -55,7 +432,7 @@ export function scaffold(options: ScaffoldOptions): ReadonlyMap<string, string>
55
432
  `# Every @meith/* dependency here is an exact version, not a range — see
56
433
  # README.md, "Upgrading", for why a range breaks the build. This makes that
57
434
  # the default for any \`npm install\` run in this project from here on,
58
- # including a plugin installed by hand later, not only the three packages
435
+ # including a plugin installed by hand later, not only the four packages
59
436
  # the scaffold pinned itself.
60
437
  save-exact=true
61
438
  `,
@@ -138,67 +515,7 @@ export function installedPluginDefinitions() {
138
515
  `,
139
516
  )
140
517
 
141
- files.set(
142
- '.env.example',
143
- `# ${name} — environment.
144
- #
145
- # Copy to .env.local for development. On the server this is \`.env\` beside the
146
- # compose file; nothing here belongs in git.
147
-
148
- # ─── Required ────────────────────────────────────────────────────────────────
149
-
150
- # Your Postgres connection string.
151
- #
152
- # If it is a managed database that offers a TRANSACTION-MODE POOLER string, use
153
- # that rather than the direct one — Neon, Supabase and their kind hand out both,
154
- # and on the direct string a board works in testing and starts refusing
155
- # connections under the first real traffic, with an error that names the
156
- # database rather than the cause. Your own Postgres, with a fixed number of
157
- # processes in front of it, does not need one.
158
- DATABASE_URL=
159
-
160
- # Session and token signing. No default, deliberately: a shipped default is a
161
- # board every reader of the source can sign a session for.
162
- #
163
- # node -e "console.log(require('crypto').randomBytes(32).toString('base64url'))"
164
- AUTH_SECRET=
165
-
166
- # The shared secret the tick caller presents to GET /api/system/tick. Generate
167
- # it the same way. Without it the tick is unauthenticated, and the tick is how
168
- # bans expire and digests send.
169
- TICK_SECRET=
170
-
171
- # ─── Optional ────────────────────────────────────────────────────────────────
172
-
173
- # fixture = deterministic in-memory sample data, no database needed. This is
174
- # what \`npm run build\` uses, and what a checkout with no database falls back to.
175
- DATA_SOURCE=postgres
176
-
177
- # Absolute, no trailing slash. Used in mail, feeds and canonical URLs — every
178
- # place a relative URL cannot work because there is no request to be relative to.
179
- #
180
- # Optional: leave it blank and the installer asks, prefilled from the address you
181
- # load /install at, and stores the answer on the board where the settings screen
182
- # can change it without a redeploy. Set it here and it wins outright.
183
- APP_URL=
184
-
185
- # Mail. Leave these alone and the installer asks for mail on first run, storing
186
- # it on the board — a settings screen with a test button, no redeploy. Set
187
- # MAIL_DRIVER here instead and the environment wins outright, which is what you
188
- # want if the credential must not live in the database.
189
- #
190
- # The default sends NOTHING: each message goes to the server log, so password
191
- # reset fails silently until mail is configured one way or the other.
192
- # MAIL_DRIVER=smtp
193
- # MAIL_SMTP_HOST=smtp.example.com
194
- # MAIL_SMTP_PORT=465
195
- # MAIL_SMTP_SECURITY=tls # tls (465) | starttls (587) | none
196
- # MAIL_SMTP_USERNAME=
197
- # MAIL_SMTP_PASSWORD=
198
- # MAIL_FROM=noreply@yourdomain.com
199
-
200
- `,
201
- )
518
+ files.set('.env.example', envExample(name, target))
202
519
 
203
520
  files.set(
204
521
  '.gitignore',
@@ -641,11 +958,20 @@ echo "<password>" | npm run community -- user:create --username <name> --email <
641
958
 
642
959
  \`\`\`sh
643
960
  npm install --save-exact @meith/web@latest @meith/cli@latest @meith/theme-default@latest
644
- git commit -am "Upgrade @meith/web, @meith/cli and @meith/theme-default"
961
+ npm install --save-exact next@$(node -p "require('./node_modules/@meith/web/package.json').dependencies.next")
962
+ git commit -am "Upgrade Meith and the Next.js version it builds with"
645
963
  git push
646
964
  \`\`\`
647
965
 
648
- That one \`package.json\` change is the whole pin: \`Dockerfile\`'s own
966
+ The second command is not optional. This board pins \`next\` itself, and
967
+ nothing bumps it for you: upgrading only the \`@meith/*\` packages leaves the
968
+ board's own pin on the old Next while \`@meith/web\` depends on the new one,
969
+ which npm resolves by installing both — the build then runs on one version
970
+ while everything reading \`package.json\` sees the other. Reading the version
971
+ out of the freshly installed \`@meith/web\` is what keeps the two the same
972
+ without anybody having to know the number.
973
+
974
+ That \`package.json\` change is the whole pin: \`Dockerfile\`'s own
649
975
  \`FROM\` line takes the version as a build argument, and
650
976
  \`.github/workflows/build.yml\` reads it straight out of \`package.json\`'s
651
977
  own \`@meith/web\` dependency when it rebuilds — nothing in \`Dockerfile\`
@@ -667,9 +993,291 @@ otherwise would be worse than its absence.
667
993
  `,
668
994
  )
669
995
 
996
+ if (target === 'vercel') {
997
+ return vercelTree(files, {
998
+ name,
999
+ repositoryUrl,
1000
+ templateRepositoryUrl: options.templateRepositoryUrl ?? DEFAULT_TEMPLATE_REPOSITORY_URL,
1001
+ })
1002
+ }
1003
+
1004
+ return files
1005
+ }
1006
+
1007
+ interface VercelTreeOptions {
1008
+ readonly name: string
1009
+ readonly repositoryUrl: string
1010
+ readonly templateRepositoryUrl: string
1011
+ }
1012
+
1013
+ function vercelTree(
1014
+ base: ReadonlyMap<string, string>,
1015
+ options: VercelTreeOptions,
1016
+ ): ReadonlyMap<string, string> {
1017
+ const files = new Map(base)
1018
+
1019
+ for (const path of SELF_HOST_DEPLOY_KIT) files.delete(path)
1020
+
1021
+ files.set(
1022
+ '.gitignore',
1023
+ `node_modules
1024
+ .next
1025
+ .meith
1026
+ .vercel
1027
+ .env
1028
+ .env.local
1029
+ .env*.local
1030
+ *.log
1031
+ .DS_Store
1032
+
1033
+ ${AT_ROOT_IGNORES}
1034
+ `,
1035
+ )
1036
+
1037
+ files.set('vercel.json', vercelJson())
1038
+ files.set('README.md', vercelReadme(options))
1039
+
670
1040
  return files
671
1041
  }
672
1042
 
1043
+ function vercelReadme({ name, repositoryUrl, templateRepositoryUrl }: VercelTreeOptions): string {
1044
+ return `# ${name}
1045
+
1046
+ A forum, built on [Meith](${repositoryUrl}), running as Vercel functions.
1047
+
1048
+ [![Deploy with Vercel](https://vercel.com/button)](${deployButtonUrl(templateRepositoryUrl)})
1049
+
1050
+ ## What the button provisions
1051
+
1052
+ - **A copy of this repository** under your own GitHub account. Vercel builds
1053
+ from it, and every later push to \`main\` redeploys.
1054
+ - **A Neon Postgres database**, attached to the project. Neon publishes the
1055
+ pooled connection string as \`DATABASE_URL\` and the direct one as
1056
+ \`DATABASE_URL_UNPOOLED\`.
1057
+ - **An Upstash Redis store**, attached the same way, for the shared cache.
1058
+ It publishes its own connection variable.
1059
+ - **A Vercel Blob store** for uploads, which publishes \`BLOB_READ_WRITE_TOKEN\`
1060
+ into the project by itself. This is the one value that used to be four hand-
1061
+ typed \`S3_*\` secrets.
1062
+ - **A Vercel project** carrying \`vercel.json\` — the build command
1063
+ \`${VERCEL_BUILD_COMMAND}\`,
1064
+ which applies the schema before it builds, materializes the board's app at
1065
+ the project root so the artefact lands where Vercel reads it, and the cron
1066
+ entry that drives the tick.
1067
+
1068
+ **Mail is the one thing the button does not set up**, and it takes one click
1069
+ after the deploy — see *Mail, in one click* below. The board boots and runs
1070
+ without it, and delivers nothing, silently, until it is done.
1071
+
1072
+ ## What to type into the deploy form
1073
+
1074
+ **Two secrets**, generated rather than chosen. Thirty-two characters is a floor
1075
+ the board enforces at boot, not a suggestion:
1076
+
1077
+ \`\`\`sh
1078
+ openssl rand -hex 32 # AUTH_SECRET
1079
+ openssl rand -hex 32 # CRON_SECRET
1080
+ \`\`\`
1081
+
1082
+ \`CRON_SECRET\` is the name Vercel Cron sends, as \`Authorization: Bearer\`, and it
1083
+ cannot be told to send another. Note that this floor is stricter than the 16
1084
+ characters Vercel's own cron documentation suggests — a value generated by
1085
+ following those instructions is refused here, and the fix is a longer secret.
1086
+
1087
+ **Two driver values**, and they are the two that turn on an external service
1088
+ the board then needs for every request:
1089
+
1090
+ \`\`\`ini
1091
+ ${VERCEL_TYPED_DRIVERS.join('\n')}
1092
+ \`\`\`
1093
+
1094
+ Neither is inferred, deliberately: the board caches in Redis and puts uploads
1095
+ in an object store because you said so, never because a connection string or a
1096
+ token happened to be present.
1097
+
1098
+ Leaving them blank fails differently, which is why the form asks for both.
1099
+ Blank \`FILESTORE_DRIVER\` means \`local\`, and the board **refuses to boot** on
1100
+ this platform rather than write uploads to a disk that is about to disappear.
1101
+ Blank \`CACHE_DRIVER\` complains about nothing: the board falls back to caching
1102
+ inside each instance, and every instance then serves whatever it last saw for
1103
+ up to a minute. That one degrades quietly, so type it.
1104
+
1105
+ The remaining three drivers do derive themselves, and the form does not ask:
1106
+ a \`DATABASE_URL\` means \`DATA_SOURCE=postgres\` and \`QUEUE_DRIVER=postgres\`, and
1107
+ a \`RESEND_API_KEY\` with a \`MAIL_FROM\` beside it means \`MAIL_DRIVER=http\`:
1108
+
1109
+ \`\`\`ini
1110
+ ${VERCEL_DERIVED_DRIVERS.join('\n')}
1111
+ \`\`\`
1112
+
1113
+ **Two connection strings copied from the stores the button just created.**
1114
+ \`DIRECT_DATABASE_URL\` takes Neon's \`DATABASE_URL_UNPOOLED\` — migrations and the
1115
+ first-run installer each hold a session-level advisory lock, which a
1116
+ transaction-mode pooler cannot hold. \`REDIS_URL\` takes whatever variable the
1117
+ Upstash store published.
1118
+
1119
+ **The address the board sends from**: \`MAIL_FROM\`. This is the only mail value
1120
+ you ever type. It has to be an address at a domain your mail provider has
1121
+ verified for you, so no default is right and the board cannot guess it — see
1122
+ *Mail, in one click* below. If you do not have one yet, put in the address you
1123
+ intend to use and finish verifying it afterwards; nothing else waits on it.
1124
+
1125
+ That is seven fields. If you would rather keep uploads somewhere you hold
1126
+ yourself — see *Leaving Vercel* below for why that matters — set
1127
+ \`FILESTORE_DRIVER=s3\` instead and add \`S3_BUCKET\`, \`S3_REGION\`,
1128
+ \`S3_ACCESS_KEY_ID\` and \`S3_SECRET_ACCESS_KEY\` in the project's environment
1129
+ settings, with \`S3_ENDPOINT\` for a bucket that is not AWS (\`S3_REGION=auto\` for
1130
+ R2). The same board runs either way.
1131
+
1132
+ ## Mail, in one click
1133
+
1134
+ A board that cannot send mail cannot reset a password, so do this before you
1135
+ invite anybody.
1136
+
1137
+ 1. Open your project on Vercel, go to **Storage → Marketplace** (or
1138
+ **Integrations**), and add **Resend**. It creates a Resend account linked to
1139
+ the project and connects your sending domain.
1140
+ 2. Verify that domain in the Resend dashboard if you have not already. Resend
1141
+ refuses to send from an address at a domain it has not verified.
1142
+ 3. Redeploy, or let the next push redeploy.
1143
+
1144
+ That is all. The integration publishes its key into the project as
1145
+ \`RESEND_API_KEY\`, and the board reads that name: with it set, and \`MAIL_FROM\`
1146
+ already in place, mail sends over Resend's HTTPS API with nothing further to
1147
+ configure.
1148
+
1149
+ The board is not tied to Resend. Its mail driver is a plain JSON-over-HTTPS
1150
+ sender that posts \`{from, to, subject, text, html, reply_to}\` with a bearer
1151
+ token — Resend's \`POST /emails\` happens to be exactly that shape, which is why
1152
+ it needs no adapter. Any provider with the same shape works: set
1153
+ \`MAIL_HTTP_ENDPOINT\`, \`MAIL_HTTP_TOKEN\` and \`MAIL_DRIVER=http\` in the
1154
+ project's environment settings, and set the first two **together** — either
1155
+ one on its own stands the Resend bridge down, so a key issued for Resend is
1156
+ never presented to an endpoint you chose. Only \`RESEND_API_KEY\` turns the
1157
+ driver on by itself. Delete it once you have moved off Resend.
1158
+
1159
+ Check it worked: sign in as the administrator and use the test button on
1160
+ **/admin → Settings → Mail**.
1161
+
1162
+ ## First run: \`/install\`
1163
+
1164
+ The build applies migrations, but an empty schema is not yet a board. Open
1165
+ \`https://<your-deployment>/install\` once the first deploy is green. It asks for
1166
+ the board's name and address and for the first administrator's username, email
1167
+ and password, creates the board and that account, and then **seals itself**:
1168
+ \`/install\` answers 404 from then on. Run it against the database you intend to
1169
+ keep — the screens are the ones
1170
+ [docs/quickstart.md](${repositoryUrl}/blob/main/docs/quickstart.md#4-run-the-installer)
1171
+ walks through.
1172
+
1173
+ ## The tick
1174
+
1175
+ \`vercel.json\` asks Vercel to call \`${TICK_PATH}\` on \`${TICK_SCHEDULE}\`. That
1176
+ route is how bans expire, digests send, mail leaves the outbox and the queue
1177
+ drains; nothing here runs it on its own, because there is no worker process on
1178
+ a function platform. Two things about it are worth knowing **before** you
1179
+ deploy rather than after:
1180
+
1181
+ - **A per-minute schedule needs a paid plan.** Hobby allows a couple of cron
1182
+ jobs and runs each of them roughly once a day, at an hour Vercel chooses;
1183
+ only paid plans accept an arbitrary cron expression. A board ticking daily
1184
+ still loses nothing — tasks are written so a missed run delays work rather
1185
+ than dropping it — but "as it happens" notifications become a daily digest in
1186
+ all but name. To keep a minute-by-minute tick on Hobby, drive
1187
+ \`${TICK_PATH}\` from something else that can call a URL on a schedule — a
1188
+ GitHub Actions workflow, a systemd timer, an uptime pinger — presenting
1189
+ \`TICK_SECRET\` instead.
1190
+ - **\`maxDuration = 300\` is validated when the project builds, not when the
1191
+ function runs.** A plan that does not allow 300 seconds therefore **fails the
1192
+ deployment** rather than clamping the request. With Fluid Compute — the
1193
+ default for new projects — Hobby allows 300 and this builds as written. With
1194
+ Fluid Compute switched off, Hobby caps a function at 60 seconds and the build
1195
+ fails. Turn Fluid Compute back on.
1196
+
1197
+ A tick that reaches the tasks and runs them answers \`200\` even when one of them
1198
+ threw, with \`ok: false\` and the failure named in \`ran\`. That is deliberate:
1199
+ schedulers retry non-2xx answers, and a task that fails every time would turn
1200
+ each retry into another attempt against whatever it is failing against.
1201
+
1202
+ ## Upgrading
1203
+
1204
+ \`\`\`sh
1205
+ npm install --save-exact @meith/web@latest @meith/cli@latest @meith/theme-default@latest
1206
+ npm install --save-exact next@$(node -p "require('./node_modules/@meith/web/package.json').dependencies.next")
1207
+ git commit -am "Upgrade Meith and the Next.js version it builds with"
1208
+ git push
1209
+ \`\`\`
1210
+
1211
+ Vercel rebuilds on the push, and the build command applies the new migrations
1212
+ before it builds. \`--save-exact\` matters and \`.npmrc\` already sets it for
1213
+ everything else installed here.
1214
+
1215
+ The second command is not optional. This board pins \`next\` itself — Vercel
1216
+ reads that pin to pick its Next.js builder — and nothing bumps it for you.
1217
+ Upgrading only the \`@meith/*\` packages leaves two versions of Next
1218
+ installed, the board built with one and the platform configured for the
1219
+ other. Reading the version out of the freshly installed \`@meith/web\` keeps
1220
+ them the same without anybody having to know the number.
1221
+
1222
+ Migrations are forward-only. Recovery is by restore, so take a backup first —
1223
+ there is no down migration to undo a destructive one.
1224
+
1225
+ ## Leaving Vercel
1226
+
1227
+ A board must stay movable, and the Blob store is the one part of this shape that
1228
+ is not portable: Neon and Upstash hand out ordinary Postgres and Redis strings
1229
+ that any host accepts, but a Vercel Blob store is reachable only through Vercel's
1230
+ own API and there is no bucket to sync out of it. **The uploads are the thing you
1231
+ have to carry out deliberately, and \`community backup\` is how.**
1232
+
1233
+ Under \`FILESTORE_DRIVER=blob\`, \`community backup\` includes the uploads **by
1234
+ default** — it walks the Blob store, pulls every object, and puts them in the
1235
+ bundle beside the database dump. This is the opposite of the \`s3\` default, which
1236
+ skips them, because a bucket has its own backup story you can drive yourself and
1237
+ a Blob store does not:
1238
+
1239
+ \`\`\`sh
1240
+ DATABASE_URL=… # Neon's pooled string
1241
+ DIRECT_DATABASE_URL=… # Neon's DATABASE_URL_UNPOOLED
1242
+ FILESTORE_DRIVER=blob
1243
+ BLOB_READ_WRITE_TOKEN=… # copy it out of the project's environment settings
1244
+ npm run community -- backup
1245
+ \`\`\`
1246
+
1247
+ Run that from a checkout of this repository, with those four values in the
1248
+ environment — the CLI talks to Neon and to the Blob store over the network, so
1249
+ it does not have to run on Vercel. The bundle it writes holds the dump *and*
1250
+ every object. Check the last line it prints: if it says *no uploads*, the
1251
+ uploads are not in the bundle and restoring it gives a board whose posts have
1252
+ broken images.
1253
+
1254
+ Restoring puts them wherever the *restoring* board's \`FILESTORE_DRIVER\` points,
1255
+ so the same bundle moves the board either onward or away:
1256
+
1257
+ \`\`\`sh
1258
+ # onto a self-hosted board with a bucket
1259
+ FILESTORE_DRIVER=s3 S3_BUCKET=… RESTORE_DATABASE_URL=… npm run community -- restore bundle.tar.gz
1260
+
1261
+ # onto a board that keeps uploads on its own disk
1262
+ RESTORE_DATABASE_URL=… npm run community -- restore bundle.tar.gz --uploads-dir ./uploads
1263
+ \`\`\`
1264
+
1265
+ Take one before you need it. A Blob store deleted with the Vercel project takes
1266
+ the attachments with it, and there is no second copy anywhere unless you made
1267
+ one.
1268
+
1269
+ ## Somewhere other than Vercel
1270
+
1271
+ Everything above is one deployment shape.
1272
+ [docs/self-hosting.md](${repositoryUrl}/blob/main/docs/self-hosting.md) is the
1273
+ same board as containers you run yourself, and \`npx create-meith <name>\`
1274
+ scaffolds that shape instead — a Dockerfile, a compose file and a workflow that
1275
+ builds the image. [docs/scaling.md](${repositoryUrl}/blob/main/docs/scaling.md)
1276
+ explains why the drivers above are what they are, and why an S3-compatible
1277
+ bucket is the portable choice for uploads everywhere but here.
1278
+ `
1279
+ }
1280
+
673
1281
  export function nextSteps(name: string): readonly string[] {
674
1282
  return [`cd ${name}`, 'npm install', 'cp .env.example .env.local', 'npm run dev']
675
1283
  }