Skip to content

Instantly share code, notes, and snippets.

@revolunet
Last active August 31, 2015 00:34
Show Gist options
  • Save revolunet/e19158a13df962a3df5e to your computer and use it in GitHub Desktop.
Save revolunet/e19158a13df962a3df5e to your computer and use it in GitHub Desktop.
reset cordova plugins
/*
if you get plugins troubles, run this from your cordova folder
will destroy and restore /plugins and /platforms/ios
*/
/*
remove iOS platform and plugins and restart from scratch
(due to some git install issues on cordova)
*/
var fs = require('fs');
var execSync = require('child_process').execSync;
var content = fs.readFileSync('./config.xml').toString();
var re = '<plugin name="([^"]+)" spec="([^"]+)" />';
var cordovaPath = '../node_modules/.bin/cordova';
console.log('☞ rm all plugins');
execSync('rm -rf ./plugins/*', {stdio: [0, 1, 2]});
console.log('☞ rm ios platform');
execSync(cordovaPath + ' platform rm ios', {stdio: [0, 1, 2]});
var matches = content.match(new RegExp(re, 'g'));
matches.forEach(function(plugin) {
var parts = plugin.match(new RegExp(re));
var name = parts[1],
spec = parts[2];
var cmd;
if (spec.substring(0, 4) === 'http') {
cmd = cordovaPath + ' plugin add ' + spec;
} else if (spec.substring(0, 3) === 'ssh') {
cmd = cordovaPath + ' plugin add ' + spec;
} else {
cmd = cordovaPath + ' plugin add ' + name + '@' + spec;
}
console.log('☞ add plugin', cmd);
execSync(cmd, {stdio: [0, 1, 2]});
});
console.log('☞ add ios platform');
execSync(cordovaPath + ' platform add ios', {stdio: [0, 1, 2]});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment