@@ -10,23 +10,19 @@ import { overrideOptions } from '../utilities/override-options';
10
10
const SilentError = require ( 'silent-error' ) ;
11
11
const PortFinder = require ( 'portfinder' ) ;
12
12
const 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 ) ;
16
14
17
15
const config = CliConfig . fromProject ( ) || CliConfig . fromGlobal ( ) ;
18
16
const defaultPort = process . env . PORT || config . get ( 'defaults.serve.port' ) ;
19
17
const defaultHost = config . get ( 'defaults.serve.host' ) ;
18
+ PortFinder . basePort = defaultPort ;
20
19
21
20
export interface ServeTaskOptions extends BuildOptions {
22
21
port ?: number ;
23
22
host ?: string ;
24
23
proxyConfig ?: string ;
25
24
liveReload ?: boolean ;
26
- liveReloadHost ?: string ;
27
- liveReloadPort ?: number ;
28
- liveReloadBaseUrl ?: string ;
29
- liveReloadLiveCss ?: boolean ;
25
+ liveReloadClient ?: string ;
30
26
ssl ?: boolean ;
31
27
sslKey ?: string ;
32
28
sslCert ?: string ;
@@ -35,80 +31,57 @@ export interface ServeTaskOptions extends BuildOptions {
35
31
}
36
32
37
33
// 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
+ ) ;
59
71
60
72
const ServeCommand = Command . extend ( {
61
73
name : 'serve' ,
62
74
description : 'Builds and serves your app, rebuilding on file changes.' ,
63
75
aliases : [ 'server' , 's' ] ,
64
76
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 ,
102
78
103
79
run : function ( commandOptions : ServeTaskOptions ) {
104
80
const ServeTask = require ( '../tasks/serve' ) . default ;
105
81
106
82
Version . assertAngularVersionIs2_3_1OrHigher ( this . project . root ) ;
107
- commandOptions . liveReloadHost = commandOptions . liveReloadHost || commandOptions . host ;
108
83
109
- return checkPort ( commandOptions . port , commandOptions . host )
110
- . then ( ( port : number ) => commandOptions . port = port )
111
- . then ( ( ) => autoFindLiveReloadPort ( commandOptions ) )
84
+ return checkExpressPort ( commandOptions )
112
85
. then ( ( opts : ServeTaskOptions ) => {
113
86
const serve = new ServeTask ( {
114
87
ui : this . ui ,
@@ -137,26 +110,4 @@ function checkExpressPort(commandOptions: ServeTaskOptions) {
137
110
} ) ;
138
111
}
139
112
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
-
162
113
export default ServeCommand ;
0 commit comments