-
Notifications
You must be signed in to change notification settings - Fork 13
/
env.js
35 lines (28 loc) · 775 Bytes
/
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
import { config } from 'dotenv'
import chalk from 'chalk'
import * as url from 'url'
import path from 'path'
const VARS = [
'UPLOAD_CLIENT_DEFAULT_PUBLIC_KEY',
'REST_CLIENT_DEFAULT_PUBLIC_KEY',
'REST_CLIENT_DEFAULT_SECRET_KEY'
]
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
const getUndefinedVars = () =>
VARS.filter((variable) => process.env[variable] == null)
const printVars = (list) => {
console.log(
chalk.red(`Please add ${chalk.bold(list.join(', '))} to .env config`)
)
}
function main() {
if (getUndefinedVars().length > 0) {
config({ path: path.join(__dirname, '.env') })
}
const undefinedVars = getUndefinedVars()
if (undefinedVars.length > 0) {
printVars(undefinedVars)
process.exit(1)
}
}
main()