2

I'm writting a cordova hook which updates plugins on before_prepare.

Three questions here:

  1. I'm getting the error: [TypeError: Cannot read property 'buffer' of undefined]
  2. I would like to stop the flow until the plugin has been updated
  3. Is it possible to know if a plugin was added from cordova plugin registry or from a git repo?

The code I'm using:

var plugin = context.requireCordovaModule('cordova-lib/src/cordova/plugin'),
    pluginNames = context.opts.cordova.plugins;

function updatePlugin(pluginNames) {
  pluginNames.forEach(function (pluginName) {
    return removePlugin(pluginName).then(function () {
      addPlugin(pluginName);
    }, function(e) {
      console.log(e); // ERROR: [TypeError: Cannot read property 'buffer' of undefined]
    });
  });
}

function removePlugin(pluginNames) {
  return plugin('rm', pluginNames);
}

function addPlugin(pluginNames) {
  return plugin('add', pluginNames);
}

updatePlugin(pluginNames);
Miquel
  • 8,339
  • 11
  • 59
  • 82

1 Answers1

2

To resolve 1 & 2, try updating your nodejs to the latest stable version, and using execSync to execute the Cordova CLI commands synchronously:

var execSync = require('child_process').execSync;
...
execSync("cordova plugin rm " + plugin);
execSync("cordova plugin add " + plugin);
Dunc
  • 18,404
  • 6
  • 86
  • 103