From 3a162915d352c92a260431f98383c84171908750 Mon Sep 17 00:00:00 2001 From: Dario Vladovic Date: Wed, 3 Jun 2020 00:03:00 +0200 Subject: [PATCH 1/4] Rename OS X to macOS --- art/{osx.js => macOS.js} | 0 bin/archeyjs | 4 ++-- index.js | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) rename art/{osx.js => macOS.js} (100%) diff --git a/art/osx.js b/art/macOS.js similarity index 100% rename from art/osx.js rename to art/macOS.js diff --git a/bin/archeyjs b/bin/archeyjs index 312f6f8..6265b7b 100755 --- a/bin/archeyjs +++ b/bin/archeyjs @@ -37,7 +37,7 @@ function out(distro, item) { 'Fedora': colors.blueB, 'CrunchBang': colors.whiteB, 'LinuxMint': colors.greenB, - 'OS X': colors.whiteB, + 'macOS': colors.whiteB, 'Windows': colors.whiteB }; return cols[distro] + item.key + ': ' + colors.clear + item.value; @@ -64,7 +64,7 @@ var distroArt = { 'ManjaroLinux': '../art/manjaro.js', 'Arch': '../art/arch.js', 'FreeBSD': '../art/freebsd.js', - 'OS X': '../art/osx.js', + 'macOS': '../art/macOS.js', 'Windows': '../art/windows.js', }; diff --git a/index.js b/index.js index c98f67a..cca42ac 100644 --- a/index.js +++ b/index.js @@ -53,7 +53,7 @@ var tasks = [ done(); }); break; - case 'OS X': + case 'macOS': exec('sw_vers', function(err, stdout, stderr) { var items = { }; stdout.trim().split('\n').forEach(function(line) { @@ -146,7 +146,7 @@ var tasks = [ done(); }); break; - case 'OS X': + case 'macOS': // port exec('port installed 2>/dev/null | wc -l', function(err, stdout, stderr) { var packages = 0; @@ -264,7 +264,7 @@ module.exports = function(onDone) { switch(os.platform()) { case 'darwin': processes = []; - distro = 'OS X'; + distro = 'macOS'; result.wm = { key: 'Window Manager', value: 'Quartz Compositor' }; fullParallel(tasks, onDone); break; From df8b37bfc8b1a46792b69a2f896cef1e9ac36050 Mon Sep 17 00:00:00 2001 From: Dario Vladovic Date: Wed, 3 Jun 2020 00:03:12 +0200 Subject: [PATCH 2/4] Prevent lockfile creation --- .npmrc | 1 + 1 file changed, 1 insertion(+) create mode 100644 .npmrc diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..c1ca392 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock = false From 8e725af02b4d11c246a5ae5d45cef6b35c31299f Mon Sep 17 00:00:00 2001 From: Dario Vladovic Date: Wed, 3 Jun 2020 00:06:37 +0200 Subject: [PATCH 3/4] Swap `bytes` with helper module Support both units in powers of two (1K = 1024) and ten (1K = 1000). --- index.js | 8 ++++---- lib/bytes.js | 12 ++++++++++++ package.json | 1 - 3 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 lib/bytes.js diff --git a/index.js b/index.js index cca42ac..04f96dc 100644 --- a/index.js +++ b/index.js @@ -1,15 +1,15 @@ var exec = require('child_process').exec, os = require('os'), - bytes = require('bytes'), + bytes = require('./lib/bytes'), colors = require('./art/colors.js'), elapsed = require('./lib/elapsed.js'), deDict = require('./lib/de-dict.json'), wmDict = require('./lib/wm-dict.json'); -function color(used, total) { +function color(used, total, base) { var quadrant = Math.min(Math.ceil( Math.floor(used / total * 100) / 33), 3), cols = [ colors.greenB, colors.greenB, colors.yellowB, colors.redB ]; - return cols[quadrant] + bytes(used) + colors.clear + ' / ' + bytes(total); + return cols[quadrant] + bytes(used, base) + colors.clear + ' / ' + bytes(total, base); } var result = { @@ -201,7 +201,7 @@ var tasks = [ used = parseInt(lines.split(/\s+/)[2], 10) * 1024, free = parseInt(lines.split(/\s+/)[3], 10) * 1024, total = used + free; - result.disk = { key: 'Disk', value: color( used, total) }; + result.disk = { key: 'Disk', value: color(used, total, 1000) }; done(); }); break; diff --git a/lib/bytes.js b/lib/bytes.js new file mode 100644 index 0000000..5301b3a --- /dev/null +++ b/lib/bytes.js @@ -0,0 +1,12 @@ +module.exports = humanSize; + +var mags = ' KMGTPEZY'; + +function humanSize(bytes, base, precision) { + if (base === undefined) base = 1024; + if (precision === undefined) precision = 2; + var magnitude = Math.min(Math.log(bytes) / Math.log(base) | 0, mags.length - 1); + var result = bytes / Math.pow(base, magnitude); + var suffix = mags[magnitude].trim() + 'B'; + return result.toFixed(precision) + suffix; +} diff --git a/package.json b/package.json index 54027b7..8ecbdc0 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,6 @@ "url": "https://github.com/mixu/archey.js/issues" }, "dependencies": { - "bytes": "~3.0.0", "optimist": "~0.6.0" } } From abdb8d8ef0478ec891a894d980dec2165cb17905 Mon Sep 17 00:00:00 2001 From: Dario Vladovic Date: Wed, 3 Jun 2020 00:07:58 +0200 Subject: [PATCH 4/4] Fix disk usage calculation on macOS 10.15+ --- index.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 04f96dc..766ade3 100644 --- a/index.js +++ b/index.js @@ -195,15 +195,27 @@ var tasks = [ switch(os.platform()) { case 'freebsd': case 'darwin': - // OSX df is weird, it doesn't have a good option for getting bytes... - exec('df -k / 2>/dev/null | tail -1', function(err, stdout, stderr) { - var lines = stdout.trim().split('\n').pop(), - used = parseInt(lines.split(/\s+/)[2], 10) * 1024, - free = parseInt(lines.split(/\s+/)[3], 10) * 1024, - total = used + free; + (function (parse) { + if(distro == 'FreeBSD') { + return exec('df -kc /', parse); + } + exec('sw_vers -productVersion', function(err, stdout, stderr) { + var version = stdout.trim(), + minorVersion = parseInt(version.split('.')[1], 10); + if(minorVersion >= 15) { + exec('df -k /System/Volumes/Data', parse); + } else { + exec('df -k /', parse); + } + }); + }(function(err, stdout, stderr) { + var line = stdout.trim().split(/\n/).pop(), + cols = line.split(/\s+/), + total = parseInt(cols[1], 10) * 1024, + used = parseInt(cols[2], 10) * 1024; result.disk = { key: 'Disk', value: color(used, total, 1000) }; done(); - }); + })); break; case 'win32': case 'win64':