Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jennyEckstein committed Nov 29, 2021
1 parent 322ace1 commit 9da2413
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
13 changes: 13 additions & 0 deletions lib/utils/get-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
7 changes: 6 additions & 1 deletion lib/utils/get-installed-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
9 changes: 7 additions & 2 deletions lib/utils/get-latest-tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ const execAsync = promisify(exec);
* Gets latest tag from provided package name.
*
* @param {string} name - Package name.
* @returns {Promise<string>} - Return latest version, if latest tag exists.
* @returns {Promise<StandardOutput>} - 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;
10 changes: 8 additions & 2 deletions lib/utils/get-latest-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ const execAsync = promisify(exec);
* Gets available versions for provided package name.
*
* @param {string} name - Package name.
* @returns {Promise<string[]>} - List of available versions.
* @returns {Promise<StandardOutput>} - 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;
12 changes: 12 additions & 0 deletions lib/utils/install-packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<StandardOutput>} - 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;

0 comments on commit 9da2413

Please sign in to comment.