@softwareventures/maintain-project
Version:
Automatically create and maintain TypeScript projects with standard settings for Software Ventures Limited
33 lines • 1.25 kB
JavaScript
import yaml from "yaml";
import { map } from "@softwareventures/array";
import { hasProperty } from "unknown";
import { bindResultFn, failure, mapResultFn, success } from "../result/result.js";
import { readProjectText } from "./read-text.js";
export async function readProjectYaml(project, path) {
return readProjectText(project, path)
.then(mapResultFn(yaml.parse))
.catch((reason) => {
if (hasProperty(reason, "code") || !(reason instanceof Error)) {
throw reason;
}
else {
return failure([{ type: "invalid-yaml", reason, path }]);
}
});
}
export async function readProjectYamlAsDocument(project, path) {
return readProjectText(project, path)
.then(mapResultFn(yaml.parseDocument))
.then(bindResultFn(document => document.errors.length === 0
? success(document)
: failure(map(document.errors, reason => ({ type: "invalid-yaml", reason, path })))))
.catch((reason) => {
if (hasProperty(reason, "code") || !(reason instanceof Error)) {
throw reason;
}
else {
return failure([{ type: "invalid-yaml", reason, path }]);
}
});
}
//# sourceMappingURL=read-yaml.js.map