diff --git a/lib/definitions/platform.d.ts b/lib/definitions/platform.d.ts index 59147db578..9972aeed3e 100644 --- a/lib/definitions/platform.d.ts +++ b/lib/definitions/platform.d.ts @@ -78,6 +78,13 @@ interface IPlatformService extends NodeJS.EventEmitter { */ shouldInstall(device: Mobile.IDevice, projectData: IProjectData, outputPath?: string): Promise; + /** + * Determines whether the project should undergo the prepare process. + * @param {IShouldPrepareInfo} shouldPrepareInfo Options needed to decide whether to prepare. + * @returns {Promise} true indicates that the project should be prepared. + */ + shouldPrepare(shouldPrepareInfo: IShouldPrepareInfo): Promise + /** * Installs the application on specified device. * When finishes, saves .nsbuildinfo in application root folder to indicate the prepare that was used to build the app. @@ -314,11 +321,18 @@ interface IPreparePlatformJSInfo extends IPreparePlatformCoreInfo, ICopyAppFiles projectFilesConfig?: IProjectFilesConfig; } -interface IPreparePlatformCoreInfo extends IPreparePlatformInfoBase { - platformSpecificData: IPlatformSpecificData +interface IShouldPrepareInfo extends IOptionalProjectChangesInfoComposition { + platformInfo: IPreparePlatformInfo; +} + +interface IOptionalProjectChangesInfoComposition { changesInfo?: IProjectChangesInfo; } +interface IPreparePlatformCoreInfo extends IPreparePlatformInfoBase, IOptionalProjectChangesInfoComposition { + platformSpecificData: IPlatformSpecificData +} + interface IPreparePlatformInfo extends IPreparePlatformInfoBase, IPlatformConfig, IPlatformTemplate, ISkipNativeCheckOptional { } interface IPlatformConfig { diff --git a/lib/services/platform-service.ts b/lib/services/platform-service.ts index d955403dd8..a63550a5fa 100644 --- a/lib/services/platform-service.ts +++ b/lib/services/platform-service.ts @@ -187,13 +187,25 @@ export class PlatformService extends EventEmitter implements IPlatformService { return _.filter(this.$platformsData.platformsNames, p => { return this.isPlatformPrepared(p, projectData); }); } - public async preparePlatform(platformInfo: IPreparePlatformInfo): Promise { + @helpers.hook('shouldPrepare') + public async shouldPrepare(shouldPrepareInfo: IShouldPrepareInfo): Promise { + shouldPrepareInfo.changesInfo = shouldPrepareInfo.changesInfo || await this.getChangesInfo(shouldPrepareInfo.platformInfo); + const requiresNativePrepare = (!shouldPrepareInfo.platformInfo.nativePrepare || !shouldPrepareInfo.platformInfo.nativePrepare.skipNativePrepare) && shouldPrepareInfo.changesInfo.nativePlatformStatus === constants.NativePlatformStatus.requiresPrepare; + + return shouldPrepareInfo.changesInfo.hasChanges || requiresNativePrepare; + } + + private async getChangesInfo(platformInfo: IPreparePlatformInfo): Promise { const platformData = this.$platformsData.getPlatformData(platformInfo.platform, platformInfo.projectData); - const changesInfo = await this.initialPrepare(platformInfo.platform, platformData, platformInfo.appFilesUpdaterOptions, platformInfo.platformTemplate, platformInfo.projectData, platformInfo.config, platformInfo.nativePrepare, platformInfo); - const requiresNativePrepare = (!platformInfo.nativePrepare || !platformInfo.nativePrepare.skipNativePrepare) && changesInfo.nativePlatformStatus === constants.NativePlatformStatus.requiresPrepare; + return this.initialPrepare(platformInfo.platform, platformData, platformInfo.appFilesUpdaterOptions, platformInfo.platformTemplate, platformInfo.projectData, platformInfo.config, platformInfo.nativePrepare, platformInfo); + } + + public async preparePlatform(platformInfo: IPreparePlatformInfo): Promise { + const changesInfo = await this.getChangesInfo(platformInfo); + const shouldPrepare = await this.shouldPrepare({ platformInfo, changesInfo }); - if (changesInfo.hasChanges || requiresNativePrepare) { + if (shouldPrepare) { // Always clear up the app directory in platforms if `--bundle` value has changed in between builds or is passed in general // this is done as user has full control over what goes in platforms when `--bundle` is passed // and we may end up with duplicate symbols which would fail the build diff --git a/test/stubs.ts b/test/stubs.ts index 2e32020b30..d9873e7cee 100644 --- a/test/stubs.ts +++ b/test/stubs.ts @@ -613,6 +613,9 @@ export class CommandsService implements ICommandsService { } export class PlatformServiceStub extends EventEmitter implements IPlatformService { + public shouldPrepare(): Promise { + return Promise.resolve(true); + } public validateOptions(): Promise { return Promise.resolve(true);