"feat: 增加助手应用配置管理功能与服务器守护进程支持"

This commit is contained in:
2025-04-27 00:35:44 +08:00
parent bcc12209e0
commit f2abfbf17c
27 changed files with 658 additions and 102 deletions

View File

@@ -4,6 +4,7 @@ import { checkFileExists, AssistantConfig } from '@/module/assistant/index.ts';
import { chalk } from '@/module/chalk.ts';
export type AssistantInitOptions = {
path?: string;
init?: boolean;
};
/**
* 助手初始化类
@@ -14,6 +15,7 @@ export class AssistantInit extends AssistantConfig {
const configDir = opts?.path || process.cwd();
super({
configDir,
init: opts?.init ?? false,
});
}
@@ -30,21 +32,30 @@ export class AssistantInit extends AssistantConfig {
}
}
checkConfigPath() {
const assistantPath = path.join(this.configDir, 'assistant-config.json');
const assistantPath = path.join(this.configDir, 'assistant-app', 'assistant-config.json');
return checkFileExists(assistantPath);
}
createAssistantConfig() {
const assistantPath = this.configPath?.configPath;
// 创建助手配置文件 assistant-config.json
if (!checkFileExists(assistantPath, true)) {
this.setConfig({
description: '助手配置文件',
});
console.log(chalk.green('助手配置文件创建成功'));
console.log(chalk.green('助手配置文件assistant-config.json创建成功'));
}
const env = this.configPath?.envConfigPath;
// 创建助手环境配置文件 env
if (!checkFileExists(env, true)) {
fs.writeFileSync(env, '# 环境配置文件\n');
console.log(chalk.green('助手环境配置文件创建成功'));
console.log(chalk.green('助手环境配置.env文件创建成功'));
}
const appsConfig = this.configPath?.appsConfigPath;
// 创建助手应用配置文件 apps
if (!checkFileExists(appsConfig, true)) {
fs.writeFileSync(appsConfig, JSON.stringify({ description: 'apps manager.', list: [] }));
console.log(chalk.green('助手应用配置文件apps.json创建成功'));
}
}
}

View File

@@ -11,6 +11,10 @@ export const proxyRoute = async (req: http.IncomingMessage, res: http.ServerResp
const appDir = assistantConfig.configPath?.pageDir;
const url = new URL(req.url, 'http://localhost');
const pathname = url.pathname;
if (pathname === '/' && _assistantConfig?.home) {
res.writeHead(302, { Location: `${_assistantConfig?.home}/` });
return res.end();
}
if (pathname.startsWith('/favicon.ico')) {
res.statusCode = 404;
res.end('Not Found Favicon');