-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
executable file
·42 lines (35 loc) · 1.02 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
'use strict';
const exec = require('child_process').exec;
const os = require('os');
const osType = os.type();
const browserCmds = { Darwin: 'open -a ' };
const browsers = {
chrome: "'Google Chrome' --args --make-default-browser",
chromeCanary: "'Google Chrome Canary' --args --make-default-browser",
firefox: "'Firefox' --args -setDefaultBrowser",
firefoxDE: "'Firefox Developer Edition' --args -setDefaultBrowser",
safari: "'Safari' --args --make-default-browser",
edge: "'Microsoft Edge' --args --make-default-browser",
edgeCanary: "'Microsoft Edge Canary' --args --make-default-browser"
};
function whichOS(browser) {
if (osType === 'Darwin' && browsers[browser]) {
return {
name: browser,
cmd: browserCmds[osType] + browsers[browser]
};
}
return {};
}
module.exports = function(args) {
var cmds = whichOS(args);
if (cmds && !cmds.name) {
console.log('Browser not found 🙀');
return false;
}
exec(cmds.cmd, error => {
if (error) {
console.error(error);
}
});
};