68 lines
2.0 KiB
JavaScript
Executable File
68 lines
2.0 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
import { hideBin } from "yargs/helpers";
|
|
import yargs from "yargs";
|
|
import { join } from "path";
|
|
import yaml from "yaml";
|
|
import fs from "fs-extra";
|
|
import consola from "consola";
|
|
import u from "@yanick/updeep-remeda";
|
|
|
|
import print from "./command/print.js";
|
|
import init from "./command/init.js";
|
|
import schema from "./command/schema.js";
|
|
import add from "./command/add.js";
|
|
import cut from "./command/cut.js";
|
|
import upcoming, { next_release } from "./command/upcoming.js";
|
|
import latest, { latest_version } from "./command/latest-version.js";
|
|
import git_gather from "./command/git-gather.js";
|
|
|
|
consola.raw = (...args) => console.log(...args);
|
|
|
|
yargs(hideBin(process.argv))
|
|
.middleware((config) => {
|
|
config.consola = consola;
|
|
config.changelog = () =>
|
|
fs.readFile(config.source, "utf-8").then(yaml.parse);
|
|
config.next_release = next_release.bind(config);
|
|
config.latest_version = latest_version.bind(config);
|
|
return config;
|
|
})
|
|
.middleware((argv) => {
|
|
argv.add_to_next = async (entry) => {
|
|
const changelog = yaml.parse(await fs.readFile(argv.source, "utf-8"));
|
|
|
|
let next = changelog.releases.find(u.matches({ version: "NEXT" }));
|
|
if (!next) {
|
|
next = { version: "NEXT", changes: [] };
|
|
changelog.releases.unshift(next);
|
|
}
|
|
|
|
if (Object.keys(entry).length === 1) {
|
|
entry = entry.desc;
|
|
}
|
|
|
|
next.changes.push(entry);
|
|
|
|
return fs.writeFile(argv.source, yaml.stringify(changelog));
|
|
};
|
|
})
|
|
.default("source", join(process.cwd(), "CHANGELOG.yml"))
|
|
.describe("source", "changelog source")
|
|
.command(init)
|
|
.command(add)
|
|
.command(print)
|
|
.command(cut)
|
|
.command(schema)
|
|
.command(upcoming)
|
|
.command({
|
|
...upcoming,
|
|
command: "next",
|
|
desc: 'alias for "upcoming"',
|
|
})
|
|
.command(latest)
|
|
.command(git_gather)
|
|
.strictCommands()
|
|
.help()
|
|
.parse();
|