import * as yaml from 'yaml' import * as fs from 'fs' import * as path from 'path' import * as globby from 'globby' export async function loadConfigurationFromGlob(cwd: string, glob: string[]): Promise { const files = await globby(glob, { cwd, absolute: true, onlyFiles: true, }); // Merge configs at the first level so they don't overwrite const result: any = {} for (const file of files) { const config: any = loadConfigurationFromFile(file) merge(result, config) } return result } export function merge(result: any, config: any) { for (const key in config) { result[key] = { ...result[key], ...config[key], } } } function loadConfigurationFromFile(file: string): any { // console.log('loadConfigurationFromFile', file) const content = fs.readFileSync(path.join(file), 'utf8') if (file.match('\.ya?ml$')) { return yaml.parse(content) } return JSON.parse(content) }