Skip to content

Commit

Permalink
fix empty env file
Browse files Browse the repository at this point in the history
  • Loading branch information
goshander committed Oct 25, 2023
1 parent b4b7dd4 commit 6e0226d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions scripts/setup-dev-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'use strict';

const path = require('path');
const {readFileSync, writeFileSync} = require('fs');
const {readFileSync, writeFileSync, openSync} = require('fs');

const SECRETS_SECTION_START = '### TEMPLATE SECRETS BEGIN';
const SECRETS_SECTION_END = '### TEMPLATE SECRETS END';
Expand All @@ -28,7 +28,14 @@ if (envName === 'development') {
}
}

const secretsSection = `${SECRETS_SECTION_START}\n${templateContent}\n${SECRETS_SECTION_END}`;
let currentEnv;

try {
currentEnv = readFileSync(path.join(appPath, '.env')).toString();
} catch (__) {
openSync(path.join(appPath, '.env'), 'w');

currentEnv = `${SECRETS_SECTION_START}\n${SECRETS_SECTION_END}`;
}

const currentEnv = readFileSync(path.join(appPath, '.env')).toString();
writeFileSync(path.join(appPath, '.env'), currentEnv.replace(REPLACE_REGEXP, secretsSection));

0 comments on commit 6e0226d

Please sign in to comment.