-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathbuild-info-file-service.ts
69 lines (57 loc) · 2.56 KB
/
build-info-file-service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import * as path from "path";
import * as helpers from "../common/helpers";
const buildInfoFileName = ".nsbuildinfo";
export class BuildInfoFileService implements IBuildInfoFileService {
constructor(
private $devicePathProvider: IDevicePathProvider,
private $fs: IFileSystem,
private $mobileHelper: Mobile.IMobileHelper,
private $projectChangesService: IProjectChangesService
) { }
public getLocalBuildInfo(platformData: IPlatformData, buildData: IBuildData): IBuildInfo {
const outputPath = buildData.outputPath || platformData.getBuildOutputPath(buildData);
const buildInfoFile = path.join(outputPath, buildInfoFileName);
if (this.$fs.exists(buildInfoFile)) {
try {
const buildInfo = this.$fs.readJson(buildInfoFile);
return buildInfo;
} catch (e) {
return null;
}
}
return null;
}
public async getDeviceBuildInfo(device: Mobile.IDevice, projectData: IProjectData): Promise<IBuildInfo> {
const deviceFilePath = await this.getDeviceBuildInfoFilePath(device, projectData);
try {
const deviceFileContent = await this.$mobileHelper.getDeviceFileContent(device, deviceFilePath, projectData);
return JSON.parse(deviceFileContent);
} catch (e) {
return null;
}
}
public saveLocalBuildInfo(platformData: IPlatformData, buildInfoFileDirname: string): void {
const buildInfoFile = path.join(buildInfoFileDirname, buildInfoFileName);
const prepareInfo = this.$projectChangesService.getPrepareInfo(platformData);
const buildInfo: IBuildInfo = {
prepareTime: prepareInfo.changesRequireBuildTime,
buildTime: new Date().toString()
};
this.$fs.writeJson(buildInfoFile, buildInfo);
}
public async saveDeviceBuildInfo(device: Mobile.IDevice, projectData: IProjectData, outputFilePath: string): Promise<void> {
const deviceFilePath = await this.getDeviceBuildInfoFilePath(device, projectData);
const appIdentifier = projectData.projectIdentifiers[device.deviceInfo.platform.toLowerCase()];
await device.fileSystem.putFile(path.join(outputFilePath, buildInfoFileName), deviceFilePath, appIdentifier);
}
private async getDeviceBuildInfoFilePath(device: Mobile.IDevice, projectData: IProjectData): Promise<string> {
const platform = device.deviceInfo.platform.toLowerCase();
const deviceRootPath = await this.$devicePathProvider.getDeviceProjectRootPath(device, {
appIdentifier: projectData.projectIdentifiers[platform],
getDirname: true
});
const result = helpers.fromWindowsRelativePathToUnix(path.join(deviceRootPath, buildInfoFileName));
return result;
}
}
$injector.register("buildInfoFileService", BuildInfoFileService);