-
Notifications
You must be signed in to change notification settings - Fork 12
/
starter.js
executable file
·69 lines (56 loc) · 1.46 KB
/
starter.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
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env node
'use strict';
const net = require('net');
const path = require('path');
//const spawn = require('child_process').spawn;
const spawn = require('cross-spawn');
const sleep = require('sleep').sleep;
const config = require('./config');
const win32 = process.platform === 'win32';
var child = null;
function getElectronArgs() {
var args = ['.'];
if (process.argv.indexOf('--2nd') != -1) {
args.push('--2nd');
}
return args
}
const server = net.createServer(function (c) {
if (child) {
if (win32) {
spawn("taskkill", ["/pid", child.pid, '/f', '/t']);
} else {
child.kill();
}
delete process.env.DEV;
}
process.env.DEV = 1
var cmd = win32 ? 'electron.cmd' : 'electron';
child = spawn(cmd, getElectronArgs());
child.stdout.on('data', function (data) {
console.log(data + '');
});
child.stderr.on('data', function (data) {
console.log(data + '');
});
child.on('close', function (code) {
console.log('child process exited with code ' + code);
});
c.write('world');
});
server.listen(config.port, function (e) {
const client = net.connect({port: config.port}, function () {
const args = ['--config', 'webpack.config.js', '--hot',
'--port', 8000, '--inline'];
spawn('webpack-dev-server', args, {
stdio: 'inherit'
});
sleep(1);
client.write('hello');
});
client.on('data', function (data) {
client.end();
});
});
server.on('error', function (e) {
});