feat(dacli): portal/datasource/apis 残留 wrapCommand 迁移 (6 exit 收口)
portal/info+release, datasource/delete (--yes 检查移入 ctx.fail), apis/info. portal/release 保留 BS-109 自动检测逻辑, 2 exit → ctx.fail. apis meta 模块 wrapCommand 化. Co-Authored-By: Claude <[email protected]>
This commit is contained in:
1 parent
980dbedbbd
commit
d8df559075
4 files changed
+116
-66
No files matched your search
+54
-39
@@ -19,8 +19,9 @@ import { JnpfClient } from '../../core/client.ts'
|
||||
import { installHelpHook } from '../../core/help.ts'
|
||||
import { log, printJson } from '../../core/log.ts'
|
||||
import { loadOpenApi, type OpenApiDoc } from './_cache.ts'
|
||||
import { setupOutputFilter, addOutputOptions, wrapCommand } from '../_output_filter.ts' // v2.1+ 输出过滤; v2.2+ wrapCommand 收口 5c
|
||||
|
||||
interface Opts { json?: boolean }
|
||||
interface Opts { json?: boolean; verbose?: boolean }
|
||||
|
||||
function parsePathMethod(input: string): { method: string; path: string } {
|
||||
// 形如 "GET /api/xxx" 或 "GET|/api/xxx" 或 "/api/xxx" (默认 GET)
|
||||
@@ -95,47 +96,61 @@ export function buildApisInfoCommand(): Command {
|
||||
const cmd = new Command('info')
|
||||
.description('查单个 API 详情 + 递归解析 $ref (展开 ActionResult.data 内层 schema)')
|
||||
.argument('<pathMethod>', 'API 路径: "GET /api/xxx" 或 "/api/xxx" (默认 GET)')
|
||||
.option('--json', '原始 JSON 输出', false)
|
||||
addOutputOptions(cmd)
|
||||
.action(async (pathMethod: string, opts: Opts) => {
|
||||
setupOutputFilter(opts)
|
||||
const c = await JnpfClient.fromToken()
|
||||
const { method, path } = parsePathMethod(pathMethod)
|
||||
const doc = await loadOpenApi(c)
|
||||
const pathNode = doc.paths[path]
|
||||
if (!pathNode) {
|
||||
const available = Object.keys(doc.paths).filter(p => p.includes(path.split('/').pop() || 'xxx'))
|
||||
log.error(`path 不存在: ${path}`)
|
||||
if (available.length) log.info(`相似 path: ${available.slice(0, 5).join(', ')}`)
|
||||
process.exit(1)
|
||||
}
|
||||
const op = pathNode[method.toLowerCase()]
|
||||
if (!op) {
|
||||
const availableMethods = Object.keys(pathNode)
|
||||
log.error(`method 不存在: ${method} ${path}`)
|
||||
log.info(`该 path 可用 method: ${availableMethods.join(', ')}`)
|
||||
process.exit(1)
|
||||
}
|
||||
const resolved = resolveOpSchemas(op, doc)
|
||||
const out = { method, path, detail: op, resolvedSchemas: resolved }
|
||||
if (opts.json) { printJson(out); return }
|
||||
log.info(`${method} ${path} 详情`)
|
||||
console.log(` summary : ${op.summary || '(无)'}`)
|
||||
console.log(` tags : ${(op.tags || []).join(', ')}`)
|
||||
console.log(` operationId: ${op.operationId || '(无)'}`)
|
||||
console.log(` parameters : ${op.parameters?.length || 0} 个`)
|
||||
console.log(` responses : ${Object.keys(op.responses || {}).length} 个`)
|
||||
const rs = resolved as { requestBody?: any; responses?: any }
|
||||
if (rs.requestBody?.schemaName) {
|
||||
console.log(` requestBody: ${rs.requestBody.schemaName} (自动解析 $ref)`)
|
||||
}
|
||||
if (rs.responses) {
|
||||
for (const [code, r] of Object.entries(rs.responses) as [string, any][]) {
|
||||
const label = r.schemaName ? `${r.schemaName}${r.data ? `.data→${r.data.schemaName || r.data.inline?.type || '?'}` : ''}` : '(inline)'
|
||||
console.log(` ${code} response: ${label}`)
|
||||
|
||||
await wrapCommand({
|
||||
command: 'apis info',
|
||||
appCode: c.appCode,
|
||||
startTime: Date.now(),
|
||||
verbose: opts.verbose,
|
||||
json: opts.json,
|
||||
fixes: [],
|
||||
}, async (ctx) => {
|
||||
try {
|
||||
const { method, path } = parsePathMethod(pathMethod)
|
||||
const doc = await loadOpenApi(c)
|
||||
const pathNode = doc.paths[path]
|
||||
if (!pathNode) {
|
||||
const available = Object.keys(doc.paths).filter(p => p.includes(path.split('/').pop() || 'xxx'))
|
||||
if (available.length) log.info(`相似 path: ${available.slice(0, 5).join(', ')}`)
|
||||
return ctx.fail(`path 不存在: ${path}`, { path, method })
|
||||
}
|
||||
const op = pathNode[method.toLowerCase()]
|
||||
if (!op) {
|
||||
const availableMethods = Object.keys(pathNode)
|
||||
log.info(`该 path 可用 method: ${availableMethods.join(', ')}`)
|
||||
return ctx.fail(`method 不存在: ${method} ${path}`, { path, method })
|
||||
}
|
||||
const resolved = resolveOpSchemas(op, doc)
|
||||
const out = { method, path, detail: op, resolvedSchemas: resolved }
|
||||
if (opts.json) { printJson(out); return ctx.success({ path, method }) }
|
||||
log.info(`${method} ${path} 详情`)
|
||||
console.log(` summary : ${op.summary || '(无)'}`)
|
||||
console.log(` tags : ${(op.tags || []).join(', ')}`)
|
||||
console.log(` operationId: ${op.operationId || '(无)'}`)
|
||||
console.log(` parameters : ${op.parameters?.length || 0} 个`)
|
||||
console.log(` responses : ${Object.keys(op.responses || {}).length} 个`)
|
||||
const rs = resolved as { requestBody?: any; responses?: any }
|
||||
if (rs.requestBody?.schemaName) {
|
||||
console.log(` requestBody: ${rs.requestBody.schemaName} (自动解析 $ref)`)
|
||||
}
|
||||
if (rs.responses) {
|
||||
for (const [code, r] of Object.entries(rs.responses) as [string, any][]) {
|
||||
const label = r.schemaName ? `${r.schemaName}${r.data ? `.data→${r.data.schemaName || r.data.inline?.type || '?'}` : ''}` : '(inline)'
|
||||
console.log(` ${code} response: ${label}`)
|
||||
}
|
||||
}
|
||||
console.log()
|
||||
console.log(' 完整 JSON (含 resolvedSchemas):')
|
||||
console.log(' ' + JSON.stringify(out, null, 2).split('\n').join('\n '))
|
||||
ctx.success({ path, method })
|
||||
} catch (e) {
|
||||
ctx.fail(`apis info 失败: ${(e as Error).message?.slice(0, 200)}`)
|
||||
}
|
||||
}
|
||||
console.log()
|
||||
console.log(' 完整 JSON (含 resolvedSchemas):')
|
||||
console.log(' ' + JSON.stringify(out, null, 2).split('\n').join('\n '))
|
||||
})
|
||||
})
|
||||
|
||||
installHelpHook(cmd, {
|
||||
|
||||
@@ -30,12 +30,6 @@ export function buildDatasourceDeleteCommand(): Command {
|
||||
setupOutputFilter(opts)
|
||||
const c = await JnpfClient.fromToken()
|
||||
|
||||
// 无 --yes 时: UX 流程控制, 不属命令失败, 不落 CommandLog (与其他 delete 命令一致)
|
||||
if (!opts.yes) {
|
||||
log.warn(`即将删除数据源 id=${opts.id}, 加 --yes 跳过确认`)
|
||||
process.exit(2)
|
||||
}
|
||||
|
||||
await wrapCommand({
|
||||
command: 'datasource delete',
|
||||
appCode: c.appCode,
|
||||
@@ -44,6 +38,9 @@ export function buildDatasourceDeleteCommand(): Command {
|
||||
json: opts.json,
|
||||
fixes: [],
|
||||
}, async (ctx) => {
|
||||
if (!opts.yes) {
|
||||
return ctx.fail(`即将删除数据源 id=${opts.id}, 加 --yes 跳过确认`, { id: opts.id })
|
||||
}
|
||||
await initWebapi(c)
|
||||
const r = (await loadDataSource.delDataSource(opts.id)) as { code?: number; msg?: string }
|
||||
if (r.code !== undefined && r.code !== 200) {
|
||||
|
||||
+36
-18
@@ -10,36 +10,54 @@ import { JnpfClient } from '../../core/client.ts'
|
||||
import { installHelpHook } from '../../core/help.ts'
|
||||
import { log, printJson } from '../../core/log.ts'
|
||||
import { initWebapi as initPortalWebapi, loadPortal } from '../../webapi/portal.ts'
|
||||
import { setupOutputFilter, addOutputOptions, wrapCommand } from '../_output_filter.ts' // v2.1+ 输出过滤; v2.2+ wrapCommand 收口 5c
|
||||
|
||||
interface InfoOpts {
|
||||
id: string
|
||||
json?: boolean
|
||||
/** v2.1+ (2026-07-21): --verbose, addOutputOptions 注入 */
|
||||
verbose?: boolean
|
||||
}
|
||||
|
||||
export function buildPortalInfoCommand(): Command {
|
||||
const cmd = new Command('info')
|
||||
.description('查看门户详情 (含布局 schema)')
|
||||
.requiredOption('--id <id>', '门户 id')
|
||||
.option('--json', '原始 JSON 输出', false)
|
||||
addOutputOptions(cmd)
|
||||
.action(async (opts: InfoOpts) => {
|
||||
setupOutputFilter(opts)
|
||||
const c = await JnpfClient.fromToken()
|
||||
await initPortalWebapi(c)
|
||||
// webapi getInfo 已 unwrap: 返回 portal 对象直接 (含 fullName, enCode, category, formData...)
|
||||
const d = (await loadPortal.getInfo(opts.id)) as Record<string, unknown>
|
||||
if (!d || !d.id) {
|
||||
log.error(`门户 id=${opts.id} 不存在或后端返空`)
|
||||
process.exit(1)
|
||||
}
|
||||
if (opts.json) {
|
||||
printJson(d)
|
||||
return
|
||||
}
|
||||
log.info(`门户 id=${opts.id} 名称=${d.fullName} 编码=${d.enCode}`)
|
||||
console.log(`category: ${d.category}`)
|
||||
console.log(`type: ${d.type}`)
|
||||
console.log(`platform: ${d.platform || '-'}`)
|
||||
console.log(`--- 完整 JSON (含 formData 布局) ---`)
|
||||
printJson(d)
|
||||
|
||||
await wrapCommand({
|
||||
command: 'portal info',
|
||||
appCode: c.appCode,
|
||||
startTime: Date.now(),
|
||||
verbose: opts.verbose,
|
||||
json: opts.json,
|
||||
fixes: [],
|
||||
}, async (ctx) => {
|
||||
try {
|
||||
await initPortalWebapi(c)
|
||||
// webapi getInfo 已 unwrap: 返回 portal 对象直接 (含 fullName, enCode, category, formData...)
|
||||
const d = (await loadPortal.getInfo(opts.id)) as Record<string, unknown>
|
||||
if (!d || !d.id) {
|
||||
return ctx.fail(`门户 id=${opts.id} 不存在或后端返空`, { id: opts.id })
|
||||
}
|
||||
if (opts.json) {
|
||||
printJson(d)
|
||||
return ctx.success({ id: opts.id })
|
||||
}
|
||||
log.info(`门户 id=${opts.id} 名称=${d.fullName} 编码=${d.enCode}`)
|
||||
console.log(`category: ${d.category}`)
|
||||
console.log(`type: ${d.type}`)
|
||||
console.log(`platform: ${d.platform || '-'}`)
|
||||
console.log(`--- 完整 JSON (含 formData 布局) ---`)
|
||||
printJson(d)
|
||||
ctx.success({ id: opts.id, enCode: d.enCode })
|
||||
} catch (e) {
|
||||
ctx.fail(`portal info 失败: ${(e as Error).message?.slice(0, 200)}`)
|
||||
}
|
||||
})
|
||||
})
|
||||
installHelpHook(cmd, {
|
||||
purpose: '查看门户的完整 schema (含布局/组件)',
|
||||
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
} from '../../webapi/portal.ts'
|
||||
import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts'
|
||||
import { loadAppContext } from '../app/context.ts'
|
||||
import { setupOutputFilter, addOutputOptions, wrapCommand } from '../_output_filter.ts' // v2.1+ 输出过滤; v2.2+ wrapCommand 收口 5c
|
||||
|
||||
interface ReleaseOpts {
|
||||
id: string
|
||||
@@ -36,6 +37,9 @@ interface ReleaseOpts {
|
||||
pcModuleParentId?: string
|
||||
appSystemId?: string
|
||||
appModuleParentId?: string
|
||||
json?: boolean
|
||||
/** v2.1+ (2026-07-21): --verbose, addOutputOptions 注入 */
|
||||
verbose?: boolean
|
||||
}
|
||||
|
||||
export function buildPortalReleaseCommand(): Command {
|
||||
@@ -50,9 +54,21 @@ export function buildPortalReleaseCommand(): Command {
|
||||
.option('--pcModuleParentId <id>', 'PC 端菜单父级 id (BS-109, 不传自动检测顶级菜单)')
|
||||
.option('--appSystemId <id>', 'App 端 systemId (BS-109)')
|
||||
.option('--appModuleParentId <id>', 'App 端菜单父级 id (BS-109, 不传自动检测顶级菜单)')
|
||||
addOutputOptions(cmd)
|
||||
.action(async (opts: ReleaseOpts) => {
|
||||
setupOutputFilter(opts)
|
||||
// === step 0 校验 --id + --pc/--app 参数 ===
|
||||
const c = await JnpfClient.fromToken()
|
||||
|
||||
await wrapCommand({
|
||||
command: 'portal release',
|
||||
appCode: c.appCode,
|
||||
startTime: Date.now(),
|
||||
verbose: opts.verbose,
|
||||
json: opts.json,
|
||||
fixes: [],
|
||||
}, async (ctx) => {
|
||||
try {
|
||||
await initPortalWebapi(c)
|
||||
|
||||
// === step 0.5 BS-109: 自动检测 pcModuleParentId/appModuleParentId ===
|
||||
@@ -157,16 +173,20 @@ export function buildPortalReleaseCommand(): Command {
|
||||
)) as typeof r
|
||||
}
|
||||
} catch (e) {
|
||||
log.error(` release 异常: ${(e as Error).message?.slice(0, 200)}`)
|
||||
process.exit(1)
|
||||
return ctx.fail(`portal release 异常: ${(e as Error).message?.slice(0, 200)}`, { id: opts.id })
|
||||
}
|
||||
const rCode = r.code ?? 200
|
||||
if (rCode !== 200) {
|
||||
const enhanced = enhanceFromBackend(r.msg || '', 'portal', { entity: 'portal' })
|
||||
log.error(` ${formatErrorLine(enhanced, { step: 0, stepName: '后端API' })}`)
|
||||
process.exit(1)
|
||||
return ctx.fail(`portal release 失败 (code=${rCode}): ${r.msg}`, { id: opts.id, code: rCode })
|
||||
}
|
||||
log.info(`✓ 门户 id=${opts.id} 已发布 (pc=${pc} app=${app}${pcModuleParentId ? `, 挂菜单父级 ${pcModuleParentId}` : ''})`)
|
||||
ctx.success({ id: opts.id, pc, app })
|
||||
} catch (e) {
|
||||
ctx.fail(`portal release 失败: ${(e as Error).message?.slice(0, 200)}`)
|
||||
}
|
||||
})
|
||||
})
|
||||
installHelpHook(cmd, {
|
||||
purpose: '发布门户 (state 0→1, 必传 pc/app/platformRelease 三参; BS-109 自动检测 pcModuleParentId)',
|
||||
|
||||
Reference in new issue
Block a user