From ab1c3c3464d209670b87a54e34af4f8949a48a4a Mon Sep 17 00:00:00 2001 From: danbulant Date: Wed, 19 Feb 2020 17:11:21 +0100 Subject: [PATCH] Working on package.json parser --- modules/package.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 modules/package.js diff --git a/modules/package.js b/modules/package.js new file mode 100644 index 0000000..87b917e --- /dev/null +++ b/modules/package.js @@ -0,0 +1,19 @@ +const fs = require("fs"); + +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; + } +} \ No newline at end of file