mirror of
https://github.com/danbulant/bpm
synced 2026-06-12 11:00:51 +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,8 +1,11 @@
|
|||
const fs = require("fs");
|
||||
const request = require("./requests");
|
||||
|
||||
const REPO = "https://registry.npmjs.org/";
|
||||
|
||||
module.exports = class Package {
|
||||
pkg = {};
|
||||
|
||||
|
||||
load(path){
|
||||
if(!fs.existsSync(path))throw Error("Path doesn't exists!");
|
||||
|
||||
|
|
@ -16,4 +19,23 @@ module.exports = class Package {
|
|||
|
||||
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