@@ -10,23 +10,19 @@ import { overrideOptions } from '../utilities/override-options';
1010const SilentError = require ( 'silent-error' ) ;
1111const PortFinder = require ( 'portfinder' ) ;
1212const Command = require ( '../ember-cli/lib/models/command' ) ;
13- const getPort = < any > denodeify ( PortFinder . getPort ) ;
14-
15- PortFinder . basePort = 49152 ;
13+ const getPort = denodeify < { host : string , port : number } , number > ( PortFinder . getPort ) ;
1614
1715const config = CliConfig . fromProject ( ) || CliConfig . fromGlobal ( ) ;
1816const defaultPort = process . env . PORT || config . get ( 'defaults.serve.port' ) ;
1917const defaultHost = config . get ( 'defaults.serve.host' ) ;
18+ PortFinder . basePort = defaultPort ;
2019
2120export interface ServeTaskOptions extends BuildOptions {
2221 port ?: number ;
2322 host ?: string ;
2423 proxyConfig ?: string ;
2524 liveReload ?: boolean ;
26- liveReloadHost ?: string ;
27- liveReloadPort ?: number ;
28- liveReloadBaseUrl ?: string ;
29- liveReloadLiveCss ?: boolean ;
25+ liveReloadClient ?: string ;
3026 ssl ?: boolean ;
3127 sslKey ?: string ;
3228 sslCert ?: string ;
@@ -35,80 +31,57 @@ export interface ServeTaskOptions extends BuildOptions {
3531}
3632
3733// Expose options unrelated to live-reload to other commands that need to run serve
38- export const baseServeCommandOptions : any = baseBuildCommandOptions . concat ( [
39- { name : 'port' , type : Number , default : defaultPort , aliases : [ 'p' ] } ,
40- {
41- name : 'host' ,
42- type : String ,
43- default : defaultHost ,
44- aliases : [ 'H' ] ,
45- description : `Listens only on ${ defaultHost } by default`
46- } ,
47- { name : 'proxy-config' , type : 'Path' , aliases : [ 'pc' ] } ,
48- { name : 'ssl' , type : Boolean , default : false } ,
49- { name : 'ssl-key' , type : String , default : 'ssl/server.key' } ,
50- { name : 'ssl-cert' , type : String , default : 'ssl/server.crt' } ,
51- {
52- name : 'open' ,
53- type : Boolean ,
54- default : false ,
55- aliases : [ 'o' ] ,
56- description : 'Opens the url in default browser' ,
57- }
58- ] ) ;
34+ export const baseServeCommandOptions : any = overrideOptions (
35+ baseBuildCommandOptions . concat ( [
36+ { name : 'port' , type : Number , default : defaultPort , aliases : [ 'p' ] } ,
37+ {
38+ name : 'host' ,
39+ type : String ,
40+ default : defaultHost ,
41+ aliases : [ 'H' ] ,
42+ description : `Listens only on ${ defaultHost } by default`
43+ } ,
44+ { name : 'proxy-config' , type : 'Path' , aliases : [ 'pc' ] } ,
45+ { name : 'ssl' , type : Boolean , default : false } ,
46+ { name : 'ssl-key' , type : String , default : 'ssl/server.key' } ,
47+ { name : 'ssl-cert' , type : String , default : 'ssl/server.crt' } ,
48+ {
49+ name : 'open' ,
50+ type : Boolean ,
51+ default : false ,
52+ aliases : [ 'o' ] ,
53+ description : 'Opens the url in default browser' ,
54+ } ,
55+ { name : 'live-reload' , type : Boolean , default : true , aliases : [ 'lr' ] } ,
56+ {
57+ name : 'live-reload-client' ,
58+ type : String ,
59+ description : 'specify the URL that the live reload browser client will use'
60+ } ,
61+ {
62+ name : 'hmr' ,
63+ type : Boolean ,
64+ default : false ,
65+ description : 'Enable hot module replacement' ,
66+ }
67+ ] ) , [
68+ { name : 'watch' , default : true } ,
69+ ]
70+ ) ;
5971
6072const ServeCommand = Command . extend ( {
6173 name : 'serve' ,
6274 description : 'Builds and serves your app, rebuilding on file changes.' ,
6375 aliases : [ 'server' , 's' ] ,
6476
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- ) ,
77+ availableOptions : baseServeCommandOptions ,
10278
10379 run : function ( commandOptions : ServeTaskOptions ) {
10480 const ServeTask = require ( '../tasks/serve' ) . default ;
10581
10682 Version . assertAngularVersionIs2_3_1OrHigher ( this . project . root ) ;
107- commandOptions . liveReloadHost = commandOptions . liveReloadHost || commandOptions . host ;
10883
109- return checkPort ( commandOptions . port , commandOptions . host )
110- . then ( ( port : number ) => commandOptions . port = port )
111- . then ( ( ) => autoFindLiveReloadPort ( commandOptions ) )
84+ return checkExpressPort ( commandOptions )
11285 . then ( ( opts : ServeTaskOptions ) => {
11386 const serve = new ServeTask ( {
11487 ui : this . ui ,
@@ -137,26 +110,4 @@ function checkExpressPort(commandOptions: ServeTaskOptions) {
137110 } ) ;
138111}
139112
140- function autoFindLiveReloadPort ( commandOptions : ServeTaskOptions ) {
141- return getPort ( { port : commandOptions . liveReloadPort , host : commandOptions . liveReloadHost } )
142- . then ( ( foundPort : number ) => {
143-
144- // if live reload port matches express port, try one higher
145- if ( foundPort === commandOptions . port ) {
146- commandOptions . liveReloadPort = foundPort + 1 ;
147- return autoFindLiveReloadPort ( commandOptions ) ;
148- }
149-
150- // port was already open
151- if ( foundPort === commandOptions . liveReloadPort ) {
152- return commandOptions ;
153- }
154-
155- // use found port as live reload port
156- commandOptions . liveReloadPort = foundPort ;
157- return commandOptions ;
158-
159- } ) ;
160- }
161-
162113export default ServeCommand ;
0 commit comments