()
| 79 | } |
| 80 | |
| 81 | async function main() { |
| 82 | const rl = createInterface({ input, output }); |
| 83 | const existing = existsSync(ENV_PATH) ? readFileSync(ENV_PATH, 'utf8') : ''; |
| 84 | const existingMap = new Map<string, string>(); |
| 85 | for (const line of existing.split(/\r?\n/)) { |
| 86 | const match = line.match(/^([A-Z0-9_]+)=(.*)$/); |
| 87 | if (match) { |
| 88 | existingMap.set(match[1], match[2]); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | const lines: string[] = []; |
| 93 | if (existing.trim().length === 0) { |
| 94 | const template = loadTemplate(); |
| 95 | if (template.trim().length > 0) { |
| 96 | lines.push(...template.split(/\r?\n/).filter((l) => !l.startsWith('RUN_E2E='))); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | lines.push('RUN_E2E=true'); |
| 101 | |
| 102 | for (const field of FIELDS) { |
| 103 | const current = existingMap.get(field.key) ?? ''; |
| 104 | const hint = field.hint ? ` (${field.hint})` : ''; |
| 105 | const prompt = `${field.prompt}${hint}${field.defaultValue ? ` [${field.defaultValue}]` : ''}: `; |
| 106 | const answer = (await rl.question(prompt)).trim(); |
| 107 | const value = answer || current || field.defaultValue || ''; |
| 108 | |
| 109 | if (!value && !field.optional) { |
| 110 | console.error(`Missing required value for ${field.key}.`); |
| 111 | await rl.close(); |
| 112 | process.exit(1); |
| 113 | } |
| 114 | |
| 115 | if (!value && field.optional) { |
| 116 | lines.push(`${field.key}=`); |
| 117 | } else { |
| 118 | lines.push(`${field.key}=${value}`); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | await rl.close(); |
| 123 | ensureDir(ENV_PATH); |
| 124 | writeFileSync(ENV_PATH, `${lines.join('\n')}\n`, 'utf8'); |
| 125 | console.log(`\nWrote ${ENV_PATH}`); |
| 126 | } |
| 127 | |
| 128 | main().catch((err) => { |
| 129 | console.error(err); |
no test coverage detected