Skip to content

Commit

Permalink
Added local version to CLI --version outputs ↞ [auto-sync from `ada…
Browse files Browse the repository at this point in the history
…mlui/js-utils`]
  • Loading branch information
adamlui authored and kudo-sync-bot committed Apr 12, 2024
1 parent 65527ab commit 044a1f9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions node.js/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,20 @@ if (process.argv.some(arg => argRegex.infoCmds.help.test(arg))) printHelpSection
// Show VERSION number if -v or --version passed
else if (process.argv.some(arg => argRegex.infoCmds.version.test(arg))) {
const globalVer = execSync(`npm view ${pkgName} version`).toString().trim() || 'none';
let localVer, currentDir = process.cwd();
while (currentDir !== '/') {
const localManifestPath = path.join(currentDir, 'package.json');
if (fs.existsSync(localManifestPath)) {
const localManifest = require(localManifestPath);
localVer = ( localManifest.dependencies?.[pkgName]
|| localManifest.devDependencies?.[pkgName]
)?.match(/(\d+\.\d+\.\d+)/)[0] || 'none';
break;
}
currentDir = path.dirname(currentDir);
}
console.info(`\nGlobal version: ${globalVer}`);
console.info(`Local version: ${localVer}`);

} else { // run MAIN routine

Expand Down

0 comments on commit 044a1f9

Please sign in to comment.