lib/actions.js
function (plugin, program, callback) {
    var cozyLight = require('./cozy-light');

    if (typeof(program) === 'function') callback = program;

    logger.info('Fetching data...');
    npmHelpers.fetchManifest(plugin,

      function addPluginToConfig (fetchErr, manifest, type) {
        if (fetchErr) {
          logger.raw(fetchErr);
          logger.error('Cannot find given plugin manifest.');
          logger.error('Make sure it lives on Github');
          logger.error('or in the given directory.');
          logger.error(plugin + ' installation failed.');
          nodeHelpers.invoke(callback, fetchErr);

        } else {
          var config = configHelpers.getConfig();
          var pluginName = manifest.name;

          if (config.plugins[pluginName]) {
            logger.info('Plugin ' + pluginName + ' already installed...');
            return nodeHelpers.invoke(callback, null, manifest, type);

          } else {
            logger.info('Installing plugin ' + pluginName + '...');
            var setupCb = function (installErr) {

              if (installErr) {
                logger.raw(installErr);
                logger.error(pluginName + ' installation failed.');
                nodeHelpers.invoke(callback, installErr, manifest, type);

              } else {
                logger.info(pluginName + ' installed. Enjoy!');

                if(cozyLight.getStatus() !== 'started') {
                  configHelpers.addPlugin(pluginName, manifest);
                  nodeHelpers.invoke(callback, null, manifest, type);

                } else {
                  configHelpers.watcher.one(function () {
                    pluginHelpers.loadPlugin(pluginName, program);
                    nodeHelpers.invoke(callback);
                  });
                  configHelpers.addPlugin(pluginName, manifest);
                }
              }
            };

            if (type === 'file') {
              return npmHelpers.link(plugin, setupCb);

            } else if (type === 'url') {
              return npmHelpers.install(plugin, setupCb);
            }
          }
        }
      });
  }
function (plugin, program, callback) {
    var cozyLight = require('./cozy-light');

    if (typeof(program) === 'function') callback = program;

    logger.info('Fetching data...');
    npmHelpers.fetchManifest(plugin,

      function addPluginToConfig (fetchErr, manifest, type) {
        if (fetchErr) {
          logger.raw(fetchErr);
          logger.error('Cannot find given plugin manifest.');
          logger.error('Make sure it lives on Github');
          logger.error('or in the given directory.');
          logger.error(plugin + ' installation failed.');
          nodeHelpers.invoke(callback, fetchErr);

        } else {
          var config = configHelpers.getConfig();
          var pluginName = manifest.name;

          if (config.plugins[pluginName]) {
            logger.info('Plugin ' + pluginName + ' already installed...');
            return nodeHelpers.invoke(callback, null, manifest, type);

          } else {
            logger.info('Installing plugin ' + pluginName + '...');
            var setupCb = function (installErr) {

              if (installErr) {
                logger.raw(installErr);
                logger.error(pluginName + ' installation failed.');
                nodeHelpers.invoke(callback, installErr, manifest, type);

              } else {
                logger.info(pluginName + ' installed. Enjoy!');

                if(cozyLight.getStatus() !== 'started') {
                  configHelpers.addPlugin(pluginName, manifest);
                  nodeHelpers.invoke(callback, null, manifest, type);

                } else {
                  configHelpers.watcher.one(function () {
                    pluginHelpers.loadPlugin(pluginName, program);
                    nodeHelpers.invoke(callback);
                  });
                  configHelpers.addPlugin(pluginName, manifest);
                }
              }
            };

            if (type === 'file') {
              return npmHelpers.link(plugin, setupCb);

            } else if (type === 'url') {
              return npmHelpers.install(plugin, setupCb);
            }
          }
        }
      });
  }
Plugin names correspond to Github repo.
A plugin name is composed of
a user name and a repository name.
Installation starts by fetching
the manifest from the repository
(package.json located at the root).
Then it installs sources and
dependencies in the cozy-light folder.

@param {String} plugin Plugin to install
(ex: cozy-labs/cozy-light-docker).
@param {Function} callback Termination.