-
Notifications
You must be signed in to change notification settings - Fork 1
/
plugins.js
47 lines (38 loc) · 1.15 KB
/
plugins.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env node
//This script will add or remove all plugins listed in package.json
//usage: node plugins.js [ add | remove ]
var command = process.argv[2] || 'add';
var packageJson = require('./package.json');
var fs = require('fs');
var path = require('path');
var sys = require('sys')
var exec = require('child_process').exec;
function createAddRemoveStatement(plugin) {
var pluginCmd = 'cordova plugin ' + command + ' ';
if(typeof plugin === 'string') {
pluginCmd += plugin;
} else {
if(command === 'add') {
pluginCmd += plugin.locator + ' ';
if(plugin.variables) {
Object.keys(plugin.variables).forEach(function(variable){
pluginCmd += '--variable ' + variable + '="' + plugin.variables[variable] + '" ';
});
}
} else {
pluginCmd += plugin.id;
}
}
return pluginCmd;
}
function processPlugin(index) {
if(index >= packageJson.cordovaPlugins.length)
return;
var plugin = packageJson.cordovaPlugins[index];
var pluginCommand = createAddRemoveStatement(plugin);
console.log(pluginCommand);
exec(pluginCommand, function(){
processPlugin(index + 1);
});
}
processPlugin(0);