39 lines
883 B
TypeScript
39 lines
883 B
TypeScript
import { app, notCNBCheck } 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'],
|
|
}).define(async (ctx) => {
|
|
if (notCNBCheck(ctx)) return;
|
|
const cmd = 'kill 1';
|
|
execCommand(cmd);
|
|
}).addTo(app); |