diff --git a/packages/uni-cli-shared/src/json/app/manifest/plus.ts b/packages/uni-cli-shared/src/json/app/manifest/plus.ts index 99c714ddc3ff6ece2f7607c9f87cfe0804034b32..0752417dd16e00e1fd2d6bbac34d34bd0c63fbd0 100644 --- a/packages/uni-cli-shared/src/json/app/manifest/plus.ts +++ b/packages/uni-cli-shared/src/json/app/manifest/plus.ts @@ -1,3 +1,4 @@ +import { isArray } from '@vue/shared' import { recursive } from 'merge' const wxPageOrientationMapping = { auto: [ @@ -14,15 +15,7 @@ export function initPlus( manifestJson: Record, pagesJson: UniApp.PagesJson ) { - // 根节点配置了统计 - if (manifestJson.uniStatistics) { - manifestJson.plus.uniStatistics = recursive( - true, - manifestJson.uniStatistics, - manifestJson.plus.uniStatistics - ) - delete manifestJson.uniStatistics - } + initUniStatistics(manifestJson) // 转换为老版本配置 if (manifestJson.plus.modules) { manifestJson.permissions = manifestJson.plus.modules @@ -102,3 +95,50 @@ export function initPlus( manifestJson.plus.popGesture = 'close' } } + +function initUniStatistics(manifestJson: Record) { + // 根节点配置了统计 + if (manifestJson.uniStatistics) { + manifestJson.plus.uniStatistics = recursive( + true, + manifestJson.uniStatistics, + manifestJson.plus.uniStatistics + ) + delete manifestJson.uniStatistics + } + if (!process.env.UNI_CLOUD_SPACES) { + return + } + let spaces = [] + try { + spaces = JSON.parse(process.env.UNI_CLOUD_SPACES) + } catch (e: any) {} + if (!isArray(spaces) || !spaces.length) { + return + } + const space = spaces[0] as { + provider?: string + id: string + name: string + clientSecret?: string + apiEndpoint?: string + } + if (!space) { + return + } + const uniStatistics = manifestJson.plus?.uniStatistics + if (!uniStatistics) { + return + } + if (uniStatistics.version === 2 || uniStatistics.version === '2') { + if (uniStatistics.uniCloud && uniStatistics.uniCloud.spaceId) { + return + } + uniStatistics.uniCloud = { + provider: space.provider, + spaceId: space.id, + clientSecret: space.clientSecret, + endpoint: space.apiEndpoint, + } + } +}