-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Retrieve package version information via `Node` script rather than `bash` to address #11
- Loading branch information
1 parent
4e3f52a
commit a1574dd
Showing
3 changed files
with
35 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict' | ||
|
||
const util = require('util') | ||
const exec = util.promisify(require('child_process').exec) | ||
|
||
const whichPackage = process.argv[2] | ||
const whichVersion = process.argv[3] | ||
|
||
/** | ||
* Get either the current or previous version of an NPM package | ||
* | ||
* @param {String} whichPackage NPM package to interrogate | ||
* @param {?String} whichVersion If 'previous' then previous version, otherwise current | ||
* | ||
* @returns {String|undefined} Current or previous version of the NPM package | ||
*/ | ||
async function getVersion(whichPackage, whichVersion) { | ||
const {stdout, stderr} = await exec(`npm show ${whichPackage} versions --json`) | ||
|
||
if (!stderr) { | ||
const offset = (whichVersion === 'previous') ? 1 : 0 | ||
const versions = JSON.parse(stdout) | ||
|
||
console.log(versions[versions.length - 1 - offset]) | ||
} | ||
} | ||
|
||
getVersion(whichPackage, whichVersion) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters