From 9da2413e08b345966f63123dfc1957b70913df0d Mon Sep 17 00:00:00 2001 From: ecksteij Date: Mon, 29 Nov 2021 10:07:59 -0500 Subject: [PATCH] Add documentation --- lib/utils/get-dependencies.js | 13 +++++++++++++ lib/utils/get-installed-versions.js | 7 ++++++- lib/utils/get-latest-tag.js | 9 +++++++-- lib/utils/get-latest-versions.js | 10 ++++++++-- lib/utils/install-packages.js | 12 ++++++++++++ 5 files changed, 46 insertions(+), 5 deletions(-) diff --git a/lib/utils/get-dependencies.js b/lib/utils/get-dependencies.js index 6c1f3f5..aa263c0 100644 --- a/lib/utils/get-dependencies.js +++ b/lib/utils/get-dependencies.js @@ -2,8 +2,21 @@ const path = require('path'); +/** + * Gets contents of package.json. + * + * @param {Object} obj - + * @param {string} [obj.dir=''] - Path to directory. + * @returns {PackageJson} - Contects of package.json from the provided directory. + */ function getDependencies({ dir = '' }) { return require(path.join(dir, 'package.json')); } +/** + * @typedef PackageJson + * @property {Object} dependencies - Production dependencies. + * @property {Object} devDependencies - Development dependencies. + */ + module.exports = getDependencies; diff --git a/lib/utils/get-installed-versions.js b/lib/utils/get-installed-versions.js index db4c655..13039d1 100644 --- a/lib/utils/get-installed-versions.js +++ b/lib/utils/get-installed-versions.js @@ -7,11 +7,16 @@ const path = require('path'); * * @param {string} currentDir - Path to package.json directory. * @param {string} name - Package name. - * @returns {string | null} - Installed version or null if not installed. + * @returns {InstalledVersion} - Installed version or null if not installed. * @throws {Error} - Unable to find installed versions, try installing node modules by running `npm i`. */ function getInstalledVersion(currentDir, name) { return require(path.join(currentDir, 'node_modules', name, 'package.json')); } +/** + * @typedef InstalledVersion + * @property {string} version - Currently installed version. + */ + module.exports = getInstalledVersion; diff --git a/lib/utils/get-latest-tag.js b/lib/utils/get-latest-tag.js index 5fe51e8..1d972f6 100644 --- a/lib/utils/get-latest-tag.js +++ b/lib/utils/get-latest-tag.js @@ -9,11 +9,16 @@ const execAsync = promisify(exec); * Gets latest tag from provided package name. * * @param {string} name - Package name. - * @returns {Promise} - Return latest version, if latest tag exists. + * @returns {Promise} - Return latest version, if latest tag exists. * @throws {Error} - Output failed JSON parse. */ async function getLatestTag(name) { - return await execAsync(`npm view ${name} dist-tags --json`); + return execAsync(`npm view ${name} dist-tags --json`); } +/** + * @typedef StandardOutput + * @property {string} stdout - Standard output. + * @property {string} stderr - Standard error. + */ module.exports = getLatestTag; diff --git a/lib/utils/get-latest-versions.js b/lib/utils/get-latest-versions.js index f28f577..42678a8 100644 --- a/lib/utils/get-latest-versions.js +++ b/lib/utils/get-latest-versions.js @@ -9,11 +9,17 @@ const execAsync = promisify(exec); * Gets available versions for provided package name. * * @param {string} name - Package name. - * @returns {Promise} - List of available versions. + * @returns {Promise} - List of available versions. * @throws {Error} - Output failed JSON parse. */ async function getLatestVersions(name) { - return await execAsync(`npm view ${name} versions --json`); + return execAsync(`npm view ${name} versions --json`); } +/** + * @typedef StandardOutput + * @property {string} stdout - Standard output. + * @property {string} stderr - Standard error. + */ + module.exports = getLatestVersions; diff --git a/lib/utils/install-packages.js b/lib/utils/install-packages.js index 350e555..2fbbc6d 100644 --- a/lib/utils/install-packages.js +++ b/lib/utils/install-packages.js @@ -5,8 +5,20 @@ const { promisify } = require('util'); const execAsync = promisify(exec); +/** + * Installs provided NPM modules as production dependencies. + * + * @param {string} pkgs - list of packages. + * @returns {Promise} - Standard output. + */ async function installPackages(pkgs) { return execAsync(`npm i ${pkgs}`); } +/** + * @typedef StandardOutput + * @property {string} stdout - Standard output. + * @property {string} stderr - Standard error. + */ + module.exports = installPackages;