-
Notifications
You must be signed in to change notification settings - Fork 72
/
prepare-env.js
39 lines (31 loc) · 1.11 KB
/
prepare-env.js
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
/*
* Write out the branch-specific configuration files to the file system.
*/
const FILE_PATH_MAP = {
'COMMON_CONFIG': 'common.config.js',
'FIREBASE_CONFIG': 'firebase.config.js',
'FIREBASE_SERVICE_ACCOUNT': 'functions/service-account.json',
'SPOTIFY_CONFIG': 'spotify.config.js',
'SPOTIFY_FUNCTIONS_CONFIG': 'functions/spotify.config.ts',
};
const fs = require('fs');
let branch = process.env.TRAVIS_BRANCH || process.env.BRANCH;
// If we're not in CI we expect the developer to install the
// required files manually.
if (!branch) {
return;
}
if (branch !== 'master' && branch !== 'develop') {
branch = 'develop';
}
const branchSuffix = `_${branch.toUpperCase()}`;
Object.keys(process.env)
.filter(envName => envName.endsWith(branchSuffix))
.forEach(envName => process.env[envName.substr(0, envName.length - branchSuffix.length)] = process.env[envName]);
Object.keys(FILE_PATH_MAP).forEach(envVar => {
const value = process.env[envVar];
if (!value) {
throw new Error(`Missing environment variable ${envVar}`);
}
fs.writeFileSync(FILE_PATH_MAP[envVar], value);
});