@@ -280,6 +280,32 @@ async function runCommandsAndInstallDependencies(
280280 await installShadcnComponents ( environment , options . targetDir , options )
281281}
282282
283+ async function seedEnvValues ( environment : Environment , options : Options ) {
284+ const envVarValues = options . envVarValues || { }
285+ const entries = Object . entries ( envVarValues )
286+ if ( entries . length === 0 ) return
287+
288+ const envLocalPath = resolve ( options . targetDir , '.env.local' )
289+ if ( ! environment . exists ( envLocalPath ) ) {
290+ return
291+ }
292+
293+ let envContents = await environment . readFile ( envLocalPath )
294+ for ( const [ key , value ] of entries ) {
295+ const escapedValue = value . replace ( / \n / g, '\\n' )
296+ const nextLine = `${ key } =${ escapedValue } `
297+ const pattern = new RegExp ( `^${ key } =.*$` , 'm' )
298+
299+ if ( pattern . test ( envContents ) ) {
300+ envContents = envContents . replace ( pattern , nextLine )
301+ } else {
302+ envContents += `${ envContents . endsWith ( '\n' ) ? '' : '\n' } ${ nextLine } \n`
303+ }
304+ }
305+
306+ await environment . writeFile ( envLocalPath , envContents )
307+ }
308+
283309function report ( environment : Environment , options : Options ) {
284310 const warnings : Array < string > = [ ]
285311 for ( const addOn of options . chosenAddOns ) {
@@ -331,6 +357,7 @@ export async function createApp(environment: Environment, options: Options) {
331357
332358 environment . startRun ( )
333359 await writeFiles ( environment , effectiveOptions )
360+ await seedEnvValues ( environment , effectiveOptions )
334361 await runCommandsAndInstallDependencies ( environment , effectiveOptions )
335362 environment . finishRun ( )
336363
0 commit comments