forked from taskcluster/taskcluster
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-env-js.js
More file actions
43 lines (36 loc) · 983 Bytes
/
generate-env-js.js
File metadata and controls
43 lines (36 loc) · 983 Bytes
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
const { dirname } = require('path');
const fs = require('fs');
const ENV_DEFAULTS = {
APPLICATION_NAME: 'Taskcluster',
TASKCLUSTER_ROOT_URL: 'https://tc.example.com',
GRAPHQL_ENDPOINT: '/graphql',
GRAPHQL_SUBSCRIPTION_ENDPOINT: '/subscription',
DOCS_ONLY: false,
UI_LOGIN_STRATEGY_NAMES: '',
GA_TRACKING_ID: '',
SENTRY_DSN: '',
};
/**
* Generate `env.js` in the static directory based on the current
* environment variables.
*/
const generateEnvJs = filename => {
const envJs = `window.env = ${
JSON.stringify(
Object.keys(ENV_DEFAULTS).reduce((acc, curr) => {
acc[curr] = process.env[curr] || ENV_DEFAULTS[curr];
return acc;
}, {}), null, 2)
};`;
const dir = dirname(filename);
if (!fs.existsSync(dir)){
fs.mkdirSync(dir);
}
if (!fs.existsSync(filename)){
fs.writeFileSync(filename, envJs, 'utf8');
}
};
module.exports = generateEnvJs
if (require.main === module) {
generateEnvJs(process.argv[2]);
}