UNPKG

714 BJavaScriptView Raw
1'use strict';
2
3const amphoraFs = require('amphora-fs'),
4 CONFIG_FILENAME = 'claycli.config';
5var CONFIG_FILE = getConfigFile();
6
7/**
8 * Grab the config file from the working directory
9 * or return undefined
10 *
11 * @returns {Object|Undefined}
12 */
13function getConfigFile() {
14 return amphoraFs.tryRequire(`${process.cwd()}/${CONFIG_FILENAME}`);
15}
16
17/**
18 * Return a value from the config file
19 *
20 * @param {String} key
21 * @returns {Any}
22 */
23function getConfigValue(key) {
24 if (!CONFIG_FILE) {
25 return undefined;
26 }
27
28 return CONFIG_FILE[key];
29}
30
31module.exports.getConfigValue = getConfigValue;
32
33// For testing
34module.exports.getConfigFile = getConfigFile;
35module.exports.setConfigFile = val => CONFIG_FILE = val;