Skip to content

Commit

Permalink
refactor: consolidate .env use
Browse files Browse the repository at this point in the history
Fix bug in script assuming same .env paths for new apps
  • Loading branch information
denis-kralj-novu committed Jun 3, 2024
1 parent 1333cd0 commit 75803c9
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions scripts/setup-env-files.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const fs = require('fs');
const path = require('path');

const prePopulateEnv = (folders, folderBasePath, exampleEnvFilePath = 'src/.example.env', envFilePath = 'src/.env') => {
for (const folder of folders) {
const prePopulateEnv = (apps, folderBasePath, exampleEnvFilePath = 'src/.example.env', envFilePath = 'src/.env') => {
console.log(`Pre-populating .env files from .example.env for [${apps.join(',')}]`);
for (const folder of apps) {
const exists = fs.existsSync(path.resolve(`${folderBasePath}/${folder}/${envFilePath}`));
if (!exists) {
console.log(`Populating ${folderBasePath}/${folder} with .env file`);
Expand All @@ -15,14 +16,10 @@ const prePopulateEnv = (folders, folderBasePath, exampleEnvFilePath = 'src/.exam
};

(async () => {
const apps = ['api', 'ws', 'worker', 'web', 'widget'];
const appsBasePath = `${__dirname}/../apps`;

console.log('----------------------------------------');
console.log('Pre-populating .env files from .example.env');

prePopulateEnv(apps, appsBasePath);

prePopulateEnv(['api', 'ws', 'worker'], appsBasePath);
prePopulateEnv(['web', 'widget'], appsBasePath, '.example.env', '.env');
console.log('Finished populating .env files');
console.log('----------------------------------------');
})();

0 comments on commit 75803c9

Please sign in to comment.