UNPKG

911 BJavaScriptView Raw
1'use strict';
2var path = require('path');
3var execFile = require('child_process').execFile;
4
5module.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
32 if (cb) {
33 args.push('/wait');
34 }
35
36 if (app) {
37 args.push(app);
38 }
39 } else {
40 if (app) {
41 cmd = app;
42 } else {
43 // http://portland.freedesktop.org/download/xdg-utils-1.1.0-rc1.tar.gz
44 cmd = path.join(__dirname, 'xdg-open');
45 }
46 }
47
48 args.push(target);
49
50 // xdg-open will block the process unless stdio is ignored
51 execFile(cmd, args, {stdio: 'ignore'}, cb);
52};