diegonetto / generator-ionic

Build hybrid mobile apps using the Ionic Framework
MIT License
1.74k stars 336 forks source link

Bug in after_plugin_add hook script #252

Open rsippl opened 9 years ago

rsippl commented 9 years ago

hooks/after_plugin_add/register_plugins.js is supposed to make sure that for a "cordova plugin add ...", a line is added to package.json, more precisely, to the cordovaPlugins array. A "ionic state restore" is able to install all plugins from the cordovaPlugins, e.g. after you check out your app from a git repo that doesn't contain the plugins directory.

There's a check in register_plugins.js that is supposed to make sure that cordovaPlugins doesn't contain duplicates. Here's how the check is being currently done:

if (packageJSON.cordovaPlugins.indexOf(plugin) !== -1) {
  packageJSON.cordovaPlugins.push(plugin);
}

"!== -1" should read "== -1". This bug causes only those plugins to be added to package.json which are already in there. If you add a new plugin, package.json won't be changed. You can add plugin entries manually, but every "ionic state restore" call (which internally calls "cordova plugin add ..." for all plugins in package.json) will duplicate the plugins list.

davidachee commented 8 years ago

+1