embark/lib/pipeline/npm.js

35 lines
1.0 KiB
JavaScript
Raw Normal View History

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";
utils.httpGet(gitUrl, function (res2) {
let body = '';
res2.on('data', function (d) {
body += d;
});
res2.on('end', function () {
callback(body);
});
});
});
});
}
};