Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quit webpack devserver on electron quit in development #273

Merged
merged 1 commit into from
Dec 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"electron": "^1.7.5",
"flatpickr": "^4.1.2",
"fs-extra": "^4.0.2",
"kill-port": "^1.0.0",
"moment": "^2.17.1",
"mousetrap": "^1.6.1",
"nib": "^1.1.2",
Expand Down
16 changes: 12 additions & 4 deletions tasks/runner.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict'

const config = require('../config')
const exec = require('child_process').exec
const spawn = require('child_process').spawn
const path = require('path')
const killPort = require('kill-port')

let YELLOW = '\x1b[33m'
let BLUE = '\x1b[34m'
Expand All @@ -20,7 +21,7 @@ function format (command, data, color) {

function run (command, color, name, env) {
env = Object.assign({ PATH }, env)
let child = exec(command, { env })
let child = spawn(command, { env, shell: true })
child.stdout.on('data', data => {
console.log(format(name, data, color))
})
Expand All @@ -41,7 +42,7 @@ function startRendererServer () {
let waitForCompile = (data) => {
if (!data.toString().includes('Compiled')) return
child.stdout.removeListener('data', waitForCompile)
resolve()
resolve(child)
}
child.stdout.on('data', waitForCompile)
})
Expand All @@ -55,5 +56,12 @@ module.exports = async function (networkPath) {
NODE_ENV: 'development',
COSMOS_NETWORK: networkPath
}, process.env)
run('electron app/src/main/index.dev.js', BLUE, 'electron', env)
let mainProcess = run('electron app/src/main/index.dev.js', BLUE, 'electron', env)

// terminate running processes on exit of main process
mainProcess.on('exit', code => {
// webpack-dev-server spins up an own process we have no access to. so we kill all processes on our port
killPort(config.port)
process.exit(0)
})
}
23 changes: 23 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2878,6 +2878,18 @@ execa@^0.4.0:
path-key "^1.0.0"
strip-eof "^1.0.0"

execa@^0.6.3:
version "0.6.3"
resolved "https://registry.yarnpkg.com/execa/-/execa-0.6.3.tgz#57b69a594f081759c69e5370f0d17b9cb11658fe"
dependencies:
cross-spawn "^5.0.1"
get-stream "^3.0.0"
is-stream "^1.1.0"
npm-run-path "^2.0.0"
p-finally "^1.0.0"
signal-exit "^3.0.0"
strip-eof "^1.0.0"

execa@^0.7.0:
version "0.7.0"
resolved "https://registry.yarnpkg.com/execa/-/execa-0.7.0.tgz#944becd34cc41ee32a63a9faf27ad5a65fc59777"
Expand Down Expand Up @@ -3360,6 +3372,10 @@ get-stream@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-3.0.0.tgz#8e943d1358dc37555054ecbe2edb05aa174ede14"

get-them-args@^1.2.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/get-them-args/-/get-them-args-1.3.1.tgz#ac1aeca013fda7db12591aaac129c58118e3daa8"

getpass@^0.1.1:
version "0.1.7"
resolved "https://registry.yarnpkg.com/getpass/-/getpass-0.1.7.tgz#5eff8e3e684d569ae4cb2b1282604e8ba62149fa"
Expand Down Expand Up @@ -4746,6 +4762,13 @@ keyboardevents-areequal@^0.2.1:
version "0.2.2"
resolved "https://registry.yarnpkg.com/keyboardevents-areequal/-/keyboardevents-areequal-0.2.2.tgz#88191ec738ce9f7591c25e9056de928b40277194"

kill-port@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/kill-port/-/kill-port-1.0.0.tgz#b2c48d3048ea800d6620ff0d4b6f8ce91f644275"
dependencies:
execa "^0.6.3"
get-them-args "^1.2.1"

killable@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/killable/-/killable-1.0.0.tgz#da8b84bd47de5395878f95d64d02f2449fe05e6b"
Expand Down