-
Notifications
You must be signed in to change notification settings - Fork 221
/
Copy pathsetEnvFile.cjs
44 lines (35 loc) · 987 Bytes
/
setEnvFile.cjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const fs = require('fs');
const os = require('os');
const path = require('path');
const { execSync } = require('child_process');
const formattedDate = new Date().getTime();
const commitHash = execSync('git rev-parse --short HEAD').toString().trim();
const buildType = process.argv[2] || 'Beta';
let data =
`BUILD_TYPE=${buildType}` +
os.EOL +
`GIT_HASH=${commitHash}` +
os.EOL +
`RELEASE_DATE=${formattedDate}`;
let existingEnvData = '';
fs.readFile(path.join(__dirname, '..', '.env'), 'utf8', (err, existingData) => {
if (err) return;
existingEnvData = existingData
.split(os.EOL)
.filter(line => {
return (
!line.startsWith('BUILD_TYPE=') &&
!line.startsWith('GIT_HASH=') &&
!line.startsWith('RELEASE_DATE=')
);
})
.join(os.EOL);
});
if (existingEnvData) {
data += os.EOL + existingEnvData;
}
fs.writeFile(path.join(__dirname, '..', '.env'), data, 'utf8', err => {
if (err) {
console.log(err);
}
});