-
Notifications
You must be signed in to change notification settings - Fork 39
/
build-env.js
49 lines (42 loc) · 2 KB
/
build-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
require('dotenv').config()
const fs = require('fs')
console.log('Building .env files...')
const appVars = [
{ originalName: 'APP_NAME', newName: 'REACT_APP_NAME' },
{ originalName: 'APP_THEME', newName: 'REACT_APP_THEME' },
{ originalName: 'ADMIN_DOMAIN', newName: 'REACT_APP_ADMIN_DOMAIN' },
{ originalName: 'SERVER_DOMAIN', newName: 'REACT_APP_SERVER_DOMAIN' },
{ originalName: 'ABOUT_URL', newName: 'REACT_APP_ABOUT_URL' },
{ originalName: 'QUARANTINE_DAYS', newName: 'REACT_APP_QUARANTINE_DAYS' },
{ originalName: 'CONTACT_WINDOW_HOURS_BEFORE', newName: 'REACT_APP_CONTACT_WINDOW_HOURS_BEFORE' },
{ originalName: 'CONTACT_WINDOW_HOURS_AFTER', newName: 'REACT_APP_CONTACT_WINDOW_HOURS_AFTER' },
{ originalName: 'CHECKPOINT_KEY_LENGTH', newName: 'REACT_APP_CHECKPOINT_KEY_LENGTH' },
{ originalName: 'LOCIZE_PRODUCT_ID', newName: 'REACT_APP_LOCIZE_PRODUCT_ID', optional: true }
]
const adminVars = [
{ originalName: 'APP_NAME', newName: 'REACT_APP_NAME' },
{ originalName: 'APP_DOMAIN', newName: 'REACT_APP_WEB_APP_DOMAIN' },
{ originalName: 'SERVER_DOMAIN', newName: 'REACT_APP_SERVER_DOMAIN' },
{ originalName: 'ADMIN_REGISTRATION_URL', newName: 'REACT_APP_REGISTRATION_URL', optional: true },
{ originalName: 'GOOGLE_API_KEY', newName: 'REACT_APP_GOOGLE_API_KEY' },
{ originalName: 'LOCIZE_PRODUCT_ID', newName: 'REACT_APP_LOCIZE_PRODUCT_ID', optional: true }
]
const buildNewEnvFile = (newVars) => {
return newVars.map(newVar => {
const value = process.env[newVar.originalName]
if (typeof value !== 'undefined') {
return `${newVar.newName}=${value}`
} else {
if (newVar.optional) {
return undefined
} else {
throw new Error(`Environment variable not set: ${newVar.originalName}`)
}
}
}).filter(v => v).join('\n')
}
const appEnvFile = buildNewEnvFile(appVars)
const adminEnvFile = buildNewEnvFile(adminVars)
fs.writeFileSync('./app/.env', appEnvFile)
fs.writeFileSync('./admin/.env', adminEnvFile)
console.log('.env files built successfully')