Skip to content

Commit da752d0

Browse files
committed
fix: move buildinfo related logic to buildInfoFileService
1 parent 0341a15 commit da752d0

File tree

7 files changed

+73
-69
lines changed

7 files changed

+73
-69
lines changed

lib/controllers/build-controller.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ export class BuildController extends EventEmitter implements IBuildController {
5858
await attachAwaitDetach(constants.BUILD_OUTPUT_EVENT_NAME, platformData.platformProjectService, handler, platformData.platformProjectService.buildProject(platformData.projectRoot, projectData, buildData));
5959

6060
const buildInfoFileDir = platformData.getBuildOutputPath(buildData);
61-
this.$buildInfoFileService.saveBuildInfoFile(platformData, buildInfoFileDir);
61+
this.$buildInfoFileService.saveLocalBuildInfo(platformData, buildInfoFileDir);
6262

6363
this.$logger.info("Project successfully built.");
6464

65-
const result = await this.$buildArtefactsService.getLatestApplicationPackagePath(platformData, buildData);
65+
const result = await this.$buildArtefactsService.getLatestAppPackagePath(platformData, buildData);
6666

6767
if (buildData.copyTo) {
68-
this.$buildArtefactsService.copyLastOutput(buildData.copyTo, platformData, buildData);
68+
this.$buildArtefactsService.copyLatestAppPackage(buildData.copyTo, platformData, buildData);
6969
this.$logger.info(`The build result is located at: ${buildInfoFileDir}`);
7070
}
7171

@@ -102,13 +102,13 @@ export class BuildController extends EventEmitter implements IBuildController {
102102
}
103103

104104
const validBuildOutputData = platformData.getValidBuildOutputData(buildData);
105-
const packages = this.$buildArtefactsService.getAllApplicationPackages(outputPath, validBuildOutputData);
105+
const packages = this.$buildArtefactsService.getAllAppPackages(outputPath, validBuildOutputData);
106106
if (packages.length === 0) {
107107
return true;
108108
}
109109

110110
const prepareInfo = this.$projectChangesService.getPrepareInfo(platformData);
111-
const buildInfo = this.$buildInfoFileService.getBuildInfoFromFile(platformData, buildData);
111+
const buildInfo = this.$buildInfoFileService.getLocalBuildInfo(platformData, buildData);
112112
if (!prepareInfo || !buildInfo) {
113113
return true;
114114
}

lib/data/build-data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ export class AndroidBuildData extends BuildData {
5454
this.keyStorePath = data.keyStorePath;
5555
this.keyStoreAliasPassword = data.keyStoreAliasPassword;
5656
this.keyStorePassword = data.keyStorePassword;
57-
this.androidBundle = data.androidBundle;
57+
this.androidBundle = data.androidBundle || data.aab;
5858
}
5959
}

lib/definitions/build.d.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ interface IBuildDataService {
3636
}
3737

3838
interface IBuildArtefactsService {
39-
getLatestApplicationPackagePath(platformData: IPlatformData, buildOutputOptions: IBuildOutputOptions): Promise<string>;
40-
getAllApplicationPackages(buildOutputPath: string, validBuildOutputData: IValidBuildOutputData): IApplicationPackage[];
41-
copyLastOutput(targetPath: string, platformData: IPlatformData, buildOutputOptions: IBuildOutputOptions): void;
39+
getAllAppPackages(buildOutputPath: string, validBuildOutputData: IValidBuildOutputData): IApplicationPackage[];
40+
getLatestAppPackagePath(platformData: IPlatformData, buildOutputOptions: IBuildOutputOptions): Promise<string>;
41+
copyLatestAppPackage(targetPath: string, platformData: IPlatformData, buildOutputOptions: IBuildOutputOptions): void;
4242
}
4343

