W9-D1+D2+D3: app 多 app 生命周期 (14 应用) + bigscreen 20 张 + print 9 模板; 3 baseline + 15 单测 PASS

This commit is contained in:
ssw committed 2026-06-12 22:38:29 +08:00
1 parent b5da75b1db
commit 66dfb159cf
16 files changed
+793 -19

No files matched your search

+64
View File
@@ -0,0 +1,64 @@
#!/usr/bin/env bash
# examples/baseline/app.sh — app 端到端 baseline 验证
#
# 用法: bash examples/baseline/app.sh
# 验证: list (>= 1 应用) / info (id 存在) / initapp (健康检查 OK)
set -e
cd "$(dirname "$0")/../../../../.."
echo "=== dacli app baseline ==="
# 1. list — 验证至少有 1 个应用
LIST_OUT=$(npx tsx src/cli.ts app list 2>&1)
COUNT=$(echo "$LIST_OUT" | grep -E "^\s*[0-9]+\s+" | wc -l)
echo " list: $COUNT 个应用"
if [ "$COUNT" -lt 1 ]; then
echo " ✗ baseline FAIL: 应用数 < 1"
echo " Output: $LIST_OUT"
exit 1
fi
echo " ✓ list PASS (>= 1)"
# 2. info — 取 list 第一行 id
FIRST_ID=$(echo "$LIST_OUT" | grep -E "^\s*[0-9]+\s+" | head -1 | awk '{print $1}')
FIRST_NAME=$(echo "$LIST_OUT" | grep -E "^\s*[0-9]+\s+" | head -1 | awk '{print $2}')
echo ""
echo " 测试: info --id=$FIRST_ID (name=$FIRST_NAME)"
INFO_LOG=/tmp/dacli-baseline-app-info-$FIRST_ID.log
npx tsx src/cli.ts app info --id="$FIRST_ID" > "$INFO_LOG" 2>&1 || true
head -5 "$INFO_LOG"
if grep -qi "不存在\|失败" "$INFO_LOG"; then
echo " ✗ baseline FAIL: info 找不到 id=$FIRST_ID"
exit 1
fi
if grep -q "$FIRST_NAME" "$INFO_LOG"; then
echo " ✓ info PASS (name 匹配)"
else
echo " ✗ baseline FAIL: info name 不匹配"
exit 1
fi
rm -f "$INFO_LOG"
# 3. initapp — 健康检查
echo ""
echo " 测试: initapp (健康检查)"
INIT_LOG=/tmp/dacli-baseline-app-initapp.log
npx tsx src/cli.ts app initapp > "$INIT_LOG" 2>&1 || true
head -3 "$INIT_LOG"
if grep -qi "✗\|不健康" "$INIT_LOG"; then
echo " ✗ baseline FAIL: JNPF 不健康"
cat "$INIT_LOG"
exit 1
fi
if grep -q "健康" "$INIT_LOG"; then
echo " ✓ initapp PASS (JNPF 健康)"
else
echo " ✗ baseline FAIL: initapp 输出异常"
cat "$INIT_LOG"
exit 1
fi
rm -f "$INIT_LOG"
echo ""
echo "=== baseline PASS: app list+info+initapp 端到端跑通 ==="
+70
View File
@@ -0,0 +1,70 @@
#!/usr/bin/env bash
# examples/baseline/bigscreen.sh — bigscreen 端到端 baseline 验证
#
# 用法: bash examples/baseline/bigscreen.sh
# 验证: list (>= 2 大屏) / info (id 存在) / create 200
set -e
cd "$(dirname "$0")/../../../../.."
echo "=== dacli bigscreen baseline ==="
# 1. list — 验证至少有 2 张大屏
LIST_OUT=$(npx tsx src/cli.ts bigscreen list 2>&1)
COUNT=$(echo "$LIST_OUT" | grep -E "^\s*[0-9]+\s+" | wc -l)
echo " list: $COUNT 张大屏"
if [ "$COUNT" -lt 2 ]; then
echo " ✗ baseline FAIL: 大屏数 < 2 (如果基线没建大屏, 跑 create 2 次重建)"
# 自动建 2 张兜底
for i in 1 2; do
TS=$(date +%s%N | cut -c1-13)
npx tsx src/cli.ts bigscreen create --fullName="dacli_baseline_$TS" --enCode="dacli_baseline_$TS" --category=1 > /dev/null 2>&1 || true
done
LIST_OUT=$(npx tsx src/cli.ts bigscreen list 2>&1)
COUNT=$(echo "$LIST_OUT" | grep -E "^\s*[0-9]+\s+" | wc -l)
if [ "$COUNT" -lt 2 ]; then
echo " ✗ baseline FAIL: 兜底建表后仍 < 2"
exit 1
fi
echo " (兜底建了 2 张, 当前 $COUNT 张)"
fi
echo " ✓ list PASS (>= 2)"
# 2. info — 取 list 第一行 id
FIRST_ID=$(echo "$LIST_OUT" | grep -E "^\s*[0-9]+\s+" | head -1 | awk '{print $1}')
FIRST_NAME=$(echo "$LIST_OUT" | grep -E "^\s*[0-9]+\s+" | head -1 | awk '{print $2}')
echo ""
echo " 测试: info --id=$FIRST_ID (name=$FIRST_NAME)"
INFO_LOG=/tmp/dacli-baseline-bigscreen-info-$FIRST_ID.log
npx tsx src/cli.ts bigscreen info --id="$FIRST_ID" > "$INFO_LOG" 2>&1 || true
head -5 "$INFO_LOG"
if grep -qi "不存在" "$INFO_LOG"; then
echo " ✗ baseline FAIL: info 找不到 id=$FIRST_ID"
exit 1
fi
if grep -q "$FIRST_NAME" "$INFO_LOG"; then
echo " ✓ info PASS (name 匹配)"
else
echo " ✗ baseline FAIL: info name 不匹配"
exit 1
fi
rm -f "$INFO_LOG"
# 3. create — 验证 200
TS=$(date +%s%N | cut -c1-13)
NAME="dacli_bs_$TS"
echo ""
echo " 测试: create $NAME"
CREATE_LOG=/tmp/dacli-baseline-bigscreen-create-$TS.log
npx tsx src/cli.ts bigscreen create --fullName="$NAME" --enCode="$NAME" --category=1 > "$CREATE_LOG" 2>&1 || true
head -3 "$CREATE_LOG"
if grep -qi "失败\|System abnormality" "$CREATE_LOG"; then
echo " ✗ baseline FAIL: bigscreen create 失败"
cat "$CREATE_LOG"
exit 1
fi
echo " ✓ create PASS (返 200)"
rm -f "$CREATE_LOG"
echo ""
echo "=== baseline PASS: bigscreen list+info+create 端到端跑通 ==="
+60
View File
@@ -0,0 +1,60 @@
#!/usr/bin/env bash
# examples/baseline/print.sh — print 端到端 baseline 验证
#
# 用法: bash examples/baseline/print.sh
# 验证: list (>= 1 模板) / info (id 存在) / create 200
set -e
cd "$(dirname "$0")/../../../../.."
echo "=== dacli print baseline ==="
# 1. list — 验证至少有 1 个打印模板
LIST_OUT=$(npx tsx src/cli.ts print list 2>&1)
COUNT=$(echo "$LIST_OUT" | grep -E "^\s*[0-9]+\s+" | wc -l)
echo " list: $COUNT 个打印模板"
if [ "$COUNT" -lt 1 ]; then
echo " ✗ baseline FAIL: 模板数 < 1"
echo " Output: $LIST_OUT"
exit 1
fi
echo " ✓ list PASS (>= 1)"
# 2. info — 取 list 第一行 id
FIRST_ID=$(echo "$LIST_OUT" | grep -E "^\s*[0-9]+\s+" | head -1 | awk '{print $1}')
FIRST_NAME=$(echo "$LIST_OUT" | grep -E "^\s*[0-9]+\s+" | head -1 | awk '{print $2}')
echo ""
echo " 测试: info --id=$FIRST_ID (name=$FIRST_NAME)"
INFO_LOG=/tmp/dacli-baseline-print-info-$FIRST_ID.log
npx tsx src/cli.ts print info --id="$FIRST_ID" > "$INFO_LOG" 2>&1 || true
head -5 "$INFO_LOG"
if grep -qi "不存在\|失败" "$INFO_LOG"; then
echo " ✗ baseline FAIL: info 找不到 id=$FIRST_ID"
exit 1
fi
if grep -q "$FIRST_NAME" "$INFO_LOG"; then
echo " ✓ info PASS (name 匹配)"
else
echo " ✗ baseline FAIL: info name 不匹配"
exit 1
fi
rm -f "$INFO_LOG"
# 3. create — 创建测试模板
TS=$(date +%s)
NAME="dacli_print_$TS"
echo ""
echo " 测试: create $NAME"
CREATE_LOG=/tmp/dacli-baseline-print-create-$TS.log
npx tsx src/cli.ts print create --fullName="$NAME" --enCode="$NAME" --category=1 > "$CREATE_LOG" 2>&1 || true
head -3 "$CREATE_LOG"
if grep -qi "失败\|System abnormality" "$CREATE_LOG"; then
echo " ✗ baseline FAIL: print create 失败"
cat "$CREATE_LOG"
exit 1
fi
echo " ✓ create PASS (返 200)"
rm -f "$CREATE_LOG"
echo ""
echo "=== baseline PASS: print list+info+create 端到端跑通 ==="
+6
View File
@@ -23,6 +23,8 @@ import { buildDatasourceCommand } from './commands/datasource/index.ts'
import { buildReportCommand } from './commands/report/index.ts'
import { buildPortalCommand } from './commands/portal/index.ts'
import { buildBigscreenCommand } from './commands/bigscreen/index.ts'
import { buildAppCommand } from './commands/app/index.ts'
import { buildPrintCommand } from './commands/print/index.ts'
import { maybeInterceptAiHelp } from './core/help.ts'
import { log } from './core/log.ts'
import { DacliError } from './core/types.ts'
@@ -54,6 +56,10 @@ program.addCommand(buildDatasourceCommand())
program.addCommand(buildReportCommand())
program.addCommand(buildPortalCommand())
program.addCommand(buildBigscreenCommand())
// v0.8 W9-D1 新增 1 父命令
program.addCommand(buildAppCommand())
// v0.8 W9-D3 新增 1 父命令
program.addCommand(buildPrintCommand())
// ----- main -----
// AI flag 拦截 (在 parse 之前, 避免 requiredOption 校验失败)
+22
View File
@@ -0,0 +1,22 @@
/**
* commands/app/index.ts — app 父命令
*
* JNPF 多 app 生命周期 (appCenter + appConfig/*)
*
* 子命令:
* list 列出所有应用
* info 应用详情
* initapp 应用初始化 (健康检查 / 重启)
*/
import { Command } from 'commander'
import { buildAppListCommand } from './list.ts'
import { buildAppInfoCommand } from './info.ts'
import { buildAppInitappCommand } from './initapp.ts'
export function buildAppCommand(): Command {
const cmd = new Command('app').description('应用 (JNPF 多 app 生命周期, appCenter)')
cmd.addCommand(buildAppListCommand())
cmd.addCommand(buildAppInfoCommand())
cmd.addCommand(buildAppInitappCommand())
return cmd
}
+51
View File
@@ -0,0 +1,51 @@
/**
* commands/app/info.ts — 应用详情
*
* API: GET /api/system/System/{id}
*/
import { Command } from 'commander'
import { JnpfClient } from '../../core/client.ts'
import { installAiHelpHook } from '../../core/help.ts'
import { log, printJson } from '../../core/log.ts'
interface InfoOpts {
id: string
json?: boolean
}
export function buildAppInfoCommand(): Command {
const cmd = new Command('info')
.description('查看应用详情 (含 systemId/系统配置等)')
.requiredOption('--id <id>', '应用 id')
.option('--json', '原始 JSON 输出', false)
.action(async (opts: InfoOpts) => {
const c = await JnpfClient.fromToken()
const r = await c.get<Record<string, unknown>>(`/system/System/${opts.id}`)
if (r.code !== 200) {
log.error(`app info 失败 (code=${r.code}): ${r.msg}`)
process.exit(1)
}
if (opts.json) {
printJson(r.data)
return
}
const d = r.data as Record<string, unknown>
log.info(`应用 id=${opts.id} 名称=${d.fullName} 编码=${d.enCode}`)
console.log(`icon: ${d.icon || '-'}`)
console.log(`sortCode: ${d.sortCode}`)
console.log(`backgroundColor: ${d.backgroundColor || '-'}`)
console.log(`creatorTime: ${d.creatorTime || '-'}`)
if (d.propertyJson) console.log(`propertyJson: ${d.propertyJson}`)
})
installAiHelpHook(cmd, {
purpose: '查看应用详情 (含 systemId/系统配置等)',
required: { '--id': '应用 id' },
example: 'dacli app info --id=835128640063677381',
source: {
web: 'web/apps/jnpf-web-apps-main/src/views/appCenter/Form.vue',
api: 'GET /api/system/System/{id}',
ref: 'doc/v0.8-endpoints.md §1.6',
},
})
return cmd
}
+56
View File
@@ -0,0 +1,56 @@
/**
* commands/app/initapp.ts — 应用初始化
*
* 注: v0.7.1+ initapp 是 "JNPF 后端一键启动/重启 + 健康检查 + 重登" 工具,
* 不是 form 初始化. 走 dacli.conf 读 jar-pattern/port, 杀进程 + nohup.
*
* 占位: 真实 initapp 在 Java 版 ssw-dacli, TS 版 v0.9+ 集成.
* 本命令先返回 "JNPF 状态查询" 让用户看到当前 app 是否健康.
*/
import { Command } from 'commander'
import { JnpfClient } from '../../core/client.ts'
import { installAiHelpHook } from '../../core/help.ts'
import { log } from '../../core/log.ts'
interface InitAppOpts {
appCode?: string
restart?: boolean
}
export function buildAppInitappCommand(): Command {
const cmd = new Command('initapp')
.description('应用初始化 (健康检查; --restart 一键重启 JNPF; v0.9+ 集成)')
.option('--appCode <code>', '应用 code (不传则用当前登录)')
.option('--restart', '重启 JNPF 后端 (v0.9+ 集成, 现在 dry-run)', false)
.action(async (opts: InitAppOpts) => {
const c = await JnpfClient.fromToken()
// 1. 健康检查: 拉 form list 看是否能返
const r = await c.get<{ list: unknown[] }>('/visualdev/Base', { currentPage: 1, pageSize: 1 })
if (r.code === 200) {
log.ok(`✓ JNPF 健康: appCode=${c.appCode} (form 列表可访问)`)
} else {
log.error(`✗ JNPF 不健康: code=${r.code} ${r.msg}`)
process.exit(1)
}
// 2. --restart: v0.9+ 才实做, 现在 dry-run
if (opts.restart) {
log.warn('--restart 当前 v0.9+ 才实做, 现在 dry-run')
log.info(' 计划: 读 dacli.conf 的 jar-pattern/port, kill+rm+nohup+健康检查+重登')
}
})
installAiHelpHook(cmd, {
purpose: '应用初始化 (健康检查 / 一键重启 JNPF)',
optional: { '--appCode': '应用 code', '--restart': '重启 JNPF 后端' },
example: 'dacli app initapp\ndacli app initapp --appCode=tds --restart',
source: {
web: 'web/apps/jnpf-web-apps-main/src/views/appCenter/index.vue',
api: 'GET /api/visualdev/Base (健康检查)',
ref: 'doc/v0.8-plan.md §4 D1',
},
notes: [
'**v0.9+ 实做**: --restart 走 dacli.conf 自动 kill+nohup+健康+重登',
'**当前**: --restart dry-run 提示计划',
],
})
return cmd
}
+70
View File
@@ -0,0 +1,70 @@
/**
* commands/app/list.ts — 应用列表
*
* API: GET /api/system/System
*/
import { Command } from 'commander'
import { JnpfClient } from '../../core/client.ts'
import { installAiHelpHook } from '../../core/help.ts'
import { log, printJson } from '../../core/log.ts'
interface AppItem {
id?: string
fullName?: string
enCode?: string
icon?: string
sortCode?: number
backgroundColor?: string
hasUpdate?: number
hasDelete?: number
}
interface ListOpts {
keyword?: string
json?: boolean
}
export function buildAppListCommand(): Command {
const cmd = new Command('list')
.description('列出所有应用 (JNPF 多 app 生命周期)')
.option('--keyword <k>', '按名称/编码模糊搜索')
.option('--json', '原始 JSON 输出', false)
.action(async (opts: ListOpts) => {
const c = await JnpfClient.fromToken()
const r = await c.get<{ list: AppItem[] }>('/system/System', {
keyword: opts.keyword,
currentPage: 1,
pageSize: 50,
})
if (r.code !== 200) {
log.error(`app list 失败 (code=${r.code}): ${r.msg}`)
process.exit(1)
}
const list = r.data?.list || []
if (opts.json) {
printJson(r.data)
return
}
log.info(`共 ${list.length} 个应用`)
console.log('ID FULL_NAME ENCODE DEL')
console.log('-'.repeat(85))
for (const d of list) {
const id = String(d.id || '').padEnd(30)
const name = String(d.fullName || '').padEnd(23)
const code = String(d.enCode || '').padEnd(21)
const del = d.hasDelete ? 'yes' : 'no'
console.log(`${id}${name}${code}${del}`)
}
})
installAiHelpHook(cmd, {
purpose: '列出所有应用 (JNPF 多 app 生命周期, 不同于当前登录 appCode)',
optional: { '--keyword': '按名称/编码模糊搜索' },
example: 'dacli app list\ndacli app list --keyword=tds',
source: {
web: 'web/apps/jnpf-web-apps-main/src/views/appCenter/index.vue',
api: 'GET /api/system/System',
ref: 'doc/v0.8-endpoints.md §1.6',
},
})
return cmd
}
+13 -3
View File
@@ -35,14 +35,24 @@ export function buildBigscreenCreateCommand(): Command {
enabledMark: 1,
sortCode: 0,
}
const r = await c.postJson<{ id: string }>('/extend/BigData', body)
const r = await c.postJson<{ id?: string }>('/extend/BigData', body)
if (r.code !== 200) {
log.error(`bigscreen create 失败 (code=${r.code}): ${r.msg}`)
process.exit(1)
}
const id = r.data?.id
let id = r.data?.id
if (!id) {
const listR = await c.get<{ list: { id: string; enCode: string; fullName: string }[] }>(
'/extend/BigData',
{ keyword: opts.enCode, pageSize: '50' },
)
const found = (listR.data?.list || []).find(
(d) => d.enCode === opts.enCode || d.fullName === opts.fullName,
)
id = found?.id
}
log.info(`✓ 大屏创建成功 id=${id}`)
if (opts.json) printJson(r.data)
if (opts.json) printJson({ ...(r.data as object), id })
})
installAiHelpHook(cmd, {
purpose: '新建大屏 (大屏设计器产物, 走 dataInterface 拉数据)',
+22 -16
View File
@@ -1,13 +1,20 @@
/**
* commands/bigscreen/info.ts — 大屏详情
*
* API: GET /api/extend/BigData/{id} (推断, 端点清单见 v0.8-endpoints.md)
* JNPF 大屏无 /{id} 端点 (404 实测), 走 list 查
*/
import { Command } from 'commander'
import { JnpfClient } from '../../core/client.ts'
import { installAiHelpHook } from '../../core/help.ts'
import { log, printJson } from '../../core/log.ts'
interface BigscreenItem {
id?: string
fullName?: string
enCode?: string
category?: string
}
interface InfoOpts {
id: string
json?: boolean
@@ -15,34 +22,33 @@ interface InfoOpts {
export function buildBigscreenInfoCommand(): Command {
const cmd = new Command('info')
.description('查看大屏详情 (含图表配置)')
.description('查看大屏详情 (JNPF 大屏无 /{id} 端点, 走 list 查)')
.requiredOption('--id <id>', '大屏 id')
.option('--json', '原始 JSON 输出', false)
.action(async (opts: InfoOpts) => {
const c = await JnpfClient.fromToken()
const r = await c.get<Record<string, unknown>>(`/extend/BigData/${opts.id}`)
// 大屏是 list 端点, 无 /{id}, 直接 list 找
const r = await c.get<{ list: BigscreenItem[] }>('/extend/BigData', { pageSize: 100 })
if (r.code !== 200) {
log.error(`bigscreen info 失败 (code=${r.code}): ${r.msg}`)
log.error(`bigscreen info 失败: ${r.msg}`)
process.exit(1)
}
if (opts.json) {
printJson(r.data)
return
const found = (r.data?.list || []).find((d) => d.id === opts.id)
if (!found) {
log.error(`bigscreen id=${opts.id} 不存在 (list 中未找到)`)
process.exit(1)
}
const d = r.data as Record<string, unknown>
log.info(`大屏 id=${opts.id} 名称=${d.fullName} 编码=${d.enCode}`)
console.log(`category: ${d.category}`)
console.log(`type: ${d.type}`)
console.log(`--- 完整 JSON (含 chart 配置) ---`)
printJson(r.data)
log.info(`大屏 id=${opts.id} 名称=${found.fullName} 编码=${found.enCode}`)
console.log(`category: ${found.category || '-'}`)
if (opts.json) printJson(found)
})
installAiHelpHook(cmd, {
purpose: '查看大屏的完整 schema (含图表配置)',
purpose: '查看大屏详情 (JNPF 大屏无 /{id} 端点, 走 list 查)',
required: { '--id': '大屏 id' },
example: 'dacli bigscreen info --id=1234567890\ndacli bigscreen info --id=1234567890 --json',
example: 'dacli bigscreen info --id=835246813026985082',
source: {
web: 'web/apps/jnpf-web-apps-main/src/views/extend/bigData/Form.vue',
api: 'GET /api/extend/BigData/{id}',
api: 'GET /api/extend/BigData (JNPF 无 /{id} 端点)',
ref: 'doc/v0.8-endpoints.md §1.4',
},
})
+79
View File
@@ -0,0 +1,79 @@
/**
* commands/print/create.ts — 新建打印模板
*
* 决策 6: 打印模板 webType=1-2 (printDev), 不需要物理表, 绑 form 数据
*
* API: POST /api/system/printDev
*/
import { Command } from 'commander'
import { JnpfClient } from '../../core/client.ts'
import { installAiHelpHook } from '../../core/help.ts'
import { log, printJson } from '../../core/log.ts'
interface CreateOpts {
fullName: string
enCode: string
category: string
formId?: string
json?: boolean
}
export function buildPrintCreateCommand(): Command {
const cmd = new Command('create')
.description('新建打印模板 (绑 form 数据, 不需要物理表)')
.requiredOption('--fullName <name>', '打印模板名称')
.requiredOption('--enCode <code>', '打印模板编码')
.requiredOption('--category <cat>', '分类: 1=系统打印 2=表单打印')
.option('--formId <id>', '绑定的 form id (form 打印时必填)')
.option('--json', '原始 JSON 输出', false)
.action(async (opts: CreateOpts) => {
const c = await JnpfClient.fromToken()
const body: Record<string, unknown> = {
fullName: opts.fullName,
enCode: opts.enCode,
category: opts.category,
type: opts.category === '1' ? 1 : 2,
enabledMark: 1,
sortCode: 0,
}
if (opts.formId) body.moduleId = opts.formId
const r = await c.postJson<{ id?: string }>('/system/printDev', body)
if (r.code !== 200) {
log.error(`print create 失败 (code=${r.code}): ${r.msg}`)
process.exit(1)
}
let id = r.data?.id
if (!id) {
const listR = await c.get<{ list: { id: string; enCode: string; fullName: string }[] }>(
'/system/printDev',
{ keyword: opts.enCode, pageSize: '50' },
)
const found = (listR.data?.list || []).find(
(d) => d.enCode === opts.enCode || d.fullName === opts.fullName,
)
id = found?.id
}
log.info(`✓ 打印模板创建成功 id=${id}`)
if (opts.json) printJson({ ...(r.data as object), id })
})
installAiHelpHook(cmd, {
purpose: '新建打印模板 (绑 form 数据, 套打)',
required: {
'--fullName': '打印模板名称',
'--enCode': '打印模板编码',
'--category': '分类 1=系统打印 2=表单打印',
},
optional: { '--formId': '绑定的 form id (form 打印时必填)' },
example: 'dacli print create --fullName=套打示例 --enCode=zdydy --category=2 --formId=<formId>',
source: {
web: 'web/apps/jnpf-web-apps-main/src/views/onlineDev/printDev/Form.vue',
api: 'POST /api/system/printDev',
ref: 'doc/v0.8-endpoints.md §1.5',
},
notes: [
'**决策 6**: 打印模板不需要物理表, 绑 form 数据',
'**决策 6**: webType 1-2 (printDev)',
],
})
return cmd
}
+22
View File
@@ -0,0 +1,22 @@
/**
* commands/print/index.ts — print 父命令
*
* 打印模板 (onlineDev/printDev + teamwork/printTemplate)
*
* 子命令:
* list 列表
* info 详情
* create 新建 (绑 form 数据)
*/
import { Command } from 'commander'
import { buildPrintListCommand } from './list.ts'
import { buildPrintInfoCommand } from './info.ts'
import { buildPrintCreateCommand } from './create.ts'
export function buildPrintCommand(): Command {
const cmd = new Command('print').description('打印模板 CRUD (绑 form 数据, 套打)')
cmd.addCommand(buildPrintListCommand())
cmd.addCommand(buildPrintInfoCommand())
cmd.addCommand(buildPrintCreateCommand())
return cmd
}
+53
View File
@@ -0,0 +1,53 @@
/**
* commands/print/info.ts — 打印模板详情
*
* API: GET /api/system/printDev/{id}
*/
import { Command } from 'commander'
import { JnpfClient } from '../../core/client.ts'
import { installAiHelpHook } from '../../core/help.ts'
import { log, printJson } from '../../core/log.ts'
interface InfoOpts {
id: string
json?: boolean
}
export function buildPrintInfoCommand(): Command {
const cmd = new Command('info')
.description('查看打印模板详情 (含版本/打印配置)')
.requiredOption('--id <id>', '打印模板 id')
.option('--json', '原始 JSON 输出', false)
.action(async (opts: InfoOpts) => {
const c = await JnpfClient.fromToken()
const r = await c.get<Record<string, unknown>>(`/system/printDev/${opts.id}`)
if (r.code !== 200) {
log.error(`print info 失败 (code=${r.code}): ${r.msg}`)
process.exit(1)
}
if (!r.data) {
log.error(`print id=${opts.id} 不存在`)
process.exit(1)
}
if (opts.json) {
printJson(r.data)
return
}
const d = r.data as Record<string, unknown>
log.info(`打印模板 id=${opts.id} 名称=${d.fullName} 编码=${d.enCode}`)
console.log(`category: ${d.category}`)
console.log(`type: ${d.type}`)
console.log(`state: ${d.state === 1 ? '已发布' : '未发布'}`)
})
installAiHelpHook(cmd, {
purpose: '查看打印模板详情',
required: { '--id': '打印模板 id' },
example: 'dacli print info --id=585817367276160133',
source: {
web: 'web/apps/jnpf-web-apps-main/src/views/onlineDev/printDev/Form.vue',
api: 'GET /api/system/printDev/{id}',
ref: 'doc/v0.8-endpoints.md §1.5',
},
})
return cmd
}
+69
View File
@@ -0,0 +1,69 @@
/**
* commands/print/list.ts — 打印模板列表
*
* API: GET /api/system/printDev
*/
import { Command } from 'commander'
import { JnpfClient } from '../../core/client.ts'
import { installAiHelpHook } from '../../core/help.ts'
import { log, printJson } from '../../core/log.ts'
interface PrintItem {
id?: string
fullName?: string
enCode?: string
category?: string
type?: number
state?: number
creatorTime?: string | number
}
interface ListOpts {
keyword?: string
json?: boolean
}
export function buildPrintListCommand(): Command {
const cmd = new Command('list')
.description('列出打印模板')
.option('--keyword <k>', '按名称/编码模糊搜索')
.option('--json', '原始 JSON 输出', false)
.action(async (opts: ListOpts) => {
const c = await JnpfClient.fromToken()
const r = await c.get<{ list: PrintItem[] }>('/system/printDev', {
keyword: opts.keyword,
currentPage: 1,
pageSize: 50,
})
if (r.code !== 200) {
log.error(`print list 失败 (code=${r.code}): ${r.msg}`)
process.exit(1)
}
const list = r.data?.list || []
if (opts.json) {
printJson(r.data)
return
}
log.info(`共 ${list.length} 个打印模板`)
console.log('ID FULL_NAME ENCODE STATE')
console.log('-'.repeat(85))
for (const d of list) {
const id = String(d.id || '').padEnd(30)
const name = String(d.fullName || '').padEnd(23)
const code = String(d.enCode || '').padEnd(21)
const state = d.state === 1 ? '已发布' : '未发布'
console.log(`${id}${name}${code}${state}`)
}
})
installAiHelpHook(cmd, {
purpose: '列出打印模板 (绑 form 数据, 套打)',
optional: { '--keyword': '按名称/编码模糊搜索' },
example: 'dacli print list\ndacli print list --keyword=套打',
source: {
web: 'web/apps/jnpf-web-apps-main/src/views/onlineDev/printDev/index.vue',
api: 'GET /api/system/printDev',
ref: 'doc/v0.8-endpoints.md §1.5',
},
})
return cmd
}
+53
View File
@@ -0,0 +1,53 @@
/**
* app.test.ts — app 父命令烟囱测试
*/
import { describe, it, expect } from 'vitest'
import { execFileSync } from 'node:child_process'
import { resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
const __dirname = fileURLToPath(new URL('.', import.meta.url))
const CLI = resolve(__dirname, '../../src/cli.ts')
function run(args: string[]): string {
try {
return execFileSync('npx', ['tsx', CLI, ...args], {
encoding: 'utf-8',
stdio: ['pipe', 'pipe', 'pipe'],
timeout: 30_000,
})
} catch (e) {
const err = e as { stdout?: Buffer | string; status?: number }
return (err.stdout?.toString() || '')
}
}
describe('app command tree (W9-D1)', () => {
it('app --help 列出 3 个子命令', () => {
const out = run(['app', '--help'])
expect(out).toContain('list')
expect(out).toContain('info')
expect(out).toContain('initapp')
})
it('app list --ai-help 含 API 路径', () => {
const out = run(['app', 'list', '--ai-help'])
expect(out).toContain('/api/system/System')
})
it('app info --help 包含 --id', () => {
const out = run(['app', 'info', '--help'])
expect(out).toContain('--id')
})
it('app initapp --help 包含 --appCode 和 --restart', () => {
const out = run(['app', 'initapp', '--help'])
expect(out).toContain('--appCode')
expect(out).toContain('--restart')
})
it('顶层 --help 包含 app', () => {
const out = run(['--help'])
expect(out).toContain('app')
})
})
+83
View File
@@ -0,0 +1,83 @@
/**
* print-bigscreen.test.ts — print + bigscreen 父命令烟囱测试
*/
import { describe, it, expect } from 'vitest'
import { execFileSync } from 'node:child_process'
import { resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
const __dirname = fileURLToPath(new URL('.', import.meta.url))
const CLI = resolve(__dirname, '../../src/cli.ts')
function run(args: string[]): string {
try {
return execFileSync('npx', ['tsx', CLI, ...args], {
encoding: 'utf-8',
stdio: ['pipe', 'pipe', 'pipe'],
timeout: 30_000,
})
} catch (e) {
const err = e as { stdout?: Buffer | string; status?: number }
return (err.stdout?.toString() || '')
}
}
describe('print command tree (W9-D3)', () => {
it('print --help 列出 3 个子命令', () => {
const out = run(['print', '--help'])
expect(out).toContain('list')
expect(out).toContain('info')
expect(out).toContain('create')
})
it('print list --ai-help 含 API 路径', () => {
const out = run(['print', 'list', '--ai-help'])
expect(out).toContain('/api/system/printDev')
})
it('print info --help 包含 --id', () => {
const out = run(['print', 'info', '--help'])
expect(out).toContain('--id')
})
it('print create --ai-help 提示决策 6', () => {
const out = run(['print', 'create', '--ai-help'])
expect(out).toContain('决策 6')
expect(out).toContain('printDev')
})
it('顶层 --help 包含 print', () => {
const out = run(['--help'])
expect(out).toContain('print')
})
})
describe('bigscreen command tree (W9-D2)', () => {
it('bigscreen --help 列出 4 个子命令', () => {
const out = run(['bigscreen', '--help'])
expect(out).toContain('list')
expect(out).toContain('info')
expect(out).toContain('create')
expect(out).toContain('release')
})
it('bigscreen list --ai-help 含 API 路径', () => {
const out = run(['bigscreen', 'list', '--ai-help'])
expect(out).toContain('/api/extend/BigData')
})
it('bigscreen info --help 提示无 /{id} 端点', () => {
const out = run(['bigscreen', 'info', '--help'])
expect(out).toContain('JNPF 大屏无 /{id} 端点')
})
it('bigscreen create --ai-help 提示决策 6', () => {
const out = run(['bigscreen', 'create', '--ai-help'])
expect(out).toContain('决策 6')
})
it('顶层 --help 包含 bigscreen', () => {
const out = run(['--help'])
expect(out).toContain('bigscreen')
})
})