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

Function tryToReadInsoConfigFile

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

Source from the content-addressed store, hash-verified

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

Callers 2

mergeOptionsAndInitFunction · 0.85

Calls 3

searchMethod · 0.80
reduceMethod · 0.80
logMethod · 0.45

Tested by

no test coverage detected