|
1 | 1 | import { execFileSync } from 'node:child_process' |
| 2 | +import { randomBytes } from 'node:crypto' |
2 | 3 | import { cpSync, existsSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs' |
3 | 4 | import { resolve } from 'node:path' |
| 5 | +import { fillEnvFromExample } from './env.js' |
4 | 6 | import { renderReadme } from './readme.js' |
5 | 7 | import { deriveToolVersions } from './toolversions.js' |
6 | 8 | import type { ScaffoldParams } from './types.js' |
7 | 9 |
|
| 10 | +/** Apps whose committed `.env.example` is copied to a runnable `.env`. */ |
| 11 | +const ENV_APPS = ['api', 'web', 'mobile'] |
| 12 | + |
8 | 13 | /** Move the transformed temp tree into the target dir, write README, git init, install, build. */ |
9 | 14 | export function finalize( |
10 | 15 | tempTree: string, |
@@ -39,6 +44,17 @@ export function finalize( |
39 | 44 | const ruby = existsSync(rubyVersionPath) ? readFileSync(rubyVersionPath, 'utf8') : undefined |
40 | 45 | writeFileSync(resolve(target, '.tool-versions'), deriveToolVersions(nvmrc, packageManager, ruby)) |
41 | 46 |
|
| 47 | + // Copy each app's .env.example -> .env (gitignored) with a generated dev auth secret, |
| 48 | + // so the project runs locally without hand-editing env files. |
| 49 | + const betterAuthSecret = randomBytes(32).toString('base64') |
| 50 | + for (const app of ENV_APPS) { |
| 51 | + const example = resolve(target, 'apps', app, '.env.example') |
| 52 | + const dotenv = resolve(target, 'apps', app, '.env') |
| 53 | + if (existsSync(example) && !existsSync(dotenv)) { |
| 54 | + writeFileSync(dotenv, fillEnvFromExample(readFileSync(example, 'utf8'), betterAuthSecret)) |
| 55 | + } |
| 56 | + } |
| 57 | + |
42 | 58 | if (opts.git) { |
43 | 59 | execFileSync('git', ['init', '-q'], { cwd: target }) |
44 | 60 | } |
|
0 commit comments