From 2127c573891895609db8d9dcd1fbf670bf99669a Mon Sep 17 00:00:00 2001 From: Fabian Date: Wed, 27 Dec 2017 17:39:06 +0100 Subject: [PATCH] quit webpack devserver on electron quit in dev env --- package.json | 1 + tasks/runner.js | 16 ++++++++++++---- yarn.lock | 23 +++++++++++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index dc3479e4c2..0391c4926a 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tasks/runner.js b/tasks/runner.js index e328e538ea..400d584218 100644 --- a/tasks/runner.js +++ b/tasks/runner.js @@ -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' @@ -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)) }) @@ -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) }) @@ -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) + }) } diff --git a/yarn.lock b/yarn.lock index 620e298a49..3eccfb8686 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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" @@ -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"