mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 05:57:09 +01:00
scripts/site-template is now bitbaum/fleet templates/app — Next.js 16, better-auth accounts (password, link, passkey, 2FA, OrangeCat/bitbaum sign-in as env-gated OIDC), en/de/fr, nonce CSP, ai-kit/mail-kit/limitkit/bip-kit, tests and CI — copied at a pinned fleet commit by scripts/templates/sync-starter.sh. CI proves the copy is exact (sync-starter.sh --check), and starter-sync.yml opens the PR when fleet's starter moves. Never edited here. The kickoff's "nextjs-tailwind" starter seeds the same app from src/lib/starter-app.generated.ts (generated from the directory, pinned by scripts/test/starter-app.ts), minus the workflows register-site.sh adds with the site's CD. The repo is seeded in one Trees API call with inline contents instead of a blob POST per file (~85 for this starter). The widget token rides in .env.production; the starter's .gitleaks.toml allows NEXT_PUBLIC_* values. The new-from-scratch picker reads the light template list, so the starter's file bodies never reach a client bundle. Both paths give the site its database and auth/seal secrets ON THE BOX (scripts/hetzner/provision-db-on-box.sh: role + database, ~/.db-credentials, /opt/<slug>/shared/.env; existing secrets never replaced; nothing printed), and record the db in the register row so every deploy applies drizzle/. register-site.sh seeds the starter's full workflow set to starter repos and the golden CI floor to anything else, never overwriting another repo's ci.yml. test-site-template.sh follows the starter (verify SSOT, design tokens instead of a local palette) and its comment stripper is fixed: the sed range deleted the page from the doc comment to EOF, so every day-zero check had been passing against an empty string. check-template-contrast.mjs and the starter-lock generator are retired with the files they checked. Claude-Session: https://claude.ai/code/session_01W7K2Gm5wcbfCi7THtmV1Hy Co-authored-by: Claude <noreply@anthropic.com>
60 lines
2.2 KiB
TypeScript
60 lines
2.2 KiB
TypeScript
/**
|
|
* `.env.example` is the contract a copy of this repo is configured from. Every
|
|
* variable `src/` reads must be named there, with the file that reads it.
|
|
*
|
|
* Before this gate, 70 of them were not: a fork found the switch for Google
|
|
* sign-in, embeddings, the Telegram bot or the daemon token only by grepping
|
|
* `process.env`. A variable may be documented commented out (`# KEY=`): the
|
|
* contract is the NAME and where it is read, not a value. Dynamic reads
|
|
* (`process.env[name]`) are the helpers that take the name as an argument and
|
|
* are not caught here by design.
|
|
*/
|
|
import assert from "node:assert/strict";
|
|
import { readFileSync, readdirSync, statSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
|
|
const NOT_CONFIG = new Set([
|
|
"NODE_ENV",
|
|
"NEXT_RUNTIME",
|
|
"HOME",
|
|
"PATH",
|
|
"NEXT_PUBLIC_",
|
|
"NEXT_PUBLIC_X",
|
|
]);
|
|
|
|
// The fleet starter's source, held as DATA for the kickoff to seed: its reads
|
|
// are the seeded app's, named in that app's own .env.example
|
|
// (scripts/site-template/.env.example, checked in fleet), never Loki's.
|
|
const NOT_LOKI_CODE = new Set([join("src", "lib", "starter-app.generated.ts")]);
|
|
|
|
function* files(dir: string): Generator<string> {
|
|
for (const name of readdirSync(dir)) {
|
|
const p = join(dir, name);
|
|
if (NOT_LOKI_CODE.has(p)) continue;
|
|
if (statSync(p).isDirectory()) yield* files(p);
|
|
else if (/\.tsx?$/.test(name)) yield p;
|
|
}
|
|
}
|
|
|
|
const example = readFileSync(".env.example", "utf8");
|
|
const named = new Set([...example.matchAll(/^#?\s*([A-Z0-9_]+)=/gm)].map((m) => m[1]));
|
|
const read = new Map<string, string>();
|
|
for (const file of files("src")) {
|
|
for (const line of readFileSync(file, "utf8").split("\n")) {
|
|
// A comment that mentions a variable is not a read of it.
|
|
if (/^\s*(\/\/|\*|\/\*)/.test(line)) continue;
|
|
for (const m of line.matchAll(/process\.env\.([A-Z0-9_]+)/g)) {
|
|
if (!read.has(m[1])) read.set(m[1], file);
|
|
}
|
|
}
|
|
}
|
|
const missing = [...read]
|
|
.filter(([k]) => !named.has(k) && !NOT_CONFIG.has(k))
|
|
.map(([k, f]) => `${k} (read by ${f})`);
|
|
assert.deepEqual(
|
|
missing,
|
|
[],
|
|
`add each to .env.example (a \`# KEY=\` line with the reader is enough):\n${missing.join("\n")}`,
|
|
);
|
|
console.log(`env-example-covers-src: ${read.size} variables read, all named`);
|