@@ -2,6 +2,7 @@ import { ERROR_SHELL_COMMAND_NOT_FOUND, LOGGER_LEVELS, OptionGroup, ShellCommand
2
2
import { onBeforeExit , processExit , sleepForever } from '@ionic/cli-framework/utils/process' ;
3
3
import chalk from 'chalk' ;
4
4
import * as path from 'path' ;
5
+ import * as url from 'url' ;
5
6
6
7
import { CommandInstanceInfo , CommandLineInputs , CommandLineOptions , CommandMetadata , CommandMetadataOption , CommandPreRun , IShellRunOptions } from '../../definitions' ;
7
8
import { COMMON_BUILD_COMMAND_OPTIONS , build } from '../../lib/build' ;
@@ -202,13 +203,15 @@ ${chalk.cyan('[1]')}: ${chalk.bold('https://ionicframework.com/docs/developer-re
202
203
options [ 'emulator' ] = true ;
203
204
}
204
205
}
206
+
205
207
if ( options [ 'native-run' ] ) {
206
208
const args = createNativeRunListArgs ( inputs , options ) ;
207
209
await this . nativeRun ( args ) ;
208
210
} else {
209
211
const args = filterArgumentsForCordova ( metadata , options ) ;
210
212
await this . runCordova ( [ 'run' , ...args . slice ( 1 ) ] , { } ) ;
211
213
}
214
+
212
215
throw new FatalException ( '' , 0 ) ;
213
216
}
214
217
@@ -234,16 +237,17 @@ ${chalk.cyan('[1]')}: ${chalk.bold('https://ionicframework.com/docs/developer-re
234
237
235
238
if ( options [ 'livereload' ] ) {
236
239
let livereloadUrl = options [ 'livereload-url' ] ? String ( options [ 'livereload-url' ] ) : undefined ;
240
+
237
241
if ( ! livereloadUrl ) {
238
242
// TODO: use runner directly
239
243
const details = await serve ( { flags : this . env . flags , config : this . env . config , log : this . env . log , prompt : this . env . prompt , shell : this . env . shell , project : this . project } , inputs , generateOptionsForCordovaBuild ( metadata , inputs , options ) ) ;
240
244
241
- if ( details . externallyAccessible === false ) {
245
+ if ( details . externallyAccessible === false && ! options [ 'native-run' ] ) {
242
246
const extra = LOCAL_ADDRESSES . includes ( details . externalAddress ) ? '\nEnsure you have proper port forwarding setup from your device to your computer.' : '' ;
243
247
this . env . log . warn ( `Your device or emulator may not be able to access ${ chalk . bold ( details . externalAddress ) } .${ extra } \n\n` ) ;
244
248
}
245
249
246
- livereloadUrl = `${ details . protocol || 'http' } ://${ details . externalAddress } :${ details . port } ` ;
250
+ livereloadUrl = `${ details . protocol || 'http' } ://${ options [ 'native-run' ] ? details . localAddress : details . externalAddress } :${ details . port } ` ;
247
251
}
248
252
249
253
const conf = await loadConfigXml ( this . integration ) ;
@@ -273,7 +277,7 @@ ${chalk.cyan('[1]')}: ${chalk.bold('https://ionicframework.com/docs/developer-re
273
277
274
278
const platform = inputs [ 0 ] ;
275
279
const packagePath = getPackagePath ( conf . getProjectInfo ( ) . name , platform , options [ 'emulator' ] as boolean ) ;
276
- const nativeRunArgs = createNativeRunArgs ( packagePath , platform , options ) ;
280
+ const nativeRunArgs = createNativeRunArgs ( packagePath , platform , livereloadUrl , options ) ;
277
281
await this . nativeRun ( nativeRunArgs ) ;
278
282
} else {
279
283
await this . runCordova ( filterArgumentsForCordova ( metadata , options ) , { stream : cordovalogws } ) ;
@@ -325,9 +329,10 @@ ${chalk.cyan('[1]')}: ${chalk.bold('https://ionicframework.com/docs/developer-re
325
329
}
326
330
}
327
331
328
- function createNativeRunArgs ( packagePath : string , platform : string , options : CommandLineOptions ) : string [ ] {
332
+ function createNativeRunArgs ( packagePath : string , platform : string , livereloadUrl : string , options : CommandLineOptions ) : string [ ] {
329
333
const opts = [ platform , '--app' , packagePath ] ;
330
- const target = options [ 'target' ] as string ;
334
+ const target = options [ 'target' ] ? String ( options [ 'target' ] ) : undefined ;
335
+
331
336
if ( target ) {
332
337
opts . push ( '--target' , target ) ;
333
338
} else if ( options [ 'emulator' ] ) {
@@ -338,10 +343,19 @@ function createNativeRunArgs(packagePath: string, platform: string, options: Com
338
343
opts . push ( '--connect' ) ;
339
344
}
340
345
346
+ if ( ! options [ 'livereload-url' ] ) {
347
+ const { port } = url . parse ( livereloadUrl ) ;
348
+ opts . push ( '--forward' , `${ port } :${ port } ` ) ;
349
+ }
350
+
341
351
if ( options [ 'json' ] ) {
342
352
opts . push ( '--json' ) ;
343
353
}
344
354
355
+ if ( options [ 'verbose' ] ) {
356
+ opts . push ( '--verbose' ) ;
357
+ }
358
+
345
359
return opts ;
346
360
}
347
361
0 commit comments