4444
interface IBuildInfoFileService {
45-
saveBuildInfoFile(platformData: IPlatformData, buildInfoFileDirname: string): void;
46-
getBuildInfoFromFile(platformData: IPlatformData, buildData: IBuildData): IBuildInfo;
45+
getLocalBuildInfo(platformData: IPlatformData, buildData: IBuildData): IBuildInfo;
46+
getDeviceBuildInfo(device: Mobile.IDevice, projectData: IProjectData): Promise<IBuildInfo>;
47+
saveLocalBuildInfo(platformData: IPlatformData, buildInfoFileDirname: string): void;
48+
saveDeviceBuildInfo(device: Mobile.IDevice, projectData: IProjectData, outputFilePath: string): Promise<void>;
4749
}

lib/definitions/run.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ interface IRunEmitter {
2222
interface IDeviceInstallAppService {
2323
installOnDevice(device: Mobile.IDevice, buildData: IBuildData, packageFile?: string): Promise<void>;
2424
installOnDeviceIfNeeded(device: Mobile.IDevice, buildData: IBuildData, packageFile?: string): Promise<void>;
25-
getDeviceBuildInfoFilePath(device: Mobile.IDevice, projectData: IProjectData): Promise<string>;
2625
shouldInstall(device: Mobile.IDevice, buildData: IBuildData): Promise<boolean>;
2726
}
2827

lib/services/build-artefacts-service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export class BuildArtefactsService implements IBuildArtefactsService {
77
private $logger: ILogger
88
) { }
99

10-
public async getLatestApplicationPackagePath(platformData: IPlatformData, buildOutputOptions: IBuildOutputOptions): Promise<string> {
10+
public async getLatestAppPackagePath(platformData: IPlatformData, buildOutputOptions: IBuildOutputOptions): Promise<string> {
1111
const outputPath = buildOutputOptions.outputPath || platformData.getBuildOutputPath(buildOutputOptions);
1212
const applicationPackage = this.getLatestApplicationPackage(outputPath, platformData.getValidBuildOutputData(buildOutputOptions));
1313
const packageFile = applicationPackage.packageName;
@@ -19,7 +19,7 @@ export class BuildArtefactsService implements IBuildArtefactsService {
1919
return packageFile;
2020
}
2121

22-
public getAllApplicationPackages(buildOutputPath: string, validBuildOutputData: IValidBuildOutputData): IApplicationPackage[] {
22+
public getAllAppPackages(buildOutputPath: string, validBuildOutputData: IValidBuildOutputData): IApplicationPackage[] {
2323
const rootFiles = this.$fs.readDirectory(buildOutputPath).map(filename => path.join(buildOutputPath, filename));
2424
let result = this.getApplicationPackagesCore(rootFiles, validBuildOutputData.packageNames);
2525
if (result) {
@@ -40,7 +40,7 @@ export class BuildArtefactsService implements IBuildArtefactsService {
4040
return [];
4141
}
4242

43-
public copyLastOutput(targetPath: string, platformData: IPlatformData, buildOutputOptions: IBuildOutputOptions): void {
43+
public copyLatestAppPackage(targetPath: string, platformData: IPlatformData, buildOutputOptions: IBuildOutputOptions): void {
4444
targetPath = path.resolve(targetPath);
4545

4646
const outputPath = buildOutputOptions.outputPath || platformData.getBuildOutputPath(buildOutputOptions);
@@ -59,7 +59,7 @@ export class BuildArtefactsService implements IBuildArtefactsService {
5959
}
6060

6161
private getLatestApplicationPackage(buildOutputPath: string, validBuildOutputData: IValidBuildOutputData): IApplicationPackage {
62-
let packages = this.getAllApplicationPackages(buildOutputPath, validBuildOutputData);
62+
let packages = this.getAllAppPackages(buildOutputPath, validBuildOutputData);
6363
const packageExtName = path.extname(validBuildOutputData.packageNames[0]);
6464
if (packages.length === 0) {
6565
this.$errors.fail(`No ${packageExtName} found in ${buildOutputPath} directory.`);
Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
11
import * as path from "path";
2+
import * as helpers from "../common/helpers";
23

34
const buildInfoFileName = ".nsbuildinfo";
45

56
export class BuildInfoFileService implements IBuildInfoFileService {
67
constructor(
8+
private $devicePathProvider: IDevicePathProvider,
79
private $fs: IFileSystem,
10+
private $mobileHelper: Mobile.IMobileHelper,
811
private $projectChangesService: IProjectChangesService
912
) { }
1013

11-
public saveBuildInfoFile(platformData: IPlatformData, buildInfoFileDirname: string): void {
12-
const buildInfoFile = path.join(buildInfoFileDirname, buildInfoFileName);
13-
14-
const prepareInfo = this.$projectChangesService.getPrepareInfo(platformData);
15-
const buildInfo: IBuildInfo = {
16-
prepareTime: prepareInfo.changesRequireBuildTime,
17-
buildTime: new Date().toString()
18-
};
19-
20-
this.$fs.writeJson(buildInfoFile, buildInfo);
21-
}
22-
23-
public getBuildInfoFromFile(platformData: IPlatformData, buildData: IBuildData): IBuildInfo {
14+
public getLocalBuildInfo(platformData: IPlatformData, buildData: IBuildData): IBuildInfo {
2415
const outputPath = buildData.outputPath || platformData.getBuildOutputPath(buildData);
2516
const buildInfoFile = path.join(outputPath, buildInfoFileName);
2617
if (this.$fs.exists(buildInfoFile)) {
@@ -34,5 +25,45 @@ export class BuildInfoFileService implements IBuildInfoFileService {
3425

3526
return null;
3627
}
28+
29+
public async getDeviceBuildInfo(device: Mobile.IDevice, projectData: IProjectData): Promise<IBuildInfo> {
30+
const deviceFilePath = await this.getDeviceBuildInfoFilePath(device, projectData);
31+
try {
32+
const deviceFileContent = await this.$mobileHelper.getDeviceFileContent(device, deviceFilePath, projectData);
33+
return JSON.parse(deviceFileContent);
34+
} catch (e) {
35+
return null;
36+
}
37+
}
38+
39+
public saveLocalBuildInfo(platformData: IPlatformData, buildInfoFileDirname: string): void {
40+
const buildInfoFile = path.join(buildInfoFileDirname, buildInfoFileName);
41+
42+
const prepareInfo = this.$projectChangesService.getPrepareInfo(platformData);
43+
const buildInfo: IBuildInfo = {
44+
prepareTime: prepareInfo.changesRequireBuildTime,
45+
buildTime: new Date().toString()
46+
};
47+
48+
this.$fs.writeJson(buildInfoFile, buildInfo);
49+
}
50+
51+
public async saveDeviceBuildInfo(device: Mobile.IDevice, projectData: IProjectData, outputFilePath: string): Promise<void> {
52+
const deviceFilePath = await this.getDeviceBuildInfoFilePath(device, projectData);
53+
const appIdentifier = projectData.projectIdentifiers[device.deviceInfo.platform];
54+
55+
await device.fileSystem.putFile(path.join(outputFilePath, buildInfoFileName), deviceFilePath, appIdentifier);
56+
}
57+
58+
private async getDeviceBuildInfoFilePath(device: Mobile.IDevice, projectData: IProjectData): Promise<string> {
59+
const platform = device.deviceInfo.platform.toLowerCase();
60+
const deviceRootPath = await this.$devicePathProvider.getDeviceProjectRootPath(device, {
61+
appIdentifier: projectData.projectIdentifiers[platform],
62+
getDirname: true
63+
});
64+
const result = helpers.fromWindowsRelativePathToUnix(path.join(deviceRootPath, buildInfoFileName));
65+
66+
return result;
67+
}
3768
}
3869
$injector.register("buildInfoFileService", BuildInfoFileService);
Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
import { TrackActionNames, HASHES_FILE_NAME } from "../../constants";
2-
import * as helpers from "../../common/helpers";
32
import * as path from "path";
43

5-
const buildInfoFileName = ".nsbuildinfo";
6-
74
export 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

Comments
 (0)