-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsetenv.ts
52 lines (47 loc) · 1.86 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
const { writeFile } = require('node:fs');
const { argv } = require('yargs');
const path = require('node:path');
const envFile = path.join(__dirname, `.env${argv.env ? `.${argv.env}` : ''}`);
// read environment variables from .env file
require('dotenv').config({
path: path.resolve(envFile),
});
// read the command line arguments passed with yargs
const environment = argv.environment;
const isProduction = environment === 'prod';
const targetPath = isProduction ? './src/environments/environment.prod.ts' : './src/environments/environment.deploy.ts';
// we have access to our environment variables
// in the process.env object thanks to dotenv
const environmentFileContent = `export const environment = {
production: ${isProduction},
TARGET_ENV: '${process.env['TARGET_ENV']}',
RemoveAADFullAccessRole: ${process.env['RemoveAADFullAccessRole']},
EnableDevTools: ${process.env['EnableDevTools']},
VTM_CLIENT_ID: "${process.env['VTM_CLIENT_ID']}",
VTM_AUTHORITY_ID: "${process.env['VTM_AUTHORITY_ID']}",
VTM_REDIRECT_URI: "${process.env['VTM_REDIRECT_URI']}",
VTM_API_URI: "${process.env['VTM_API_URI']}",
VTM_API_CLIENT_ID: "${process.env['VTM_API_CLIENT_ID']}",
LOGS_API_KEY: "${process.env['LOGS_API_KEY']}",
DOCUMENT_RETRIEVAL_API_KEY: "${process.env['DOCUMENT_RETRIEVAL_API_KEY']}",
FEEDBACK_URI: "${process.env['FEEDBACK_URI']}",
SENTRY_DSN: "${process.env['SENTRY_DSN']}",
VTM_GTM_CONTAINER_ID: "${process.env['VTM_GTM_CONTAINER_ID']}",
VTM_GTM_MEASUREMENT_ID: "${process.env['VTM_GTM_MEASUREMENT_ID']}",
};
`;
const filesToWrite = [
{
path: targetPath,
contents: environmentFileContent,
},
];
// write the content to the respective file
filesToWrite.forEach(({ path, contents }) => {
writeFile(path, contents, (err: string) => {
if (err) {
console.log(err);
}
console.log(`Wrote variables to ${path}`);
});
});