const path = require('path');
const fs = require('fs');
const flatten = require('lodash.flatten');

/**
 * Filter dependencies by name pattern
 * @param  {String} dependency Name of the dependency
 * @return {Boolean}           If dependency is a rnpm plugin
 */
const isPlugin = (dependency) => !!~dependency.indexOf('rnpm-plugin-');

/**
 * Get default actions from rnpm's package.json
 * @type {Array}
 */
const getActions = (cwd) => {
  const packagePath = path.join(cwd, 'package.json');

  if (!fs.existsSync(packagePath)) {
    return [];
  }

  const pjson = require(packagePath);

  return flatten(
      Object.keys(pjson.dependencies || {}),
      Object.keys(pjson.devDependencies || {})
    )
    .filter(isPlugin)
    .map(getPluginConfig(cwd));
};

/**
 * Get plugin config
 * @param  {String} name Name of the plugin
 * @return {Object}      Plugin's config
 */
const getPluginConfig = cwd => name =>
  require(path.join(cwd, 'node_modules', name));

/**
 * Compose a list of dependencies from default actions,
 * package's dependencies & devDependencies
 * @type {Array}
 */
const pluginsList = flatten([
  getActions(path.join(__dirname, '..')),
  getActions(process.cwd())
]);

module.exports = () => pluginsList;

@@ -339,24 +339,17 @@
 *%0A * Get
- default
+s
  actions
@@ -358,14 +358,90 @@
 rom 
-rnpm's
+package.json in the cwd given%0A * @param %7BString%7D cwd Path to the folder to get the
  pac
@@ -449,16 +449,21 @@
 age.json
+ from
 %0A * @typ
@@ -456,39 +456,105 @@
 n from%0A * @type 
+ 
 %7BArray%7D
+      Array of actions or an empty array if no package.json found
 %0A */%0Aconst getAc
@@ -1146,58 +1146,51 @@
 from
- default actions,%0A * package's dependencies & devD
+%0A * rnpm dependencies and current project d
 epen

Fix style