From d665ef196da39745d316e461f9d42cfef9d9c12c Mon Sep 17 00:00:00 2001 From: Saeed Ganji Date: Fri, 16 Aug 2019 13:27:06 +0430 Subject: [PATCH] feat(webpack): use: host & port && add: shutdownAppServer --- .../webpack/aurelia_project/tasks/run.ext | 37 ++++++++++++++++++- skeleton/webpack/package.json | 2 + 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/skeleton/webpack/aurelia_project/tasks/run.ext b/skeleton/webpack/aurelia_project/tasks/run.ext index 79268fcf3..88f85bfd9 100644 --- a/skeleton/webpack/aurelia_project/tasks/run.ext +++ b/skeleton/webpack/aurelia_project/tasks/run.ext @@ -1,8 +1,41 @@ import { NPM } from 'aurelia-cli'; +import { CLIOptions } from 'aurelia-cli'; +import * as project from '../aurelia.json'; -export default function() { +var find = require('find-process'); +var kill = require('tree-kill'); + +const port = CLIOptions.getFlagValue('port') || project.platform.port; +const host = CLIOptions.getFlagValue('host') || project.platform.host || "localhost"; + +const run = () => { console.log('`au run` is an alias of the `npm start`, you may use either of those; see README for more details.'); const args = process.argv.slice(3); - return (new NPM()).run('start',['--', ...args]); + + if (!CLIOptions.hasFlag('port')) { + args.push('--port'); + args.push(port); + } + if (!CLIOptions.hasFlag('host')) { + args.push('--host'); + args.push(host); + } + + return (new NPM()).run('start', ['--', ...args]); } + +const shutdownAppServer = () => { + return new Promise(resolve => { + find('port', port) + .then(function (list) { + if (list.length) { + kill(list[0].pid, 'SIGKILL', function (err) { + resolve(); + }); + } + }); + }); +}; + +export { run as default, shutdownAppServer }; diff --git a/skeleton/webpack/package.json b/skeleton/webpack/package.json index 03b4d960c..9a64c26b1 100644 --- a/skeleton/webpack/package.json +++ b/skeleton/webpack/package.json @@ -68,6 +68,8 @@ "html-loader": "", "istanbul-instrumenter-loader": "", "webpack-bundle-analyzer": "", + "find-process": "^1.4.2", + "tree-kill": "^1.2.1", }, "scripts": { "build": "webpack --env.production --env.extractCss",