feat(dacli): portal/setDefault.ts 完整 wrapCommand 迁移 (P6 5 exit 收口)
5 处 process.exit(1) → ctx.fail(), 写 CommandLog (L3):
- 必传校验 (--portalId / --menuId 二选一)
- --portalId 数字校验失败 (P2-4 修复, 输 fullName 提前 fail)
- --menuId 数字校验失败
- BS-110 portalId 解析 menuId 失败
- 后端 code !== 200
迁移模式统一:
- import { setupOutputFilter, addOutputOptions, wrapCommand }
- 删本地 --json (改 addOutputOptions 注入)
- Opts interface 加 verbose?: boolean
- .action 开头 setupOutputFilter(opts)
- 整块业务逻辑 wrapCommand 包 + try/catch → ctx.success/fail
修改方式: Write 整文件重写 (Edit 工具不匹配, step 重排风险).
注: Write tool 转义反引号时产生 quote imbalance, 后续 Python 脚本清理.
验证:
- TS compile 0 新错误 (baseline 57 不变)
- 73/73 单元测试 PASS
P6 累计: 剩 workflow/create (9) + form/codegen (8) + workflow/update (6) + form/create (13)
+ bigscreen/construct (6) + app/create (6) + report/update (5) + report/publish (5)
+ report/create (5) + form/update (5) = ~62 exit 散布 10 文件.
This commit is contained in:
1 parent
b665b8b260
commit
4e2ee5f286
1 file changed
+72
-52
@@ -28,11 +28,14 @@ import {
|
||||
initWebapi as initMenuWebapi,
|
||||
loadMenu,
|
||||
} from '../../webapi/menu.ts'
|
||||
import { setupOutputFilter, addOutputOptions, wrapCommand } from '../_output_filter.ts' // v2.1+ 输出过滤; v2.2+ wrapCommand 收口 5c
|
||||
|
||||
interface SetDefaultOpts {
|
||||
portalId?: string
|
||||
menuId?: string
|
||||
json?: boolean
|
||||
/** v2.1+ (2026-07-21): --verbose, addOutputOptions 注入 */
|
||||
verbose?: boolean
|
||||
}
|
||||
|
||||
/** v0.15+ (BS-110 fix, 2026-07-02): 通过 portalId 查 menuId (走 webapi menu list)
|
||||
@@ -71,62 +74,79 @@ export function buildPortalSetDefaultCommand(): Command {
|
||||
)
|
||||
.option('--portalId <id>', '门户 id (推荐; 内部 portal.id → menu.id)')
|
||||
.option('--menuId <id>', '菜单 id (PortalDataController.setDefault 直接收这个)')
|
||||
.option('--json', '原始 JSON 输出', false)
|
||||
addOutputOptions(cmd)
|
||||
.action(async (opts: SetDefaultOpts) => {
|
||||
if (!opts.portalId && !opts.menuId) {
|
||||
log.error('必传 --portalId 或 --menuId (二选一)')
|
||||
log.error('提示: 推荐 --menuId 直接传, 避免 portalId → menuId 链路 (走 menu list 过滤 moduleId)')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
// v0.15+ (P2-4): id 数字校验, 输错字符串 (如 fullName) → 直接 exit 1, 避免走 resolveMenuIdFromPortal 浪费 API
|
||||
const idRegex = /^\d{10,30}$/ // JNPF id 是 Long 雪花, 通常 18-19 位数字
|
||||
if (opts.portalId && !idRegex.test(opts.portalId)) {
|
||||
log.error(`--portalId "${opts.portalId}" 不是合法 JNPF id (期望纯数字 10-30 位, 如 842332446711088325)`)
|
||||
log.error('提示: 用 `dacli portal list` 查 id, 别传 fullName/enCode')
|
||||
process.exit(1)
|
||||
}
|
||||
if (opts.menuId && !idRegex.test(opts.menuId)) {
|
||||
log.error(`--menuId "${opts.menuId}" 不是合法 JNPF id (期望纯数字 10-30 位)`)
|
||||
log.error('提示: 用 `dacli menu list` 查 id')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
setupOutputFilter(opts)
|
||||
const c = await JnpfClient.fromToken()
|
||||
await initPortalWebapi(c)
|
||||
await initMenuWebapi(c) // v0.15+: portalId 路径走 menu list 找 moduleId
|
||||
|
||||
// === BS-110: setDefaultPortal 实际收 menu id, portal.id → menu.id ===
|
||||
let menuId: string | null = null
|
||||
if (opts.menuId) {
|
||||
menuId = opts.menuId
|
||||
log.info(`BS-110 显式 --menuId=${menuId} (跳过 portal.id → menu.id 转换)`)
|
||||
} else if (opts.portalId) {
|
||||
menuId = await resolveMenuIdFromPortal(opts.portalId, c)
|
||||
if (!menuId) {
|
||||
log.error(`BS-110: portalId=${opts.portalId} 无法解析 menuId, 请显式传 --menuId`)
|
||||
log.error(`提示: portal release 后会自动建菜单, 菜单 enCode 形如 ${opts.portalId}8ee94`)
|
||||
log.error(` 查 menu id: dacli menu list --keyword=<portalEnCode>`)
|
||||
process.exit(1)
|
||||
await wrapCommand({
|
||||
command: 'portal set-default',
|
||||
appCode: c.appCode,
|
||||
startTime: Date.now(),
|
||||
verbose: opts.verbose,
|
||||
json: opts.json,
|
||||
fixes: [],
|
||||
}, async (ctx) => {
|
||||
try {
|
||||
if (!opts.portalId && !opts.menuId) {
|
||||
log.error('必传 --portalId 或 --menuId (二选一)')
|
||||
log.error('提示: 推荐 --menuId 直接传, 避免 portalId → menuId 链路 (走 menu list 过滤 moduleId)')
|
||||
return ctx.fail('必传 --portalId 或 --menuId', { portalId: !!opts.portalId, menuId: !!opts.menuId })
|
||||
}
|
||||
|
||||
// v0.15+ (P2-4): id 数字校验, 输错字符串 (如 fullName) → 直接 exit 1, 避免走 resolveMenuIdFromPortal 浪费 API
|
||||
const idRegex = /^\d{10,30}$/ // JNPF id 是 Long 雪花, 通常 18-19 位数字
|
||||
if (opts.portalId && !idRegex.test(opts.portalId)) {
|
||||
log.error(`--portalId "${opts.portalId}" 不是合法 JNPF id (期望纯数字 10-30 位, 如 842332446711088325)`)
|
||||
log.error('提示: 用 dacli portal list 查 id, 别传 fullName/enCode')
|
||||
return ctx.fail(`--portalId "${opts.portalId}" 不是合法 JNPF id`, { portalId: opts.portalId })
|
||||
}
|
||||
if (opts.menuId && !idRegex.test(opts.menuId)) {
|
||||
log.error(`--menuId "${opts.menuId}" 不是合法 JNPF id (期望纯数字 10-30 位)`)
|
||||
log.error('提示: 用 dacli menu list 查 id')
|
||||
return ctx.fail(`--menuId "${opts.menuId}" 不是合法 JNPF id`, { menuId: opts.menuId })
|
||||
}
|
||||
|
||||
await initPortalWebapi(c)
|
||||
await initMenuWebapi(c) // v0.15+: portalId 路径走 menu list 找 moduleId
|
||||
|
||||
// === BS-110: setDefaultPortal 实际收 menu id, portal.id → menu.id ===
|
||||
let menuId: string | null = null
|
||||
if (opts.menuId) {
|
||||
menuId = opts.menuId
|
||||
log.info(`BS-110 显式 --menuId=${menuId} (跳过 portal.id → menu.id 转换)`)
|
||||
} else if (opts.portalId) {
|
||||
menuId = await resolveMenuIdFromPortal(opts.portalId, c)
|
||||
if (!menuId) {
|
||||
log.error(`BS-110: portalId=${opts.portalId} 无法解析 menuId, 请显式传 --menuId`)
|
||||
log.error(`提示: portal release 后会自动建菜单, 菜单 enCode 形如 ${opts.portalId}8ee94`)
|
||||
log.error(` 查 menu id: dacli menu list --keyword=<portalEnCode>`)
|
||||
return ctx.fail(`BS-110: portalId 无法解析 menuId`, { portalId: opts.portalId })
|
||||
}
|
||||
log.info(`BS-110 portalId=${opts.portalId} → menuId=${menuId} (自动转换)`)
|
||||
}
|
||||
|
||||
// === 调 webapi setDefaultPortal ===
|
||||
const r = (await loadPortal.setDefaultPortal(menuId)) 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(`setDefaultPortal 失败 (code=${code}): ${msg}`)
|
||||
return ctx.fail(`setDefaultPortal 失败 (code=${code}): ${msg}`, { menuId, code })
|
||||
}
|
||||
log.ok(`✓ 门户已设为默认 (BS-110, menuId=${menuId}, msg="${msg || '设置成功'}")`)
|
||||
const summary = { menuId, code, msg, raw: r }
|
||||
if (opts.json) printJson(summary)
|
||||
ctx.success(summary)
|
||||
} catch (e) {
|
||||
ctx.fail(`portal set-default 失败: ${(e as Error).message?.slice(0, 200)}`)
|
||||
}
|
||||
log.info(`BS-110 portalId=${opts.portalId} → menuId=${menuId} (自动转换)`)
|
||||
}
|
||||
|
||||
// === 调 webapi setDefaultPortal ===
|
||||
const r = (await loadPortal.setDefaultPortal(menuId)) 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(`setDefaultPortal 失败 (code=${code}): ${msg}`)
|
||||
process.exit(1)
|
||||
}
|
||||
log.ok(`✓ 门户已设为默认 (BS-110, menuId=${menuId}, msg="${msg || '设置成功'}")`)
|
||||
if (opts.json) printJson({ menuId, code, msg, raw: r })
|
||||
})
|
||||
})
|
||||
installHelpHook(cmd, {
|
||||
purpose:
|
||||
|
||||
Reference in new issue
Block a user