2017-07-02 17:33:11 +00:00
|
|
|
let utils = require('../utils/utils.js');
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
// TODO: need to refactor to make it truly generalistic, perhaps by
|
|
|
|
// downloading the tarball itself
|
|
|
|
getPackageVersion: function(packageName, version, callback) {
|
|
|
|
let npmRegistry = "http://registry.npmjs.org/" + packageName + "/" + version;
|
|
|
|
|
|
|
|
utils.httpGet(npmRegistry, function (res) {
|
|
|
|
|
|
|
|
let body = '';
|
|
|
|
res.on('data', function (d) {
|
|
|
|
body += d;
|
|
|
|
});
|
|
|
|
res.on('end', function () {
|
|
|
|
let registryJSON = JSON.parse(body);
|
|
|
|
let gitHash = registryJSON.gitHead;
|
|
|
|
let repo = registryJSON.homepage.split("github.com/")[1];
|
|
|
|
|
2017-07-02 22:03:14 +00:00
|
|
|
let gitUrl = "http://raw.githubusercontent.com/" + repo + "/" + gitHash + "/dist/" + packageName + ".js";
|
2017-07-02 17:33:11 +00:00
|
|
|
utils.httpGet(gitUrl, function (res2) {
|
|
|
|
let body = '';
|
|
|
|
res2.on('data', function (d) {
|
|
|
|
body += d;
|
|
|
|
});
|
|
|
|
res2.on('end', function () {
|
|
|
|
callback(body);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|