@@ -164,14 +164,11 @@ export class PlatformService implements IPlatformService {
164
164
platform = platform . toLowerCase ( ) ;
165
165
166
166
this . preparePlatform ( platform ) . wait ( ) ;
167
-
168
- // We need to set device option here
169
- var cachedDeviceOption = options . device ;
170
- options . device = true ;
171
- this . buildPlatform ( platform ) . wait ( ) ;
172
- options . device = cachedDeviceOption ;
173
-
174
- this . deploy ( platform ) . wait ( ) ;
167
+ if ( options . emulator ) {
168
+ this . deployOnEmulator ( platform ) . wait ( ) ;
169
+ } else {
170
+ this . deployOnDevice ( platform ) . wait ( ) ;
171
+ }
175
172
} ) . future < void > ( ) ( ) ;
176
173
}
177
174
@@ -191,35 +188,21 @@ export class PlatformService implements IPlatformService {
191
188
} ) . future < void > ( ) ( ) ;
192
189
}
193
190
194
- public deploy ( platform : string ) : IFuture < void > {
191
+ public deployOnDevice ( platform : string ) : IFuture < void > {
195
192
return ( ( ) => {
196
- platform = platform . toLowerCase ( ) ;
197
-
198
193
this . validatePlatformInstalled ( platform ) ;
194
+ platform = platform . toLowerCase ( ) ;
199
195
200
196
var platformData = this . $platformsData . getPlatformData ( platform ) ;
201
197
202
- // Get latest package that is produced from build
203
- var candidates = this . $fs . readDirectory ( platformData . buildOutputPath ) . wait ( ) ;
204
- var packages = _ . filter ( candidates , candidate => {
205
- return _ . contains ( platformData . validPackageNames , candidate ) ;
206
- } ) . map ( currentPackage => {
207
- currentPackage = path . join ( platformData . buildOutputPath , currentPackage ) ;
208
-
209
- return {
210
- pkg : currentPackage ,
211
- time : this . $fs . getFsStats ( currentPackage ) . wait ( ) . mtime
212
- } ;
213
- } ) ;
214
-
215
- packages = _ . sortBy ( packages , pkg => pkg . time ) . reverse ( ) ; // We need to reverse because sortBy always sorts in ascending order
216
-
217
- if ( packages . length === 0 ) {
218
- var packageExtName = path . extname ( platformData . validPackageNames [ 0 ] ) ;
219
- this . $errors . fail ( "No %s found in %s directory" , packageExtName , platformData . buildOutputPath )
220
- }
198
+ // We need to build for device
199
+ var cachedDeviceOption = options . device ;
200
+ options . device = true ;
201
+ this . buildPlatform ( platform ) . wait ( ) ;
202
+ options . device = cachedDeviceOption ;
221
203
222
- var packageFile = packages [ 0 ] . pkg ;
204
+ // Get latest package that is produced from build
205
+ var packageFile = this . getLatestApplicationPackageForDevice ( platformData ) . wait ( ) . packageName ;
223
206
this . $logger . out ( "Using " , packageFile ) ;
224
207
225
208
this . $devicesServices . initialize ( platform , options . device ) . wait ( ) ;
@@ -229,6 +212,25 @@ export class PlatformService implements IPlatformService {
229
212
} ) . future < void > ( ) ( ) ;
230
213
}
231
214
215
+ public deployOnEmulator ( platform : string ) : IFuture < void > {
216
+ return ( ( ) => {
217
+ this . validatePlatformInstalled ( platform ) ;
218
+ platform = platform . toLowerCase ( ) ;
219
+
220
+ var platformData = this . $platformsData . getPlatformData ( platform ) ;
221
+ var emulatorServices = platformData . emulatorServices ;
222
+
223
+ emulatorServices . checkAvailability ( ) . wait ( ) ;
224
+
225
+ this . buildPlatform ( platform ) . wait ( ) ;
226
+
227
+ var packageFile = this . getLatestApplicationPackageForEmulator ( platformData ) . wait ( ) . packageName ;
228
+ this . $logger . out ( "Using " , packageFile ) ;
229
+
230
+ emulatorServices . startEmulator ( packageFile , options . emulator ) . wait ( ) ;
231
+ } ) . future < void > ( ) ( ) ;
232
+ }
233
+
232
234
private validatePlatform ( platform : string ) : void {
233
235
if ( ! platform ) {
234
236
this . $errors . fail ( "No platform specified." )
@@ -299,5 +301,46 @@ export class PlatformService implements IPlatformService {
299
301
} ) ;
300
302
} ) . future < void > ( ) ( ) ;
301
303
}
304
+
305
+ private getApplicationPackages ( buildOutputPath : string , validPackageNames : string [ ] ) : IFuture < IApplicationPackage [ ] > {
306
+ return ( ( ) => {
307
+ // Get latest package that is produced from build
308
+ var candidates = this . $fs . readDirectory ( buildOutputPath ) . wait ( ) ;
309
+ var packages = _ . filter ( candidates , candidate => {
310
+ return _ . contains ( validPackageNames , candidate ) ;
311
+ } ) . map ( currentPackage => {
312
+ currentPackage = path . join ( buildOutputPath , currentPackage ) ;
313
+
314
+ return {
315
+ packageName : currentPackage ,
316
+ time : this . $fs . getFsStats ( currentPackage ) . wait ( ) . mtime
317
+ } ;
318
+ } ) ;
319
+
320
+ return packages ;
321
+ } ) . future < IApplicationPackage [ ] > ( ) ( ) ;
322
+ }
323
+
324
+ private getLatestApplicationPackage ( buildOutputPath : string , validPackageNames : string [ ] ) : IFuture < IApplicationPackage > {
325
+ return ( ( ) => {
326
+ var packages = this . getApplicationPackages ( buildOutputPath , validPackageNames ) . wait ( ) ;
327
+ if ( packages . length === 0 ) {
328
+ var packageExtName = path . extname ( validPackageNames [ 0 ] ) ;
329
+ this . $errors . fail ( "No %s found in %s directory" , packageExtName , buildOutputPath ) ;
330
+ }
331
+
332
+ packages = _ . sortBy ( packages , pkg => pkg . time ) . reverse ( ) ; // We need to reverse because sortBy always sorts in ascending order
333
+
334
+ return packages [ 0 ] ;
335
+ } ) . future < IApplicationPackage > ( ) ( ) ;
336
+ }
337
+
338
+ private getLatestApplicationPackageForDevice ( platformData : IPlatformData ) {
339
+ return this . getLatestApplicationPackage ( platformData . deviceBuildOutputPath , platformData . validPackageNamesForDevice ) ;
340
+ }
341
+
342
+ private getLatestApplicationPackageForEmulator ( platformData : IPlatformData ) {
343
+ return this . getLatestApplicationPackage ( platformData . emulatorBuildOutputPath || platformData . deviceBuildOutputPath , platformData . validPackageNamesForEmulator || platformData . validPackageNamesForDevice ) ;
344
+ }
302
345
}
303
346
$injector . register ( "platformService" , PlatformService ) ;
0 commit comments