UNPKG

1.09 kBJavaScriptView Raw
1const spawn = require('child_process').spawn;
2const which = require('which');
3
4function resolveModule(module, resolver) {
5 try {
6 return (resolver || require)(module);
7 } catch (_) {
8 // ignore
9 }
10}
11
12const electron = process.env.ELECTRON_PATH ||
13 resolveModule('electron') ||
14 resolveModule('electron-prebuilt') ||
15 resolveModule('electron', which.sync);
16
17if (!electron) {
18 console.error('');
19 console.error(' Can not find `electron` in the $PATH and $ELECTRON_PATH is not set.');
20 console.error(' Please either set $ELECTRON_PATH or `npm install electron`.');
21 console.error('');
22 process.exit(1);
23}
24
25module.exports = appPath => {
26 const args = process.argv.slice(2);
27 args.unshift(appPath);
28
29 const child = spawn(electron, args);
30 child.stdout.pipe(process.stdout);
31 process.stdin.pipe(child.stdin);
32
33 child.stderr.on('data', function(data) {
34 const str = data.toString('utf8');
35 // it's Chromium, STFU
36 if (str.match(/^\[\d+:\d+/)) {
37 return;
38 }
39 process.stderr.write(data);
40 });
41 child.on('exit', code => {
42 process.exit(code);
43 });
44};