forked from unlock-protocol/unlock
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig-builder.js
More file actions
37 lines (33 loc) · 1.06 KB
/
config-builder.js
File metadata and controls
37 lines (33 loc) · 1.06 KB
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
/* eslint no-console: 0 */
// This needs to be written as ES5 because it is consumed by Webpack too to assess the config
const dotenv = require('dotenv')
const path = require('path')
const unlockEnv = process.env.UNLOCK_ENV || 'dev'
dotenv.config({
path: path.resolve(__dirname, '..', `.env.${unlockEnv}.local`),
})
// Remember to add mapping in webpack for all environment variables below
const requiredVariables = ['SMTP_HOST', 'SMTP_USERNAME', 'SMTP_PASSWORD']
requiredVariables.forEach((envVar) => {
if (!process.env[envVar]) {
if (['test'].indexOf(unlockEnv) === -1) {
console.error(`Environment variable ${envVar} is required.`)
}
if (['dev', 'test'].indexOf(unlockEnv) === -1) {
process.exit(1)
}
}
})
console.log(
`module.exports = ${JSON.stringify({
host: process.env.SMTP_HOST,
port: process.env.SMTP_PORT || 587,
secure: false,
auth: {
user: process.env.SMTP_USERNAME,
pass: process.env.SMTP_PASSWORD,
},
unlockEnv,
sender: process.env.SMTP_FROM_ADDRESS || 'hello@unlock-protocol.com',
})}`
)