MCPcopy Create free account
hub / github.com/TanStack/cli / writeEnvExample

Function writeEnvExample

packages/create/src/create-app.ts:339–375  ·  view source on GitHub ↗
(environment: Environment, options: Options)

Source from the content-addressed store, hash-verified

337}
338
339async function writeEnvExample(environment: Environment, options: Options) {
340 const envExamplePath = resolve(options.targetDir, '.env.example')
341 const existing = environment.exists(envExamplePath)
342 ? await environment.readFile(envExamplePath)
343 : ''
344
345 const declared = new Set<string>()
346 for (const match of existing.matchAll(/^([A-Z_][A-Z0-9_]*)=/gm)) {
347 declared.add(match[1])
348 }
349
350 const sections: Array<string> = []
351 for (const addOn of options.chosenAddOns) {
352 const lines: Array<string> = []
353 for (const envVar of addOn.envVars || []) {
354 if (declared.has(envVar.name)) continue
355 declared.add(envVar.name)
356 if (envVar.description) {
357 const required = envVar.required ? ' (required)' : ''
358 lines.push(`# ${envVar.description}${required}`)
359 }
360 lines.push(`${envVar.name}=`)
361 }
362 if (lines.length > 0) {
363 sections.push(`# ${addOn.name}\n${lines.join('\n')}`)
364 }
365 }
366
367 if (sections.length === 0) return
368
369 const additions = sections.join('\n\n')
370 const newContent = existing
371 ? `${existing.trimEnd()}\n\n${additions}\n`
372 : `${additions}\n`
373
374 await environment.writeFile(envExamplePath, newContent)
375}
376
377const SHIPPING_CATEGORIES = new Set(['auth', 'database', 'orm', 'deploy'])
378

Callers 1

createAppFunction · 0.70

Calls 1

addMethod · 0.80

Tested by

no test coverage detected