import { app } from '../../app.ts'; import './cnb-dev-env.ts'; import { useKey } from '@kevisual/context'; import { spawnSync } from 'node:child_process'; export const execCommand = (command: string, options: { cwd?: string } = {}) => { const { cwd } = options; return spawnSync(command, { stdio: 'inherit', shell: true, cwd: cwd, env: process.env, }); }; app.route({ path: 'cnb-board', key: 'is-cnb-board', description: '检查是否是 cnb-board 环境', middleware: ['auth-admin'] }).define(async (ctx) => { const isCNB = useKey('CNB'); ctx.body = { isCNB: !!isCNB, }; }).addTo(app); app.route({ path: 'cnb-board', key: 'exit', description: 'cnb的工作环境退出程序', middleware: ['auth-admin'], }).define(async (ctx) => { const cmd = 'kill 1'; execCommand(cmd); }).addTo(app);