feat: 助手配置与服务命令扩展及依赖更新

This commit is contained in:
2025-04-27 03:26:50 +08:00
parent f2abfbf17c
commit 75d181ef43
25 changed files with 296 additions and 64 deletions

View File

@@ -0,0 +1,31 @@
import { program, Command } from '@/program.ts';
import { spawnSync } from 'node:child_process';
const command = new Command('server')
.description('启动服务')
.option('-d, --daemon', '是否以守护进程方式运行')
.option('-n, --name <name>', '服务名称')
.option('-p, --port <port>', '服务端口')
.option('-s, --start', '是否启动服务')
.action((options) => {
const { port } = options;
const shellCommands = [];
if (options.daemon) {
shellCommands.push('-d');
}
if (options.name) {
shellCommands.push(`-n ${options.name}`);
}
if (options.start) {
shellCommands.push('-s');
}
if (port) {
shellCommands.push(`-p ${port}`);
}
console.log(`Assistant server shell command: asst-server ${shellCommands.join(' ')}`);
const child = spawnSync('asst-server', shellCommands, {
stdio: 'inherit',
shell: true,
});
});
program.addCommand(command);

View File

@@ -1,6 +1,9 @@
import { program, Command } from '@/program.ts';
import { AssistantInit } from '@/services/init/index.ts';
import path from 'node:path';
import fs from 'node:fs';
import inquirer from 'inquirer';
import chalk from 'chalk';
type InitCommandOptions = {
path?: string;
@@ -24,3 +27,39 @@ const Init = new Command('init')
});
program.addCommand(Init);
const removeCommand = new Command('remove')
.description('删除助手配置文件') // TODO
.option('-p --path <path>', '助手路径,默认为执行命令的目录,如果助手路径不存在则创建。')
.action((opts) => {
if (opts.path && !opts.path.startsWith('/')) {
opts.path = path.join(process.cwd(), opts.path);
} else if (opts.path) {
opts.path = path.resolve(opts.path);
}
const configDir = AssistantInit.detectConfigDir(opts.path);
const assistantDir = path.join(configDir, 'assistant-app');
if (fs.existsSync(assistantDir)) {
inquirer
.prompt([
{
type: 'confirm',
name: 'confirm',
message: `确定要删除助手配置文件吗?\n助手配置文件路径${assistantDir}`,
default: false,
},
])
.then((answers) => {
if (answers.confirm) {
fs.rmSync(assistantDir, { recursive: true, force: true });
console.log(chalk.green('助手配置文件已删除'));
} else {
console.log(chalk.blue('助手配置文件未删除'));
}
});
} else {
console.log(chalk.blue('助手配置文件不存在'));
}
});
program.addCommand(removeCommand);