feat: 助手配置与服务命令扩展及依赖更新
This commit is contained in:
		
							
								
								
									
										1
									
								
								assistant/src/services/app/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								assistant/src/services/app/index.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | ||||
| // app downlaod | ||||
| @@ -2,6 +2,7 @@ import fs from 'node:fs'; | ||||
| import path from 'node:path'; | ||||
| import { checkFileExists, AssistantConfig } from '@/module/assistant/index.ts'; | ||||
| import { chalk } from '@/module/chalk.ts'; | ||||
| import { HttpsPem } from '@/module/assistant/https/sign.ts'; | ||||
| export type AssistantInitOptions = { | ||||
|   path?: string; | ||||
|   init?: boolean; | ||||
| @@ -15,8 +16,11 @@ export class AssistantInit extends AssistantConfig { | ||||
|     const configDir = opts?.path || process.cwd(); | ||||
|     super({ | ||||
|       configDir, | ||||
|       init: opts?.init ?? false, | ||||
|       init: false, | ||||
|     }); | ||||
|     if (opts?.init) { | ||||
|       this.init(); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   async init() { | ||||
| @@ -24,38 +28,51 @@ export class AssistantInit extends AssistantConfig { | ||||
|     if (!this.checkConfigPath()) { | ||||
|       console.log(chalk.blue('助手路径不存在,正在创建...')); | ||||
|       super.init(); | ||||
|       this.createAssistantConfig(); | ||||
|     } else { | ||||
|       super.init(); | ||||
|       console.log(chalk.yellow('助手路径已存在')); | ||||
|       return; | ||||
|     } | ||||
|     this.createAssistantConfig(); | ||||
|     this.createEnvConfig(); | ||||
|     this.createOtherConfig(); | ||||
|   } | ||||
|   checkConfigPath() { | ||||
|     const assistantPath = path.join(this.configDir, 'assistant-app', 'assistant-config.json'); | ||||
|     return checkFileExists(assistantPath); | ||||
|   } | ||||
|   createEnvConfig() { | ||||
|     const env = this.configPath?.envConfigPath; | ||||
|     // 创建助手环境配置文件 env | ||||
|     if (!checkFileExists(env, true)) { | ||||
|       fs.writeFileSync(env, '# 环境配置文件\n'); | ||||
|       console.log(chalk.green('助手环境配置.env文件创建成功')); | ||||
|     } | ||||
|   } | ||||
|   createOtherConfig() { | ||||
|     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 创建成功')); | ||||
|     } | ||||
|     // create pem dir // | ||||
|     const pemDir = path.join(this.configPath?.configDir, 'pem'); | ||||
|     if (!checkFileExists(pemDir)) { | ||||
|       new HttpsPem(this); | ||||
|       console.log(chalk.green('助手证书目录创建成功')); | ||||
|     } | ||||
|   } | ||||
|   createAssistantConfig() { | ||||
|     const assistantPath = this.configPath?.configPath; | ||||
|     // 创建助手配置文件 assistant-config.json | ||||
|     if (!checkFileExists(assistantPath, true)) { | ||||
|       this.setConfig({ | ||||
|         description: '助手配置文件', | ||||
|         home: '/root/center', | ||||
|         proxy: [], | ||||
|         apiProxyList: [], | ||||
|       }); | ||||
|       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('助手环境配置.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创建成功')); | ||||
|     } | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user