feat(dacli): report/release.ts 完整 wrapCommand 迁移 (P6 6 exit 收口)
6 处 process.exit(1) → ctx.fail(), 写 CommandLog (L3):
- step 1: id 不存在
- step 1.5a: basic info 校验失败 (fullName/enCode/category)
- step 1.5b: numeric 校验失败 (sortCode/enabledMark)
- step 2: --type=1 必传 --cells 缺失
- step 2.5: --cells 不是合法 JSON
- step 4: 后端 code !== 200
每步 summary 含 id/type/code/msg/errors 详细 (供 dacli log last 复盘).
DEPRECATION 警告 (v0.16+) 保留在 wrapCommand 内, log.warn 进 buffer (quiet
模式下汇总输出, verbose 立即可见), 不影响 exit code.
迁移模式统一:
- import { setupOutputFilter, addOutputOptions, wrapCommand }
- 删本地 --json (改 addOutputOptions 注入)
- Opts interface 加 verbose?: boolean
- .action 开头 setupOutputFilter(opts)
- 整块 step machine (step 1-4) wrapCommand 包 + try/catch → ctx.success/fail
- validateBasicInfo/validateNumeric 错误保留 log.error 输出 (用户感知)
修改方式: Write 整文件重写 (Edit 工具不匹配, step machine 重排风险).
验证:
- TS compile 0 新错误 (baseline 57 不变)
- 73/73 单元测试 PASS
P6 累计: 剩 form/create (13) + workflow/create (9) + form/codegen (8) + workflow/update (6)
+ di/create (6) + bigscreen/construct (6) + app/create (6) + report/update (5) + report/publish (5)
+ report/create (5) + portal/setDefault (5) + form/update (5) = ~73 exit 散布 12 文件.
form/audit.ts + log/last.ts 跳过 (semantic 退出码 / meta-recursive).
This commit is contained in:
1 parent
8b8f9cf5b3
commit
9a59adc9ac
1 file changed
+104
-83
+104
-83
@@ -22,6 +22,7 @@ import { installHelpHook } from '../../core/help.ts'
|
||||
import { log, printJson } from '../../core/log.ts'
|
||||
import { initWebapi as initReportWebapi, loadReport } from '../../webapi/report.ts'
|
||||
import { validateBasicInfo, validateNumeric } from './_validate.ts' // v0.15+ (P1-1)
|
||||
import { setupOutputFilter, addOutputOptions, wrapCommand } from '../_output_filter.ts' // v2.1+ 输出过滤; v2.2+ wrapCommand 收口 5c
|
||||
|
||||
interface ReleaseOpts {
|
||||
id: string
|
||||
@@ -32,6 +33,8 @@ interface ReleaseOpts {
|
||||
queryList?: string
|
||||
versionId?: string
|
||||
json?: boolean
|
||||
/** v2.1+ (2026-07-21): --verbose, addOutputOptions 注入 */
|
||||
verbose?: boolean
|
||||
}
|
||||
|
||||
interface ReportForm {
|
||||
@@ -61,95 +64,113 @@ export function buildReportReleaseCommand(): Command {
|
||||
.option('--columnList <json>', '列定义 JSON 数组字符串')
|
||||
.option('--queryList <json>', '查询参数 JSON 数组字符串')
|
||||
.option('--versionId <id>', '版本 id (留空则创建新版本)')
|
||||
.option('--json', '原始 JSON 输出', false)
|
||||
addOutputOptions(cmd)
|
||||
.action(async (opts: ReleaseOpts) => {
|
||||
// v0.16+ (v0.16-1) DEPRECATION 警告: 引导用户用新命令
|
||||
log.warn('⚠️ report release 命令 v0.16+ 已 deprecated, 推荐用 save/publish 替代')
|
||||
log.warn(' - dacli report save (type=0 隐式, 保存设计)')
|
||||
log.warn(' - dacli report publish (type=1 隐式, 发布+部署)')
|
||||
log.warn(' - release 仍可用到 v0.18 (1 季度 deprecation 周期)')
|
||||
setupOutputFilter(opts)
|
||||
const c = await JnpfClient.fromToken()
|
||||
await initReportWebapi(c)
|
||||
|
||||
// === step 1: 拉报表现状 ===
|
||||
const current = (await loadReport.getReportInfo(opts.id)) as ReportForm
|
||||
if (!current || !current.id) {
|
||||
log.error(`report id=${opts.id} 不存在, 无法 release`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
// === step 1.5: v0.15+ (P1-1) 校验当前报表的 fullName/enCode/category/sortCode ===
|
||||
// 之前 _validate.ts 零引用, release 不校验 → enCode 漂移能过; 现统一从 _validate 走
|
||||
const vBasic = validateBasicInfo({
|
||||
fullName: current.fullName,
|
||||
enCode: current.enCode,
|
||||
category: current.category,
|
||||
})
|
||||
if (!vBasic.ok) {
|
||||
for (const err of vBasic.errors) log.error(` [${vBasic.stepName}] ${err.message}`)
|
||||
process.exit(1)
|
||||
}
|
||||
const vNum = validateNumeric({ sortCode: 0 }) // sortCode 不强制, 只校验 enabledMark 等
|
||||
if (!vNum.ok) {
|
||||
for (const err of vNum.errors) log.error(` [${vNum.stepName}] ${err.message}`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
// === step 2: 校验 type=1 必传 cells ===
|
||||
const releaseType = Number(opts.type || 1)
|
||||
if (releaseType === 1 && !opts.cells) {
|
||||
log.error('--type=1 (发布) 必传 --cells <json> (设计内容不能为空)')
|
||||
log.error('提示: --type=0 (仅保存设计) 不强制 cells, 但仍建议提供')
|
||||
process.exit(1)
|
||||
}
|
||||
// v0.15+ (P2-2): --cells JSON 预校验, 防止双重 stringify 导致设计器反序列化失败
|
||||
if (opts.cells) {
|
||||
await wrapCommand({
|
||||
command: 'report release',
|
||||
appCode: c.appCode,
|
||||
startTime: Date.now(),
|
||||
verbose: opts.verbose,
|
||||
json: opts.json,
|
||||
fixes: [],
|
||||
}, async (ctx) => {
|
||||
try {
|
||||
JSON.parse(opts.cells)
|
||||
// v0.16+ (v0.16-1) DEPRECATION 警告: 引导用户用新命令
|
||||
log.warn('⚠️ report release 命令 v0.16+ 已 deprecated, 推荐用 save/publish 替代')
|
||||
log.warn(' - dacli report save (type=0 隐式, 保存设计)')
|
||||
log.warn(' - dacli report publish (type=1 隐式, 发布+部署)')
|
||||
log.warn(' - release 仍可用到 v0.18 (1 季度 deprecation 周期)')
|
||||
|
||||
await initReportWebapi(c)
|
||||
|
||||
// === step 1: 拉报表现状 ===
|
||||
const current = (await loadReport.getReportInfo(opts.id)) as ReportForm
|
||||
if (!current || !current.id) {
|
||||
log.error(`report id=${opts.id} 不存在, 无法 release`)
|
||||
return ctx.fail(`report id=${opts.id} 不存在`, { id: opts.id })
|
||||
}
|
||||
|
||||
// === step 1.5: v0.15+ (P1-1) 校验当前报表的 fullName/enCode/category/sortCode ===
|
||||
// 之前 _validate.ts 零引用, release 不校验 → enCode 漂移能过; 现统一从 _validate 走
|
||||
const vBasic = validateBasicInfo({
|
||||
fullName: current.fullName,
|
||||
enCode: current.enCode,
|
||||
category: current.category,
|
||||
})
|
||||
if (!vBasic.ok) {
|
||||
for (const err of vBasic.errors) log.error(` [${vBasic.stepName}] ${err.message}`)
|
||||
return ctx.fail(`basic info 校验失败: ${vBasic.errors.length} 条`, { id: opts.id, errors: vBasic.errors.map(e => e.message) })
|
||||
}
|
||||
const vNum = validateNumeric({ sortCode: 0 }) // sortCode 不强制, 只校验 enabledMark 等
|
||||
if (!vNum.ok) {
|
||||
for (const err of vNum.errors) log.error(` [${vNum.stepName}] ${err.message}`)
|
||||
return ctx.fail(`numeric 校验失败: ${vNum.errors.length} 条`, { id: opts.id, errors: vNum.errors.map(e => e.message) })
|
||||
}
|
||||
|
||||
// === step 2: 校验 type=1 必传 cells ===
|
||||
const releaseType = Number(opts.type || 1)
|
||||
if (releaseType === 1 && !opts.cells) {
|
||||
log.error('--type=1 (发布) 必传 --cells <json> (设计内容不能为空)')
|
||||
log.error('提示: --type=0 (仅保存设计) 不强制 cells, 但仍建议提供')
|
||||
return ctx.fail(`--type=1 必传 --cells`, { id: opts.id, type: releaseType })
|
||||
}
|
||||
// v0.15+ (P2-2): --cells JSON 预校验, 防止双重 stringify 导致设计器反序列化失败
|
||||
if (opts.cells) {
|
||||
try {
|
||||
JSON.parse(opts.cells)
|
||||
} catch (e) {
|
||||
log.error(`--cells 不是合法 JSON 字符串: ${(e as Error).message?.slice(0, 100)}`)
|
||||
log.error('提示: 后端 ReportCrForm.cells 是 String, 期望前端传 JSON.stringify 后的结果')
|
||||
return ctx.fail(`--cells 不是合法 JSON 字符串`, { id: opts.id, error: (e as Error).message?.slice(0, 100) })
|
||||
}
|
||||
}
|
||||
|
||||
// === step 3: 构造 saveVersion body (镜像 web 端 Form.vue handleSubmit) ===
|
||||
// 后端 ReportUpForm 要求几乎所有字段都在, 跟 update 一样先 getReportInfo 拿全字段,
|
||||
// 然后 spread 覆盖用户传入字段. 这里与 update 区别是: release 同时支持 type=0/1.
|
||||
// v0.15+ (P1-2): spread 后 delete systemId — 防止 testspace 报表 release 时透传老 systemId
|
||||
// 跨应用污染 (e.g. 切到 workSystem token 后 release testspace 创建的报表)
|
||||
const body: Record<string, unknown> = {
|
||||
...current,
|
||||
id: opts.id,
|
||||
type: releaseType,
|
||||
versionId: opts.versionId || current.versionId || null,
|
||||
}
|
||||
delete body.systemId // P1-2 修复: 让后端按当前 token 自动注入
|
||||
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
|
||||
|
||||
// === step 4: 调 webapi saveReport (Proxy 走 loadReport.saveVersion) ===
|
||||
// web 端 saveVersion 走 reportHttp.post({url: '/api/Report/Save', data}),
|
||||
// 后端返 {code:200, msg:'保存成功', data:null} → shim unwrap 后 data=null.
|
||||
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 release 失败 (code=${code}): ${msg}`)
|
||||
return ctx.fail(`report release 失败 (code=${code}): ${msg}`, { id: opts.id, code })
|
||||
}
|
||||
log.ok(
|
||||
`✓ 报表 ${releaseType === 1 ? '发布' : '保存'}成功 id=${opts.id} ` +
|
||||
`(BS-新116, type=${releaseType}, msg="${msg || '保存成功'}")`,
|
||||
)
|
||||
const summary = { id: opts.id, type: releaseType, code, msg, raw: r }
|
||||
if (opts.json) printJson(summary)
|
||||
ctx.success(summary)
|
||||
} catch (e) {
|
||||
log.error(`--cells 不是合法 JSON 字符串: ${(e as Error).message?.slice(0, 100)}`)
|
||||
log.error('提示: 后端 ReportCrForm.cells 是 String, 期望前端传 JSON.stringify 后的结果')
|
||||
process.exit(1)
|
||||
ctx.fail(`report release 失败: ${(e as Error).message?.slice(0, 200)}`)
|
||||
}
|
||||
}
|
||||
|
||||
// === step 3: 构造 saveVersion body (镜像 web 端 Form.vue handleSubmit) ===
|
||||
// 后端 ReportUpForm 要求几乎所有字段都在, 跟 update 一样先 getReportInfo 拿全字段,
|
||||
// 然后 spread 覆盖用户传入字段. 这里与 update 区别是: release 同时支持 type=0/1.
|
||||
// v0.15+ (P1-2): spread 后 delete systemId — 防止 testspace 报表 release 时透传老 systemId
|
||||
// 跨应用污染 (e.g. 切到 workSystem token 后 release testspace 创建的报表)
|
||||
const body: Record<string, unknown> = {
|
||||
...current,
|
||||
id: opts.id,
|
||||
type: releaseType,
|
||||
versionId: opts.versionId || current.versionId || null,
|
||||
}
|
||||
delete body.systemId // P1-2 修复: 让后端按当前 token 自动注入
|
||||
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
|
||||
|
||||
// === step 4: 调 webapi saveReport (Proxy 走 loadReport.saveVersion) ===
|
||||
// web 端 saveVersion 走 reportHttp.post({url: '/api/Report/Save', data}),
|
||||
// 后端返 {code:200, msg:'保存成功', data:null} → shim unwrap 后 data=null.
|
||||
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 release 失败 (code=${code}): ${msg}`)
|
||||
process.exit(1)
|
||||
}
|
||||
log.ok(
|
||||
`✓ 报表 ${releaseType === 1 ? '发布' : '保存'}成功 id=${opts.id} ` +
|
||||
`(BS-新116, type=${releaseType}, msg="${msg || '保存成功'}")`,
|
||||
)
|
||||
if (opts.json) printJson({ id: opts.id, type: releaseType, code, msg, raw: r })
|
||||
})
|
||||
})
|
||||
installHelpHook(cmd, {
|
||||
purpose:
|
||||
|
||||
Reference in new issue
Block a user