diff --git a/lib/definitions/project-changes.d.ts b/lib/definitions/project-changes.d.ts index 9096f1cee9..7da52ca180 100644 --- a/lib/definitions/project-changes.d.ts +++ b/lib/definitions/project-changes.d.ts @@ -1,14 +1,14 @@ interface IAppFilesHashes { - appFilesHashes: IStringDictionary; + appFilesHashes?: IStringDictionary; } interface IPrepareInfo extends IAddedNativePlatform, IAppFilesHashes { - time: string; - bundle: boolean; - release: boolean; - projectFileHash: string; - changesRequireBuild: boolean; - changesRequireBuildTime: string; + time?: string; + bundle?: boolean; + release?: boolean; + projectFileHash?: string; + changesRequireBuild?: boolean; + changesRequireBuildTime?: string; iOSProvisioningProfileUUID?: string; } diff --git a/lib/services/platform-service.ts b/lib/services/platform-service.ts index 364b9953f4..dde16c0de0 100644 --- a/lib/services/platform-service.ts +++ b/lib/services/platform-service.ts @@ -806,10 +806,10 @@ export class PlatformService extends EventEmitter implements IPlatformService { private shouldPersistWebpackFiles(platform: string, projectData: IProjectData, prepareInfo: IPrepareInfo, appFilesUpdaterOptions: IAppFilesUpdaterOptions, nativePrepare: INativePrepare): boolean { const hasPlatformDirectory = this.hasPlatformDirectory(platform, projectData); const isWebpackWatcherStarted = this.$usbLiveSyncService.isInitialized; - const hasNativePlatformStatus = !prepareInfo || !prepareInfo.nativePlatformStatus; + const hasNativePlatformStatus = prepareInfo && prepareInfo.nativePlatformStatus; const requiresPlatformAdd = prepareInfo && prepareInfo.nativePlatformStatus === constants.NativePlatformStatus.requiresPlatformAdd; const shouldAddNativePlatform = !nativePrepare || !nativePrepare.skipNativePrepare; - const shouldAddPlatform = hasNativePlatformStatus || (requiresPlatformAdd && shouldAddNativePlatform); + const shouldAddPlatform = !hasNativePlatformStatus || (requiresPlatformAdd && shouldAddNativePlatform); const result = appFilesUpdaterOptions.bundle && isWebpackWatcherStarted && hasPlatformDirectory && shouldAddPlatform; return result; } diff --git a/lib/services/prepare-platform-native-service.ts b/lib/services/prepare-platform-native-service.ts index 1c788c9ff9..e1f01e57b7 100644 --- a/lib/services/prepare-platform-native-service.ts +++ b/lib/services/prepare-platform-native-service.ts @@ -19,6 +19,8 @@ export class PreparePlatformNativeService extends PreparePlatformService impleme info.platformData.platformProjectService.ensureConfigurationFileInAppResources(info.projectData); await info.platformData.platformProjectService.interpolateData(info.projectData, info.config); info.platformData.platformProjectService.afterCreateProject(info.platformData.projectRoot, info.projectData); + this.$projectChangesService.setNativePlatformStatus(info.platformData.normalizedPlatformName, info.projectData, + { nativePlatformStatus: constants.NativePlatformStatus.requiresPrepare }); } public async preparePlatform(config: IPreparePlatformJSInfo): Promise { @@ -111,7 +113,7 @@ export class PreparePlatformNativeService extends PreparePlatformService impleme } const previousPrepareInfo = this.$projectChangesService.getPrepareInfo(platform, projectData); - if (!previousPrepareInfo) { + if (!previousPrepareInfo || previousPrepareInfo.nativePlatformStatus !== constants.NativePlatformStatus.alreadyPrepared) { return; } diff --git a/lib/services/project-changes-service.ts b/lib/services/project-changes-service.ts index fd828b92bd..ac3be05546 100644 --- a/lib/services/project-changes-service.ts +++ b/lib/services/project-changes-service.ts @@ -173,8 +173,13 @@ export class ProjectChangesService implements IProjectChangesService { this._prepareInfo = this._prepareInfo || this.getPrepareInfo(platform, projectData); if (this._prepareInfo) { this._prepareInfo.nativePlatformStatus = addedPlatform.nativePlatformStatus; - this.savePrepareInfo(platform, projectData); + } else { + this._prepareInfo = { + nativePlatformStatus: addedPlatform.nativePlatformStatus + }; } + + this.savePrepareInfo(platform, projectData); } private async ensurePrepareInfo(platform: string, projectData: IProjectData, projectChangesOptions: IProjectChangesOptions): Promise { diff --git a/test/platform-service.ts b/test/platform-service.ts index 8fbdf85ec8..9d280bb9db 100644 --- a/test/platform-service.ts +++ b/test/platform-service.ts @@ -921,6 +921,7 @@ describe('Platform Service Tests', () => { appResourcesDestinationDirectoryPath: testDirData.appResourcesFolderPath, normalizedPlatformName: "Android", projectRoot: testDirData.tempFolder, + configurationFileName: "configFileName", platformProjectService: { prepareProject: (): any => null, prepareAppResources: (): any => null, diff --git a/test/project-changes-service.ts b/test/project-changes-service.ts index 8dd5f7946d..47eae49639 100644 --- a/test/project-changes-service.ts +++ b/test/project-changes-service.ts @@ -176,4 +176,16 @@ describe("Project Changes Service Tests", () => { assert.isFalse(!!androidChanges.signingChanged, "Android signingChanged expected to be false"); }); }); + + describe("setNativePlatformStatus", () => { + it("creates prepare info and sets only the native platform status when there isn't an existing prepare info", () => { + for (const platform of ["ios", "android"]) { + serviceTest.projectChangesService.setNativePlatformStatus(platform, serviceTest.projectData, { nativePlatformStatus: Constants.NativePlatformStatus.requiresPrepare }); + + const actualPrepareInfo = serviceTest.projectChangesService.getPrepareInfo(platform, serviceTest.projectData); + + assert.deepEqual(actualPrepareInfo, { nativePlatformStatus: Constants.NativePlatformStatus.requiresPrepare }); + } + }); + }); }); diff --git a/test/stubs.ts b/test/stubs.ts index 0708ee4dc2..f27c7f3d45 100644 --- a/test/stubs.ts +++ b/test/stubs.ts @@ -303,7 +303,7 @@ export class ProjectDataStub implements IProjectData { projectDir: string; projectName: string; get platformsDir(): string { - return this.plafromsDir; + return this.plafromsDir || (this.projectDir && path.join(this.projectDir, "platforms")) || ""; } set platformsDir(value) { this.plafromsDir = value;