1 | import { readFileSync } from 'fs';
|
2 | import { safeLoad } from 'js-yaml';
|
3 | import { getLogger } from './logging';
|
4 |
|
5 | const FILE_SUFFIX = '.yaml';
|
6 |
|
7 | export const loadYamlConfiguration = (pathToFile: string): any => {
|
8 | if (pathToFile && pathToFile.endsWith(FILE_SUFFIX)) {
|
9 | const yamlConfig = safeLoad(readFileSync(pathToFile, 'utf8'));
|
10 | getLogger().debug(`Successfully loaded YAML config: ${pathToFile}`);
|
11 | return yamlConfig;
|
12 | }
|
13 | getLogger().warn(`Skipping unsupported file: ${pathToFile}`);
|
14 | return undefined;
|
15 | };
|
16 |
|
17 | export const nameFromYamlConfig = (fileName: string): string =>
|
18 | fileName.substr(0, fileName.indexOf(FILE_SUFFIX));
|