packages/lambda/src/index.js
function loadLambdas() {
  const lambdasPath = path.join(process.cwd(), plugin.config.lambdasPath);

  // This event allows to inject code before loading all APIs
  return plugin.myrmex.fire('beforeLambdasLoad')
  .then(() => {
    // Retrieve configuration path of all Lambdas
    return Promise.promisify(fs.readdir)(lambdasPath);
  })
  .then((subdirs) => {
    // Load all Lambdas configurations
    const lambdaPromises = [];
    _.forEach(subdirs, (subdir) => {
      const lambdaPath = path.join(lambdasPath, subdir);
      // subdir is the identifier of the Lambda, so we pass it as the second argument
      lambdaPromises.push(loadLambda(lambdaPath, subdir));
    });
    return Promise.all(lambdaPromises);
  })
  .then((lambdas) => {
    // This event allows to inject code to add or delete or alter lambda configurations
    return plugin.myrmex.fire('afterLambdasLoad', lambdas);
  })
  .spread((lambdas) => {
    return Promise.resolve(lambdas);
  })
  .catch(e => {
    // In case the project does not have any Lambda yet, an exception will be thrown
    // We silently ignore it
    if (e.code === 'ENOENT' && path.basename(e.path) === 'lambdas') {
      return Promise.resolve([]);
    }
    return Promise.reject(e);
  });
}
function loadLambdas() {
  const lambdasPath = path.join(process.cwd(), plugin.config.lambdasPath);

  // This event allows to inject code before loading all APIs
  return plugin.myrmex.fire('beforeLambdasLoad')
  .then(() => {
    // Retrieve configuration path of all Lambdas
    return Promise.promisify(fs.readdir)(lambdasPath);
  })
  .then((subdirs) => {
    // Load all Lambdas configurations
    const lambdaPromises = [];
    _.forEach(subdirs, (subdir) => {
      const lambdaPath = path.join(lambdasPath, subdir);
      // subdir is the identifier of the Lambda, so we pass it as the second argument
      lambdaPromises.push(loadLambda(lambdaPath, subdir));
    });
    return Promise.all(lambdaPromises);
  })
  .then((lambdas) => {
    // This event allows to inject code to add or delete or alter lambda configurations
    return plugin.myrmex.fire('afterLambdasLoad', lambdas);
  })
  .spread((lambdas) => {
    return Promise.resolve(lambdas);
  })
  .catch(e => {
    // In case the project does not have any Lambda yet, an exception will be thrown
    // We silently ignore it
    if (e.code === 'ENOENT' && path.basename(e.path) === 'lambdas') {
      return Promise.resolve([]);
    }
    return Promise.reject(e);
  });
}
function loadLambdas ( ) { const lambdasPath = path . join ( process . cwd ( ) , plugin . config . lambdasPath ) ; // This event allows to inject code before loading all APIs return plugin . myrmex . fire ( 'beforeLambdasLoad' ) . then ( ( ) => { // Retrieve configuration path of all Lambdas return Promise . promisify ( fs . readdir ) ( lambdasPath ) ; } ) . then ( ( subdirs ) => { // Load all Lambdas configurations const lambdaPromises = [ ] ; _ . forEach ( subdirs , ( subdir ) => { const lambdaPath = path . join ( lambdasPath , subdir ) ; // subdir is the identifier of the Lambda, so we pass it as the second argument lambdaPromises . push ( loadLambda ( lambdaPath , subdir ) ) ; } ) ; return Promise . all ( lambdaPromises ) ; } ) . then ( ( lambdas ) => { // This event allows to inject code to add or delete or alter lambda configurations return plugin . myrmex . fire ( 'afterLambdasLoad' , lambdas ) ; } ) . spread ( ( lambdas ) => { return Promise . resolve ( lambdas ) ; } ) . catch ( e => { // In case the project does not have any Lambda yet, an exception will be thrown // We silently ignore it if ( e . code === 'ENOENT' && path . basename ( e . path ) === 'lambdas' ) { return Promise . resolve ( [ ] ) ; } return Promise . reject ( e ) ; } ) ; }
Load all lambda configurations
@return {Promise<[Lambda]>} - promise of an array of lambdas
Load all lambda configurations