diff --git a/.claude/skills/dacli-ts/SKILL.md b/.claude/skills/dacli-ts/SKILL.md index 1db9674..280117d 100644 --- a/.claude/skills/dacli-ts/SKILL.md +++ b/.claude/skills/dacli-ts/SKILL.md @@ -81,7 +81,7 @@ description: Use when working with JNPF platform form/menu/workflow creation, da | 命令 | 端到端验证 | 子命令 | 备注 | |------|------------|--------|------| -| `dacli login / status / switch-app` | ✅ | 3 顶层 | token 持久化 + dbLinkId 自动检测 | +| `dacli app login / status / switch-app` | ✅ | 3 顶层 | token 持久化 + dbLinkId 自动检测 | | `dacli form` | ✅ | list/info/create/release/delete/export/import/clone/validate/**fix-columndata** (10) | v0.7.1 修 columnData 缺字段, 加修老 form 工具 | | `dacli dm` | ✅ | list/create/drop/fields (4) | 物理表 CRUD | | `dacli dict` | ✅ | type-list/data-list (2) | 字典类型 + 数据 | @@ -254,7 +254,7 @@ npx tsx src/cli.ts switch-app --appCode=tds # 业务 | 原因 | 解决 | |------|------| -| `dbLinkId='0'` 错 | 先 `dacli status` 看真实 dbLinkId | +| `dbLinkId='0'` 错 | 先 `dacli app status` 看真实 dbLinkId | | `tables[].fields[]` 缺字段 | 用 `type=4` 视图绕开 | | `category='0'` 错 | `dacli form list` 看已有 form 的 category | | 服务器限流 | `sleep 30` 重试 | @@ -303,15 +303,15 @@ form create → 失败 → 改字段 → form create → 失败 → 改 type → ```bash # 1. 切到 baseline 应用 -dacli switch-app --appCode=developSystem -dacli login --appCode=developSystem +dacli app switch --appCode=developSystem +dacli app login --appCode=developSystem # 2. 找到目标表单 dacli form list | jq '.data.list[] | select(.enCode=="leaveApply") | .id' # 3. 导出 + 导入到 tds dacli form export --out=/tmp/leaveApply.json -dacli switch-app --appCode=tds +dacli app switch --appCode=tds dacli form import /tmp/leaveApply.json --enCode=leaveApply_clone # 4. 发布 @@ -350,10 +350,10 @@ SKIP_PLAYWRIGHT=1 bash examples/baseline/all.sh ```bash # ===== 登录/状态 (✅ v0.1 跑通) ===== -dacli login --appCode=tds # 默认 admin/123456, baseUrl 自动从 env/nginx/127.0.0.1:30000 探活 -dacli switch-app --appCode=developSystem # 切应用 (覆盖 token) -dacli status # 看登录态 -dacli status --json # 脚本用 +dacli app login --appCode=tds # 默认 admin/123456, baseUrl 自动从 env/nginx/127.0.0.1:30000 探活 +dacli app switch --appCode=developSystem # 切应用 (覆盖 token) +dacli app status # 看登录态 +dacli app status --json # 脚本用 # ===== 表单只读 (✅ v0.1 跑通) ===== dacli form list # 列当前应用所有表单 diff --git a/.claude/skills/dacli-ts/examples/baseline/all.sh b/.claude/skills/dacli-ts/examples/baseline/all.sh index 054433d..3d08bc3 100755 --- a/.claude/skills/dacli-ts/examples/baseline/all.sh +++ b/.claude/skills/dacli-ts/examples/baseline/all.sh @@ -65,7 +65,7 @@ py() { python3 -c "$1"; } # 拿 form list (enCode id type state webType 数组, 一行一个 form) list_forms_tsv() { local app="$1" - dacli switch-app --appCode="$app" >/dev/null + dacli app switch --appCode="$app" >/dev/null dacli form list --limit=200 --json 2>/dev/null \ | py " import json, sys @@ -154,7 +154,7 @@ for app in "${SOURCE_APPS[@]}"; do fi # 2) 切到目标 + import - dacli switch-app --appCode="$TARGET_APP" >/dev/null 2>&1 || true + dacli app switch --appCode="$TARGET_APP" >/dev/null 2>&1 || true # 用 timestamp 后缀避免重跑时"重名"冲突 (幂等) clone_enc="${enc}_clone_$(date +%H%M%S)_$$" # 先清旧 clone (idempotent) - 删的是另一 run 的 clone, 不影响本次 diff --git a/.claude/skills/dacli-ts/examples/baseline/template.sh b/.claude/skills/dacli-ts/examples/baseline/template.sh index 53d5711..058c879 100644 --- a/.claude/skills/dacli-ts/examples/baseline/template.sh +++ b/.claude/skills/dacli-ts/examples/baseline/template.sh @@ -16,14 +16,14 @@ TARGET_APP="tds" # 目标 app (通常 tds) # ========== 1. 切到源 app, 导出 ========== echo "▶ [1/6] 导出 $APP_CODE / $ENCODE (id=$ORIGINAL_ID) ..." -dacli switch-app --appCode=$APP_CODE -dacli login --appCode=$APP_CODE +dacli app switch --appCode=$APP_CODE +dacli app login --appCode=$APP_CODE dacli form export $ORIGINAL_ID --out=/tmp/${ENCODE}-orig.json # ========== 2. 切到目标 app, 导入 ========== echo "▶ [2/6] 导入到 $TARGET_APP ..." -dacli switch-app --appCode=$TARGET_APP -dacli login --appCode=$TARGET_APP +dacli app switch --appCode=$TARGET_APP +dacli app login --appCode=$TARGET_APP dacli form import /tmp/${ENCODE}-orig.json --enCode=$CLONE_ENCODE # ========== 3. 拿克隆 id ========== diff --git a/.claude/skills/dacli-ts/examples/create-master-sub-form.sh b/.claude/skills/dacli-ts/examples/create-master-sub-form.sh index 94059dd..31addbc 100644 --- a/.claude/skills/dacli-ts/examples/create-master-sub-form.sh +++ b/.claude/skills/dacli-ts/examples/create-master-sub-form.sh @@ -87,7 +87,7 @@ echo " 子表: $SUB_TABLE" echo " 表单 id: $FORM_ID (type=4 视图占位, 真实主子表用 form clone 现有 baseline)" echo "" echo "⚠ 提示: type=1 主子表 schema 复杂, 推荐 baseline 路径:" -echo " 1. dacli switch-app --appCode=workSystem" +echo " 1. dacli app switch --appCode=workSystem" echo " 2. dacli form list --keyword=订单 # 找现有主子表" echo " 3. dacli form clone --newEnCode=$ENCODE" echo " 4. dacli form release " diff --git a/.claude/skills/dacli-ts/references/anti-patterns.md b/.claude/skills/dacli-ts/references/anti-patterns.md index 2cd4d5e..42ca4f7 100644 --- a/.claude/skills/dacli-ts/references/anti-patterns.md +++ b/.claude/skills/dacli-ts/references/anti-patterns.md @@ -168,7 +168,7 @@ dacli workflow create --formId=$CLONE_ID ... **反模式**: ```bash # 调试 developSystem 的某张表单 -dacli switch-app --appCode=developSystem +dacli app switch --appCode=developSystem dacli form update --enCode=资产 # ↑ 把 developSystem 的 form 改了, baseline 污染 ``` @@ -176,7 +176,7 @@ dacli form update --enCode=资产 **正确**: ```bash # baseline 只读, 调试全在 tds / 测试 app -dacli switch-app --appCode=tds +dacli app switch --appCode=tds dacli form clone --newEnCode=test dacli form update --enCode=资产 ``` @@ -198,10 +198,10 @@ done **正确**: ```bash -dacli clear-app --app-code=tds --dry-run # 先预览 -dacli clear-app --app-code=tds # 实跑 (需 TTY) +dacli app clear --app-code=tds --dry-run # 先预览 +dacli app clear --app-code=tds # 实跑 (需 TTY) # 或只清当前会话 -dacli clear-app --app-code=tds --skip-db # 跳过 DB +dacli app clear --app-code=tds --skip-db # 跳过 DB ``` **为什么**: `clear-app` 一键备份 + 清理 (含文件 + pom + yml + DB), `form delete` 是单条操作。 diff --git a/.claude/skills/dacli-ts/references/baseline/README.md b/.claude/skills/dacli-ts/references/baseline/README.md index f2f561d..17e6cad 100644 --- a/.claude/skills/dacli-ts/references/baseline/README.md +++ b/.claude/skills/dacli-ts/references/baseline/README.md @@ -38,8 +38,8 @@ JNPF 部署时自带 2 个应用,里面有大量**官方写的**功能表单 ```bash # 1. 切到 baseline 应用 -dacli switch-app --appCode=developSystem -dacli login --appCode=developSystem +dacli app switch --appCode=developSystem +dacli app login --appCode=developSystem # 2. 列出所有 form, 找到目标 dacli form list @@ -49,8 +49,8 @@ dacli form list dacli form export 469065268790880645 --out=/tmp/leaveApply-orig.json # 4. 切到 tds 应用 -dacli switch-app --appCode=tds -dacli login --appCode=tds +dacli app switch --appCode=tds +dacli app login --appCode=tds # 5. 导入到 tds (改 enCode 避免冲突) dacli form import /tmp/leaveApply-orig.json --enCode=leaveApply_clone @@ -80,15 +80,15 @@ CLONE_ENCODE="${ENCODE}_clone" echo "=== baseline 复刻: developSystem / $ENCODE ===" # 1. 切到源 app -dacli switch-app --appCode=developSystem -dacli login --appCode=developSystem +dacli app switch --appCode=developSystem +dacli app login --appCode=developSystem # 2. 导出原表单 dacli form export $ORIGINAL_ID --out=/tmp/$ENCODE-orig.json # 3. 切到目标 app -dacli switch-app --appCode=tds -dacli login --appCode=tds +dacli app switch --appCode=tds +dacli app login --appCode=tds # 4. 导入 dacli form import /tmp/$ENCODE-orig.json --enCode=$CLONE_ENCODE diff --git a/.claude/skills/dacli-ts/references/baseline/developSystem.md b/.claude/skills/dacli-ts/references/baseline/developSystem.md index 277e6d6..64e45c0 100644 --- a/.claude/skills/dacli-ts/references/baseline/developSystem.md +++ b/.claude/skills/dacli-ts/references/baseline/developSystem.md @@ -62,8 +62,8 @@ ```bash #!/bin/bash set -e -dacli switch-app --appCode=developSystem -dacli login --appCode=developSystem +dacli app switch --appCode=developSystem +dacli app login --appCode=developSystem # 拉所有表单 (pageSize=100) dacli form list --pageSize=100 > /tmp/developSystem-forms.json diff --git a/.claude/skills/dacli-ts/references/baseline/workSystem.md b/.claude/skills/dacli-ts/references/baseline/workSystem.md index c0ed6f5..f0c7ba0 100644 --- a/.claude/skills/dacli-ts/references/baseline/workSystem.md +++ b/.claude/skills/dacli-ts/references/baseline/workSystem.md @@ -54,8 +54,8 @@ ```bash #!/bin/bash set -e -dacli switch-app --appCode=workSystem -dacli login --appCode=workSystem +dacli app switch --appCode=workSystem +dacli app login --appCode=workSystem dacli form list --pageSize=100 > /tmp/workSystem-forms.json dacli workflow list > /tmp/workSystem-workflows.json diff --git a/.claude/skills/dacli-ts/references/commands.md b/.claude/skills/dacli-ts/references/commands.md index 85c5a27..608cdc2 100644 --- a/.claude/skills/dacli-ts/references/commands.md +++ b/.claude/skills/dacli-ts/references/commands.md @@ -23,9 +23,9 @@ ```bash dacli --version dacli --help -dacli login --appCode=tds -dacli status [--json] -dacli switch-app --appCode= +dacli app login --appCode=tds +dacli app status [--json] +dacli app switch --appCode= ``` --- diff --git a/.claude/skills/dacli-ts/references/patterns.md b/.claude/skills/dacli-ts/references/patterns.md index 221117e..28bc2c8 100644 --- a/.claude/skills/dacli-ts/references/patterns.md +++ b/.claude/skills/dacli-ts/references/patterns.md @@ -13,12 +13,12 @@ **dacli 流程**: ```bash # 1. 拉 baseline (找最相近的克隆) -dacli switch-app --appCode=developSystem +dacli app switch --appCode=developSystem dacli form list --keyword=资产 # → 找到 id=469065268790880645, enCode=asset # 2. 克隆到 tds -dacli switch-app --appCode=tds +dacli app switch --appCode=tds dacli form clone 469065268790880645 --newEnCode=myAsset # 3. (可选) 改字段名/enCode diff --git a/.claude/skills/dacli-ts/references/troubleshooting.md b/.claude/skills/dacli-ts/references/troubleshooting.md index 7bcf970..55278ff 100644 --- a/.claude/skills/dacli-ts/references/troubleshooting.md +++ b/.claude/skills/dacli-ts/references/troubleshooting.md @@ -18,7 +18,7 @@ **排查**: ```bash # 1. 看 baseUrl -dacli status +dacli app status # 期望: API: http://127.0.0.1:13880/api (一个 /api) # 2. curl 直测 (绕过 dacli) @@ -34,7 +34,7 @@ curl -X POST "http://127.0.0.1:13880/api/oauth/Login" \ **修复**: - 限流 → `sleep 30` 等恢复 - URL 重复 → 检查 path 是否含 `/api` (应不含) -- token 过期 → `dacli login --appCode=tds` 重新登录 +- token 过期 → `dacli app login --appCode=tds` 重新登录 --- @@ -50,7 +50,7 @@ curl -X POST "http://127.0.0.1:13880/api/oauth/Login" \ **排查**: ```bash # 1. 拿真实 dbLinkId -dacli status +dacli app status # 或: curl /api/system/DataSource # 2. 看已有 form 的 category @@ -228,11 +228,11 @@ await page.locator('button[type="primary"]').first().click() **修复**: ```bash # 看当前 app -dacli status +dacli app status # → 显示当前 app_code # 切到正确 app -dacli switch-app --appCode=developSystem +dacli app switch --appCode=developSystem # 列所有 dacli form list --pageSize=100 @@ -269,7 +269,7 @@ dacli form import /tmp/v2.json --enCode=v2 ```bash # 1. 看状态 -dacli status +dacli app status # 2. 拿 raw 错误 (含 code/msg/data) # dacli form create ... 2>&1 | head -50 diff --git a/CLAUDE.md b/CLAUDE.md index ba2c054..cd9c82c 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -20,7 +20,7 @@ npx playwright install chromium # 装浏览器 (baseline E2E 用) # CLI 调用 npx tsx src/cli.ts --help # 入口 (启动 < 500ms) -npx tsx src/cli.ts login --appCode=tds # 登录 +npx tsx src/cli.ts app login --appCode=tds # 登录 (v0.9 归入 app 命名空间) npx tsx src/cli.ts form list # 列已有表单 # 提取 web 源码到 src/data/*.json diff --git a/doc/RESUME.md b/doc/RESUME.md index a2e2cf2..8150ac4 100644 --- a/doc/RESUME.md +++ b/doc/RESUME.md @@ -24,7 +24,7 @@ - 改源码 + 跑 typecheck + 跑 test + 跑 baseline + commit (正常流程) - 改 prompt.md / RESUME.md / v0.8-*.md 段 (记进度) - 跑 `git log` / `git diff` / `git status` 查状态 -- 跑 `dacli status` / `dacli form list` / `dacli apis list` 查真实数据 +- 跑 `dacli app status` / `dacli form list` / `dacli apis list` 查真实数据 - 跑 `npx playwright install chromium` 装环境 - 跑 `npm install` 装新依赖 - 写 vitest 单测 / Playwright spec @@ -73,7 +73,7 @@ **v0.8 末追加 (2026-06-13 TDS 功能清单验证)**: - 盲点 24 已修 (log login/operate category 字符串→int '1'/'3'), 见 [盲点 24 记忆](~/.claude/projects/-home-ubuntu-ccWorkDir-dacli/memory/dacli-blindspot-24-log-category-string.md) - TDS 98 子功能 dacli 覆盖率 70% (16✅+53⚠️), 详见 `docs/tds/verification/v0.8/summary.md` -- v0.9 W13 入口: `dacli initapp -- --appCode=tdc --restart` + 批量建 53 个 ⚠️ 表/form +- v0.9 W13 入口: `dacli app init -- --appCode=tdc --restart` + 批量建 53 个 ⚠️ 表/form ## 4. 任务面板 (v0.8 全部完结 → v0.9 待启动) diff --git a/doc/api.md b/doc/api.md index 129e37d..3997523 100644 --- a/doc/api.md +++ b/doc/api.md @@ -271,31 +271,31 @@ dacli workflow reject --opinion= ### 7.1 `login` ``` -dacli login --account= --password= --appCode= +dacli app login --account= --password= --appCode= ``` ### 7.2 `status` ``` -dacli status +dacli app status ``` ### 7.3 `switch-app` ``` -dacli switch-app --appCode= +dacli app switch --appCode= ``` ### 7.4 `logs` ``` -dacli logs [--level=error] [--lines=50] +dacli tool logs [--level=error] [--lines=50] ``` ### 7.5 `initapp` ``` -dacli initapp --appCode= --appName= [--dbName=] [--restart] +dacli app init --appCode= --appName= [--dbName=] [--restart] ``` ## 8. 文档/API 命令 (镜像 Java 版) diff --git a/doc/baseline.md b/doc/baseline.md index ece71fb..7581069 100644 --- a/doc/baseline.md +++ b/doc/baseline.md @@ -43,8 +43,8 @@ ```bash # 1. 切到源 app, 登录 -dacli switch-app --appCode=developSystem -dacli login --appCode=developSystem +dacli app switch --appCode=developSystem +dacli app login --appCode=developSystem # 2. 找到目标 id (用 enCode 查) ORIGINAL_ID=$(dacli form list | jq -r '.data.list[] | select(.enCode=="leaveApply") | .id') @@ -53,8 +53,8 @@ ORIGINAL_ID=$(dacli form list | jq -r '.data.list[] | select(.enCode=="leaveAppl dacli form export $ORIGINAL_ID --out=/tmp/leaveApply-orig.json # 4. 切到 tds, 登录 -dacli switch-app --appCode=tds -dacli login --appCode=tds +dacli app switch --appCode=tds +dacli app login --appCode=tds # 5. 导入 (改 enCode 避免冲突) dacli form import /tmp/leaveApply-orig.json --enCode=leaveApply_clone diff --git a/doc/help-system.md b/doc/help-system.md index 5bfc4d5..9fc58fa 100644 --- a/doc/help-system.md +++ b/doc/help-system.md @@ -38,7 +38,7 @@ TS 版**增强 5 个 flag**, 让 AI 一次对话就能用对命令。 - `--enCode `: 表单英文编码 (^[a-z0-9][a-z0-9.]*$) - `--type <1|2|3|4>`: 1=自定义 2=系统 3=接口 4=视图 - `--webType <1|2|3>`: 1=仅表单 2=表单+列表 3=树 -- `--dbLinkId `: 业务库 id (从 dacli status 拿) +- `--dbLinkId `: 业务库 id (从 dacli app status 拿) - `--category `: 字典分类 (从已有 form list 查) - `--fields `: type≠4 必填, 字段定义数组 diff --git a/doc/plan.md b/doc/plan.md index 1ad0078..77ac0ce 100644 --- a/doc/plan.md +++ b/doc/plan.md @@ -88,7 +88,7 @@ ## Week 1: 脚手架 + 核心管道 -**目标**: 跑通 `dacli login + form list + form create (type=4) + release (跳过) + form delete` +**目标**: 跑通 `dacli app login + form list + form create (type=4) + release (跳过) + form delete` | Day | 任务 | 产出 | |-----|------|------| diff --git a/doc/v0.8-endpoints.md b/doc/v0.8-endpoints.md index ed127ae..f87ab28 100644 --- a/doc/v0.8-endpoints.md +++ b/doc/v0.8-endpoints.md @@ -121,7 +121,7 @@ | POST | `/api/app/Data` | app 常用数据 | **dacli 命令**: -- `dacli app list` / `dacli app create` / `dacli app initapp` / `dacli app info` +- `dacli app list` / `dacli app create` / `dacli app init` / `dacli app info` --- diff --git a/doc/v0.8.1-changelog.md b/doc/v0.8.1-changelog.md index 4f014ec..abe9fd3 100644 --- a/doc/v0.8.1-changelog.md +++ b/doc/v0.8.1-changelog.md @@ -83,7 +83,7 @@ **业务库 dbLinkId 错** (dm list 返 400 "Database connection failed"): - 当前 `tdc` app 用 dbLinkId=`835238244797916229` (是 `dacli_baseline_*` 表, 测试用) - 真实 tdc 业务库 `tdc_connector_{tenant_id}` 多租户隔离 -- v0.9 W13 待办: `dacli initapp -- --appCode=tdc --restart` 自动校准 dbLinkId +- v0.9 W13 待办: `dacli app init -- --appCode=tdc --restart` 自动校准 dbLinkId --- diff --git a/prompt.md b/prompt.md index 76a5b5e..6cbce17 100644 --- a/prompt.md +++ b/prompt.md @@ -28,7 +28,7 @@ - 改源码 + 跑 typecheck + 跑 test + 跑 baseline + commit (正常流程) - 改 prompt.md / RESUME.md / v0.8-*.md 段 (记进度) - 跑 `git log` / `git diff` / `git status` 查状态 -- 跑 `dacli status` / `dacli form list` / `dacli apis list` 查真实数据 +- 跑 `dacli app status` / `dacli form list` / `dacli apis list` 查真实数据 - 跑 `npx playwright install chromium` 装环境 - 跑 `npm install` 装新依赖 - 写 vitest 单测 / Playwright spec @@ -551,9 +551,9 @@ npx playwright test e2e/visual/-diff.spec.ts ```bash # ===== 登录/状态 ===== -dacli login --appCode=tds -dacli switch-app --appCode=developSystem # 切到 baseline -dacli status +dacli app login --appCode=tds +dacli app switch --appCode=developSystem # 切到 baseline +dacli app status # ===== baseline 复刻 (74 张) ===== bash examples/baseline/all.sh # 一键全跑 74 张 @@ -584,7 +584,7 @@ dacli apis refresh dacli apis list --tag=visualReport # 报表 (待 v0.8 W8 实测 tag) dacli apis list --tag=visualPortal # 门户 (待 v0.8 W8 实测 tag) # 列 developSystem/workSystem 现有报表/门户样例 (作 baseline) -dacli switch-app --appCode=workSystem +dacli app switch --appCode=workSystem dacli form list | jq -r '.data.list[] | "\(.id) \(.category) \(.fullName)"' | head -50 ``` diff --git a/src/cli.ts b/src/cli.ts index c28d793..e4db3ca 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -8,9 +8,6 @@ * AI 友好: 每个命令支持 --ai-help / --example / --source */ import { Command } from 'commander' -import { buildLoginCommand } from './commands/login.ts' -import { buildStatusCommand } from './commands/status.ts' -import { buildSwitchAppCommand } from './commands/switchapp.ts' import { buildFormCommand } from './commands/form/index.ts' import { buildDmCommand } from './commands/dm/index.ts' import { buildDictCommand } from './commands/dict/index.ts' @@ -46,12 +43,12 @@ const program = new Command() .version(VERSION) .showHelpAfterError(true) -// ----- 顶层命令 ----- -program.addCommand(buildLoginCommand()) -program.addCommand(buildStatusCommand()) -program.addCommand(buildSwitchAppCommand()) - // ----- 嵌套父命令 ----- +// v0.9 命名规范化: 顶层命令全部归入 app 命名空间 +// dacli login → dacli app login +// dacli status → dacli app status +// dacli switchapp → dacli app switch +// dacli initapp → dacli app init program.addCommand(buildFormCommand()) program.addCommand(buildDmCommand()) program.addCommand(buildDictCommand()) diff --git a/src/commands/app/create.ts b/src/commands/app/create.ts index 9be4b1f..85a2cf0 100644 --- a/src/commands/app/create.ts +++ b/src/commands/app/create.ts @@ -198,7 +198,7 @@ export function buildAppCreateCommand(): Command { log.ok(` ✓ 已登录 + 保存 token (appCode=${opts.appCode}, dbLinkId=${tf.dbLinkId})`) } catch (e) { log.warn(` ⚠ 切换登录失败: ${(e as Error).message}`) - log.warn(` 请手动: dacli login --account=admin --password=123456 --appCode=${opts.appCode}`) + log.warn(` 请手动: dacli app login --account=admin --password=123456 --appCode=${opts.appCode}`) } log.info('================================') @@ -228,7 +228,7 @@ export function buildAppCreateCommand(): Command { }) installAiHelpHook(cmd, { - purpose: '真·创建 JNPF 应用 (System+DB+DataSource+授权+重登, 端到端 0 差错). 替代 Java 版 dacli initapp.', + purpose: '真·创建 JNPF 应用 (System+DB+DataSource+授权+重登, 端到端 0 差错). 替代 Java 版 dacli app init.', required: { '--appCode': '应用编码 (英文, 唯一)', '--appName': '应用中文名称', diff --git a/src/commands/app/index.ts b/src/commands/app/index.ts index b6b9786..38dd214 100644 --- a/src/commands/app/index.ts +++ b/src/commands/app/index.ts @@ -3,22 +3,32 @@ * * JNPF 多 app 生命周期 (appCenter + appConfig/*) * - * 子命令: + * 子命令 (v0.9 命名规范化: 顶层 login/status/switchapp/initapp 全部归入 app): * list 列出所有应用 * info 应用详情 - * initapp 应用初始化 (健康检查 / 重启) + * create 真·创建 JNPF 应用 + * init 应用初始化 (健康检查 / 重启; 原 initapp) + * login 登录 JNPF (原顶层 login) + * status 显示登录状态 (原顶层 status) + * switch 切换当前应用 (原顶层 switchapp / switch-app) */ import { Command } from 'commander' import { buildAppListCommand } from './list.ts' import { buildAppInfoCommand } from './info.ts' -import { buildAppInitappCommand } from './initapp.ts' +import { buildAppInitCommand } from './init.ts' import { buildAppCreateCommand } from './create.ts' +import { buildAppLoginCommand } from './login.ts' +import { buildAppStatusCommand } from './status.ts' +import { buildAppSwitchCommand } from './switch.ts' export function buildAppCommand(): Command { const cmd = new Command('app').description('应用 (JNPF 多 app 生命周期, appCenter)') cmd.addCommand(buildAppListCommand()) cmd.addCommand(buildAppInfoCommand()) - cmd.addCommand(buildAppInitappCommand()) + cmd.addCommand(buildAppInitCommand()) cmd.addCommand(buildAppCreateCommand()) + cmd.addCommand(buildAppLoginCommand()) + cmd.addCommand(buildAppStatusCommand()) + cmd.addCommand(buildAppSwitchCommand()) return cmd } diff --git a/src/commands/app/initapp.ts b/src/commands/app/initapp.ts deleted file mode 100644 index eb5cff1..0000000 --- a/src/commands/app/initapp.ts +++ /dev/null @@ -1,56 +0,0 @@ -/** - * 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 (不传则用当前登录)') - .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 -} diff --git a/src/commands/dm/drop.ts b/src/commands/dm/drop.ts index 5271215..ff04a15 100644 --- a/src/commands/dm/drop.ts +++ b/src/commands/dm/drop.ts @@ -45,7 +45,7 @@ export function buildDmDropCommand(): Command { optional: { '--dbLinkId': '业务库 id' }, example: 'dacli dm drop --table=test_table --yes', source: { api: 'DELETE /api/system/DataModel/{dbLinkId}/Table/{table}' }, - notes: ['生产环境务必先用 dacli initapp --backup 备份'], + notes: ['生产环境务必先用 dacli app init --backup 备份'], }) return cmd } diff --git a/src/commands/login.ts b/src/commands/login.ts deleted file mode 100644 index da03b08..0000000 --- a/src/commands/login.ts +++ /dev/null @@ -1,50 +0,0 @@ -/** - * commands/login.ts - */ -import { Command } from 'commander' -import { JnpfClient } from '../core/client.ts' -import { DEFAULT_ACCOUNT, DEFAULT_APP_CODE, DEFAULT_PASSWORD, getTokenPath } from '../core/config.ts' -import { installAiHelpHook } from '../core/help.ts' -import { log } from '../core/log.ts' - -export function buildLoginCommand(): Command { - const cmd = new Command('login') - .description('登录 JNPF (默认 admin/123456@developSystem), 持久化 token 到 .dacli-token/token.json') - .option('--account ', '账号', DEFAULT_ACCOUNT) - .option('--password

