Browse Source

promisify checkPlatformExact

develop
ray-1337 3 years ago
parent
commit
ae573a642b
  1. 20
      src/Util.js

20
src/Util.js

@ -1,4 +1,6 @@
const {exec} = require("child_process"); const {exec} = require("child_process");
const {promisify} = require("util");
const promisifiedExec = promisify(exec);
module.exports.checkNodeVersion = function () { module.exports.checkNodeVersion = function () {
let currentApropriateVersion = 14; let currentApropriateVersion = 14;
@ -24,20 +26,22 @@ module.exports.checkPlatform = function () {
return true; return true;
}; };
module.exports.getDistroInfo = function () { module.exports.getDistroInfo = async function () {
let current = { let current = {
distributorID: null, distributorVersion: null distributorID: null, distributorVersion: null
}; };
// check version try {
exec('lsb_release -i -r', (error, stdout, stderr) => { // check version
if (error || stderr) { let {stdout, stderr} = await promisifiedExec('lsb_release -i -r');
if (stderr) {
throw new Error(`Error while checking Linux distribution information: ${stderr ? stderr : error}`); throw new Error(`Error while checking Linux distribution information: ${stderr ? stderr : error}`);
}; };
if (stdout) { if (stdout) {
// sanitize // sanitize
let parsed = res let parsed = stdout
.split(/\r|\n/gi) // remove break lines .split(/\r|\n/gi) // remove break lines
.map(x => x.replace(/\s/gi, "")) // remove spaces, only remains [e.g. DistributorID:Ubuntu] .map(x => x.replace(/\s/gi, "")) // remove spaces, only remains [e.g. DistributorID:Ubuntu]
.filter(x => x); // filter empty string .filter(x => x); // filter empty string
@ -55,13 +59,13 @@ module.exports.getDistroInfo = function () {
if (splitViaColon) current.distributorVersion = splitViaColon.pop().toLowerCase(); if (splitViaColon) current.distributorVersion = splitViaColon.pop().toLowerCase();
}; };
}; };
}); } catch {};
return current; return current;
}; };
module.exports.checkPlatformExact = function () { module.exports.checkPlatformExact = async function () {
let distroInfo = this.getDistroInfo(); let distroInfo = await this.getDistroInfo();
if (!distroInfo?.distributorID || !distroInfo?.distributorVersion) { if (!distroInfo?.distributorID || !distroInfo?.distributorVersion) {
throw new Error("Missing distro platform information."); throw new Error("Missing distro platform information.");
}; };

Loading…
Cancel
Save