diff --git a/lib/controllers/prepare-controller.ts b/lib/controllers/prepare-controller.ts index 6680861f12..4fe1c87582 100644 --- a/lib/controllers/prepare-controller.ts +++ b/lib/controllers/prepare-controller.ts @@ -47,7 +47,7 @@ export class PrepareController extends EventEmitter { result = { hasNativeChanges, platform: prepareData.platform.toLowerCase() }; } - this.$projectChangesService.savePrepareInfo(platformData); + await this.$projectChangesService.savePrepareInfo(platformData, projectData, prepareData); this.$logger.info(`Project successfully prepared (${prepareData.platform.toLowerCase()})`); diff --git a/lib/services/platform/add-platform-service.ts b/lib/services/platform/add-platform-service.ts index 115fe3d1b7..e97e3b801b 100644 --- a/lib/services/platform/add-platform-service.ts +++ b/lib/services/platform/add-platform-service.ts @@ -61,7 +61,7 @@ export class AddPlatformService implements IAddPlatformService { platformData.platformProjectService.ensureConfigurationFileInAppResources(projectData); await platformData.platformProjectService.interpolateData(projectData); platformData.platformProjectService.afterCreateProject(platformData.projectRoot, projectData); - this.$projectChangesService.setNativePlatformStatus(platformData, { nativePlatformStatus: NativePlatformStatus.requiresPrepare }); + await this.$projectChangesService.setNativePlatformStatus(platformData, projectData, { nativePlatformStatus: NativePlatformStatus.requiresPrepare }); } } $injector.register("addPlatformService", AddPlatformService); diff --git a/lib/services/platform/prepare-native-platform-service.ts b/lib/services/platform/prepare-native-platform-service.ts index 6328c50955..6b3549cb3f 100644 --- a/lib/services/platform/prepare-native-platform-service.ts +++ b/lib/services/platform/prepare-native-platform-service.ts @@ -47,7 +47,7 @@ export class PrepareNativePlatformService implements IPrepareNativePlatformServi } platformData.platformProjectService.interpolateConfigurationFile(projectData); - this.$projectChangesService.setNativePlatformStatus(platformData, { nativePlatformStatus: NativePlatformStatus.alreadyPrepared }); + await this.$projectChangesService.setNativePlatformStatus(platformData, projectData, { nativePlatformStatus: NativePlatformStatus.alreadyPrepared }); return hasChanges; } diff --git a/lib/services/project-changes-service.ts b/lib/services/project-changes-service.ts index 8148b806aa..6df11e4140 100644 --- a/lib/services/project-changes-service.ts +++ b/lib/services/project-changes-service.ts @@ -136,12 +136,16 @@ export class ProjectChangesService implements IProjectChangesService { return prepareInfo; } - public savePrepareInfo(platformData: IPlatformData): void { + public async savePrepareInfo(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise { + if (!this._prepareInfo) { + await this.ensurePrepareInfo(platformData, projectData, prepareData); + } + const prepareInfoFilePath = this.getPrepareInfoFilePath(platformData); this.$fs.writeJson(prepareInfoFilePath, this._prepareInfo); } - public setNativePlatformStatus(platformData: IPlatformData, addedPlatform: IAddedNativePlatform): void { + public async setNativePlatformStatus(platformData: IPlatformData, projectData: IProjectData, addedPlatform: IAddedNativePlatform): Promise { this._prepareInfo = this._prepareInfo || this.getPrepareInfo(platformData); if (this._prepareInfo && addedPlatform.nativePlatformStatus === NativePlatformStatus.alreadyPrepared) { this._prepareInfo.nativePlatformStatus = addedPlatform.nativePlatformStatus; @@ -151,7 +155,7 @@ export class ProjectChangesService implements IProjectChangesService { }; } - this.savePrepareInfo(platformData); + await this.savePrepareInfo(platformData, projectData, null); } private async ensurePrepareInfo(platformData: IPlatformData, projectData: IProjectData, prepareData: PrepareData): Promise { diff --git a/lib/services/webpack/webpack.d.ts b/lib/services/webpack/webpack.d.ts index e6732c79b3..3a597b4ae2 100644 --- a/lib/services/webpack/webpack.d.ts +++ b/lib/services/webpack/webpack.d.ts @@ -19,8 +19,8 @@ declare global { checkForChanges(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise; getPrepareInfoFilePath(platformData: IPlatformData): string; getPrepareInfo(platformData: IPlatformData): IPrepareInfo; - savePrepareInfo(platformData: IPlatformData): void; - setNativePlatformStatus(platformData: IPlatformData, addedPlatform: IAddedNativePlatform): void; + savePrepareInfo(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise; + setNativePlatformStatus(platformData: IPlatformData, projectData: IProjectData, addedPlatform: IAddedNativePlatform): void; currentChanges: IProjectChangesInfo; } diff --git a/test/project-changes-service.ts b/test/project-changes-service.ts index b7bd3ffdfd..737e3e66c5 100644 --- a/test/project-changes-service.ts +++ b/test/project-changes-service.ts @@ -170,9 +170,9 @@ describe("Project Changes Service Tests", () => { }); describe("setNativePlatformStatus", () => { - it("creates prepare info and sets only the native platform status when there isn't an existing prepare info", () => { + it("creates prepare info and sets only the native platform status when there isn't an existing prepare info", async () => { for (const platform of ["ios", "android"]) { - serviceTest.projectChangesService.setNativePlatformStatus(serviceTest.getPlatformData(platform), { nativePlatformStatus: Constants.NativePlatformStatus.requiresPrepare }); + await serviceTest.projectChangesService.setNativePlatformStatus(serviceTest.getPlatformData(platform), serviceTest.projectData, { nativePlatformStatus: Constants.NativePlatformStatus.requiresPrepare }); const actualPrepareInfo = serviceTest.projectChangesService.getPrepareInfo(serviceTest.getPlatformData(platform)); @@ -183,10 +183,10 @@ describe("Project Changes Service Tests", () => { it(`shouldn't reset prepare info when native platform status is ${Constants.NativePlatformStatus.alreadyPrepared} and there is existing prepare info`, async () => { for (const platform of ["ios", "android"]) { await serviceTest.projectChangesService.checkForChanges(serviceTest.getPlatformData(platform), serviceTest.projectData, {}); - serviceTest.projectChangesService.savePrepareInfo(serviceTest.getPlatformData(platform)); + await serviceTest.projectChangesService.savePrepareInfo(serviceTest.getPlatformData(platform), serviceTest.projectData, null); const prepareInfo = serviceTest.projectChangesService.getPrepareInfo(serviceTest.getPlatformData(platform)); - serviceTest.projectChangesService.setNativePlatformStatus(serviceTest.getPlatformData(platform), { nativePlatformStatus: Constants.NativePlatformStatus.alreadyPrepared }); + await serviceTest.projectChangesService.setNativePlatformStatus(serviceTest.getPlatformData(platform), serviceTest.projectData, { nativePlatformStatus: Constants.NativePlatformStatus.alreadyPrepared }); const actualPrepareInfo = serviceTest.projectChangesService.getPrepareInfo(serviceTest.getPlatformData(platform)); prepareInfo.nativePlatformStatus = Constants.NativePlatformStatus.alreadyPrepared; @@ -198,7 +198,7 @@ describe("Project Changes Service Tests", () => { it(`should reset prepare info when native platform status is ${nativePlatformStatus} and there is existing prepare info`, async () => { for (const platform of ["ios", "android"]) { await serviceTest.projectChangesService.checkForChanges(serviceTest.getPlatformData(platform), serviceTest.projectData, {}); - serviceTest.projectChangesService.setNativePlatformStatus(serviceTest.getPlatformData(platform), { nativePlatformStatus: nativePlatformStatus }); + await serviceTest.projectChangesService.setNativePlatformStatus(serviceTest.getPlatformData(platform), serviceTest.projectData, { nativePlatformStatus: nativePlatformStatus }); const actualPrepareInfo = serviceTest.projectChangesService.getPrepareInfo(serviceTest.getPlatformData(platform)); assert.deepEqual(actualPrepareInfo, { nativePlatformStatus: nativePlatformStatus }); diff --git a/test/stubs.ts b/test/stubs.ts index e61e357fae..353a0162d4 100644 --- a/test/stubs.ts +++ b/test/stubs.ts @@ -749,7 +749,7 @@ export class ProjectChangesService implements IProjectChangesService { return null; } - public savePrepareInfo(platformData: IPlatformData): void { + public async savePrepareInfo(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise { } public getPrepareInfoFilePath(platformData: IPlatformData): string { @@ -760,7 +760,7 @@ export class ProjectChangesService implements IProjectChangesService { return {}; } - public setNativePlatformStatus(platformData: IPlatformData, addedPlatform: IAddedNativePlatform): void { + public async setNativePlatformStatus(platformData: IPlatformData, projectData: IProjectData, addedPlatform: IAddedNativePlatform): Promise { return; } }