From ae573a642bdac4dbef2e3b8e7747c1f6ec8ad135 Mon Sep 17 00:00:00 2001 From: ray-1337 <33544674+ray-1337@users.noreply.github.com> Date: Mon, 11 Apr 2022 23:51:08 +0200 Subject: [PATCH] promisify checkPlatformExact --- src/Util.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Util.js b/src/Util.js index e3e3798..7bb258b 100644 --- a/src/Util.js +++ b/src/Util.js @@ -1,4 +1,6 @@ const {exec} = require("child_process"); +const {promisify} = require("util"); +const promisifiedExec = promisify(exec); module.exports.checkNodeVersion = function () { let currentApropriateVersion = 14; @@ -24,20 +26,22 @@ module.exports.checkPlatform = function () { return true; }; -module.exports.getDistroInfo = function () { +module.exports.getDistroInfo = async function () { let current = { distributorID: null, distributorVersion: null }; - // check version - exec('lsb_release -i -r', (error, stdout, stderr) => { - if (error || stderr) { + try { + // check version + let {stdout, stderr} = await promisifiedExec('lsb_release -i -r'); + + if (stderr) { throw new Error(`Error while checking Linux distribution information: ${stderr ? stderr : error}`); }; if (stdout) { // sanitize - let parsed = res + let parsed = stdout .split(/\r|\n/gi) // remove break lines .map(x => x.replace(/\s/gi, "")) // remove spaces, only remains [e.g. DistributorID:Ubuntu] .filter(x => x); // filter empty string @@ -55,13 +59,13 @@ module.exports.getDistroInfo = function () { if (splitViaColon) current.distributorVersion = splitViaColon.pop().toLowerCase(); }; }; - }); + } catch {}; return current; }; -module.exports.checkPlatformExact = function () { - let distroInfo = this.getDistroInfo(); +module.exports.checkPlatformExact = async function () { + let distroInfo = await this.getDistroInfo(); if (!distroInfo?.distributorID || !distroInfo?.distributorVersion) { throw new Error("Missing distro platform information."); };