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

Function writeEnvExample

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

Source from the content-addressed store, hash-verified

455}
456
457async 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
495const SHIPPING_CATEGORIES = new Set(['auth', 'database', 'orm', 'deploy'])
496

Callers 1

createAppFunction · 0.70

Calls 2

joinPathsFunction · 0.85
addMethod · 0.80

Tested by

no test coverage detected