| 455 | } |
| 456 | |
| 457 | async function writeEnvExample(environment: Environment, options: Options) { |
| 458 | const envExamplePath = joinPaths(options.targetDir, '.env.example') |
| 459 | const existing = environment.exists(envExamplePath) |
| 460 | ? await environment.readFile(envExamplePath) |
| 461 | : '' |
| 462 | |
| 463 | const declared = new Set<string>() |
| 464 | for (const match of existing.matchAll(/^([A-Z_][A-Z0-9_]*)=/gm)) { |
| 465 | declared.add(match[1]) |
| 466 | } |
| 467 | |
| 468 | const sections: Array<string> = [] |
| 469 | for (const addOn of options.chosenAddOns) { |
| 470 | const lines: Array<string> = [] |
| 471 | for (const envVar of addOn.envVars || []) { |
| 472 | if (declared.has(envVar.name)) continue |
| 473 | declared.add(envVar.name) |
| 474 | if (envVar.description) { |
| 475 | const required = envVar.required ? ' (required)' : '' |
| 476 | lines.push(`# ${envVar.description}${required}`) |
| 477 | } |
| 478 | lines.push(`${envVar.name}=`) |
| 479 | } |
| 480 | if (lines.length > 0) { |
| 481 | sections.push(`# ${addOn.name}\n${lines.join('\n')}`) |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | if (sections.length === 0) return |
| 486 | |
| 487 | const additions = sections.join('\n\n') |
| 488 | const newContent = existing |
| 489 | ? `${existing.trimEnd()}\n\n${additions}\n` |
| 490 | : `${additions}\n` |
| 491 | |
| 492 | await environment.writeFile(envExamplePath, newContent) |
| 493 | } |
| 494 | |
| 495 | const SHIPPING_CATEGORIES = new Set(['auth', 'database', 'orm', 'deploy']) |
| 496 | |