Skip to content

Instantly share code, notes, and snippets.

@chfritz
Last active July 19, 2016 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chfritz/5e99ffaef3662620cc0b to your computer and use it in GitHub Desktop.
Save chfritz/5e99ffaef3662620cc0b to your computer and use it in GitHub Desktop.
Make it easy to add cordova plugins to meteor just from knowing the github url.
#!/bin/bash
# Given a github url for a corvoda plugin, such as
#
# https://api.github.com/repos/cordova-sms/cordova-sms-plugin/
#
# this node.js script will generate the appropriate format for "meteor
# add" using the last commit for the tarball and pass it to meteor add.
# For instance, for the above:
#
# cordova:com.cordova.plugins.sms@https://github.com/cordova-sms/cordova-sms-plugin/tarball/17c4da078f6c0d9f762ac10f5015440ee1c81d07
#
# You can now do (in your meteor project directory):
#
# meteor_add_cordova.sh https://github.com/cordova-sms/cordova-sms-plugin
#
# Requirements:
# npm install -g request xmljson
#
read -r -d '' X << EOC
var githubUrl = "$1";
var request = require('request'); // 2.61.0
var xmljson = require('xmljson');
var id;
var sha;
function getId(next) {
var url = githubUrl.replace("github.com", "raw.githubusercontent.com")
+ "/master/plugin.xml";
request( url, function (error, response, body) {
if (!error && response.statusCode == 200) {
xmljson.to_json(body, function(err, res) {
// console.log(res.plugin.$.id);
id = res.plugin.$.id;
next();
});
} else {
console.log(error, response);
}
});
}
function getSHA(next) {
var url = githubUrl.replace("github.com", "api.github.com/repos")
+ "/commits/master";
request( {
url: url,
headers: {
'User-Agent': 'request'
}
}, function (error, response, body) {
if (!error && response.statusCode == 200) {
var obj = JSON.parse(body);
sha = obj.sha;
next();
} else {
console.log(error, response);
}
});
}
getId(function() {
getSHA(function() {
console.log("cordova:" + id + "@" + githubUrl + "/tarball/" + sha);
})
});
EOC
URL=$(echo "$X" | node)
echo "Adding $URL"
meteor add $URL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment