Skip to content

Commit

Permalink
Fixed errors
Browse files Browse the repository at this point in the history
  • Loading branch information
adithyanotfound committed Oct 29, 2024
1 parent 2c0942f commit d9c3976
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,35 +74,26 @@ export async function main(): Promise<void> {
const url = new URL(endpoint);
isConnected = await checkConnection(url.origin);
}
const envPath = '.env';
const currentEnvContent = fs.readFileSync(envPath, 'utf8');
const talawaApiUrl = dotenv.parse(currentEnvContent).REACT_APP_TALAWA_URL;

const talawaApiUrl = dotenv.parse(
fs.readFileSync('.env'),
).REACT_APP_TALAWA_URL;

fs.readFile('.env', 'utf8', (err, data) => {
const result = data.replace(
`REACT_APP_TALAWA_URL=${talawaApiUrl}`,
`REACT_APP_TALAWA_URL=${endpoint}`,
);
fs.writeFileSync('.env', result, 'utf8');
});
const updatedEnvContent = currentEnvContent.replace(
`REACT_APP_TALAWA_URL=${talawaApiUrl}`,
`REACT_APP_TALAWA_URL=${endpoint}`,
);

fs.writeFileSync(envPath, updatedEnvContent, 'utf8');
const websocketUrl = endpoint.replace(/^http(s)?:\/\//, 'ws$1://');
const currentWebSocketUrl = dotenv.parse(
fs.readFileSync('.env'),
).REACT_APP_BACKEND_WEBSOCKET_URL;
const currentWebSocketUrl =
dotenv.parse(updatedEnvContent).REACT_APP_BACKEND_WEBSOCKET_URL;

fs.readFile('.env', 'utf8', (err, data) => {
if (err) {
console.error('Error reading .env file:', err);
process.exit(1);
}
const result = data.replace(
`REACT_APP_BACKEND_WEBSOCKET_URL=${currentWebSocketUrl}`,
`REACT_APP_BACKEND_WEBSOCKET_URL=${websocketUrl}`,
);
fs.writeFileSync('.env', result, 'utf8');
});
const finalEnvContent = updatedEnvContent.replace(
`REACT_APP_BACKEND_WEBSOCKET_URL=${currentWebSocketUrl}`,
`REACT_APP_BACKEND_WEBSOCKET_URL=${websocketUrl}`,
);

fs.writeFileSync(envPath, finalEnvContent, 'utf8');
}

const { shouldUseRecaptcha } = await inquirer.prompt({
Expand Down

0 comments on commit d9c3976

Please sign in to comment.