Skip to content

Commit

Permalink
did recommended changes to setup.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
VanshikaSabharwal committed Nov 17, 2024
1 parent c0884d1 commit eac28f7
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ import { askForCustomPort } from './src/setup/askForCustomPort/askForCustomPort'
// Update the .env file with new values
const updateEnvFile = (key: string, value: string): void => {
const currentEnvContent = fs.readFileSync('.env', 'utf8');
const updatedEnvContent = currentEnvContent.replace(
new RegExp(`^${key}=.*$`, 'm'),
`${key}=${value}`,
);
fs.writeFileSync('.env', updatedEnvContent, 'utf8');
const keyRegex = new RegExp(`^${key}=.*$`, 'm');
if (keyRegex.test(currentEnvContent)) {
const updatedEnvContent = currentEnvContent.replace(
keyRegex,
`${key}=${value}`,
);
fs.writeFileSync('.env', updatedEnvContent, 'utf8');
} else {
fs.appendFileSync('.env', `\n${key}=${value}`, 'utf8');
}
};

// Handle .env file creation or validation
Expand Down

0 comments on commit eac28f7

Please sign in to comment.