From 86a3401ef66fb670e2f24b86a5066550b4db9f00 Mon Sep 17 00:00:00 2001 From: Pouya Date: Tue, 29 Jun 2021 19:36:58 +0200 Subject: [PATCH] Change null -> false --- cnf/generic.js | 7 ++++--- cnf/install.js | 2 +- cnf/linux.js | 32 +++++++++++++++++++------------- cnf/macos.js | 8 +++++--- cnf/windows.js | 7 ++++--- 5 files changed, 33 insertions(+), 23 deletions(-) diff --git a/cnf/generic.js b/cnf/generic.js index e71fb31..3c11589 100644 --- a/cnf/generic.js +++ b/cnf/generic.js @@ -1,13 +1,14 @@ const { sudo } = require("../utils/sudo"); -const { spawnSync } = require("child_process"); +const { execSync } = require("child_process"); const installCommandGeneric = (commands, os, variant, config) => { const command = commands[variant?.toLowerCase()] || commands[os]; if (!command) { - return null; + return false; } const stdio = config.log > 2 ? "inherit" : "ignore"; - spawnSync(sudo(command), { stdio }); + execSync(sudo(command), { stdio }); + return true; }; module.exports.installCommandGeneric = installCommandGeneric; diff --git a/cnf/install.js b/cnf/install.js index b2a8489..5a158b2 100644 --- a/cnf/install.js +++ b/cnf/install.js @@ -13,7 +13,7 @@ const installCommand = (commands, { os, variant }, config) => { return installCommandWindows(commands, config); } if (os === "linux") { - installCommandLinux(commands, variant, config); + return installCommandLinux(commands, variant, config); } return installCommandGeneric(commands, os, variant, config); }; diff --git a/cnf/linux.js b/cnf/linux.js index fe23e0f..121e0fb 100644 --- a/cnf/linux.js +++ b/cnf/linux.js @@ -1,54 +1,60 @@ const { managers } = require("../os"); const { sudo } = require("../utils/sudo"); -const { spawnSync } = require("child_process"); +const { execSync } = require("child_process"); const installCommandLinux = (commands, variant, config) => { const command = commands[variant] || commands.linux; if (!command) { - return null; + return false; } if (variant === "ubuntu") { const name = command.match(/apt-get install (.*)/)?.[1]; if (!name) { - return null; + return false; } managers.ubuntu.repo.update([], config); - return managers.ubuntu.install([name], [], config); + managers.ubuntu.install([name], [], config); + return true; } if (variant === "debian") { const name = command.match(/apt-get install (.*)/)?.[1]; if (!name) { - return null; + return false; } managers.debian.repo.update([], config); - return managers.debian.install([name], [], config); + managers.debian.install([name], [], config); + return true; } if (variant === "raspbian") { const name = command.match(/apt-get install (.*)/)?.[1]; if (!name) { - return null; + return false; } managers.raspbian.repo.update([], config); - return managers.raspbian.install([name], [], config); + managers.raspbian.install([name], [], config); + return true; } if (variant === "arch") { const name = command.match(/pacman -S (.*)/)?.[1]; if (!name) { - return null; + return false; } managers.arch.repo.update([], config); - return managers.arch.install([name], [], config); + managers.arch.install([name], [], config); + return true; } if (variant === "alpine") { const name = command.match(/apk add (.*)/)?.[1]; if (!name) { - return null; + return false; } managers.alpine.repo.update([], config); - return managers.alpine.install([name], [], config); + managers.alpine.install([name], [], config); + return true; } const stdio = config.log > 2 ? "inherit" : "ignore"; - spawnSync(sudo(command), { stdio }); + execSync(sudo(command), { stdio }); + return true; }; module.exports.installCommandLinux = installCommandLinux; diff --git a/cnf/macos.js b/cnf/macos.js index e124f7c..08cc3c8 100644 --- a/cnf/macos.js +++ b/cnf/macos.js @@ -3,13 +3,15 @@ const { managers } = require("../os"); const installCommandMacOS = (commands, config) => { const command = commands["osx"] || commands["darwin"]; if (!command) { - return null; + return false; } const name = command.match(/brew install (.*)/)?.[1]; if (!name) { - return null; + console.log({ name }); + return false; } - return managers.macos.install([name], [], config); + managers.macos.install([name], [], config); + return true; }; module.exports.installCommandMacOS = installCommandMacOS; diff --git a/cnf/windows.js b/cnf/windows.js index a935eab..3923eda 100644 --- a/cnf/windows.js +++ b/cnf/windows.js @@ -1,13 +1,14 @@ const { sudo } = require("../utils/sudo"); -const { spawnSync } = require("child_process"); +const { execSync } = require("child_process"); const installCommandWindows = (commands, config) => { const command = commands["windows"] || commands["win32"]; if (!command) { - return null; + return false; } const stdio = config.log > 2 ? "inherit" : "ignore"; - spawnSync(sudo(command), { stdio }); + execSync(sudo(command), { stdio }); + return true; }; module.exports.installCommandWindows = installCommandWindows;