Skip to content

Commit d665ef1

Browse files
shahabganji3cp
authored andcommitted
feat(webpack): use: host & port && add: shutdownAppServer
1 parent b832ed1 commit d665ef1

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed
Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,41 @@
11
import { NPM } from 'aurelia-cli';
2+
import { CLIOptions } from 'aurelia-cli';
3+
import * as project from '../aurelia.json';
24

3-
export default function() {
5+
var find = require('find-process');
6+
var kill = require('tree-kill');
7+
8+
const port = CLIOptions.getFlagValue('port') || project.platform.port;
9+
const host = CLIOptions.getFlagValue('host') || project.platform.host || "localhost";
10+
11+
const run = () => {
412
console.log('`au run` is an alias of the `npm start`, you may use either of those; see README for more details.');
513

614
const args = process.argv.slice(3);
7-
return (new NPM()).run('start',['--', ...args]);
15+
16+
if (!CLIOptions.hasFlag('port')) {
17+
args.push('--port');
18+
args.push(port);
19+
}
20+
if (!CLIOptions.hasFlag('host')) {
21+
args.push('--host');
22+
args.push(host);
23+
}
24+
25+
return (new NPM()).run('start', ['--', ...args]);
826
}
27+
28+
const shutdownAppServer = () => {
29+
return new Promise(resolve => {
30+
find('port', port)
31+
.then(function (list) {
32+
if (list.length) {
33+
kill(list[0].pid, 'SIGKILL', function (err) {
34+
resolve();
35+
});
36+
}
37+
});
38+
});
39+
};
40+
41+
export { run as default, shutdownAppServer };

skeleton/webpack/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@
6868
"html-loader": "",
6969
"istanbul-instrumenter-loader": "",
7070
"webpack-bundle-analyzer": "",
71+
"find-process": "^1.4.2",
72+
"tree-kill": "^1.2.1",
7173
},
7274
"scripts": {
7375
"build": "webpack --env.production --env.extractCss",

0 commit comments

Comments
 (0)