feat(dacli): report/publish.ts 完整 wrapCommand 迁移 (P6 5 exit 收口)
5 处 process.exit(1) → ctx.fail(): - 拉原报表失败 - validateReportCreate 校验失败 (basic info 缺) - --cells 必传缺失 (publish 隐式 type=1) - --cells 不是合法 JSON - 后端 code !== 200 (含 enhanceFromBackend 错误增强) 修改方式: Write 整文件重写. 与 report/release/update 同 pattern (P2-2 cells JSON 预校验保留). 验证: - TS compile 0 新错误 (baseline 57 不变) - 73/73 单元测试 PASS
This commit is contained in:
1 parent
06224b8133
commit
39166d11c6
1 file changed
+82
-62
@@ -26,6 +26,7 @@ import { log, printJson } from '../../core/log.ts'
|
||||
import { initWebapi as initReportWebapi, loadReport } from '../../webapi/report.ts'
|
||||
import { validateReportCreate } from './_validate.ts'
|
||||
import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts'
|
||||
import { setupOutputFilter, addOutputOptions, wrapCommand } from '../_output_filter.ts' // v2.1+ 输出过滤; v2.2+ wrapCommand 收口 5c
|
||||
|
||||
interface PublishOpts {
|
||||
id: string
|
||||
@@ -35,6 +36,8 @@ interface PublishOpts {
|
||||
queryList?: string
|
||||
versionId?: string
|
||||
json?: boolean
|
||||
/** v2.1+ (2026-07-21): --verbose, addOutputOptions 注入 */
|
||||
verbose?: boolean
|
||||
}
|
||||
|
||||
export function buildReportPublishCommand(): Command {
|
||||
@@ -48,72 +51,89 @@ export function buildReportPublishCommand(): Command {
|
||||
.option('--columnList <json>', '列定义 JSON 数组字符串')
|
||||
.option('--queryList <json>', '查询参数 JSON 数组字符串')
|
||||
.option('--versionId <id>', '版本 id (留空则创建新版本)')
|
||||
.option('--json', '原始 JSON 输出', false)
|
||||
addOutputOptions(cmd)
|
||||
.action(async (opts: PublishOpts) => {
|
||||
setupOutputFilter(opts)
|
||||
const c = await JnpfClient.fromToken()
|
||||
await initReportWebapi(c)
|
||||
|
||||
// 拉原报表 (跟 update 一致)
|
||||
const current = (await loadReport.getReportInfo(opts.id)) as Record<string, unknown>
|
||||
if (!current || !current.id) {
|
||||
log.error(`report publish 失败: 拉原报表 id=${opts.id} 失败`)
|
||||
process.exit(1)
|
||||
}
|
||||
await wrapCommand({
|
||||
command: 'report publish',
|
||||
appCode: c.appCode,
|
||||
startTime: Date.now(),
|
||||
verbose: opts.verbose,
|
||||
json: opts.json,
|
||||
fixes: [],
|
||||
}, async (ctx) => {
|
||||
try {
|
||||
await initReportWebapi(c)
|
||||
|
||||
// step machine 校验 (validateReportCreate 返 {ok, steps: StepValidation[]})
|
||||
const vBasic = validateReportCreate({
|
||||
fullName: current.fullName as string,
|
||||
enCode: current.enCode as string,
|
||||
category: current.category as string,
|
||||
})
|
||||
if (!vBasic.ok) {
|
||||
for (const step of vBasic.steps) {
|
||||
for (const err of step.errors) log.error(` [${step.stepName}] ${err.message}`)
|
||||
// 拉原报表 (跟 update 一致)
|
||||
const current = (await loadReport.getReportInfo(opts.id)) as Record<string, unknown>
|
||||
if (!current || !current.id) {
|
||||
log.error(`report publish 失败: 拉原报表 id=${opts.id} 失败`)
|
||||
return ctx.fail(`report id=${opts.id} 不存在`, { id: opts.id })
|
||||
}
|
||||
|
||||
// step machine 校验 (validateReportCreate 返 {ok, steps: StepValidation[]})
|
||||
const vBasic = validateReportCreate({
|
||||
fullName: current.fullName as string,
|
||||
enCode: current.enCode as string,
|
||||
category: current.category as string,
|
||||
})
|
||||
if (!vBasic.ok) {
|
||||
for (const step of vBasic.steps) {
|
||||
for (const err of step.errors) log.error(` [${step.stepName}] ${err.message}`)
|
||||
}
|
||||
return ctx.fail(`basic info 校验失败: ${vBasic.steps.reduce((n, s) => n + s.errors.length, 0)} 条`, { id: opts.id })
|
||||
}
|
||||
|
||||
// v0.16+ (P2-2): --cells 必传 (type=1 必填) + JSON 预校验
|
||||
if (!opts.cells) {
|
||||
log.error('--cells 必传 (publish 隐式 type=1, 后端要求 cells 非空)')
|
||||
return ctx.fail(`--cells 必传`, { id: opts.id })
|
||||
}
|
||||
try {
|
||||
JSON.parse(opts.cells)
|
||||
} catch (e) {
|
||||
log.error(`--cells 不是合法 JSON 字符串: ${(e as Error).message?.slice(0, 100)}`)
|
||||
return ctx.fail(`--cells 不是合法 JSON 字符串`, { id: opts.id, error: (e as Error).message?.slice(0, 100) })
|
||||
}
|
||||
|
||||
// 构造 body (跟 release --type=1 一致, type 写死 1)
|
||||
const body: Record<string, unknown> = {
|
||||
...current,
|
||||
id: opts.id,
|
||||
type: 1, // v0.16+ publish 隐式 type=1 (真正发布+部署)
|
||||
versionId: opts.versionId || current.versionId || null,
|
||||
}
|
||||
if (opts.cells !== undefined) body.cells = opts.cells
|
||||
if (opts.dataSets !== undefined) body.dataSetList = opts.dataSets
|
||||
if (opts.columnList !== undefined) body.columnList = opts.columnList
|
||||
if (opts.queryList !== undefined) body.queryList = opts.queryList
|
||||
|
||||
// 调 webapi saveVersion (走 web 端镜像, 端点 /api/Report/Save type=1)
|
||||
const r = (await loadReport.saveVersion(body)) as unknown
|
||||
let code: number | undefined
|
||||
let msg: string | undefined
|
||||
if (r && typeof r === 'object') {
|
||||
const obj = r as { code?: number; msg?: string }
|
||||
code = obj.code
|
||||
msg = obj.msg
|
||||
}
|
||||
if (code !== undefined && code !== 200) {
|
||||
log.error(`report publish 失败 (code=${code}): ${msg}`)
|
||||
const enhanced = enhanceFromBackend(msg || '', 'report', { entity: 'report' })
|
||||
log.error(` ${formatErrorLine(enhanced, { step: 1, stepName: '后端API' })}`)
|
||||
return ctx.fail(`report publish 失败 (code=${code}): ${msg}`, { id: opts.id, code })
|
||||
}
|
||||
log.ok(`✓ 报表已发布+部署 id=${opts.id} (v0.16+ 新 publish 命令, type=1)`)
|
||||
const summary = { id: opts.id, code, msg, raw: r }
|
||||
if (opts.json) printJson(summary)
|
||||
ctx.success(summary)
|
||||
} catch (e) {
|
||||
ctx.fail(`report publish 失败: ${(e as Error).message?.slice(0, 200)}`)
|
||||
}
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
// v0.16+ (P2-2): --cells 必传 (type=1 必填) + JSON 预校验
|
||||
if (!opts.cells) {
|
||||
log.error('--cells 必传 (publish 隐式 type=1, 后端要求 cells 非空)')
|
||||
process.exit(1)
|
||||
}
|
||||
try {
|
||||
JSON.parse(opts.cells)
|
||||
} catch (e) {
|
||||
log.error(`--cells 不是合法 JSON 字符串: ${(e as Error).message?.slice(0, 100)}`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
// 构造 body (跟 release --type=1 一致, type 写死 1)
|
||||
const body: Record<string, unknown> = {
|
||||
...current,
|
||||
id: opts.id,
|
||||
type: 1, // v0.16+ publish 隐式 type=1 (真正发布+部署)
|
||||
versionId: opts.versionId || current.versionId || null,
|
||||
}
|
||||
if (opts.cells !== undefined) body.cells = opts.cells
|
||||
if (opts.dataSets !== undefined) body.dataSetList = opts.dataSets
|
||||
if (opts.columnList !== undefined) body.columnList = opts.columnList
|
||||
if (opts.queryList !== undefined) body.queryList = opts.queryList
|
||||
|
||||
// 调 webapi saveVersion (走 web 端镜像, 端点 /api/Report/Save type=1)
|
||||
const r = (await loadReport.saveVersion(body)) as unknown
|
||||
let code: number | undefined
|
||||
let msg: string | undefined
|
||||
if (r && typeof r === 'object') {
|
||||
const obj = r as { code?: number; msg?: string }
|
||||
code = obj.code
|
||||
msg = obj.msg
|
||||
}
|
||||
if (code !== undefined && code !== 200) {
|
||||
log.error(`report publish 失败 (code=${code}): ${msg}`)
|
||||
const enhanced = enhanceFromBackend(msg || '', 'report', { entity: 'report' })
|
||||
log.error(` ${formatErrorLine(enhanced, { step: 1, stepName: '后端API' })}`)
|
||||
process.exit(1)
|
||||
}
|
||||
log.ok(`✓ 报表已发布+部署 id=${opts.id} (v0.16+ 新 publish 命令, type=1)`)
|
||||
if (opts.json) printJson({ id: opts.id, code, msg, raw: r })
|
||||
})
|
||||
})
|
||||
installHelpHook(cmd, {
|
||||
purpose: '发布+部署报表 (v0.16+ 新增, 替代 release --type=1)',
|
||||
@@ -143,4 +163,4 @@ export function buildReportPublishCommand(): Command {
|
||||
],
|
||||
})
|
||||
return cmd
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user