@@ -4,6 +4,8 @@ import { baseBuildCommandOptions } from './build';
4
4
import { CliConfig } from '../models/config' ;
5
5
import { Version } from '../upgrade/version' ;
6
6
import { ServeTaskOptions } from './serve' ;
7
+ import { checkPort } from '../utilities/check-port' ;
8
+ import { overrideOptions } from '../utilities/override-options' ;
7
9
8
10
const SilentError = require ( 'silent-error' ) ;
9
11
const PortFinder = require ( 'portfinder' ) ;
@@ -60,53 +62,52 @@ const ServeCommand = Command.extend({
60
62
description : 'Builds and serves your app, rebuilding on file changes.' ,
61
63
aliases : [ 'server' , 's' ] ,
62
64
63
- availableOptions : baseServeCommandOptions . concat ( [
64
- { name : 'live-reload' , type : Boolean , default : true , aliases : [ 'lr' ] } ,
65
- {
66
- name : 'live-reload-host' ,
67
- type : String ,
68
- aliases : [ 'lrh' ] ,
69
- description : 'Defaults to host'
70
- } ,
71
- {
72
- name : 'live-reload-base-url' ,
73
- type : String ,
74
- aliases : [ 'lrbu' ] ,
75
- description : 'Defaults to baseURL'
76
- } ,
77
- {
78
- name : 'live-reload-port' ,
79
- type : Number ,
80
- aliases : [ 'lrp' ] ,
81
- description : '(Defaults to port number within [49152...65535])'
82
- } ,
83
- {
84
- name : 'live-reload-live-css' ,
85
- type : Boolean ,
86
- default : true ,
87
- description : 'Whether to live reload CSS (default true)'
88
- } ,
89
- {
90
- name : 'hmr' ,
91
- type : Boolean ,
92
- default : false ,
93
- description : 'Enable hot module replacement' ,
94
- }
95
- ] ) ,
65
+ availableOptions : overrideOptions (
66
+ baseServeCommandOptions . concat ( [
67
+ { name : 'live-reload' , type : Boolean , default : true , aliases : [ 'lr' ] } ,
68
+ {
69
+ name : 'live-reload-host' ,
70
+ type : String ,
71
+ aliases : [ 'lrh' ] ,
72
+ description : 'Defaults to host'
73
+ } ,
74
+ {
75
+ name : 'live-reload-base-url' ,
76
+ type : String ,
77
+ aliases : [ 'lrbu' ] ,
78
+ description : 'Defaults to baseURL'
79
+ } ,
80
+ {
81
+ name : 'live-reload-port' ,
82
+ type : Number ,
83
+ aliases : [ 'lrp' ] ,
84
+ description : '(Defaults to port number within [49152...65535])'
85
+ } ,
86
+ {
87
+ name : 'live-reload-live-css' ,
88
+ type : Boolean ,
89
+ default : true ,
90
+ description : 'Whether to live reload CSS (default true)'
91
+ } ,
92
+ {
93
+ name : 'hmr' ,
94
+ type : Boolean ,
95
+ default : false ,
96
+ description : 'Enable hot module replacement' ,
97
+ }
98
+ ] ) , [
99
+ { name : 'watch' , default : true } ,
100
+ ]
101
+ ) ,
96
102
97
103
run : function ( commandOptions : ServeTaskOptions ) {
98
104
const ServeTask = require ( '../tasks/serve' ) . default ;
99
105
100
- const additionalDefaults : any = {
101
- watch : true
102
- } ;
103
-
104
- commandOptions = Object . assign ( { } , additionalDefaults , commandOptions ) ;
105
-
106
106
Version . assertAngularVersionIs2_3_1OrHigher ( this . project . root ) ;
107
107
commandOptions . liveReloadHost = commandOptions . liveReloadHost || commandOptions . host ;
108
108
109
- return checkExpressPort ( commandOptions )
109
+ return checkPort ( commandOptions . port , commandOptions . host )
110
+ . then ( ( port : number ) => commandOptions . port = port )
110
111
. then ( ( ) => autoFindLiveReloadPort ( commandOptions ) )
111
112
. then ( ( opts : ServeTaskOptions ) => {
112
113
const serve = new ServeTask ( {
0 commit comments