1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-13 03:35:52 +01:00
verdaccio/tools/getPackageJson.js
Satyam Yadav dac28d31dd fix: adds webpack banner plugin to tag bundles with version (#784)
refactor: updates let to const in generateBanner module

refactor: adds getPackageJson module to get vlues from package.json

refactor: adds jsdoc comments in getPackageJson module
2018-06-29 11:10:09 +05:30

26 lines
674 B
JavaScript

import fs from 'fs';
import path from 'path';
/**
* A module to get package informations from package.json
* @module getPackageJson
* @param {...string} keys from package.json if no arguments passed it returns package.json content as object
* @returns {object} with given keys or content of package.json as object
*/
/**
* Returns package info
*/
const getPackageJson = function(...args) {
const packageJSON = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json')));
if (!args.length) {
return packageJSON;
}
return args.reduce((out, key) => {
out[key] = packageJSON[key];
return out;
}, {});
};
module.exports = getPackageJson;