mirror of
https://github.com/danbulant/bpm
synced 2026-06-24 17:12:02 +00:00
Get info of given package
This commit is contained in:
parent
950b76e728
commit
f4dcb1d333
1 changed files with 23 additions and 1 deletions
|
|
@ -1,4 +1,7 @@
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
const request = require("./requests");
|
||||||
|
|
||||||
|
const REPO = "https://registry.npmjs.org/";
|
||||||
|
|
||||||
module.exports = class Package {
|
module.exports = class Package {
|
||||||
pkg = {};
|
pkg = {};
|
||||||
|
|
@ -16,4 +19,23 @@ module.exports = class Package {
|
||||||
|
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get(pkg){
|
||||||
|
return new Promise((res, rej) => {
|
||||||
|
if(!pkg)return rej("No package name given");
|
||||||
|
|
||||||
|
request(REPO + pkg + "/").then((res) => {
|
||||||
|
var o = JSON.parse(res);
|
||||||
|
if(o.error == "Not found"){
|
||||||
|
console.log("The package providen couldn't be found on the NPM repository");
|
||||||
|
return rej(404);
|
||||||
|
}
|
||||||
|
|
||||||
|
res("found");
|
||||||
|
}).catch(e => {
|
||||||
|
console.warn(e);
|
||||||
|
rej(e);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue