temp
This commit is contained in:
44
assistant/src/services/init/index.ts
Normal file
44
assistant/src/services/init/index.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import path from 'node:path';
|
||||
import { checkFileExists, AssistantConfig } from '@/module/assistant/index.ts';
|
||||
import { chalk } from '@/module/chalk.ts';
|
||||
export type AssistantInitOptions = {
|
||||
path?: string;
|
||||
};
|
||||
/**
|
||||
* 助手初始化类
|
||||
* @class AssistantInit
|
||||
*/
|
||||
export class AssistantInit extends AssistantConfig {
|
||||
constructor(opts?: AssistantInitOptions) {
|
||||
const configDir = opts?.path || process.cwd();
|
||||
super({
|
||||
configDir,
|
||||
});
|
||||
}
|
||||
|
||||
async init() {
|
||||
// 1. 检查助手路径是否存在
|
||||
if (!this.checkConfigPath()) {
|
||||
console.log(chalk.blue('助手路径不存在,正在创建...'));
|
||||
super.init();
|
||||
this.createAssistantConfig();
|
||||
} else {
|
||||
super.init();
|
||||
console.log(chalk.yellow('助手路径已存在'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
checkConfigPath() {
|
||||
const assistantPath = path.join(this.configDir, 'assistant-config.json');
|
||||
return checkFileExists(assistantPath);
|
||||
}
|
||||
createAssistantConfig() {
|
||||
const assistantPath = this.configPath?.configPath;
|
||||
if (!checkFileExists(assistantPath, true)) {
|
||||
this.setConfig({
|
||||
description: '助手配置文件',
|
||||
});
|
||||
console.log(chalk.green('助手配置文件创建成功'));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user