Ionic CLI is not using plugin variables from package.json

Hi,

I added my plugins in package.json as described here: http://jbavari.github.io/blog/2014/06/24/managing-cordova-plugins-with-package-dot-json-and-hooks/

  "cordovaPlugins": [
    { "locator": "android.support.v4" },
    { "locator": "plugin.http.request" },
    { "locator": "org.apache.cordova.console" },
    { "locator": "org.apache.cordova.geolocation" },
    {
      "locator": "https://github.com/Wizcorp/phonegap-facebook-plugin",
      "variables": {
        "APP_ID": "15515151515151",
        "APP_NAME": "MyApp"
      }
    }
  ]

Notice that variables for the facebook plugin are included. Yet when I run ionic platform add ios, I get this error:

Running command: /Users/jbelis/Sources/applicationtwiing/hooks/before_platform_add/init_directories.js /Users/jbelis/Sources/applicationtwiing
Creating ios project...
Running command: /Users/jbelis/Sources/applicationtwiing/hooks/after_prepare/010_add_platform_class.js /Users/jbelis/Sources/applicationtwiing
add to body class: platform-ios
Running command: /Users/jbelis/Sources/applicationtwiing/hooks/after_prepare/020_remove_sass_from_platforms.js /Users/jbelis/Sources/applicationtwiing
Installing "android.support.v4" for ios
Installing "com.phonegap.plugins.facebookconnect" for ios
Failed to install 'com.phonegap.plugins.facebookconnect':Error: Variable(s) missing: APP_ID, APP_NAME
    at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/install.js:304:23
    at _fulfilled (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:787:54)
    at self.promiseDispatch.done (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:816:30)
    at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:749:13)
    at /usr/local/lib/node_modules/cordova/node_modules/q/q.js:557:44
    at flush (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:108:17)
    at process._tickCallback (node.js:419:13)
Error: Variable(s) missing: APP_ID, APP_NAME
    at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/install.js:304:23
    at _fulfilled (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:787:54)
    at self.promiseDispatch.done (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:816:30)
    at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:749:13)
    at /usr/local/lib/node_modules/cordova/node_modules/q/q.js:557:44
    at flush (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:108:17)
    at process._tickCallback (node.js:419:13)

My hooks folder has a “after_platform_add/010_install_plugins.js” which is supposed to add the plugin and use the variables attribute if present.
This suggests that ionic/cordova is not even using my hooks and trying to add plugins assuming none of them has variables

Any idea why?

Thanks.

I don’t think that capability is built into Ionic CLI or cordova.

You can try changing /after_plugin_add/010_install_plugins.js to something like this:


/**
 * 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) {
  if (typeof plugin === 'string') {
    exec('cordova plugin add ' + plugin, function (error, stdout, stderr) {
      sys.puts(stdout);
    });
  } else {
    var cmd = plugin.locator + ' ';
    if (plugin.variables) {
      Object.keys(plugin.variables).forEach(function(variable) {
        cmd += '--variable ' + variable + '="' + plugin.variables[variable] + '" ';
      });
    }
    exec('cordova plugin add ' + cmd, function (error, stdout, stderr) {
      sys.puts(stdout);
    });
  }
});

But this will have problems with registering and deregistering of plugins because those scripts expect a simple array rather than an array of objects.

That would be great to have variables handle by the package.json as well. Hope this will come in the future.

There is a way to manage the variables with package.json today?

I dont think it is necessary at all anymore to have this hook, for me ionic takes care of everything nicely if I just delete the hook.