', '密码 (明文; 96 字符 hex 视为已加密)', DEFAULT_PASSWORD) - .option('--appCode ', '应用代码 (developSystem | workSystem | tds)', DEFAULT_APP_CODE) - .option('--baseUrl ', 'JNPF API 根地址 (含 /api)') - .action(async (opts: { account: string; password: string; appCode: string; baseUrl?: string }) => { - const c = await JnpfClient.login({ - account: opts.account, - password: opts.password, - appCode: opts.appCode, - baseUrl: opts.baseUrl, - forceLogin: true, - }) - log.ok(`登录成功: ${c.account} @ ${c.appCode}`) - log.dim(`baseUrl : ${c.baseUrl}`) - log.dim(`token : ${c.token.slice(0, 32)}... (${c.token.length} chars)`) - if (c.dbLinkId) log.dim(`dbLinkId : ${c.dbLinkId}`) - log.dim(`saved to : ${getTokenPath()}`) - }) - - installAiHelpHook(cmd, { - purpose: '登录 JNPF, 把 token 写到 .dacli-token/token.json, 后续命令自动复用', - optional: { - '--account': '账号 (默认 admin)', - '--password': '密码 (默认 123456; 已是 96 字符 hex 时跳过加密)', - '--appCode': '应用代码 (默认 developSystem)', - '--baseUrl': '强制指定 baseUrl, 否则按 [env JNPF_BASE_URL → http://nginx/api → http://127.0.0.1:30000/api] 依次尝试', - }, - example: 'dacli login --appCode=tds', - source: { web: 'web/.../auth.ts:27 loginApi', api: 'POST /api/oauth/Login' }, - notes: [ - 'token 7 天有效', - '已加密的 96 字符 hex 不会重复加密', - 'detectDbLinkId 自动从 /system/DataSource 拉业务库 id', - ], - }) - - return cmd -} diff --git a/src/commands/menu/list.ts b/src/commands/menu/list.ts index 94f4150..97edc38 100644 --- a/src/commands/menu/list.ts +++ b/src/commands/menu/list.ts @@ -40,7 +40,7 @@ export function buildMenuListCommand(): Command { optional: { '--keyword': '搜索关键字', '--flat': '平铺打印' }, example: 'dacli menu list', source: { api: 'GET /api/system/Menu/ModuleBySystem' }, - notes: ['先 dacli switchapp --appCode=X 切到目标应用, 才能看到对应菜单'], + notes: ['先 dacli app switch --appCode=X 切到目标应用, 才能看到对应菜单'], }) return cmd } diff --git a/src/commands/status.ts b/src/commands/status.ts deleted file mode 100644 index f2fc25a..0000000 --- a/src/commands/status.ts +++ /dev/null @@ -1,49 +0,0 @@ -/** - * commands/status.ts - */ -import { Command } from 'commander' -import { loadToken, getTokenPath, currentBaseUrl } from '../core/config.ts' -import { installAiHelpHook } from '../core/help.ts' -import { log } from '../core/log.ts' - -export function buildStatusCommand(): Command { - const cmd = new Command('status') - .description('显示当前登录状态 + baseUrl + appCode + dbLinkId + token 路径') - .option('--json', '以 JSON 输出 (便于脚本)', false) - .action((opts: { json?: boolean }) => { - const t = loadToken() - if (opts.json) { - console.log(JSON.stringify({ - tokenPath: getTokenPath(), - baseUrl: t?.baseUrl || currentBaseUrl(), - loggedIn: !!t, - account: t?.account, - appCode: t?.appCode, - dbLinkId: t?.dbLinkId, - loginAt: t?.loginAt, - tokenLen: t?.token.length, - }, null, 2)) - return - } - if (!t) { - log.warn('未登录. 先跑: dacli login') - log.dim(`baseUrl: ${currentBaseUrl()}`) - log.dim(`token path: ${getTokenPath()}`) - return - } - log.ok(`已登录: ${t.account} @ ${t.appCode}`) - log.dim(`baseUrl : ${t.baseUrl}`) - log.dim(`dbLinkId : ${t.dbLinkId || '(unknown)'}`) - log.dim(`loginAt : ${t.loginAt}`) - log.dim(`token len : ${t.token.length}`) - log.dim(`token path: ${getTokenPath()}`) - }) - - installAiHelpHook(cmd, { - purpose: '显示当前登录状态. 写脚本前先跑一下确认登录态', - optional: { '--json': '以 JSON 输出' }, - example: 'dacli status', - }) - - return cmd -} diff --git a/src/commands/storage/use.ts b/src/commands/storage/use.ts index ba63e90..0b34a44 100644 --- a/src/commands/storage/use.ts +++ b/src/commands/storage/use.ts @@ -51,7 +51,7 @@ export function buildStorageUseCommand(): Command { log.info(`✓ ${ymlPath}: default-platform: ${cfg.defaultPlatform} → ${platform}`) log.info('') log.info('请手动重启 JNPF 生效:') - log.info(' dacli initapp --restart # 自动 kill + nohup + 健康检查 + 重登') + log.info(' dacli app init --restart # 自动 kill + nohup + 健康检查 + 重登') log.info(' # 或: pkill -f jnpf-admin && nohup java -jar ... &') } catch (e) { log.error(`写 yml 失败: ${(e as Error).message}`) diff --git a/src/commands/switchapp.ts b/src/commands/switchapp.ts deleted file mode 100644 index e26006b..0000000 --- a/src/commands/switchapp.ts +++ /dev/null @@ -1,37 +0,0 @@ -/** - * commands/switchapp.ts — 切换 appCode (登录新 app 并覆盖 token) - */ -import { Command } from 'commander' -import { JnpfClient } from '../core/client.ts' -import { DEFAULT_ACCOUNT, DEFAULT_PASSWORD, loadToken } from '../core/config.ts' -import { installAiHelpHook } from '../core/help.ts' -import { log } from '../core/log.ts' - -export function buildSwitchAppCommand(): Command { - const cmd = new Command('switchApp') - .alias('switch-app') - .description('切换当前应用 (重新登录新 appCode 并覆盖 token)') - .requiredOption('--appCode ', '目标应用代码') - .option('--account ', '账号') - .option('--password

', '密码') - .action(async (opts: { appCode: string; account?: string; password?: string }) => { - const cached = loadToken() - const c = await JnpfClient.login({ - account: opts.account || cached?.account || DEFAULT_ACCOUNT, - password: opts.password || DEFAULT_PASSWORD, - appCode: opts.appCode, - baseUrl: cached?.baseUrl, - forceLogin: true, - }) - log.ok(`切换成功: ${c.account} @ ${c.appCode}`) - log.dim(`dbLinkId : ${c.dbLinkId || '(unknown)'}`) - }) - - installAiHelpHook(cmd, { - purpose: '切换当前应用, 重新登录并覆盖本地 token. baseline 复刻常用', - required: { '--appCode': '目标应用 (developSystem | workSystem | tds)' }, - example: ['dacli switchapp --appCode=developSystem', 'dacli switchapp --appCode=tds'], - }) - - return cmd -} diff --git a/tests/e2e/smoke.spec.ts b/tests/e2e/smoke.spec.ts index b021689..7946d1c 100644 --- a/tests/e2e/smoke.spec.ts +++ b/tests/e2e/smoke.spec.ts @@ -22,7 +22,7 @@ test('JNPF web UI 加载 (nginx)', async ({ page }) => { await page.waitForLoadState('networkidle', { timeout: 30_000 }) }) -test('dacli login + form list 端到端', async () => { +test('dacli app login + form list 端到端 (v0.9 命名规范化: login → app login)', async () => { // 用子进程跑 dacli (与生产用法一致) const out = execSync( `npx tsx src/cli.ts form list --json 2>&1 | head -200`, diff --git a/tests/unit/app.test.ts b/tests/unit/app.test.ts index 2357210..8097d4c 100644 --- a/tests/unit/app.test.ts +++ b/tests/unit/app.test.ts @@ -23,11 +23,15 @@ function run(args: string[]): string { } describe('app command tree (W9-D1)', () => { - it('app --help 列出 3 个子命令', () => { + it('app --help 列出 7 个子命令 (v0.9: 归并 login/status/switch/init)', () => { const out = run(['app', '--help']) expect(out).toContain('list') expect(out).toContain('info') - expect(out).toContain('initapp') + expect(out).toContain('init') + expect(out).toContain('create') + expect(out).toContain('login') + expect(out).toContain('status') + expect(out).toContain('switch') }) it('app list --ai-help 含 API 路径', () => { @@ -40,8 +44,8 @@ describe('app command tree (W9-D1)', () => { expect(out).toContain('--id') }) - it('app initapp --help 包含 --appCode 和 --restart', () => { - const out = run(['app', 'initapp', '--help']) + it('app init --help 包含 --appCode 和 --restart (原 initapp, v0.9 简化)', () => { + const out = run(['app', 'init', '--help']) expect(out).toContain('--appCode') expect(out).toContain('--restart') }) diff --git a/tests/unit/cli-help.test.ts b/tests/unit/cli-help.test.ts index 456343e..0c2f697 100644 --- a/tests/unit/cli-help.test.ts +++ b/tests/unit/cli-help.test.ts @@ -31,12 +31,15 @@ describe('cli help', () => { expect(out).toContain('0.1.0') }) - it('--help 列出顶层命令', () => { + it('--help 列出顶层命令 (v0.9 命名规范化: login/status/switchapp/initapp 全部归入 app)', () => { const out = run(['--help']) - expect(out).toContain('login') - expect(out).toContain('status') - expect(out).toContain('switchApp') + // 顶层不再有 login/status/switchapp + expect(out).toContain('app') expect(out).toContain('form') + // 顶层 --help 不再列 login/status/switchApp/initapp (它们现在在 app 下) + expect(out).not.toMatch(/^\s+login\s/m) + expect(out).not.toMatch(/^\s+status\s/m) + expect(out).not.toMatch(/^\s+switchApp\s/m) }) it('form --help 列出子命令', () => { @@ -51,9 +54,9 @@ describe('cli help', () => { expect(out).toContain('validate') }) - it('login --ai-help 输出 markdown', () => { - const out = run(['login', '--ai-help']) - expect(out).toContain('# dacli login') + it('app login --ai-help 输出 markdown', () => { + const out = run(['app', 'login', '--ai-help']) + expect(out).toContain('# dacli app login') expect(out).toContain('## 用途') expect(out).toContain('admin') })