-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetenv.ts
More file actions
33 lines (28 loc) · 1.12 KB
/
setenv.ts
File metadata and controls
33 lines (28 loc) · 1.12 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
const { writeFile } = require('fs');
const { argv } = require('yargs');
// read environment variables from .env file
require('dotenv').config();
const getBoilerPlateEnvContent = require('./project-envs/angular-boilerplate.env');
// read the command line arguments passed with yargs
console.log(argv);
const environment = argv.environment ?? '';
const project = argv.project ?? 'angular-boilerplate';
const isProduction = environment === ('prod' || 'stage' || 'qa');
console.log('PROJECT :: ', project);
console.log('ENVIRONMENT :: ', environment);
console.log('IsProd::', isProduction);
if (!['angular-boilerplate'].includes(project)) {
console.log('Invalid project name');
process.exit(-1);
}
const environmentFileContent = getBoilerPlateEnvContent(isProduction);
const targetPath = environment
? `./projects/${project}/src/environments/environment.${environment}.ts`
: `./projects/${project}/src/environments/environment.ts`;
// write the content to the respective file
writeFile(targetPath, environmentFileContent, function (err) {
if (err) {
console.log(err);
}
console.log(`Wrote variables to ${targetPath}`);
});