@@ -342,13 +342,13 @@ export class PlatformService extends EventEmitter implements IPlatformService {
342
342
343
343
const platformData = this . $platformsData . getPlatformData ( platform , projectData ) ;
344
344
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 ) ;
346
346
if ( ! this . $fs . exists ( outputPath ) ) {
347
347
return true ;
348
348
}
349
349
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 ) ;
352
352
if ( packages . length === 0 ) {
353
353
return true ;
354
354
}
@@ -450,7 +450,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {
450
450
451
451
const platformData = this . $platformsData . getPlatformData ( platform , projectData ) ;
452
452
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 ) ;
454
454
return ! localBuildInfo || ! deviceBuildInfo || deviceBuildInfo . buildTime !== localBuildInfo . buildTime ;
455
455
}
456
456
@@ -561,12 +561,12 @@ export class PlatformService extends EventEmitter implements IPlatformService {
561
561
await this . $devicesService . execute ( action , this . getCanExecuteAction ( platform , runOptions ) ) ;
562
562
}
563
563
564
- private getBuildOutputPath ( platform : string , platformData : IPlatformData , options : IShouldInstall ) : string {
564
+ private getBuildOutputPath ( platform : string , platformData : IPlatformData , options : IBuildForDevice ) : string {
565
565
if ( platform . toLowerCase ( ) === this . $devicePlatformsConstants . iOS . toLowerCase ( ) ) {
566
- return options . buildForDevice ? platformData . getDeviceBuildOutputPath ( options ) : platformData . emulatorBuildOutputPath ;
566
+ return options . buildForDevice ? platformData . deviceBuildOutputPath : platformData . emulatorBuildOutputPath ;
567
567
}
568
568
569
- return platformData . getDeviceBuildOutputPath ( options ) ;
569
+ return platformData . deviceBuildOutputPath ;
570
570
}
571
571
572
572
private async getDeviceBuildInfoFilePath ( device : Mobile . IDevice , projectData : IProjectData ) : Promise < string > {
@@ -586,7 +586,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {
586
586
}
587
587
}
588
588
589
- private getBuildInfo ( platform : string , platformData : IPlatformData , options : IShouldInstall , buildOutputPath ?: string ) : IBuildInfo {
589
+ private getBuildInfo ( platform : string , platformData : IPlatformData , options : IBuildForDevice , buildOutputPath ?: string ) : IBuildInfo {
590
590
buildOutputPath = buildOutputPath || this . getBuildOutputPath ( platform , platformData , options ) ;
591
591
const buildInfoFile = path . join ( buildOutputPath , buildInfoFileName ) ;
592
592
if ( this . $fs . exists ( buildInfoFile ) ) {
@@ -746,27 +746,50 @@ export class PlatformService extends EventEmitter implements IPlatformService {
746
746
return platformData . platformProjectService . isPlatformPrepared ( platformData . projectRoot , projectData ) ;
747
747
}
748
748
749
- private getApplicationPackages ( buildOutputPath : string , validPackageNames : string [ ] ) : IApplicationPackage [ ] {
749
+ private getApplicationPackages ( buildOutputPath : string , validBuildOutputData : IValidBuildOutputData ) : IApplicationPackage [ ] {
750
750
// 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
+ }
762
768
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 ) ) ;
764
780
}
765
781
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 ) ;
768
791
if ( packages . length === 0 ) {
769
- const packageExtName = path . extname ( validPackageNames [ 0 ] ) ;
792
+ const packageExtName = path . extname ( validBuildOutputData . packageNames [ 0 ] ) ;
770
793
this . $errors . fail ( "No %s found in %s directory" , packageExtName , buildOutputPath ) ;
771
794
}
772
795
@@ -776,11 +799,11 @@ export class PlatformService extends EventEmitter implements IPlatformService {
776
799
}
777
800
778
801
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 } ) ) ;
780
803
}
781
804
782
805
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 } ) ) ;
784
807
}
785
808
786
809
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 {
813
836
} else {
814
837
this . $errors . failWithoutHelp ( "Native Platform cannot be updated." ) ;
815
838
}
816
-
817
839
}
818
840
819
841
private async updatePlatformCore ( platformData : IPlatformData , updateOptions : IUpdatePlatformOptions , projectData : IProjectData , config : IPlatformOptions ) : Promise < void > {
0 commit comments