diff --git a/packages/cocos-cli-types/__tests__/__snapshots__/dts-snapshot.test.ts.snap b/packages/cocos-cli-types/__tests__/__snapshots__/dts-snapshot.test.ts.snap index 1c71dccd0..30fd28a5b 100644 --- a/packages/cocos-cli-types/__tests__/__snapshots__/dts-snapshot.test.ts.snap +++ b/packages/cocos-cli-types/__tests__/__snapshots__/dts-snapshot.test.ts.snap @@ -3979,6 +3979,7 @@ export declare interface PlatformConfigItem { pluginPath: string; createTemplateLabel?: string; supportTextureCompress: boolean; + customBuildStages?: IBuildStageItem[]; } export declare interface PlatformPackageOptionMap { 'web-desktop': webDesktopOptions; diff --git a/src/core/builder/@types/protected/build-plugin.ts b/src/core/builder/@types/protected/build-plugin.ts index 28ae545ba..ad1cf5c10 100644 --- a/src/core/builder/@types/protected/build-plugin.ts +++ b/src/core/builder/@types/protected/build-plugin.ts @@ -64,6 +64,7 @@ export interface PlatformConfigItem { pluginPath: string; createTemplateLabel?: string; supportTextureCompress: boolean; + customBuildStages?: IBuildStageItem[]; } export interface IPlatformRegisterInfo { diff --git a/src/core/builder/manager/plugin.ts b/src/core/builder/manager/plugin.ts index 495dcfb1e..70bf318e0 100644 --- a/src/core/builder/manager/plugin.ts +++ b/src/core/builder/manager/plugin.ts @@ -926,17 +926,27 @@ export class PluginManager extends EventEmitter { } public queryPlatformConfig(): PlatformConfigItem[] { - return Object.entries(this.platformConfig).map(([platform, config]) => ({ - platform, - displayName: translateDisplayValue(config.name || platform) || platform, - platformType: config.platformType, - isNative: NATIVE_PLATFORM.includes(platform as Platform), - doc: config.doc, - // 打包平台路径 - pluginPath: config.pluginPath || this.platformRegisterInfoPool.get(platform)?.path || '', - createTemplateLabel: config.createTemplateLabel && translateDisplayValue(config.createTemplateLabel), - supportTextureCompress: !!config.texture, - })); + return Object.entries(this.platformConfig).map(([platform, config]) => { + const customStages = this.customBuildStages[platform]; + const stageConfigs = customStages + ? this.sortPkgNameWidthPriority(Object.keys(customStages)) + .flatMap((pkgName) => customStages[pkgName] || []) + .map((stage) => lodash.cloneDeep(stage)) + : undefined; + + return { + platform, + displayName: translateDisplayValue(config.name || platform) || platform, + platformType: config.platformType, + isNative: NATIVE_PLATFORM.includes(platform as Platform), + doc: config.doc, + // 打包平台路径 + pluginPath: config.pluginPath || this.platformRegisterInfoPool.get(platform)?.path || '', + createTemplateLabel: config.createTemplateLabel && translateDisplayValue(config.createTemplateLabel), + supportTextureCompress: !!config.texture, + customBuildStages: stageConfigs?.length ? stageConfigs : undefined, + }; + }); } public getRegisteredPlatforms(): string[] { diff --git a/src/core/builder/test/query-platform-build-schema.spec.ts b/src/core/builder/test/query-platform-build-schema.spec.ts index 586706ac9..5fdb80f44 100644 --- a/src/core/builder/test/query-platform-build-schema.spec.ts +++ b/src/core/builder/test/query-platform-build-schema.spec.ts @@ -183,6 +183,57 @@ describe('PluginManager platform config schema queries', () => { })); }); + it('queryPlatformConfig returns custom build stages registered from platform config', async () => { + await (pm as any).internalRegister({ + platform: 'test', + path: '/plugins/test', + type: 'register', + config: { + priority: 0, + customBuildStages: [{ + name: 'make', + displayName: 'Make', + description: 'Make Description', + hook: 'make', + }], + }, + }); + await (pm as any).internalRegister({ + platform: 'test', + path: '/plugins/custom', + type: 'plugin', + pkgName: 'custom', + config: { + priority: 10, + customBuildStages: [{ + name: 'deploy', + displayName: 'Deploy', + description: 'Deploy Description', + hook: 'deploy', + hidden: true, + }], + }, + }); + + const [result] = pm.queryPlatformConfig(); + + expect(result.customBuildStages).toEqual([{ + name: 'deploy', + displayName: 'Deploy', + description: 'Deploy Description', + hook: 'deploy', + hidden: true, + }, { + name: 'make', + displayName: 'Make', + description: 'Make Description', + hook: 'make', + }]); + + result.customBuildStages![0].displayName = 'Changed'; + expect((pm as any).customBuildStages.test.custom[0].displayName).toBe('Deploy'); + }); + it('returns common options and platform options for a platform', () => { const result = pm.getPlatformBuildSchema('test');