Last active
September 21, 2015 10:11
-
-
Save pluswave/9690cbe3ce2e6de1b543 to your computer and use it in GitHub Desktop.
why not ionic plugin update ? so my own solution here.
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 fs = require('fs'); | |
var child_process = require('child_process'); | |
if( process.argv.length != 3 ){ | |
console.log("usage: " + process.argv[1] + " packagename"); | |
process.exit(1); | |
} | |
fs.readFile("plugins/fetch.json", {encoding: 'utf8'}, function(error, data){ | |
if( error ){ | |
console.log("readFile plugins/fetch.json error, are you in an ionic project directory ?"); | |
process.exit(2); | |
} | |
else{ | |
var pkgname = process.argv[2]; | |
var pkgcfgs = JSON.parse(data); | |
var config = pkgcfgs[pkgname]; | |
if( ! config ){ | |
console.log("no such plugins installed: " + pkgname); | |
process.exit(3); | |
} | |
var url = config.source.url || config.source.path || config.source.id; | |
var variables = config.variables; | |
// console.log(url); | |
// console.log(variables); | |
if (!url){ | |
console.log("don't know how to fetch the plugin, please report a bug"); | |
process.exit(4); | |
} | |
var cmd = 'ionic'; | |
var rm_args = ['plugin','rm', pkgname]; | |
var add_args = ['plugin', 'add', url ]; | |
for( var k in variables ){ | |
add_args.push('--variable'); | |
add_args.push(k + "=" + variables[k]); | |
} | |
console.log("removing current plugin ... "); | |
var rm_process = child_process.spawn(cmd, rm_args, {stdio: 'inherit'}); | |
rm_process.on('close', function(){ | |
console.log("adding new version plugin from " + url); | |
var add_process = child_process.spawn(cmd, add_args, {stdio: 'inherit'}); | |
add_process.on('close', function(r){ | |
process.exit(r); | |
}); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment