Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova how to install missing plugins after checkout project from repo?

I just cloned repository of the cordova app, but in .gitignore file added dir /plugins.

How can i install these missing plugins? U tried to find any config file where used plugins are saved, but without luck.

Many thanks for any advice.

like image 312
redrom Avatar asked May 12 '15 14:05

redrom


4 Answers

You can use ionic state to manage plugins and plateforms.

https://github.com/driftyco/ionic-cli#ionic-state


Read package.json and install listed plugins / plateforms :

ionic state restore

Save current plugins / platforms to the package.json :

ionic state save

Remove everything ! (including the default Ionic plugins ...) :

ionic state clear

Remove everything and bring back what you have specified in your package.json :

ionic state reset
like image 159
TeChn4K Avatar answered Nov 23 '22 17:11

TeChn4K


cordova prepare seemed to do the trick for me. After cloning my repository I was getting a "No platforms added to this project" error when running cordova requirements, even though the platforms were listed in the config.xml. Running cordova prepare filled out the plugins directories, allowingcordova requirements to run.

like image 26
Matt McMinn Avatar answered Nov 23 '22 17:11

Matt McMinn


If you added the add_plugin & remove plugin hooks, your package.json shall have a cordovaPlugins list.

If yes, then, the solution that i used is to remove the platform and add it again to fetch for all plugins

cordova platform remove android
cordova platform add android

here are the needed hooks

hooks/after_plugin_add/010_register_plugin.js

#!/usr/bin/env node
/**
 * Push plugins to cordovaPlugins array after_plugin_add
 */
var fs = require('fs');
var packageJSON = require('../../package.json');

packageJSON.cordovaPlugins = packageJSON.cordovaPlugins || [];
process.env.CORDOVA_PLUGINS.split(',').forEach(function (plugin) {
  if(packageJSON.cordovaPlugins.indexOf(plugin) == -1) {
    packageJSON.cordovaPlugins.push(plugin);
  }
});

fs.writeFileSync('package.json', JSON.stringify(packageJSON, null, 2));

hooks/after_plugin_rm/010_deregister_plugin.js

#!/usr/bin/env node
/**
     * Remove plugins from cordovaPlugins array after_plugin_rm
     */
    var fs = require('fs');
    var packageJSON = require('../../package.json');

    packageJSON.cordovaPlugins = packageJSON.cordovaPlugins || [];

    process.env.CORDOVA_PLUGINS.split(',').forEach(function (plugin) {
      var index = packageJSON.cordovaPlugins.indexOf(plugin);
      if (index > -1) {
        packageJSON.cordovaPlugins.splice(index, 1);
      }
    });

    fs.writeFile('package.json', JSON.stringify(packageJSON, null, 2));

hooks/after_platform_add/010_install_plugins.js

#!/usr/bin/env node

/**
 * Install all plugins listed in package.json
 * https://raw.githubusercontent.com/diegonetto/generator-ionic/master/templates/hooks/after_platform_add/install_plugins.js
 */
var exec = require('child_process').exec;
var path = require('path');
var sys = require('sys');

var packageJSON = require('../../package.json');
var cmd = process.platform === 'win32' ? 'cordova.cmd' : 'cordova';
// var script = path.resolve(__dirname, '../../node_modules/cordova/bin', cmd);

packageJSON.cordovaPlugins = packageJSON.cordovaPlugins || [];
packageJSON.cordovaPlugins.forEach(function (plugin) {
  exec('cordova plugin add ' + plugin, function (error, stdout, stderr) {
    sys.puts(stdout);
  });
});

One other solution is to add a task for plugin installation as described on this page : http://jbavari.github.io/blog/2014/06/24/managing-cordova-plugins-with-package-dot-json-and-hooks/

like image 26
aorfevre Avatar answered Nov 23 '22 17:11

aorfevre


You can use

ionic cordova prepare <platform>

It will give you the list of plugins that are not installed with error message.

like image 28
Sunny Drall Avatar answered Nov 23 '22 17:11

Sunny Drall