UNPKG

libyear

Version:

A simple measure of software dependency freshness

45 lines (44 loc) 1.78 kB
import { cosmiconfig } from "cosmiconfig"; import { merge } from "lodash-es"; import { safeParseInt } from "./style/number.js"; const getCliConfiguration = ({ limitDriftCollective, limitDriftIndividual, limitPulseCollective, limitPulseIndividual, limitReleasesCollective, limitReleasesIndividual, limitMajorCollective, limitMajorIndividual, limitMinorCollective, limitMinorIndividual, limitPatchCollective, limitPatchIndividual, }) => ({ limit: { drift: { collective: safeParseInt(limitDriftCollective), individual: safeParseInt(limitDriftIndividual), }, pulse: { collective: safeParseInt(limitPulseCollective), individual: safeParseInt(limitPulseIndividual), }, releases: { collective: safeParseInt(limitReleasesCollective), individual: safeParseInt(limitReleasesIndividual), }, major: { collective: safeParseInt(limitMajorCollective), individual: safeParseInt(limitMajorIndividual), }, minor: { collective: safeParseInt(limitMinorCollective), individual: safeParseInt(limitMinorIndividual), }, patch: { collective: safeParseInt(limitPatchCollective), individual: safeParseInt(limitPatchIndividual), }, }, }); const getCosmiconfig = async (filePath) => { const explorer = cosmiconfig("libyear"); try { const result = filePath ? await explorer.load(filePath) : await explorer.search(); return (result?.config ?? {}); } catch { return {}; } }; export const getConfiguration = async (args) => merge(await getCosmiconfig(args.config), getCliConfiguration(args));