MCPcopy
hub / github.com/Kong/insomnia / tryToReadInsoConfigFile

Function tryToReadInsoConfigFile

packages/insomnia-inso/src/cli.ts:72–101  ·  view source on GitHub ↗
(configFile?: string, workingDir?: string)

Source from the content-addressed store, hash-verified

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

Callers 2

mergeOptionsAndInitFunction · 0.85

Calls 3

reduceMethod · 0.45
logMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected