MCPcopy Create free account
hub / github.com/Kong/insomnia / tryToReadInsoConfigFile

Function tryToReadInsoConfigFile

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

Source from the content-addressed store, hash-verified

73configureV3ClientDefaults();
74
75export 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
106const localAppDir = getAppDataDir(getDefaultProductName());
107

Callers 2

mergeOptionsAndInitFunction · 0.85

Calls 2

reduceMethod · 0.80
logMethod · 0.45

Tested by

no test coverage detected