Created
July 27, 2014 01:55
-
-
Save ganchenkor/b5453e12641edb9f5fc4 to your computer and use it in GitHub Desktop.
Cordova hook install plugins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var exec = require('child-process-promise').exec; | |
var fs = require('fs'); | |
var path = require('path'); | |
var sys = require('sys'); | |
var cordova = require('cordova'); | |
var pluginlist = [ | |
"de.appplant.cordova.plugin.email-composer", | |
"org.apache.cordova.globalization", | |
"org.apache.cordova.contacts" | |
]; | |
pluginlist = pluginlist.sort(sortArray); | |
var pluginPath = cordova.findProjectRoot() + "/plugins"; | |
var installedPlugins = findPlugins(pluginPath).sort(sortArray); | |
if(arraysIdentical(installedPlugins, pluginlist)){ | |
return true; | |
} else { | |
pluginlist.forEach(function (plug) { | |
exec("cordova plugin add " + plug, puts); | |
}); | |
} | |
function puts(error,stdout,stderr){ | |
sys.puts(stdout); | |
}; | |
function arraysIdentical(a, b) { | |
var i = a.length; | |
if (i != b.length) return false; | |
while (i--) { | |
if (a[i] !== b[i]) return false; | |
} | |
return true; | |
}; | |
function findPlugins(pluginPath) { | |
var plugins = [], | |
stats; | |
if (fs.existsSync(pluginPath)) { | |
plugins = fs.readdirSync(pluginPath).filter(function (fileName) { | |
stats = fs.statSync(path.join(pluginPath, fileName)); | |
return fileName != '.svn' && fileName != 'CVS' && stats.isDirectory(); | |
}); | |
} | |
return plugins; | |
}; | |
function sortArray(a, b) | |
{ | |
var va = (a === null) ? "" : "" + a, | |
vb = (b === null) ? "" : "" + b; | |
return va > vb ? 1 : ( va === vb ? 0 : -1 ); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment