baldrick-broth
Version:
Build automation tool and task runner
29 lines (28 loc) • 680 B
JavaScript
import fs from 'node:fs/promises';
import YAML from 'yaml';
import { willFail } from './railway.js';
export const readYaml = async (filename) => {
let content;
try {
content = await fs.readFile(filename, { encoding: 'utf8' });
}
catch {
return willFail({
message: `The yaml file cannot be found: ${filename}`,
filename,
});
}
try {
const value = YAML.parse(content);
return {
status: 'success',
value,
};
}
catch {
return willFail({
message: `The yaml file cannot be parsed: ${filename}`,
filename,
});
}
};