-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetPackage.js
33 lines (30 loc) · 986 Bytes
/
getPackage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const fs = require('fs');
const path = require('path');
const { currentDirectory, pkgJson } = require('./config');
const projectDirectory = path.join(currentDirectory, '..', '..');
function getPackage(arg) {
return new Promise((resolve, reject) => {
const pkgJson = path.join(projectDirectory, 'package.json');
if (fs.existsSync(pkgJson)) {
const packageJsonContent = fs.readFileSync(pkgJson, 'utf8'); // reading buffer package.json
const parsedJson = JSON.parse(packageJsonContent);
if (parsedJson) {
if (parsedJson[arg]) {
const data = Object.keys(parsedJson[arg]);
resolve(data);
} else {
resolve([]);
}
} else {
resolve([]);
}
} else {
reject('Error Finding Dependencies');
console.error(
'package.json file does not exist., not in the correct path',
);
}
});
}
// module.exports = getPackageJsonDependencies;
module.exports = getPackage;