Skip to content

Commit

Permalink
feat(webpack): use: host & port && add: shutdownAppServer
Browse files Browse the repository at this point in the history
  • Loading branch information
shahabganji authored and 3cp committed Sep 3, 2019
1 parent b832ed1 commit d665ef1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
37 changes: 35 additions & 2 deletions skeleton/webpack/aurelia_project/tasks/run.ext
Original file line number Diff line number Diff line change
@@ -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 };
2 changes: 2 additions & 0 deletions skeleton/webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit d665ef1

Please sign in to comment.