()
| 25 | }; |
| 26 | |
| 27 | export async function loadConfig(): Promise<BaseAIConfig> { |
| 28 | const explorer = cosmiconfig('baseai', { |
| 29 | searchPlaces: ['baseai/baseai.config.ts'], |
| 30 | loaders: { |
| 31 | '.ts': TypeScriptLoader() |
| 32 | } |
| 33 | }); |
| 34 | try { |
| 35 | let result = await explorer.search(); |
| 36 | if (!result) { |
| 37 | // throw new Error('No config file found'); |
| 38 | p.cancel('Failed to create config file'); |
| 39 | process.exit(1); |
| 40 | } |
| 41 | |
| 42 | // BaseAI config is expected to be in the config key of the config file |
| 43 | const config = result.config.config; |
| 44 | if (config) { |
| 45 | return { |
| 46 | ...defaultConfig, |
| 47 | ...config, |
| 48 | log: { |
| 49 | ...defaultConfig.log, |
| 50 | ...config.log |
| 51 | } |
| 52 | }; |
| 53 | } |
| 54 | } catch (error) { |
| 55 | // console.log(error); |
| 56 | p.cancel('Error: Unable to load config file'); |
| 57 | process.exit(1); |
| 58 | } |
| 59 | return defaultConfig; |
| 60 | } |
no test coverage detected