1 | 'use strict';
|
2 | var path = require('path');
|
3 | var execFile = require('child_process').execFile;
|
4 |
|
5 | module.exports = function (target, app, cb) {
|
6 | if (typeof target !== 'string') {
|
7 | throw new Error('Expected a `target`');
|
8 | }
|
9 |
|
10 | if (typeof app === 'function') {
|
11 | cb = app;
|
12 | app = null;
|
13 | }
|
14 |
|
15 | var cmd;
|
16 | var args = [];
|
17 |
|
18 | if (process.platform === 'darwin') {
|
19 | cmd = 'open';
|
20 |
|
21 | if (cb) {
|
22 | args.push('-W');
|
23 | }
|
24 |
|
25 | if (app) {
|
26 | args.push('-a', app);
|
27 | }
|
28 | } else if (process.platform === 'win32') {
|
29 | cmd = 'cmd';
|
30 | args.push('/c', 'start');
|
31 | target = target.replace(/&/g, '^&');
|
32 |
|
33 | if (cb) {
|
34 | args.push('/wait');
|
35 | }
|
36 |
|
37 | if (app) {
|
38 | args.push(app);
|
39 | }
|
40 | } else {
|
41 | if (app) {
|
42 | cmd = app;
|
43 | } else {
|
44 |
|
45 | cmd = path.join(__dirname, 'xdg-open');
|
46 | }
|
47 | }
|
48 |
|
49 | args.push(target);
|
50 |
|
51 |
|
52 | execFile(cmd, args, {stdio: 'ignore'}, cb);
|
53 | };
|