57 lines
2.3 KiB
TypeScript
57 lines
2.3 KiB
TypeScript
/**
|
|
* commands/app/init.ts — `dacli app init` (原 `dacli app initapp`, v0.9 进一步简化为 init)
|
|
*
|
|
* 注: v0.7.1+ init 是 "JNPF 后端一键启动/重启 + 健康检查 + 重登" 工具,
|
|
* 不是 form 初始化. 走 dacli.conf 读 jar-pattern/port, 杀进程 + nohup.
|
|
*
|
|
* 占位: 真实 init 在 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 buildAppInitCommand(): Command {
|
|
const cmd = new Command('init')
|
|
.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 init\ndacli app init --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
|
|
}
|