diff --git a/src/commands/app/clear.ts b/src/commands/app/clear.ts
index 6647e88..59e6877 100644
--- a/src/commands/app/clear.ts
+++ b/src/commands/app/clear.ts
@@ -1,5 +1,5 @@
/**
- * commands/app/clear.ts — `dacli app clear`
+ * commands/app/clear.ts — `dacli app clear` (v2.1+ P1-2c 三层接入 + audit trail, v3.0+ P1-2d docs 全清)
*
* 清除 JNPF 应用的本地资源 + 数据库记录
* - DB 操作: 走 ssw-common 端点 POST /api/ssw/db/clear (PG/MySQL 自动适配)
@@ -21,10 +21,28 @@
*
* ⚠ v10.6.1 DDL bug 复刻: Phase 1 (备份) + Phase 2 (单事务 DELETE) + Phase 3 (drop 空表) 必须分开
* 详见 ssw-common DbClearServiceImpl.clearMainTables
+ *
+ * v2.1+ P1-2c (2026-07-21) 三层接入 (destructive command 强 audit):
+ * L1: --verbose (默认静默, dry-run 时显示完整预览) / --json (--dry-run + --json 给 AI 解析清单)
+ * L2: 跨命令 auto-fix pipeline
+ * - appCode 含 `-`/`_` 自动 strip (S-X1 silent, BS-新38) — 注意 appCode 正则 ^[a-z][a-z0-9_-]{1,31}$
+ * 允许 `-`/`_`, 但跨命令一致性建议 strip, 不破坎清理但让后续 app login/init 用一致 enCode
+ * - G-X1 suggest
+ * L3: 关键 — destructive command audit trail, 强制落 CommandLog
+ * - 即使 --dry-run 也落 (AI 跑 dry-run 会被审计, 防止恶意试探)
+ * - 真实执行后落 (回滚命令 + 时间戳 + 备份位置)
+ *
+ * v3.0+ P1-2d (2026-07-21) docs/{app}/ 完整清理 — 修复上一版缺口:
+ * 历史限制: DOC_HTML_FILES 只清 4 个 html, 实际 docs 目录常含 8+ MD 文件 + 4 子目录
+ * (_assets/test_logs/screenshots/scripts), 与 docs/jxcj 实测一致 (设计文档 会遗留)
+ * 修复: 加 --clean-docs flag (默认 false 保持向后兼容)
+ * true: docs/{app}/ 整体 rename 到 history-bak/{ts}/docs/ (8+ MD + 4 子目录 全部进备份)
+ * false: 保持原行为 (只清 4 html) + DRY-RUN 警告提示残留 docs
+ * 理由: docs/{app}/ 是设计依据 + 历史档案, 默认不改; 需要"完整干净"时显式 --clean-docs
*/
import { Command } from 'commander'
import { spawn } from 'node:child_process'
-import { existsSync, readFileSync, writeFileSync, copyFileSync, mkdirSync, renameSync, cpSync, rmSync } from 'node:fs'
+import { existsSync, readdirSync, readFileSync, writeFileSync, copyFileSync, mkdirSync, renameSync, cpSync, rmSync } from 'node:fs'
import { dirname, join, relative, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { createInterface } from 'node:readline/promises'
@@ -35,6 +53,8 @@ import { log } from '../../core/log.ts'
import { DacliError } from '../../core/types.ts'
import { clearToken, getTokenPath, loadToken } from '../../core/config.ts'
import { JnpfClient } from '../../core/client.ts'
+import { runCommandAutoFix, fetchExistingLists } from '../_auto_fix.ts' // v2.1+ (2026-07-21): 跨命令 auto-fix (S-X1/S-X2 silent + G-X1 suggest)
+import { setupOutputFilter, printCommandEnd } from '../_output_filter.ts' // v2.1+ (2026-07-21): stdout 三模式 + CommandLog 落盘
// =====================================================================
// 常量
@@ -51,8 +71,11 @@ interface ClearOpts {
appCode: string
dryRun?: boolean
skipDb?: boolean
+ cleanDocs?: boolean
restart?: boolean
workspace?: string
+ verbose?: boolean
+ json?: boolean
}
interface Paths {
@@ -113,9 +136,58 @@ export function buildAppClearCommand(): Command {
.option('--dry-run', '只预览, 不实际删除/备份 (任何环境可用, 无需 TTY)', false)
.option('--skip-db', '跳过数据库清理 (仅清理本地文件 + 构建配置)', false)
.option('--no-restart', '清理后不询问 create 重建 (默认询问 Y/N)', false)
+ .option('--clean-docs', 'v3.0+ P1-2d: 同时把 docs/{app}/ 整体移到 history-bak/docs/ (含 8+ MD + _assets/test_logs/screenshots 子目录). 默认 false 保持向后兼容, docs 是设计依据建议保留', false)
.option('--workspace
', '工程根目录 (默认 $ccWorkDir 或 cwd)')
+ .option('--verbose', '完整输出 (含 dry-run 详细预览)', false)
+ .option('--json', '原始 JSON 输出 (--dry-run + --json 给 AI 解析清单; 真实执行时仍走人类 TTY)', false)
.action(async (opts: ClearOpts) => {
- await runClear(opts)
+ // v2.1+ L1: stdout 三模式 (default=quiet, --verbose=完整 dry-run, --json=仅 dry-run 输出 JSON)
+ setupOutputFilter(opts)
+ const startTime = Date.now()
+ const c = await JnpfClient.fromToken().catch(() => ({ appCode: '' } as { appCode: string }))
+
+ // v2.1+ L2 silent+suggest: 跨命令 auto-fix pipeline
+ // appCode 正则本身允许 `-`/`_`, S-X1 会 strip 但合法, 只是让 appCode 在后续 login/init 用一致 enCode
+ const fixCtx = await fetchExistingLists(c as unknown as Awaited>, c.appCode || 'testspace')
+ const cmdFix = runCommandAutoFix(opts as unknown as Record, fixCtx)
+ if (cmdFix.silent.length > 0) {
+ Object.assign(opts, cmdFix.opts)
+ }
+
+ // v2.1+ P1-2c: 集中 try/catch 把 runClear 的 DacliError + requireTty 的 process.exit 都接住
+ // 后统一调 printCommandEnd (audit trail 关键)
+ try {
+ await runClear(opts)
+ printCommandEnd({
+ command: 'app clear',
+ appCode: opts.appCode,
+ summary: {
+ appCode: opts.appCode,
+ dryRun: !!opts.dryRun,
+ skipDb: !!opts.skipDb,
+ cleanDocs: !!opts.cleanDocs,
+ },
+ fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions],
+ duration_ms: Date.now() - startTime,
+ verbose: opts.verbose,
+ json: opts.json,
+ })
+ } catch (e) {
+ // runClear 抛 DacliError (--dry-run 中), requireTty 抛错 (process.exit(1) 替换见 L405 改造)
+ const errorMsg = e instanceof DacliError ? e.message : (e as Error)?.message ?? String(e)
+ printCommandEnd({
+ command: 'app clear',
+ appCode: opts.appCode,
+ result: 'failure',
+ summary: { appCode: opts.appCode, dryRun: !!opts.dryRun, cleanDocs: !!opts.cleanDocs },
+ fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions],
+ error: errorMsg,
+ duration_ms: Date.now() - startTime,
+ verbose: opts.verbose,
+ json: opts.json,
+ })
+ process.exit(1)
+ }
})
installHelpHook(cmd, {
@@ -188,7 +260,7 @@ async function runClear(opts: ClearOpts): Promise {
if (!opts.dryRun) requireTty()
// ---- (3) 收集目标 (只读, 无副作用) ----
- const fileTargets = collectFileTargets(layout, opts.appCode)
+ const fileTargets = collectFileTargets(layout, opts.appCode, !!opts.cleanDocs)
const pomCount = countPomDependency(layout, opts.appCode)
const ymlHasDs = ymlDatasourceExists(layout, opts.appCode)
let dbPreview: DbClearPreview | null = null
@@ -223,6 +295,15 @@ async function runClear(opts: ClearOpts): Promise {
previewTs,
})
+ // v3.0+ P1-2d: docsAppDir 残留警告 (默认 --clean-docs=false 行为, 但提示用户有残留)
+ if (!opts.cleanDocs && existsSync(layout.docsAppDir)) {
+ const docsFiles = readdirSync(layout.docsAppDir).filter(f => !f.startsWith('.') && f !== 'history-bak')
+ if (docsFiles.length > 0) {
+ log.warn(`⚠️ docs/${opts.appCode}/ 残留 ${docsFiles.length} 项 (默认保留): ${docsFiles.slice(0, 8).join(', ')}${docsFiles.length > 8 ? '...' : ''}`)
+ log.warn(` 如需完整清理, 加 --clean-docs (会移到 history-bak/${fsTsBakHint()}/docs/)`)
+ }
+ }
+
const hasAnything =
fileTargets.length > 0 ||
pomCount > 0 ||
@@ -383,6 +464,13 @@ function formatTs(pattern: 'yyyyMMddHHmmss' | 'yyyyMMdd-HHmmss'): string {
: `${Y}${M}${D}${h}${m}${s}`
}
+/**
+ * v3.0+ P1-2d: dry-run 时提示的备份目录占位符 (实际执行时由 formatTs('yyyyMMdd-HHmmss') 生成)
+ */
+function fsTsBakHint(): string {
+ return ''
+}
+
function requireTty(): void {
if (process.stdin.isTTY && process.stdout.isTTY) return
const lines = [
@@ -400,7 +488,8 @@ function requireTty(): void {
'='.repeat(70),
]
for (const l of lines) process.stderr.write(l + '\n')
- process.exit(1)
+ // v2.1+ P1-2c: 改为抛错, 让外层 .action() try/catch 接住并落 CommandLog audit trail
+ throw new DacliError('拒绝执行: 检测到非交互式终端, 破坏性操作只允许在 TTY 中人工执行')
}
function printAiProhibitionBanner(): void {
@@ -453,11 +542,17 @@ function resolveWorkspace(workspaceOpt?: string): string {
return resolve(process.cwd())
}
-function collectFileTargets(layout: Paths, appCode: string): FileTarget[] {
+function collectFileTargets(layout: Paths, appCode: string, cleanDocs = false): FileTarget[] {
const out: FileTarget[] = []
- for (const name of DOC_HTML_FILES) {
- const p = join(layout.docsAppDir, name)
- if (existsSync(p)) out.push({ path: p, isDir: false })
+ // v3.0+ P1-2d: --clean-docs=true 时把 docsAppDir 整体打包成单个 FileTarget (dir)
+ if (cleanDocs && existsSync(layout.docsAppDir)) {
+ out.push({ path: layout.docsAppDir, isDir: true })
+ } else {
+ // 历史行为: DOC_HTML_FILES (plan/testcase/debug/summary.html) — 即使 docsAppDir 有其它 8+ MD + 4 子目录, 不动
+ for (const name of DOC_HTML_FILES) {
+ const p = join(layout.docsAppDir, name)
+ if (existsSync(p)) out.push({ path: p, isDir: false })
+ }
}
const bootMod = join(layout.bootDir, `ssw-${appCode}`)
if (existsSync(bootMod)) out.push({ path: bootMod, isDir: true })
diff --git a/src/commands/app/create.ts b/src/commands/app/create.ts
index dbfa79a..a5a0761 100644
--- a/src/commands/app/create.ts
+++ b/src/commands/app/create.ts
@@ -1,5 +1,5 @@
/**
- * commands/app/create.ts — 真·应用创建 (v3.0+ step 1/4 走 webapi/system 镜像)
+ * commands/app/create.ts — 真·应用创建 (v3.0+ step 1/4 走 webapi/system 镜像, v2.1+ 三层接入)
*
* 借鉴: Java 版 InitAppCommand.java + web 版 appCenter/Form.vue + appConfig/appAuth/index.vue
*
@@ -11,18 +11,12 @@
* 5. login(newAppCode) + saveToken (TS 版本地, 保留 JnpfClient.login)
*
* v3.0+ (2026-06-29 regression audit P0): 部分 webapi 镜像化
- * - step 1: getSystemList + create 走 webapi/system (web 端同名函数, 复用 query + body schema)
- * - step 4: saveAppAuth 走 webapi/system (web 端同名函数)
- * - step 2/3: ssw-common 特有 (web 无等价接口), 保留 c.postJson
- * - step 5: 端到端流程核心, 保留 JnpfClient.login (有 encryptPassword 逻辑)
- *
- * 兼容:
- * - ssw-common 不存在 → 步骤 2/3 警告跳过, 用户后续手动建 DataSource
- * - 应用已存在 → 走"幂等"模式, 跳过创建, 返回已有 systemId
- *
- * 不做 (留给后续):
- * - 写 application-dev.yml: TS 版不动文件系统, 改在 ssw-common 走 spring 默认
- * - 重启 JNPF: 走 dacli.conf, 留给 v0.9 集成
+ * v2.1+ (2026-07-21) 三层接入:
+ * L1: --verbose / --json 三模式
+ * L2: 跨命令 auto-fix pipeline (S-X1/S-X2 silent + G-X1 suggest, appCode 含 `-`/`_` 自动 strip)
+ * L3: 完成后落 CommandLog (含 systemId/dbLinkId), 失败也落
+ * v2.1+ (P1-2b 2026-07-21): 4 处 process.exit(1) 改为 throw AppCreateError, 外层 action 用 try/catch
+ * 集中调 printCommandEnd failure 路径; 之前 L3 不覆盖 step 1/2/3 失败
*/
import { Command } from 'commander'
import { JnpfClient } from '../../core/client.ts'
@@ -38,6 +32,19 @@ import {
create as createSystem,
saveAppAuth,
} from '../../webapi/system.ts'
+import { runCommandAutoFix, fetchExistingLists } from '../_auto_fix.ts' // v2.1+ (2026-07-21): 跨命令 auto-fix (S-X1/S-X2 silent + G-X1 suggest)
+import { setupOutputFilter, printCommandEnd } from '../_output_filter.ts' // v2.1+ (2026-07-21): stdout 三模式 + CommandLog 落盘
+
+/**
+ * v2.1+ P1-2b: AppCreateError — 用于 runCreate 内部 4 处 process.exit(1) 替换
+ * 让外层 .action 的 try/catch 能接住, 统一调 printCommandEnd failure 路径
+ */
+export class AppCreateError extends Error {
+ constructor(public stepName: string, message: string, public exitCode = 1) {
+ super(`[${stepName}] ${message}`)
+ this.name = 'AppCreateError'
+ }
+}
interface CreateOpts {
appCode: string
@@ -51,7 +58,10 @@ interface CreateOpts {
skipGrant?: boolean
/** 跳过 ssw-common 真建 DB (默认走) */
skipDb?: boolean
+ /** 内部: P0-3 fallback 守卫 */
+ __skipDbRetried?: boolean
json?: boolean
+ verbose?: boolean
}
interface AppItem {
@@ -77,9 +87,85 @@ export function buildAppCreateCommand(): Command {
.option('--force-rebuild', '已存在时强制删旧 datasource 重建', false)
.option('--skip-grant', '跳过 saveAppAuthorization', false)
.option('--skip-db', '跳过 ssw-common 真建 DB (用户已建好)', false)
+ .option('--verbose', '完整输出 (含 step machine、API 调用等过程日志)', false)
.option('--json', '原始 JSON 输出', false)
.action(async (opts: CreateOpts) => {
- await runCreate(opts)
+ // v2.1+ L1: stdout 三模式
+ setupOutputFilter(opts)
+ const startTime = Date.now()
+
+ let c: Awaited>
+ try {
+ c = await JnpfClient.fromToken()
+ } catch {
+ // 无登录态时无 c.appCode, 后面用 testspace 占位, 此处 c 后续会被 runCreate 内部重 login 覆盖
+ c = { appCode: '', account: '', baseUrl: '', token: '' } as unknown as Awaited>
+ }
+
+ // v2.1+ L2 silent+suggest: 跨命令 auto-fix pipeline (S-X1/S-X2/G-X1)
+ const fixCtx = await fetchExistingLists(c, c.appCode || 'testspace')
+ const cmdFix = runCommandAutoFix(opts as unknown as Record, fixCtx)
+ if (cmdFix.silent.length > 0) {
+ Object.assign(opts, cmdFix.opts)
+ }
+
+ // v2.1+ P1-2b: 集中 try/catch 替换 4 处 process.exit(1)
+ try {
+ const result = await runCreate(opts)
+ // success path — 落 CommandLog
+ log.info('================================')
+ log.ok('应用创建完成')
+ const { systemId, dbLinkId, dbName } = result
+ const summary = {
+ appCode: opts.appCode,
+ appName: opts.appName,
+ systemId,
+ dbLinkId,
+ dbName,
+ }
+ if (opts.json) {
+ console.log(JSON.stringify(summary, null, 2))
+ } else {
+ log.info(` appCode : ${summary.appCode}`)
+ log.info(` appName : ${summary.appName}`)
+ log.info(` systemId : ${summary.systemId}`)
+ log.info(` dbLinkId : ${summary.dbLinkId || '(跳过 DB)'}`)
+ log.info(` dbName : ${summary.dbName}`)
+ log.info('')
+ log.info('下一步:')
+ log.info(` dacli form list # 应有 0 个 form`)
+ log.info(` dacli dm create --table=... # 建第一个业务表`)
+ log.info(` dacli form create --enCode=... --table=...`)
+ log.info(` 浏览器: http://nginx/jnpf_app_${opts.appCode}`)
+ }
+ printCommandEnd({
+ command: 'app create',
+ appCode: opts.appCode,
+ summary: { appCode: opts.appCode, systemId, dbLinkId, dbName },
+ fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions],
+ duration_ms: Date.now() - startTime,
+ verbose: opts.verbose,
+ json: opts.json,
+ })
+ } catch (e) {
+ if (e instanceof AppCreateError) {
+ log.error(` ✗ 应用创建失败 [${e.stepName}]: ${e.message}`)
+ } else {
+ log.error(` ✗ 应用创建失败: ${(e as Error).message}`)
+ }
+ printCommandEnd({
+ command: 'app create',
+ appCode: opts.appCode,
+ result: 'failure',
+ summary: { appCode: opts.appCode, appName: opts.appName },
+ fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions],
+ error: e instanceof AppCreateError ? e.message : (e as Error).message,
+ duration_ms: Date.now() - startTime,
+ verbose: opts.verbose,
+ json: opts.json,
+ })
+ process.exit(1)
+ }
})
installHelpHook(cmd, {
@@ -112,6 +198,8 @@ export function buildAppCreateCommand(): Command {
' step 1: getSystemList + create 走 webapi/system (web 端同名)',
' step 4: saveAppAuth 走 webapi/system (web 端同名)',
' step 2/3: ssw-common 特有 (web 无等价), 保留 c.postJson',
+ '**v2.1+ P1-2b (2026-07-21)**: 三层接入, runCreate 4 处 process.exit(1) → throw AppCreateError',
+ ' L1/L2/L3 集中到 .action() 的 try/catch, 失败也落 CommandLog',
'**幂等**: 应用/DataSource 已存在则复用 (除 --force-rebuild)',
'**ssw-common 必需**: 真建 DB 走 /common/dblinkExt/createDatabase, 未加载时 --skip-db 跳过',
'**yml**: 不动文件, ssw-common 走 spring.datasource.* 默认 (host/port/user/pwd)',
@@ -126,19 +214,22 @@ export function buildAppCreateCommand(): Command {
* runCreate — step 0/1/2/3/4/5 真·创建 JNPF 应用的核心流程.
*
* P0-3 (2026-07-15): 提取为独立函数, 让 step 2 DB 创建失败时自动 fallback --skip-db 重试整流程.
+ * v2.1+ P1-2b (2026-07-21): 4 处 process.exit(1) → throw AppCreateError, 由外层 .action() catch + printCommandEnd.
+ *
+ * 返回 success summary (systemId/dbLinkId/dbName), 失败 throw AppCreateError
+ *
* 守卫: __skipDbRetried 内部标记, 防止无限递归 (只重试 1 次).
*/
-async function runCreate(opts: CreateOpts): Promise {
+async function runCreate(opts: CreateOpts): Promise<{ systemId: string; dbLinkId: string; dbName: string }> {
// P0-3 守卫: 防止 fallback 无限递归
- const __skipDbRetried = (opts as CreateOpts & { __skipDbRetried?: boolean }).__skipDbRetried
+ const __skipDbRetried = !!(opts as CreateOpts).__skipDbRetried
const dbName = opts.dbName || opts.appCode
log.info(`开始创建应用: ${opts.appCode} (${opts.appName})`)
- log.dim(` dbName=${dbName}, force-rebuild=${!!opts.forceRebuild}, skip-db=${!!opts.skipDb}, skip-grant=${!!opts.skipGrant}, retried=${!!__skipDbRetried}`)
+ log.dim(` dbName=${dbName}, force-rebuild=${!!opts.forceRebuild}, skip-db=${!!opts.skipDb}, skip-grant=${!!opts.skipGrant}, retried=${__skipDbRetried}`)
// === step 0 拿当前 token (复用登录态; 无 token 时强制 admin 登录拿平台 token) ===
- // === 0. 拿当前 token (复用登录态; 无 token 时强制 admin 登录拿平台 token) ===
// v0.11f+ (2026-06-27 用户反馈): 旧版 fromToken 失败直接抛错 → 死循环
- // 新版: fromToken 失败时, 用 admin/123456 + developSystem 占位强制登录, 拿平台级 token
+ // 新版: fromToken 失败时, 用 admin/123456 + testspace 占位强制登录, 拿平台级 token
// 这样即使 base_system 全空也能 create
let c: Awaited>
try {
@@ -149,16 +240,12 @@ async function runCreate(opts: CreateOpts): Promise {
c = await JnpfClient.login({
account: opts.account || 'admin',
password: opts.password || '123456',
- appCode: 'testspace', // 平台占位, 拿 system=testspace 的 token (统一测试场, 默认已存在; 备选 developSystem 也是 JNPF baseline 占位但首选 testspace)
- // 跳过 base_system 检测 (这步就是创建 system 本身)
- // ClientOptions 没有 checkSystem 字段, 用 any cast 透传给 JnpfClient (login.ts v0.11f+ 内部已读)
+ appCode: 'testspace', // 平台占位
} as any)
log.dim(` 强制登录: ${c.account} @ ${c.appCode} (baseUrl=${c.baseUrl})`)
}
// === step 1 创建系统 (幂等: 已存在则复用) ===
- // === 1. 创建系统 (幂等: 已存在则复用) ===
- // v3.0+ P0: 走 webapi/system.getSystemList + create (替代直接 c.get/postJson)
log.info('[1/5] 创建系统...')
await initSystemWebapi(c)
const sysListRaw = (await getSystemList({ keyword: opts.appCode, currentPage: 1, pageSize: 50 })) as { list?: AppItem[] } | AppItem[]
@@ -182,22 +269,19 @@ async function runCreate(opts: CreateOpts): Promise {
if (rCode !== undefined && rCode !== 200) {
const enhanced = enhanceFromBackend((r as { msg?: string })?.msg || '', 'appSystem', { entity: 'app' })
log.error(` ✗ ${formatErrorLine(enhanced, { step: 1, stepName: '创建系统' })}`)
- process.exit(1)
+ throw new AppCreateError('step 1 createSystem', enhanced.message || `code=${rCode}`)
}
// 创建后再查一次拿 id
const afterRaw = (await getSystemList({ keyword: opts.appCode, currentPage: 1, pageSize: 50 })) as { list?: AppItem[] } | AppItem[]
const after = (Array.isArray(afterRaw) ? { list: afterRaw } : afterRaw) || { list: [] }
systemId = after.list?.find((x) => x.enCode === opts.appCode)?.id || ''
if (!systemId) {
- log.error(` ✗ 系统创建后未找到 id, 可能 JNPF 异常`)
- process.exit(1)
+ throw new AppCreateError('step 1 createSystem', '系统创建后未找到 id, 可能 JNPF 异常')
}
log.ok(` ✓ 系统创建: systemId=${systemId}`)
}
// === step 2 创建 DB (ssw-common /dblinkExt/createDatabase) ===
- // dbType 自动从 yml 的 spring.datasource.db-type 推断 (默认连接, 避免硬编码)
- // P0-3 (2026-07-15): code=400 数据库创建失败 (DB 已存在/权限不足) 自动 fallback --skip-db 重试
let dbLinkId = ''
if (!opts.skipDb) {
const dbType = loadDbProfile().dbType
@@ -214,7 +298,7 @@ async function runCreate(opts: CreateOpts): Promise {
return runCreate({ ...opts, skipDb: true, __skipDbRetried: true } as CreateOpts)
} else {
log.error(` ✗ createDatabase 失败 (已 fallback --skip-db 仍失败): code=${r2.code} ${r2.msg}`)
- process.exit(1)
+ throw new AppCreateError('step 2 createDatabase', `code=${r2.code} ${r2.msg}`)
}
} else {
log.dim(' (--skip-db 跳过)')
@@ -243,20 +327,17 @@ async function runCreate(opts: CreateOpts): Promise {
}
const r3 = await c.postJson('/common/dblinkExt/create', body)
// dblinkExt/create 返回格式: {"code":200, "msg":"", "data":null}
- // 兼容 data 也可能有 id 的旧版本
const newId = r3.code === 200 ? (typeof r3.data === 'string' ? r3.data : r3.msg) : ''
if (r3.code === 200 && newId) {
dbLinkId = String(newId)
log.ok(` ✓ DataSource 创建: dbLinkId=${dbLinkId}`)
} else {
- log.error(` ✗ dblinkExt/create 失败: code=${r3.code} ${r3.msg}`)
- process.exit(1)
+ throw new AppCreateError('step 3 dblinkExt/create', `code=${r3.code} ${r3.msg}`)
}
}
}
// === 4. 授权: isAllDevUser=1 全员开发者可见此应用 ===
- // v3.0+ P0: 走 webapi/system.saveAppAuth (替代直接 c.postJson)
if (!opts.skipGrant) {
log.info('[4/5] 授权 (isAllDevUser=1)...')
const grantBody = {
@@ -268,7 +349,6 @@ async function runCreate(opts: CreateOpts): Promise {
devUsers: [] as string[],
}
const r4 = await saveAppAuth(grantBody)
- // webapi 镜像响应: 直接返回 data, 错误由 defHttp shim 抛
if (r4) {
log.ok(` ✓ 授权完成 (全员可见)`)
} else {
@@ -278,7 +358,7 @@ async function runCreate(opts: CreateOpts): Promise {
log.dim(' (--skip-grant 跳过)')
}
- // === 5. 重新登录 newAppCode + 保存 token ===
+ // === 5. 重新登录 newAppCode + 保存 token (失败仅 warn, 不 throw) ===
log.info('[5/5] 重新登录新 appCode...')
try {
const c2 = await JnpfClient.login({
@@ -302,28 +382,6 @@ async function runCreate(opts: CreateOpts): Promise {
log.warn(` 请手动: dacli app login --account=admin --password=123456 --appCode=${opts.appCode}`)
}
- log.info('================================')
- log.ok('应用创建完成')
- const summary = {
- appCode: opts.appCode,
- appName: opts.appName,
- systemId,
- dbLinkId,
- dbName,
- }
- if (opts.json) {
- console.log(JSON.stringify(summary, null, 2))
- } else {
- log.info(` appCode : ${summary.appCode}`)
- log.info(` appName : ${summary.appName}`)
- log.info(` systemId : ${summary.systemId}`)
- log.info(` dbLinkId : ${summary.dbLinkId || '(跳过 DB)'}`)
- log.info(` dbName : ${summary.dbName}`)
- log.info('')
- log.info('下一步:')
- log.info(` dacli form list # 应有 0 个 form`)
- log.info(` dacli dm create --table=... # 建第一个业务表`)
- log.info(` dacli form create --enCode=... --table=...`)
- log.info(` 浏览器: http://nginx/jnpf_app_${opts.appCode}`)
- }
+ // 返回 success summary 给 .action() 的 printCommandEnd
+ return { systemId, dbLinkId, dbName }
}