Skip to content

Commit

Permalink
Change null -> false
Browse files Browse the repository at this point in the history
  • Loading branch information
pouya-eghbali committed Jun 29, 2021
1 parent d9785fe commit 86a3401
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 23 deletions.
7 changes: 4 additions & 3 deletions cnf/generic.js
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion cnf/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
32 changes: 19 additions & 13 deletions cnf/linux.js
Original file line number Diff line number Diff line change
@@ -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;
8 changes: 5 additions & 3 deletions cnf/macos.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
7 changes: 4 additions & 3 deletions cnf/windows.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 86a3401

Please sign in to comment.