-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
57 lines (53 loc) · 1.45 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'use strict';
var which = require('which');
var INSTALL_CMD = {
brew: 'brew install',
port: 'sudo port install',
pkgin: 'sudo pkgin install',
choco: 'choco install',
'apt-get': 'sudo apt-get install',
yum: 'sudo yum install',
dnf: 'sudo dnf install',
nix: 'nix-env --install',
zypper: 'sudo zypper in',
emerge: 'sudo emerge -a',
pacman: 'sudo pacman -S',
pkg: 'pkg install',
pkg_add: 'pkg_add',
crew: 'crew install'
};
var PKG_MANAGERS = {
darwin: ['brew', 'port', 'pkgin'],
win32: ['choco'],
linux: ['apt-get', 'yum', 'dnf', 'nix', 'zypper', 'emerge', 'pacman', 'crew'],
freebsd: ['pkg', 'pkg_add'],
sunos: ['pkg']
// netbsd?
};
/**
* Gets the system packaging install command.
*
* @returns {string} System packaging install command.
* E.g. 'sudo apg-get install' for Debian based systems.
* Defaults to 'your_package_manager install' if no package manager is found.
* @throws Throws if `process.platform` is none of darwin, freebsd, linux, sunos or win32.
*/
module.exports = function getInstallCmd() {
var managers = PKG_MANAGERS[process.platform];
if (!managers || !managers.length) {
throw new Error('unknown platform \'' + process.platform + '\'');
}
managers = managers.filter(function (mng) {
try {
// TODO: Optimize?
which.sync(mng);
return true;
} catch (e) {
return false;
}
});
if (!managers.length) {
return 'your_package_manager install';
}
return INSTALL_CMD[managers[0]];
};