UNPKG

659 BPlain TextView Raw
1import { readFileSync } from 'fs';
2import { safeLoad } from 'js-yaml';
3import { getLogger } from './logging';
4
5const FILE_SUFFIX = '.yaml';
6
7export 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
17export const nameFromYamlConfig = (fileName: string): string =>
18 fileName.substr(0, fileName.indexOf(FILE_SUFFIX));