From 67ee30062672404af0df4abb34a0ac0f70b7e383 Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Thu, 21 Sep 2017 09:14:21 +0200 Subject: [PATCH] extended versions() (added yarn, gulp, grunt, tsc, git) --- CHANGELOG.md | 1 + README.md | 1 + lib/osinfo.js | 53 ++++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 46 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 957d342..ebe51de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -98,6 +98,7 @@ Other changes | Version | Date | Comment | | -------------- | -------------- | -------- | +| 3.30.0 | 2017-09-21 | extended `versions()` (added `yarn`, `gulp`, `grunt`, `tsc`, `git`) | | 3.29.0 | 2017-09-15 | extended windows support `services()`, optimized `diskLayout()` (OSX), bugfixes | | 3.28.0 | 2017-09-14 | extended windows support `processes()` | | 3.27.1 | 2017-09-13 | updated Raspberry version detection `system()` (Pi 3, Zero) | diff --git a/README.md b/README.md index bcd0bef..e6e7404 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ async function cpu() { ## News and Changes ### Latest Activity +- Version 3.30.0: extended `versions()` (added `yarn`, `gulp`, `grunt`, `tsc`, `git`) - Version 3.29.0: extended windows support `services()` - Version 3.28.0: extended windows support `processes()` - Version 3.27.0: added raw data to `currentLoad()`, fixed `networkInterfaces()` MAC problem node 8.x diff --git a/lib/osinfo.js b/lib/osinfo.js index a32dccf..fdf10a5 100644 --- a/lib/osinfo.js +++ b/lib/osinfo.js @@ -221,28 +221,63 @@ function versions(callback) { process.nextTick(() => { let result = { kernel: os.release(), + openssl: process.versions.openssl, node: process.versions.node, v8: process.versions.v8, npm: '', + yarn: '', pm2: '', - openssl: process.versions.openssl + gulp: '', + grunt: '', + git: '', + tsc: '', }; - let lines = []; + let parts = []; exec("npm -v", function (error, stdout) { if (!error) { result.npm = stdout.toString().split('\n')[0]; } exec("pm2 -v", function (error, stdout) { if (!error) { - lines = stdout.toString().split('\n'); - if (lines.length >= 2) { - result.pm2 = lines[lines.length - 2]; + parts = stdout.toString().split('\n'); + if (parts.length >= 2) { + result.pm2 = parts[parts.length - 2]; } } - if (callback) { - callback(result) - } - resolve(result); + exec("yarn --version", function (error, stdout) { + if (!error) { + result.yarn = stdout.toString().split('\n')[0]; + } + exec("gulp --version", function (error, stdout) { + if (!error) { + result.gulp = stdout.toString().split('\n')[0] || ''; + result.gulp = (result.gulp.toLowerCase().split('version')[1] || '').trim(); + } + exec("tsc --version", function (error, stdout) { + if (!error) { + result.tsc = stdout.toString().split('\n')[0] || ''; + result.tsc = (result.tsc.toLowerCase().split('version')[1] || '').trim(); + } + exec("grunt --version", function (error, stdout) { + if (!error) { + result.grunt = stdout.toString().split('\n')[0] || ''; + result.grunt = (result.grunt.toLowerCase().split('cli v')[1] || '').trim(); + } + exec("git --version", function (error, stdout) { + if (!error) { + result.git = stdout.toString().split('\n')[0] || ''; + result.git = (result.git.toLowerCase().split('version')[1] || '').trim(); + result.git = (result.git.split(' ')[0] || '').trim(); + } + if (callback) { + callback(result) + } + resolve(result); + }); + }); + }); + }); + }); }); }); });