wishforge-ide/scripts/setup-local.mjs
eust-w b47a07e8d2 chore: baseline snapshot of the Codex-delivered code before review
Imports the previously untracked working tree as-is so that the review
changes that follow (requirements -> design -> implementation) can be
reviewed as diffs and reverted if needed. No content changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 13:18:04 +08:00

13 lines
1.6 KiB
JavaScript

import { randomBytes } from 'node:crypto';
import { readFile, writeFile, mkdir } from 'node:fs/promises';
try { await readFile('.env.local'); console.log('.env.local already exists; preserving it.'); process.exit(0); } catch {}
const secret = () => randomBytes(32).toString('hex');
const dbPassword = secret();
const devToken = secret();
const config = `# Local only. Generated secrets; never commit this file.\nDATABASE_ADMIN_URL=postgresql://wishforge:wishforge-dev-only@127.0.0.1:55432/wishforge\nDATABASE_URL=postgresql://wishforge_app:${dbPassword}@127.0.0.1:55432/wishforge\nWF_DATABASE_APP_PASSWORD=${dbPassword}\nWF_DEV_AUTH_TOKEN=${devToken}\nWF_WORKER_TOKEN=${secret()}\nWF_VERIFIER_TOKEN=${secret()}\nWF_DEPLOYER_TOKEN=${secret()}\nWF_EVALUATOR_TOKEN=${secret()}\nWF_VAULT_KEY=${secret()}\nWF_SESSION_SECRET=${secret()}\nWF_PUBLIC_URL=http://localhost:3000\nWF_API_URL=http://127.0.0.1:4000\nWF_REGION=local\nWF_DISPATCH_TENANTS=demo\nPORT=4000\nTEMPORAL_ADDRESS=127.0.0.1:7233\nOIDC_ISSUER=http://127.0.0.1:4100/realms/wishforge\nOIDC_AUDIENCE=wishforge-api\nOIDC_CLIENT_ID=wishforge-web\nWF_WEB_CLIENT_ID=wishforge-web\n`;
await writeFile('.env.local', config, { mode: 0o600, flag: 'wx' });
await mkdir('apps/web', { recursive: true });
const webOnly = config.split('\n').filter(line => /^(WF_DEV_AUTH_TOKEN|WF_SESSION_SECRET|WF_PUBLIC_URL|WF_API_URL|OIDC_ISSUER|OIDC_CLIENT_ID)=/.test(line)).join('\n') + '\n';
await writeFile('apps/web/.env.local', webOnly, { mode: 0o600, flag: 'wx' }).catch(e => { if (e.code !== 'EEXIST') throw e; });
console.log('Created private .env.local files. Start infra, then run db:migrate and db:seed.');