packages/api-gateway/src/index.js
function loadModels() {
  const modelSpecsPath = path.join(process.cwd(), plugin.config.modelsPath);

  return plugin.myrmex.fire('beforeModelsLoad')
  .spread(() => {
    return Promise.promisify(fs.readdir)(modelSpecsPath);
  })
  .then(fileNames => {
    // Load all the model specifications
    return Promise.map(fileNames, fileName => {
      const modelSpecPath = path.join(modelSpecsPath, fileName);
      const modelName = path.parse(fileName).name;
      return loadModel(modelSpecPath, modelName);
    });
  })
  .then(models => {
    return plugin.myrmex.fire('afterModelsLoad', models);
  })
  .spread(models => {
    return Promise.resolve(models);
  })
  .catch(e => {
    if (e.code === 'ENOENT' && path.basename(e.path) === path.basename(plugin.config.modelsPath)) {
      return Promise.resolve([]);
    }
    Promise.reject(e);
  });
}
function loadModels() {
  const modelSpecsPath = path.join(process.cwd(), plugin.config.modelsPath);

  return plugin.myrmex.fire('beforeModelsLoad')
  .spread(() => {
    return Promise.promisify(fs.readdir)(modelSpecsPath);
  })
  .then(fileNames => {
    // Load all the model specifications
    return Promise.map(fileNames, fileName => {
      const modelSpecPath = path.join(modelSpecsPath, fileName);
      const modelName = path.parse(fileName).name;
      return loadModel(modelSpecPath, modelName);
    });
  })
  .then(models => {
    return plugin.myrmex.fire('afterModelsLoad', models);
  })
  .spread(models => {
    return Promise.resolve(models);
  })
  .catch(e => {
    if (e.code === 'ENOENT' && path.basename(e.path) === path.basename(plugin.config.modelsPath)) {
      return Promise.resolve([]);
    }
    Promise.reject(e);
  });
}
function loadModels ( ) { const modelSpecsPath = path . join ( process . cwd ( ) , plugin . config . modelsPath ) ; return plugin . myrmex . fire ( 'beforeModelsLoad' ) . spread ( ( ) => { return Promise . promisify ( fs . readdir ) ( modelSpecsPath ) ; } ) . then ( fileNames => { // Load all the model specifications return Promise . map ( fileNames , fileName => { const modelSpecPath = path . join ( modelSpecsPath , fileName ) ; const modelName = path . parse ( fileName ) . name ; return loadModel ( modelSpecPath , modelName ) ; } ) ; } ) . then ( models => { return plugin . myrmex . fire ( 'afterModelsLoad' , models ) ; } ) . spread ( models => { return Promise . resolve ( models ) ; } ) . catch ( e => { if ( e . code === 'ENOENT' && path . basename ( e . path ) === path . basename ( plugin . config . modelsPath ) ) { return Promise . resolve ( [ ] ) ; } Promise . reject ( e ) ; } ) ; }
Load all Model specifications
@returns {Promise<[Models]>} - the promise of an array containing all models
Load all Model specifications