mirror of
https://github.com/danbulant/bpm
synced 2026-06-18 22:11:19 +00:00
Move parser away
This commit is contained in:
parent
ff5efe401d
commit
fc6617970c
2 changed files with 49 additions and 14 deletions
|
|
@ -10,20 +10,6 @@ var parser = new Parser;
|
|||
module.exports = class Package {
|
||||
pkg = {};
|
||||
|
||||
load(path){
|
||||
if(!fs.existsSync(path))throw Error("Path doesn't exists!");
|
||||
|
||||
try {
|
||||
var json = JSON.parse(fs.readFileSync(path));
|
||||
} catch(e){
|
||||
throw Error("Invalid JSON file");
|
||||
}
|
||||
|
||||
this.pkg = json;
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
get(pkg){
|
||||
return new Promise((res, rej) => {
|
||||
if(!pkg){
|
||||
|
|
|
|||
49
modules/parser.js
Normal file
49
modules/parser.js
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
const Console = require("./console");
|
||||
var console = new Console;
|
||||
|
||||
module.exports = class PackageParser {
|
||||
load(path){
|
||||
if (!fs.existsSync(path)) throw Error("Path doesn't exists!");
|
||||
|
||||
try {
|
||||
var json = JSON.parse(fs.readFileSync(path));
|
||||
} catch (e) {
|
||||
throw Error("Invalid JSON file");
|
||||
}
|
||||
|
||||
this.pkg = json;
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
getName(){
|
||||
if(this.pkg.name)return this.pkg.name;
|
||||
throw Error("Name isn't specified in the package.json");
|
||||
}
|
||||
|
||||
getDescription() {
|
||||
if (this.pkg.description) return this.pkg.description;
|
||||
throw Error("Description isn't specified in the package.json");
|
||||
}
|
||||
|
||||
getDependencies(dev = false){
|
||||
if(dev){
|
||||
var deps = this.pkg.devDependencies;
|
||||
} else {
|
||||
var deps = this.pkg.dependencies;
|
||||
}
|
||||
if(!deps) return {};
|
||||
|
||||
return deps;
|
||||
}
|
||||
|
||||
getPeerDependencies(){
|
||||
if (this.pkg.peerDependencies) return this.pkg.peerDependencies;
|
||||
return {};
|
||||
}
|
||||
|
||||
getOptionalDependencies(){
|
||||
if (this.pkg.optionalDependencies) return this.pkg.optionalDependencies;
|
||||
return {};
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue