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

Function seedEnvValues

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

Source from the content-addressed store, hash-verified

311}
312
313async function seedEnvValues(environment: Environment, options: Options) {
314 const envVarValues = options.envVarValues || {}
315 const entries = Object.entries(envVarValues)
316 if (entries.length === 0) return
317
318 const envLocalPath = resolve(options.targetDir, '.env.local')
319 if (!environment.exists(envLocalPath)) {
320 return
321 }
322
323 let envContents = await environment.readFile(envLocalPath)
324 for (const [key, value] of entries) {
325 const escapedValue = value.replace(/\n/g, '\\n')
326 const nextLine = `${key}=${escapedValue}`
327 const pattern = new RegExp(`^${key}=.*$`, 'm')
328
329 if (pattern.test(envContents)) {
330 envContents = envContents.replace(pattern, nextLine)
331 } else {
332 envContents += `${envContents.endsWith('\n') ? '' : '\n'}${nextLine}\n`
333 }
334 }
335
336 await environment.writeFile(envLocalPath, envContents)
337}
338
339async function writeEnvExample(environment: Environment, options: Options) {
340 const envExamplePath = resolve(options.targetDir, '.env.example')

Callers 1

createAppFunction · 0.70

Calls 2

testMethod · 0.80
replaceMethod · 0.65

Tested by

no test coverage detected