2026-07-26 23:47:30 +08:00
|
|
|
import { readFileSync } from 'node:fs'
|
|
|
|
|
import { createRequire } from 'node:module'
|
|
|
|
|
import path from 'node:path'
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 整包与插件发布共用的配置验证门禁。只阻断新产物;已安装 App 不在线查询吊销状态。
|
|
|
|
|
*/
|
2026-07-27 00:39:26 +08:00
|
|
|
export async function validateReleaseConfig({ projectRoot, packageName }) {
|
2026-07-26 23:47:30 +08:00
|
|
|
const hostRequire = createRequire(path.join(projectRoot, 'package.json'))
|
|
|
|
|
const commonMetro = hostRequire('@xuqm/rn-common/metro')
|
|
|
|
|
const configFile = commonMetro.findConfigFile(projectRoot)
|
|
|
|
|
if (!configFile) {
|
|
|
|
|
throw new Error('exactly one .xuqmconfig file is required in src/assets/config for Release')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const content = readFileSync(configFile, 'utf8').trim()
|
|
|
|
|
const resolved = commonMetro.decryptConfigAtBuildTime(content)
|
2026-07-27 00:39:26 +08:00
|
|
|
if (typeof packageName !== 'string' || packageName.trim() === '') {
|
|
|
|
|
throw new Error('A package identity is required for Release validation')
|
|
|
|
|
}
|
2026-07-26 23:47:30 +08:00
|
|
|
const response = await fetch(
|
|
|
|
|
`${String(resolved.serverUrl).replace(/\/$/, '')}/api/sdk/build/config/validate`,
|
|
|
|
|
{
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: { 'Content-Type': 'application/json' },
|
2026-07-27 00:39:26 +08:00
|
|
|
body: JSON.stringify({ content, packageName }),
|
2026-07-26 23:47:30 +08:00
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
throw new Error(`Release config validation service failed: HTTP ${response.status}`)
|
|
|
|
|
}
|
|
|
|
|
const payload = await response.json()
|
|
|
|
|
const result = payload.data ?? payload
|
|
|
|
|
if (result.valid !== true) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
`Release config rejected (${result.errorCode ?? 'CONFIG_INVALID'}): ${result.message ?? 'unknown error'}`,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|