File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed
Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -382,10 +382,20 @@ export async function addOrUpdateEnvironmentVariables({
382382 ) ;
383383 } else {
384384 try {
385- const newContent = dotEnvFileContent . replace (
386- / ^ N E X T _ P U B L I C _ P O S T H O G _ K E Y = .* $ / m,
387- `NEXT_PUBLIC_POSTHOG_KEY=${ projectApiKey } ` ,
388- ) ;
385+ let newContent = dotEnvFileContent ;
386+
387+ if ( dotEnvFileContent . match ( / ^ N E X T _ P U B L I C _ P O S T H O G _ K E Y = .* $ / m) ) {
388+ newContent = dotEnvFileContent . replace (
389+ / ^ N E X T _ P U B L I C _ P O S T H O G _ K E Y = .* $ / m,
390+ `NEXT_PUBLIC_POSTHOG_KEY=${ projectApiKey } ` ,
391+ ) ;
392+ } else {
393+ if ( ! dotEnvFileContent . endsWith ( '\n' ) ) {
394+ newContent += '\n' ;
395+ }
396+ newContent += envVarContent ;
397+ }
398+
389399 await fs . promises . writeFile ( targetEnvFilePath , newContent , {
390400 encoding : 'utf8' ,
391401 flag : 'w' ,
You can’t perform that action at this time.
0 commit comments