(filename: string)
| 68 | } |
| 69 | |
| 70 | export const loadConfigFile = async (filename: string): Promise<ProfilesByName> => { |
| 71 | if (!yamlExists(filename)) { |
| 72 | return {} |
| 73 | } |
| 74 | |
| 75 | const parsed = yaml.load(await readFile(filename, 'utf-8')) |
| 76 | if (parsed) { |
| 77 | if (typeof parsed === 'object' && !Array.isArray(parsed)) { |
| 78 | const errors: string[] = [] |
| 79 | const config: ProfilesByName = {} |
| 80 | for (const [profileName, profile] of Object.entries(parsed)) { |
| 81 | if (typeof(profile) === 'object' && !Array.isArray(profile)) { |
| 82 | config[profileName] = profile |
| 83 | } else { |
| 84 | errors.push(`bad profile ${profileName}; profile must be an object`) |
| 85 | } |
| 86 | } |
| 87 | if (errors.length) { |
| 88 | return fatalError(`${errors.join('\n')}\n${seeConfigDocs}`) |
| 89 | } |
| 90 | return config |
| 91 | } else { |
| 92 | return fatalError('invalid config file format\n' + seeConfigDocs) |
| 93 | } |
| 94 | } |
| 95 | return {} |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Merge profiles from `preferred` and `secondary`, favoring any config entries from `preferred` |
no test coverage detected