All files / src/args getConfig.js

100% Statements 18/18
75% Branches 3/4
100% Functions 2/2
100% Lines 18/18
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 422x 2x   2x 2x 2x   2x 2x 2x       2x               2x 2x   2x 2x 1x     1x     1x   1x     2x        
const path = require('path')
const fs = require('fs-extra')
 
const log = require('../log')
const { getArg } = require('./getArg')
const { CONFIG } = require('./argOptions')
 
const getConfigLocation = () => {
  const configArg = getArg(process.argv, CONFIG)
  const configLocation = configArg
    ? path.resolve(configArg)
    : `${process.cwd()}/interbit.config.js`
 
  return configLocation
}
 
/**
 * Gets the Interbit configuration file from disk based on the `--config`
 * command-line argument.
 * @returns {Object|undefined} The configuration file, if found, as a JSON object.
 */
const getConfig = () => {
  const configLocation = getConfigLocation()
 
  const doesConfigExist = fs.existsSync(configLocation)
  if (!doesConfigExist) {
    return undefined
  }
 
  log.info(`Loading config at ${configLocation}`)
 
  // eslint-disable-next-line
  const interbitConfig = require(configLocation)
 
  return interbitConfig
}
 
module.exports = {
  getConfig,
  getConfigLocation
}