libyear
Version:
A simple measure of software dependency freshness
74 lines (73 loc) • 4.39 kB
JavaScript
import { getInferredPackageManager, getParsedPackageManager, } from "../fetch/package-manager.js";
import { libyear } from "../libyear.js";
import { getArgs } from "./args.js";
import { getConfiguration } from "./configuration.js";
import { print } from "./print.js";
const validateLimit = (limit) => Number.isNaN(Number(limit)) ? undefined : Number(limit);
export const cli = async () => {
const { all, dev, help, json, packageManager, preReleases, quiet, sort, ...rest } = getArgs();
if (help) {
console.log([
"─── Usage ".padEnd(Math.min(process.stdout.columns, 100), "─"),
"$ libyear <options>",
"─── Options ".padEnd(Math.min(process.stdout.columns, 100), "─"),
"--all Include dependencies from the whole project.",
"--config Path to a libyear configuration file.",
"--dev Include dev dependencies.",
"--help, -h Show help.",
"--json Outputs the report to the console as valid JSON.",
'--package-manager Accepts "berry", "npm", "pnpm", "yarn"',
"--pre-releases Include pre-releases in latest versions.",
"--quiet, -q Exclude up-to-date dependencies from results.",
"--sort Column to sort individual results by.",
"--limit-drift-collective, -D Drift limit to warn on for all dependencies.",
"--limit-drift-individual, -d Drift limit to warn on for individual dependencies.",
"--limit-pulse-collective, -P Pulse limit to warn on for all dependencies.",
"--limit-pulse-individual, -p Pulse limit to warn on for individual dependencies.",
"--limit-releases-collective, -R Releases limit to warn on for all dependencies.",
"--limit-releases-individual, -r Releases limit to warn on for individual dependencies.",
"--limit-major-collective, -X Major releases limit to warn on for all dependencies.",
"--limit-major-individual, -x Major releases limit to warn on for individual dependencies.",
"--limit-minor-collective, -Y Minor releases limit to warn on for all dependencies.",
"--limit-minor-individual, -y Minor releases limit to warn on for individual dependencies.",
"--limit-patch-collective, -Z Patch releases limit to warn on for all dependencies.",
"--limit-patch-individual, -z Patch releases limit to warn on for individual dependencies.",
].join("\n"));
return;
}
// run libyear
try {
const report = await libyear(getParsedPackageManager(packageManager ?? (await getInferredPackageManager())), { all, dev, preReleases, quiet, sort });
if (json) {
console.log(JSON.stringify(report));
}
else {
const { overrides, limit } = await getConfiguration(rest).then(({ overrides, limit: { drift, pulse, releases, major, minor, patch } = {}, }) => ({
overrides,
limit: {
driftCollective: validateLimit(drift?.collective),
driftIndividual: validateLimit(drift?.individual),
pulseCollective: validateLimit(pulse?.collective),
pulseIndividual: validateLimit(pulse?.individual),
releasesCollective: validateLimit(releases?.collective),
releasesIndividual: validateLimit(releases?.individual),
majorCollective: validateLimit(major?.collective),
majorIndividual: validateLimit(major?.individual),
minorCollective: validateLimit(minor?.collective),
minorIndividual: validateLimit(minor?.individual),
patchCollective: validateLimit(patch?.collective),
patchIndividual: validateLimit(patch?.individual),
},
}));
print(report, limit, overrides);
}
}
catch (error) {
if (json) {
console.log(JSON.stringify(error));
}
else {
console.error(error.message);
}
}
};