-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathset-env.ts
36 lines (34 loc) · 1.26 KB
/
set-env.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
// Configure Angular `environment.prod.ts` file path
// @ts-ignore
const targetPath = process.env.PRODUCTION ? './src/environments/environment.prod.ts' : './src/environments/environment.ts';
// Load node modules
// tslint:disable-next-line:no-var-requires
require('dotenv').config();
// @ts-ignore
// tslint:disable-next-line:no-var-requires
const fs = require('fs');
// `environment.prod.ts` file structure
// @ts-ignore
const envConfigFile = `export const environment = {
appName: '${process.env.APP_NAME || ''}',
apiUrl: '${process.env.API_URL || ''}',
envName: '${process.env.ENV_NAME}',
production: ${process.env.PRODUCTION},
hmr: ${process.env.HMR},
debug: '${process.env.DEBUG}',
encryptKey: '${process.env.ENCRYPT_KEY || ''}',
sentryDsn: '${process.env.SENTRY_DSN || ''}',
socketType: '${process.env.SOCKET_TYPE || ''}',
socketUrl: '${process.env.SOCKET_URL || ''}',
centrifugoUrl: '${process.env.CENTRIFUGO_URL || ''}',
};
`;
console.log('The file `environment.prod.ts` will be written with the following content: \n');
console.log(envConfigFile);
fs.writeFile(targetPath, envConfigFile, (err: any) => {
if (err) {
throw console.error(err);
} else {
console.log(`Angular environment.ts file generated correctly at ${targetPath} \n`);
}
});