-
Notifications
You must be signed in to change notification settings - Fork 9
/
set-env.ts
34 lines (30 loc) · 1.06 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
import { writeFile } from 'fs';
import { argv } from 'yargs';
// This is good for local dev environments, when it's better to
// store a projects environment variables in a .gitignore'd file
require('dotenv').config();
// Would be passed to script like this:
// `ts-node set-env.ts --environment=dev`
// we get it from yargs's argv object
const environment = argv.environment;
const isProd = environment === 'prod';
const targetPath = `./src/environments/environment.${environment}.ts`;
const envConfigFile = `
export const environment = {
production: ${isProd},
firebase: {
apiKey: '${process.env.FIREBASE_API_KEY}',
authDomain: '${process.env.FIREBASE_AUTH_DOMAIN}',
databaseURL: '${process.env.FIREBASE_DATABASE_URL}',
projectId: '${process.env.FIREBASE_PROJECT_ID}',
storageBucket: '${process.env.FIREBASE_STORAGE_BUCKET}',
messagingSenderId: '${process.env.FIREBASE_MESSAGING_SENDER_ID}'
}
};
`;
writeFile(targetPath, envConfigFile, function (err) {
if (err) {
console.log(err);
}
console.log(`Output generated at ${targetPath}`);
});