1
1
import { TrackActionNames , HASHES_FILE_NAME } from "../../constants" ;
2
- import * as helpers from "../../common/helpers" ;
3
2
import * as path from "path" ;
4
3
5
- const buildInfoFileName = ".nsbuildinfo" ;
6
-
7
4
export class DeviceInstallAppService {
8
5
constructor (
9
6
private $analyticsService : IAnalyticsService ,
10
7
private $buildArtefactsService : IBuildArtefactsService ,
11
- private $devicePathProvider : IDevicePathProvider ,
8
+ private $buildInfoFileService : IBuildInfoFileService ,
12
9
private $fs : IFileSystem ,
13
10
private $logger : ILogger ,
14
11
private $mobileHelper : Mobile . IMobileHelper ,
15
- private $buildInfoFileService : IBuildInfoFileService ,
16
12
private $projectDataService : IProjectDataService ,
17
13
private $platformsDataService : IPlatformsDataService
18
14
) { }
19
15
20
16
public async installOnDevice ( device : Mobile . IDevice , buildData : IBuildData , packageFile ?: string ) : Promise < void > {
21
17
this . $logger . info ( `Installing on device ${ device . deviceInfo . identifier } ...` ) ;
22
18
19
+ const platform = device . deviceInfo . platform . toLowerCase ( ) ;
23
20
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 ) ;
25
22
26
23
await this . $analyticsService . trackEventActionInGoogleAnalytics ( {
27
24
action : TrackActionNames . Deploy ,
@@ -30,31 +27,25 @@ export class DeviceInstallAppService {
30
27
} ) ;
31
28
32
29
if ( ! packageFile ) {
33
- packageFile = await this . $buildArtefactsService . getLatestApplicationPackagePath ( platformData , buildData ) ;
30
+ packageFile = await this . $buildArtefactsService . getLatestAppPackagePath ( platformData , buildData ) ;
34
31
}
35
32
36
33
await platformData . platformProjectService . cleanDeviceTempFolder ( device . deviceInfo . identifier , projectData ) ;
37
34
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 ) ;
40
37
41
- const outputFilePath = buildData . outputPath ;
38
+ await device . applicationManager . reinstallApplication ( appIdentifier , packageFile ) ;
42
39
43
40
await this . updateHashesOnDevice ( {
44
41
device,
45
- appIdentifier : projectData . projectIdentifiers [ platform ] ,
42
+ appIdentifier,
46
43
outputFilePath,
47
44
platformData
48
45
} ) ;
49
46
50
47
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 ) ;
58
49
}
59
50
60
51
this . $logger . info ( `Successfully installed on device with identifier '${ device . deviceInfo . identifier } '.` ) ;
@@ -67,15 +58,6 @@ export class DeviceInstallAppService {
67
58
}
68
59
}
69
60
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
-
79
61
public async shouldInstall ( device : Mobile . IDevice , buildData : IBuildData ) : Promise < boolean > {
80
62
const projectData = this . $projectDataService . getProjectData ( buildData . projectDir ) ;
81
63
const platformData = this . $platformsDataService . getPlatformData ( device . deviceInfo . platform , projectData ) ;
@@ -84,8 +66,8 @@ export class DeviceInstallAppService {
84
66
return true ;
85
67
}
86
68
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 } ) ;
89
71
90
72
return ! localBuildInfo || ! deviceBuildInfo || deviceBuildInfo . buildTime !== localBuildInfo . buildTime ;
91
73
}
@@ -98,22 +80,12 @@ export class DeviceInstallAppService {
98
80
}
99
81
100
82
let hashes = { } ;
101
- const hashesFilePath = path . join ( outputFilePath || platformData . getBuildOutputPath ( null ) , HASHES_FILE_NAME ) ;
83
+ const hashesFilePath = path . join ( outputFilePath , HASHES_FILE_NAME ) ;
102
84
if ( this . $fs . exists ( hashesFilePath ) ) {
103
85
hashes = this . $fs . readJson ( hashesFilePath ) ;
104
86
}
105
87
106
88
await device . fileSystem . updateHashesOnDevice ( hashes , appIdentifier ) ;
107
89
}
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
- }
118
90
}
119
91
$injector . register ( "deviceInstallAppService" , DeviceInstallAppService ) ;
0 commit comments