fork of hey-api/openapi-ts because I need some additional things
1import type { AnyObject, MaybeArray } from '@hey-api/types';
2import { loadConfig } from 'c12';
3
4import type { Logger } from '../logger';
5import { mergeConfigs } from './merge';
6
7export async function loadConfigFile<T extends AnyObject>({
8 configFile,
9 logger,
10 name,
11 userConfig,
12}: {
13 configFile: string | undefined;
14 logger: Logger;
15 name: string;
16 userConfig: T;
17}): Promise<{
18 configFile: string | undefined;
19 configs: ReadonlyArray<T>;
20 foundConfig: boolean;
21}> {
22 const eventC12 = logger.timeEvent('c12');
23 const { config: fileConfig, configFile: loadedConfigFile } = await loadConfig<MaybeArray<T>>({
24 configFile,
25 name,
26 });
27 eventC12.timeEnd();
28
29 const fileConfigs = fileConfig instanceof Array ? fileConfig : [fileConfig];
30 const mergedConfigs = fileConfigs.map((config) => mergeConfigs<T>(config, userConfig));
31 const foundConfig = fileConfigs.some((config) => Object.keys(config).length > 0);
32
33 return { configFile: loadedConfigFile, configs: mergedConfigs, foundConfig };
34}