@pagopa/dx-cli
Version:
A CLI useful to manage DX tools.
15 lines (14 loc) • 768 B
JavaScript
import { errAsync, okAsync, ResultAsync } from "neverthrow";
const getCodemodById = (registry, id) => registry
.getById(id)
.andThen((codemod) => codemod
? okAsync(codemod)
: errAsync(new Error(`Codemod with id ${id} not found`)));
const safeGetInfo = (getInfo) => ResultAsync.fromPromise(getInfo(), (error) => new Error("Failed to get info", { cause: error }));
export const applyCodemodById = (registry, getInfo) => (id) => ResultAsync.combine([
safeGetInfo(getInfo),
getCodemodById(registry, id),
]).andThen(([info, codemod]) => ResultAsync.fromPromise(codemod.apply(info), (error) => {
const message = error instanceof Error ? `: ${error.message}` : "";
return new Error("Failed to apply codemod" + message, { cause: error });
}));