add to the directory

This commit is contained in:
Yanick Champoux 2023-05-18 14:48:47 -04:00
parent 09d60859e1
commit f759989698
3 changed files with 52 additions and 24 deletions

View File

@ -24,11 +24,14 @@
"author": "Yanick Champoux <yanick@babyl.ca> (http://techblog.babyl.ca/)", "author": "Yanick Champoux <yanick@babyl.ca> (http://techblog.babyl.ca/)",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@sindresorhus/slugify": "^2.2.1",
"@yanick/updeep-remeda": "^2.2.0", "@yanick/updeep-remeda": "^2.2.0",
"ajv": "^8.12.0", "ajv": "^8.12.0",
"consola": "^3.1.0", "consola": "^3.1.0",
"filenamify": "^6.0.0",
"fs-extra": "^11.1.1", "fs-extra": "^11.1.1",
"markdown-utils": "^1.0.0", "markdown-utils": "^1.0.0",
"nanoid": "^4.0.2",
"remeda": "^1.14.0", "remeda": "^1.14.0",
"semver": "^7.5.0", "semver": "^7.5.0",
"simple-git": "^3.18.0", "simple-git": "^3.18.0",

View File

@ -10,6 +10,8 @@ import u from "@yanick/updeep-remeda";
import { once } from "remeda"; import { once } from "remeda";
import simpleGit from "simple-git"; import simpleGit from "simple-git";
import Ajv from "ajv"; import Ajv from "ajv";
import { nanoid } from "nanoid";
import slugify from "@sindresorhus/slugify";
import print from "./command/print.js"; import print from "./command/print.js";
import init from "./command/init.js"; import init from "./command/init.js";
@ -54,12 +56,35 @@ yargs(hideBin(process.argv))
argv.yargs = yargs; argv.yargs = yargs;
argv.add_to_next = async (entry) => { argv.add_to_next = async (entry) => {
const changelog = yaml.parse(await fs.readFile(argv.source, "utf-8")); const dir = await argv.changelog().then((c) => c.project.next_directory);
if (dir) {
await fs.ensureDir(dir);
const filename = join(
dir,
[
entry.ticket,
entry.feat,
slugify(entry.desc, {
separator: "_",
}).slice(0, 10),
]
.filter((x) => x)
.join("-") + ".yml"
);
argv.consola.info(`writing change to ${filename}`);
if (fs.existsSync(filename)) {
argv.consola.error(`file ${filename} already exist`);
yargs.exit(1);
}
return fs.writeFile(filename, yaml.stringify([entry]));
}
const changelog = await argv.changelog();
let next = changelog.releases.find(u.matches({ version: "NEXT" })); let next = changelog.releases.find(u.matches({ version: "NEXT" }));
if (!next) { if (!next) {
next = { version: "NEXT", changes: [] }; changelog.releases.unshift(base_next_version);
changelog.releases.unshift(next);
} }
if (Object.keys(entry).length === 1) { if (Object.keys(entry).length === 1) {
@ -68,7 +93,7 @@ yargs(hideBin(process.argv))
next.changes.push(entry); next.changes.push(entry);
return fs.writeFile(argv.source, yaml.stringify(changelog)); return argv.save_changelog();
}; };
}) })
.default("source", join(process.cwd(), "CHANGELOG.yml")) .default("source", join(process.cwd(), "CHANGELOG.yml"))

View File

@ -15,7 +15,7 @@ const handler = async (config) => {
config.consola.start(`adding '${entry.desc}' to the changelog`); config.consola.start(`adding '${entry.desc}' to the changelog`);
config.add_to_next(entry); await config.add_to_next(entry);
config.consola.success("done!"); config.consola.success("done!");
}; };