11import { TrackActionNames , HASHES_FILE_NAME } from "../../constants" ;
2- import * as helpers from "../../common/helpers" ;
32import * as path from "path" ;
43
5- const buildInfoFileName = ".nsbuildinfo" ;
6-
74export class DeviceInstallAppService {
85 constructor (
96 private $analyticsService : IAnalyticsService ,
107 private $buildArtefactsService : IBuildArtefactsService ,
11- private $devicePathProvider : IDevicePathProvider ,
8+ private $buildInfoFileService : IBuildInfoFileService ,
129 private $fs : IFileSystem ,
1310 private $logger : ILogger ,
1411 private $mobileHelper : Mobile . IMobileHelper ,
15- private $buildInfoFileService : IBuildInfoFileService ,
1612 private $projectDataService : IProjectDataService ,
1713 private $platformsDataService : IPlatformsDataService
1814 ) { }
1915
2016 public async installOnDevice ( device : Mobile . IDevice , buildData : IBuildData , packageFile ?: string ) : Promise < void > {
2117 this . $logger . info ( `Installing on device ${ device . deviceInfo . identifier } ...` ) ;
2218
19+ const platform = device . deviceInfo . platform . toLowerCase ( ) ;
2320 const projectData = this . $projectDataService . getProjectData ( buildData . projectDir ) ;
24- const platformData = this . $platformsDataService . getPlatformData ( device . deviceInfo . platform , projectData ) ;
21+ const platformData = this . $platformsDataService . getPlatformData ( platform , projectData ) ;
2522
2623 await this . $analyticsService . trackEventActionInGoogleAnalytics ( {
2724 action : TrackActionNames . Deploy ,
@@ -30,31 +27,25 @@ export class DeviceInstallAppService {
3027 } ) ;
3128
3229 if ( ! packageFile ) {
33- packageFile = await this . $buildArtefactsService . getLatestApplicationPackagePath ( platformData , buildData ) ;
30+ packageFile = await this . $buildArtefactsService . getLatestAppPackagePath ( platformData , buildData ) ;
3431 }
3532
3633 await platformData . platformProjectService . cleanDeviceTempFolder ( device . deviceInfo . identifier , projectData ) ;
3734
38- const platform = device . deviceInfo . platform . toLowerCase ( ) ;
39- await device . applicationManager . reinstallApplication ( projectData . projectIdentifiers [ platform ] , packageFile ) ;
35+ const appIdentifier = projectData . projectIdentifiers [ platform ] ;
36+ const outputFilePath = buildData . outputPath || platformData . getBuildOutputPath ( buildData ) ;
4037
41- const outputFilePath = buildData . outputPath ;
38+ await device . applicationManager . reinstallApplication ( appIdentifier , packageFile ) ;
4239
4340 await this . updateHashesOnDevice ( {
4441 device,
45- appIdentifier : projectData . projectIdentifiers [ platform ] ,
42+ appIdentifier,
4643 outputFilePath,
4744 platformData
4845 } ) ;
4946
5047 if ( ! buildData . release ) {
51- const deviceFilePath = await this . getDeviceBuildInfoFilePath ( device , projectData ) ;
52- const options = buildData ;
53- options . buildForDevice = ! device . isEmulator ;
54- const buildInfoFilePath = outputFilePath || platformData . getBuildOutputPath ( buildData ) ;
55- const appIdentifier = projectData . projectIdentifiers [ platform ] ;
56-
57- await device . fileSystem . putFile ( path . join ( buildInfoFilePath , buildInfoFileName ) , deviceFilePath , appIdentifier ) ;
48+ await this . $buildInfoFileService . saveDeviceBuildInfo ( device , projectData , outputFilePath ) ;
5849 }
5950
6051 this . $logger . info ( `Successfully installed on device with identifier '${ device . deviceInfo . identifier } '.` ) ;
@@ -67,15 +58,6 @@ export class DeviceInstallAppService {
6758 }
6859 }
6960
70- public async getDeviceBuildInfoFilePath ( device : Mobile . IDevice , projectData : IProjectData ) : Promise < string > {
71- const platform = device . deviceInfo . platform . toLowerCase ( ) ;
72- const deviceRootPath = await this . $devicePathProvider . getDeviceProjectRootPath ( device , {
73- appIdentifier : projectData . projectIdentifiers [ platform ] ,
74- getDirname : true
75- } ) ;
76- return helpers . fromWindowsRelativePathToUnix ( path . join ( deviceRootPath , buildInfoFileName ) ) ;
77- }
78-
7961 public async shouldInstall ( device : Mobile . IDevice , buildData : IBuildData ) : Promise < boolean > {
8062 const projectData = this . $projectDataService . getProjectData ( buildData . projectDir ) ;
8163 const platformData = this . $platformsDataService . getPlatformData ( device . deviceInfo . platform , projectData ) ;
@@ -84,8 +66,8 @@ export class DeviceInstallAppService {
8466 return true ;
8567 }
8668
87- const deviceBuildInfo : IBuildInfo = await this . getDeviceBuildInfo ( device , projectData ) ;
88- const localBuildInfo = this . $buildInfoFileService . getBuildInfoFromFile ( platformData , { ...buildData , buildForDevice : ! device . isEmulator } ) ;
69+ const deviceBuildInfo : IBuildInfo = await this . $buildInfoFileService . getDeviceBuildInfo ( device , projectData ) ;
70+ const localBuildInfo = this . $buildInfoFileService . getLocalBuildInfo ( platformData , { ...buildData , buildForDevice : ! device . isEmulator } ) ;
8971
9072 return ! localBuildInfo || ! deviceBuildInfo || deviceBuildInfo . buildTime !== localBuildInfo . buildTime ;
9173 }
@@ -98,22 +80,12 @@ export class DeviceInstallAppService {
9880 }
9981
10082 let hashes = { } ;
101- const hashesFilePath = path . join ( outputFilePath || platformData . getBuildOutputPath ( null ) , HASHES_FILE_NAME ) ;
83+ const hashesFilePath = path . join ( outputFilePath , HASHES_FILE_NAME ) ;
10284 if ( this . $fs . exists ( hashesFilePath ) ) {
10385 hashes = this . $fs . readJson ( hashesFilePath ) ;
10486 }
10587
10688 await device . fileSystem . updateHashesOnDevice ( hashes , appIdentifier ) ;
10789 }
108-
109- private async getDeviceBuildInfo ( device : Mobile . IDevice , projectData : IProjectData ) : Promise < IBuildInfo > {
110- const deviceFilePath = await this . getDeviceBuildInfoFilePath ( device , projectData ) ;
111- try {
112- const deviceFileContent = await this . $mobileHelper . getDeviceFileContent ( device , deviceFilePath , projectData ) ;
113- return JSON . parse ( deviceFileContent ) ;
114- } catch ( e ) {
115- return null ;
116- }
117- }
11890}
11991$injector . register ( "deviceInstallAppService" , DeviceInstallAppService ) ;
0 commit comments