Created
October 9, 2018 07:34
-
-
Save rike422/48c4ac7d74a36a9f608af380bed60717 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const yaml = require("js-yaml"); | |
const fs = require("fs"); | |
const path = require("path"); | |
const setting = {}; | |
const CONFIG_DIR = path.join(__dirname, "../", "config"); | |
const ENVIRONMENTS_CONFIG_DIR = path.join(CONFIG_DIR, "settings"); | |
const LOCAL_CONFIG_YAML = path.join(CONFIG_DIR, "settings.local.yml"); | |
const CONFIG_YAML = path.join(CONFIG_DIR, "settings.yml"); | |
function readYAML(path) { | |
return yaml.safeLoad(fs.readFileSync(path, "utf8")); | |
} | |
const baseConfig = readYAML(CONFIG_YAML); | |
function environmentsConfig() { | |
const env = process.env.NODE_ENV || "development"; | |
let file = ""; | |
if (env == "development") { | |
file = "development.yml"; | |
} else if (env == "production") { | |
file = "production.yml"; | |
} else { | |
file = "test.yml"; | |
} | |
return readYAML(path.join(ENVIRONMENTS_CONFIG_DIR, file)); | |
} | |
function localConfig() { | |
if (fs.existsSync(LOCAL_CONFIG_YAML)) { | |
return readYAML(LOCAL_CONFIG_YAML); | |
} else { | |
return {}; | |
} | |
} | |
exports.config = Object.assign( | |
{}, | |
baseConfig, | |
environmentsConfig(), | |
localConfig() | |
); | |
exports.private = { | |
environmentsConfig, | |
localConfig, | |
readYAML | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment