-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetenv.ts
More file actions
47 lines (41 loc) · 1.18 KB
/
setenv.ts
File metadata and controls
47 lines (41 loc) · 1.18 KB
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
// Imports as require
require('dotenv').config();
const { writeFile } = require('fs');
const { argv } = require('yargs');
// Arguments passed with yargs
const environment = argv.environment;
// Define environment
const isProduction = environment === 'prod';
const targetPath = isProduction
? `./src/environments/environment.prod.ts`
: `./src/environments/environment.ts`;
// Set environment vaiables for loop
const envArr = [
'REAPP_MEALDB_API_KEY',
'REAPP_EDAMAM_RECIPE_API_ID',
'REAPP_EDAMAM_RECIPE_API_KEY',
'REAPP_EDAMAM_FOOD_API_ID',
'REAPP_EDAMAM_FOOD_API_KEY',
];
// Loop environment variables array
const envVars = () => {
let returnStr = '';
envArr.forEach(envVar => {
returnStr += `${envVar}: '${process.env[envVar]}',\n`
});
return returnStr;
}
// Setup Angular environment file data
const environmentFileContent = `
export const environment = {
production: ${isProduction},
${envVars()}
};
`;
// Write data to respective environment file
writeFile(targetPath, environmentFileContent, function (err:any) {
if (err) {
console.log(`Error occured while getting environmnet: ${err}`);
}
console.log(`Environment successfully copied.`);
});