-
Notifications
You must be signed in to change notification settings - Fork 32
/
set-env.ts
48 lines (40 loc) · 1.25 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
37
38
39
40
41
42
43
44
45
46
47
48
const fs = require('fs');
const writeFile = fs.writeFile;
const targetPathes = [
'projects/sample-app/src/environments/environment.ts',
'projects/customizations-example/src/environments/environment.ts',
];
require('dotenv').config();
const devEnvConfig = {
production: false,
};
const prodEnvConfig = {
production: true,
};
const envConfig: { [key: string]: any } =
process.env.ANGULAR_ENV === 'production' ? prodEnvConfig : devEnvConfig;
const tokenUrl = process.env.STREAM_TOKEN_URL
? `'${process.env.STREAM_TOKEN_URL}'`
: `''`;
// `environment.ts` file structure
const envConfigFile = `export const environment = {
${Object.keys(envConfig).map((k) => `${k}: ${envConfig[k]},`)}
apiKey: '${process.env.STREAM_API_KEY}',
userId: '${process.env.STREAM_USER_ID}',
userToken: '${process.env.STREAM_USER_TOKEN}',
tokenUrl: ${tokenUrl},
channelsFilter: ${process.env.STREAM_CHANNELS_FILTER}
};
// I am a generated file, do not modify me directly, see set-env script
`;
targetPathes.forEach((targetPath) => {
writeFile(targetPath, envConfigFile, (err: any) => {
if (err) {
throw err;
} else {
console.log(
`Angular environment.ts file generated correctly at ${targetPath} \n`
);
}
});
});