* fix(setup): write .env.local not .env, fix npm->pnpm in completion message
setup.mjs was writing AUTH_SECRET to the git-tracked .env file instead of
.env.local, creating a security risk for users who commit their fork.
Also fixes the completion message which incorrectly instructed users to run
npm run dev instead of pnpm dev (project uses pnpm@9).
* ci: add multi-OS matrix for pnpm setup, fix stale action versions
Adds ubuntu/windows/macos matrix to test-setup job so the install
instructions are verified on all three platforms on every PR. Fixes
actions/checkout, pnpm/action-setup, and actions/setup-node all
pointing at non-existent @v6. Splits into two jobs: test-setup
(3 OS) and test-dev (ubuntu-only, needs Docker).
* fix(ci): use pnpm run setup not pnpm setup
pnpm setup is pnpm's built-in shell config command (writes to .bashrc).
pnpm run setup runs the project script. All three occurrences fixed.
* fix(dev): load .env.local in dev.mjs before spawning workers
Turbopack workers inherit process.env at spawn time, before Next.js
completes its own .env.local loading. If ENCRYPTION_MASTER_KEY is not
already in process.env when concurrently spawns next dev, the
instrumentation.ts startup check sees it as unset and crashes the server.
Fix: loadEnv('.env.local') in dev.mjs after loading .env so all secrets
are present in process.env before any child processes are spawned.
Also fix CI idempotency test: pnpm setup calls pnpm's built-in shell
config command, not the project setup script. Changed to pnpm run setup.
62 lines
2.0 KiB
JavaScript
62 lines
2.0 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* @file setup.mjs
|
|
* @description One-command local setup utility.
|
|
* Generates a .env file from .env.example and auto-fills sensitive
|
|
* secrets (like AUTH_SECRET) with secure random values.
|
|
* @module scripts
|
|
*/
|
|
|
|
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
import { randomBytes } from "crypto";
|
|
import { resolve } from "path";
|
|
|
|
const ROOT = resolve(import.meta.dirname, "..");
|
|
const EXAMPLE = resolve(ROOT, ".env.example");
|
|
const TARGET = resolve(ROOT, ".env.local");
|
|
|
|
if (existsSync(TARGET)) {
|
|
console.log("✅ .env.local already exists — skipping setup.");
|
|
console.log(" Delete it and re-run if you want to regenerate.");
|
|
process.exit(0);
|
|
}
|
|
|
|
if (!existsSync(EXAMPLE)) {
|
|
console.error("❌ .env.example not found. Are you in the right directory?");
|
|
process.exit(1);
|
|
}
|
|
|
|
const secret = randomBytes(32).toString("hex");
|
|
const encryptionKey = randomBytes(32).toString("hex");
|
|
let content = readFileSync(EXAMPLE, "utf8");
|
|
|
|
// Fill in the AUTH_SECRET line
|
|
if (content.includes("AUTH_SECRET=")) {
|
|
content = content.replace(/^AUTH_SECRET=.*$/m, `AUTH_SECRET=${secret}`);
|
|
} else {
|
|
content += `\nAUTH_SECRET=${secret}\n`;
|
|
}
|
|
|
|
// Fill in the ENCRYPTION_MASTER_KEY line
|
|
if (content.includes("ENCRYPTION_MASTER_KEY=")) {
|
|
content = content.replace(/^ENCRYPTION_MASTER_KEY=.*$/m, `ENCRYPTION_MASTER_KEY=${encryptionKey}`);
|
|
} else {
|
|
content += `\nENCRYPTION_MASTER_KEY=${encryptionKey}\n`;
|
|
}
|
|
|
|
// Strip comment-only sections (keep values)
|
|
content = content
|
|
.split("\n")
|
|
.map((line) => {
|
|
// Un-comment AUTH_SECRET if it was commented out
|
|
if (line.trim().startsWith("# AUTH_SECRET=")) return line.replace("# ", "");
|
|
return line;
|
|
})
|
|
.join("\n");
|
|
|
|
writeFileSync(TARGET, content, "utf8");
|
|
|
|
console.log("✅ .env.local created with generated AUTH_SECRET and ENCRYPTION_MASTER_KEY.");
|
|
console.log(" Fill in any optional API keys (Cesium, Bing, OpenSky, etc.)");
|
|
console.log(" then run: pnpm dev");
|