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

Function seedEnvValues

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

Source from the content-addressed store, hash-verified

429}
430
431async function seedEnvValues(environment: Environment, options: Options) {
432 const envVarValues = options.envVarValues || {}
433 const entries = Object.entries(envVarValues)
434 if (entries.length === 0) return
435
436 const envLocalPath = joinPaths(options.targetDir, '.env.local')
437 if (!environment.exists(envLocalPath)) {
438 return
439 }
440
441 let envContents = await environment.readFile(envLocalPath)
442 for (const [key, value] of entries) {
443 const escapedValue = value.replace(/\n/g, '\\n')
444 const nextLine = `${key}=${escapedValue}`
445 const pattern = new RegExp(`^${key}=.*$`, 'm')
446
447 if (pattern.test(envContents)) {
448 envContents = envContents.replace(pattern, nextLine)
449 } else {
450 envContents += `${envContents.endsWith('\n') ? '' : '\n'}${nextLine}\n`
451 }
452 }
453
454 await environment.writeFile(envLocalPath, envContents)
455}
456
457async function writeEnvExample(environment: Environment, options: Options) {
458 const envExamplePath = joinPaths(options.targetDir, '.env.example')

Callers 1

createAppFunction · 0.70

Calls 3

joinPathsFunction · 0.85
testMethod · 0.80
replaceMethod · 0.65

Tested by

no test coverage detected