(configFile?: string, workingDir?: string)
| 73 | configureV3ClientDefaults(); |
| 74 | |
| 75 | export const tryToReadInsoConfigFile = async (configFile?: string, workingDir?: string) => { |
| 76 | try { |
| 77 | const explorer = await cosmiconfig('inso'); |
| 78 | // set or detect .insorc in workingDir or cwd https://github.com/cosmiconfig/cosmiconfig?tab=readme-ov-file#explorersearch |
| 79 | const results = configFile ? await explorer.load(configFile) : await explorer.search(workingDir || process.cwd()); |
| 80 | |
| 81 | if (results && !results?.isEmpty) { |
| 82 | logger.debug(`Found config file at ${results?.filepath}.`); |
| 83 | const scripts = results.config?.scripts || {}; |
| 84 | const filePath = results.filepath; |
| 85 | const options = ['workingDir', 'ci', 'verbose', 'printOptions'].reduce((acc, key) => { |
| 86 | const value = results.config?.options?.[key]; |
| 87 | if (value) { |
| 88 | return { ...acc, [key]: value }; |
| 89 | } |
| 90 | return acc; |
| 91 | }, {}); |
| 92 | |
| 93 | return { options, scripts, filePath }; |
| 94 | } |
| 95 | } catch (error) { |
| 96 | // Report fatal error when loading from explicitly defined config file |
| 97 | if (configFile) { |
| 98 | console.log(`Could not find config file at ${configFile}.`); |
| 99 | console.error(error); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | return {}; |
| 104 | }; |
| 105 | |
| 106 | const localAppDir = getAppDataDir(getDefaultProductName()); |
| 107 |
no test coverage detected