1
0
mirror of https://github.com/osmarks/random-stuff synced 2024-10-31 19:06:15 +00:00
random-stuff/config.ts

22 lines
610 B
TypeScript
Raw Normal View History

2020-08-12 19:31:12 +00:00
import { parse } from "toml"
import { readFileSync } from "fs"
import { join } from "path"
import { path } from "ramda"
import * as log from "./log"
const defaults = {
production: process.env.NODE_ENV === "production"
}
const config = parse(readFileSync(process.env.CONFIG_FILE || join(__dirname, "..", "config.toml"), { encoding: "utf8" }))
export const get = key => {
const arrKey = key.split(".")
const out = path(arrKey, config) || path(arrKey, defaults)
if (out === undefined) {
log.error(`Configuration parameter ${key} missing`)
process.exit(1)
}
return out
}