-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappProps.js
34 lines (30 loc) · 912 Bytes
/
appProps.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
const path = require("path")
const fs = require("fs")
module.exports = ({ appPath = "" } = {}) => {
const pkg = require(path.resolve(appPath, "package.json"))
let secrets
try {
if (fs.existsSync(path.resolve(appPath, "secretProps.js"))) {
secrets = require(path.resolve(appPath, "secretProps.js"))
} else {
secrets = require(path.resolve(appPath, "secretProps.json"))
}
} catch (e) {
secrets = {}
}
const appProps = pkg.appProps || {}
const props = {}
for (let propName in appProps) {
let value = appProps[propName]
if (typeof value !== "string") value = appProps[propName].value
props[propName] = value
}
for (let propName in secrets) {
if (!props.hasOwnProperty(propName))
throw Error(
`Secret property ${propName} is not defined in package.json -> appProps`
)
props[propName] = secrets[propName]
}
return props
}