-
Notifications
You must be signed in to change notification settings - Fork 1
/
env.js
65 lines (57 loc) · 1.18 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const _ = require('lodash');
const util = require('util');
const nconf = require('nconf');
const env = module.exports;
const vars = {
// Schema
SCHEMA_CLIENT_ID: {
required: true,
export: true,
},
SCHEMA_CLIENT_KEY: {
required: true,
export: true,
redacted: true,
},
// Algolia
ALGOLIA_APP_ID: {
required: true,
export: true,
},
ALGOLIA_API_KEY: {
required: true,
export: true,
redacted: true,
},
ALGOLIA_PREFIX: {
export: true,
},
ALGOLIA_INDEXES: {
export: true,
},
};
_.each(vars, (envProps, envName) => {
let envVal = nconf.get(envName) || '[UNDEFINED]';
// Required
if (envProps.required && envVal === '[UNDEFINED]') {
// eslint-disable-next-line no-console
console.error(
`├── Missing ENV Variable: ${envName}. Check your .env file.`
);
process.exit(1);
}
// Cast to Number
if (envProps.type === Number) {
envVal = Number(envVal);
}
// Export
if (envProps.export) {
env[envName] = envVal;
}
// Redacted
if (envProps.redacted) {
envVal = '[REDACTED]';
}
// eslint-disable-next-line no-console
console.log(`├── ${envName}=${envVal} ──┤`);
});