@@ -342,13 +342,13 @@ export class PlatformService extends EventEmitter implements IPlatformService {
342342
343343 const platformData = this . $platformsData . getPlatformData ( platform , projectData ) ;
344344 const forDevice = ! buildConfig || buildConfig . buildForDevice ;
345- outputPath = outputPath || ( forDevice ? platformData . getDeviceBuildOutputPath ( buildConfig ) : platformData . emulatorBuildOutputPath || platformData . getDeviceBuildOutputPath ( buildConfig ) ) ;
345+ outputPath = outputPath || ( forDevice ? platformData . deviceBuildOutputPath : platformData . emulatorBuildOutputPath || platformData . deviceBuildOutputPath ) ;
346346 if ( ! this . $fs . exists ( outputPath ) ) {
347347 return true ;
348348 }
349349
350- const packageNames = platformData . getValidPackageNames ( { isForDevice : forDevice } ) ;
351- const packages = this . getApplicationPackages ( outputPath , packageNames ) ;
350+ const validBuildOutputData = platformData . getValidBuildOutputData ( { isForDevice : forDevice } ) ;
351+ const packages = this . getApplicationPackages ( outputPath , validBuildOutputData ) ;
352352 if ( packages . length === 0 ) {
353353 return true ;
354354 }
@@ -450,7 +450,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {
450450
451451 const platformData = this . $platformsData . getPlatformData ( platform , projectData ) ;
452452 const deviceBuildInfo : IBuildInfo = await this . getDeviceBuildInfo ( device , projectData ) ;
453- const localBuildInfo = this . getBuildInfo ( platform , platformData , { buildForDevice : ! device . isEmulator , release : release . release } , outputPath ) ;
453+ const localBuildInfo = this . getBuildInfo ( platform , platformData , { buildForDevice : ! device . isEmulator } , outputPath ) ;
454454 return ! localBuildInfo || ! deviceBuildInfo || deviceBuildInfo . buildTime !== localBuildInfo . buildTime ;
455455 }
456456
@@ -561,12 +561,12 @@ export class PlatformService extends EventEmitter implements IPlatformService {
561561 await this . $devicesService . execute ( action , this . getCanExecuteAction ( platform , runOptions ) ) ;
562562 }
563563
564- private getBuildOutputPath ( platform : string , platformData : IPlatformData , options : IShouldInstall ) : string {
564+ private getBuildOutputPath ( platform : string , platformData : IPlatformData , options : IBuildForDevice ) : string {
565565 if ( platform . toLowerCase ( ) === this . $devicePlatformsConstants . iOS . toLowerCase ( ) ) {
566- return options . buildForDevice ? platformData . getDeviceBuildOutputPath ( options ) : platformData . emulatorBuildOutputPath ;
566+ return options . buildForDevice ? platformData . deviceBuildOutputPath : platformData . emulatorBuildOutputPath ;
567567 }
568568
569- return platformData . getDeviceBuildOutputPath ( options ) ;
569+ return platformData . deviceBuildOutputPath ;
570570 }
571571
572572 private async getDeviceBuildInfoFilePath ( device : Mobile . IDevice , projectData : IProjectData ) : Promise < string > {
@@ -586,7 +586,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {
586586 }
587587 }
588588
589- private getBuildInfo ( platform : string , platformData : IPlatformData , options : IShouldInstall , buildOutputPath ?: string ) : IBuildInfo {
589+ private getBuildInfo ( platform : string , platformData : IPlatformData , options : IBuildForDevice , buildOutputPath ?: string ) : IBuildInfo {
590590 buildOutputPath = buildOutputPath || this . getBuildOutputPath ( platform , platformData , options ) ;
591591 const buildInfoFile = path . join ( buildOutputPath , buildInfoFileName ) ;
592592 if ( this . $fs . exists ( buildInfoFile ) ) {
@@ -746,27 +746,50 @@ export class PlatformService extends EventEmitter implements IPlatformService {
746746 return platformData . platformProjectService . isPlatformPrepared ( platformData . projectRoot , projectData ) ;
747747 }
748748
749- private getApplicationPackages ( buildOutputPath : string , validPackageNames : string [ ] ) : IApplicationPackage [ ] {
749+ private getApplicationPackages ( buildOutputPath : string , validBuildOutputData : IValidBuildOutputData ) : IApplicationPackage [ ] {
750750 // Get latest package` that is produced from build
751- const candidates = this . $fs . readDirectory ( buildOutputPath ) ;
752- const packages = _ . filter ( candidates , candidate => {
753- return _ . includes ( validPackageNames , candidate ) ;
754- } ) . map ( currentPackage => {
755- currentPackage = path . join ( buildOutputPath , currentPackage ) ;
756-
757- return {
758- packageName : currentPackage ,
759- time : this . $fs . getFsStats ( currentPackage ) . mtime
760- } ;
761- } ) ;
751+ let result = this . getApplicationPackagesCore ( this . $fs . readDirectory ( buildOutputPath ) . map ( filename => path . join ( buildOutputPath , filename ) ) , validBuildOutputData . packageNames ) ;
752+ if ( result ) {
753+ return result ;
754+ }
755+
756+ const candidates = this . $fs . enumerateFilesInDirectorySync ( buildOutputPath ) ;
757+ result = this . getApplicationPackagesCore ( candidates , validBuildOutputData . packageNames ) ;
758+ if ( result ) {
759+ return result ;
760+ }
761+
762+ if ( validBuildOutputData . regexes && validBuildOutputData . regexes . length ) {
763+ return this . createApplicationPackages ( candidates . filter ( filepath => _ . some ( validBuildOutputData . regexes , regex => regex . test ( path . basename ( filepath ) ) ) ) ) ;
764+ }
765+
766+ return [ ] ;
767+ }
762768
763- return packages ;
769+ private getApplicationPackagesCore ( candidates : string [ ] , validPackageNames : string [ ] ) : IApplicationPackage [ ] {
770+ const packages = candidates . filter ( filePath => _ . includes ( validPackageNames , path . basename ( filePath ) ) ) ;
771+ if ( packages . length > 0 ) {
772+ return this . createApplicationPackages ( packages ) ;
773+ }
774+
775+ return null ;
776+ }
777+
778+ private createApplicationPackages ( packages : string [ ] ) : IApplicationPackage [ ] {
779+ return packages . map ( filepath => this . createApplicationPackage ( filepath ) ) ;
764780 }
765781
766- private getLatestApplicationPackage ( buildOutputPath : string , validPackageNames : string [ ] ) : IApplicationPackage {
767- let packages = this . getApplicationPackages ( buildOutputPath , validPackageNames ) ;
782+ private createApplicationPackage ( packageName : string ) : IApplicationPackage {
783+ return {
784+ packageName,
785+ time : this . $fs . getFsStats ( packageName ) . mtime
786+ } ;
787+ }
788+
789+ private getLatestApplicationPackage ( buildOutputPath : string , validBuildOutputData : IValidBuildOutputData ) : IApplicationPackage {
790+ let packages = this . getApplicationPackages ( buildOutputPath , validBuildOutputData ) ;
768791 if ( packages . length === 0 ) {
769- const packageExtName = path . extname ( validPackageNames [ 0 ] ) ;
792+ const packageExtName = path . extname ( validBuildOutputData . packageNames [ 0 ] ) ;
770793 this . $errors . fail ( "No %s found in %s directory" , packageExtName , buildOutputPath ) ;
771794 }
772795
@@ -776,11 +799,11 @@ export class PlatformService extends EventEmitter implements IPlatformService {
776799 }
777800
778801 public getLatestApplicationPackageForDevice ( platformData : IPlatformData , buildConfig : IBuildConfig , outputPath ?: string ) : IApplicationPackage {
779- return this . getLatestApplicationPackage ( outputPath || platformData . getDeviceBuildOutputPath ( buildConfig ) , platformData . getValidPackageNames ( { isForDevice : true , isReleaseBuild : buildConfig . release } ) ) ;
802+ return this . getLatestApplicationPackage ( outputPath || platformData . deviceBuildOutputPath , platformData . getValidBuildOutputData ( { isForDevice : true , isReleaseBuild : buildConfig . release } ) ) ;
780803 }
781804
782805 public getLatestApplicationPackageForEmulator ( platformData : IPlatformData , buildConfig : IBuildConfig , outputPath ?: string ) : IApplicationPackage {
783- return this . getLatestApplicationPackage ( outputPath || platformData . emulatorBuildOutputPath || platformData . getDeviceBuildOutputPath ( buildConfig ) , platformData . getValidPackageNames ( { isForDevice : false , isReleaseBuild : buildConfig . release } ) ) ;
806+ return this . getLatestApplicationPackage ( outputPath || platformData . emulatorBuildOutputPath || platformData . deviceBuildOutputPath , platformData . getValidBuildOutputData ( { isForDevice : false , isReleaseBuild : buildConfig . release } ) ) ;
784807 }
785808
786809 private async updatePlatform ( platform : string , version : string , platformTemplate : string , projectData : IProjectData , config : IPlatformOptions ) : Promise < void > {
@@ -813,7 +836,6 @@ export class PlatformService extends EventEmitter implements IPlatformService {
813836 } else {
814837 this . $errors . failWithoutHelp ( "Native Platform cannot be updated." ) ;
815838 }
816-
817839 }
818840
819841 private async updatePlatformCore ( platformData : IPlatformData , updateOptions : IUpdatePlatformOptions , projectData : IProjectData , config : IPlatformOptions ) : Promise < void > {
0 commit comments