-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathsetenv.ts
40 lines (34 loc) · 902 Bytes
/
setenv.ts
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
const { writeFile } = require('fs');
// read environment variables from .env file
require('dotenv').config();
const targetPath = `./src/environments/environment.env.ts`;
const enableMaintenace = () => {
if (process.env.MAINTENANCE) {
return `
MAINTENANCE: '${ process.env.MAINTENANCE }',
`;
} else {
return '';
}
};
const enableGTAG = () => {
if (process.env.GTAGID) {
return `
GTAGID: '${ process.env.GTAGID }',
`;
} else {
return '';
}
};
// we have access to our environment variables
// in the process.env object thanks to dotenv
const environmentFileContent = `
export const environment = {${enableMaintenace()}${enableGTAG()}};
`;
// write the content to the respective file
writeFile(targetPath, environmentFileContent, (err) => {
if (err) {
console.warn(err);
}
console.info(`Wrote ${ environmentFileContent } to ${ targetPath }`);
});