packages/cli/src/load-project.js
function getConfig() {
  // Load the myrmex main configuration file
  let config = {};
  try {
    // try to load a myrmex.json or myrmex.js file
    config = require(path.join(process.cwd(), 'myrmex'));
  } catch (e) {
    // Silently ignore if there is no configuration file
    return config;
  }

  config.config = config.config || {};

  // Load sub-configuration files
  config.configPath = config.configPath || './config';
  const configPath = path.join(process.cwd(), config.configPath);
  let files = [];
  try {
    files = fs.readdirSync(configPath);
  } catch (e) {
    // Silently ignore if there is no configuration directory
  }
  files.forEach(file => {
    const parse = path.parse(file);
    // We load all .js and .json files in the configuration directory
    if (['.js', '.json'].indexOf(parse.ext) !== -1) {
      config.config[parse.name] = _.merge(config.config[parse.name] || {}, require(path.join(configPath, file)));
    }
  });

  // Add configuration passed by environment variables
  Object.keys(process.env).forEach(key => {
    const prefix = 'MYRMEX_';
    if (key.substring(0, prefix.length) === prefix) {
      // We transform
      //     MYRMEX_myConfig_levels = value
      // into
      //     { config: { myConfig: { levels: value } } }
      function addParts(config, parts, value) {
        const part = parts.shift();
        if (parts.length === 0) {
          // Convert string values "true" and "false" to booleans
          if (value === 'false') { value = false; }
          if (value === 'true') { value = true; }
          config[part] = value;
        } else {
          if (config[part] === undefined) {
            config[part] = {};
          }
          addParts(config[part], parts, value);
        }
      }
      addParts(config.config, key.substring(prefix.length).split('_'), process.env[key]);
    }
  });

  return config;
}
function getConfig() {
  // Load the myrmex main configuration file
  let config = {};
  try {
    // try to load a myrmex.json or myrmex.js file
    config = require(path.join(process.cwd(), 'myrmex'));
  } catch (e) {
    // Silently ignore if there is no configuration file
    return config;
  }

  config.config = config.config || {};

  // Load sub-configuration files
  config.configPath = config.configPath || './config';
  const configPath = path.join(process.cwd(), config.configPath);
  let files = [];
  try {
    files = fs.readdirSync(configPath);
  } catch (e) {
    // Silently ignore if there is no configuration directory
  }
  files.forEach(file => {
    const parse = path.parse(file);
    // We load all .js and .json files in the configuration directory
    if (['.js', '.json'].indexOf(parse.ext) !== -1) {
      config.config[parse.name] = _.merge(config.config[parse.name] || {}, require(path.join(configPath, file)));
    }
  });

  // Add configuration passed by environment variables
  Object.keys(process.env).forEach(key => {
    const prefix = 'MYRMEX_';
    if (key.substring(0, prefix.length) === prefix) {
      // We transform
      //     MYRMEX_myConfig_levels = value
      // into
      //     { config: { myConfig: { levels: value } } }
      function addParts(config, parts, value) {
        const part = parts.shift();
        if (parts.length === 0) {
          // Convert string values "true" and "false" to booleans
          if (value === 'false') { value = false; }
          if (value === 'true') { value = true; }
          config[part] = value;
        } else {
          if (config[part] === undefined) {
            config[part] = {};
          }
          addParts(config[part], parts, value);
        }
      }
      addParts(config.config, key.substring(prefix.length).split('_'), process.env[key]);
    }
  });

  return config;
}
function getConfig ( ) { // Load the myrmex main configuration file let config = { } ; try { // try to load a myrmex.json or myrmex.js file config = require ( path . join ( process . cwd ( ) , 'myrmex' ) ) ; } catch ( e ) { // Silently ignore if there is no configuration file return config ; } config . config = config . config || { } ; // Load sub-configuration files config . configPath = config . configPath || './config' ; const configPath = path . join ( process . cwd ( ) , config . configPath ) ; let files = [ ] ; try { files = fs . readdirSync ( configPath ) ; } catch ( e ) { // Silently ignore if there is no configuration directory } files . forEach ( file => { const parse = path . parse ( file ) ; // We load all .js and .json files in the configuration directory if ( [ '.js' , '.json' ] . indexOf ( parse . ext ) !== - 1 ) { config . config [ parse . name ] = _ . merge ( config . config [ parse . name ] || { } , require ( path . join ( configPath , file ) ) ) ; } } ) ; // Add configuration passed by environment variables Object . keys ( process . env ) . forEach ( key => { const prefix = 'MYRMEX_' ; if ( key . substring ( 0 , prefix . length ) === prefix ) { // We transform //     MYRMEX_myConfig_levels = value // into //     { config: { myConfig: { levels: value } } } function addParts ( config , parts , value ) { const part = parts . shift ( ) ; if ( parts . length === 0 ) { // Convert string values "true" and "false" to booleans if ( value === 'false' ) { value = false ; } if ( value === 'true' ) { value = true ; } config [ part ] = value ; } else { if ( config [ part ] === undefined ) { config [ part ] = { } ; } addParts ( config [ part ] , parts , value ) ; } } addParts ( config . config , key . substring ( prefix . length ) . split ( '_' ) , process . env [ key ] ) ; } } ) ; return config ; }
Check if the directory in which the command is launched contains a myrmex.json configuration file and return it
@return {Object} - an object that will be consumed by a Myrmex instance
Check if the directory in which the command is launched contains a myrmex . json configuration file and return it