add more CR padding

This commit is contained in:
Yanick Champoux 2023-05-10 15:33:16 -04:00
parent 8f8a16d025
commit a326be7211

View File

@ -1,12 +1,12 @@
import * as R from 'remeda'; import * as R from "remeda";
import fs from 'fs-extra'; import fs from "fs-extra";
import yaml from 'yaml'; import yaml from "yaml";
import mkd from 'markdown-utils'; import mkd from "markdown-utils";
const render_header = (source) => { const render_header = (source) => {
let header = '# Changelog'; let header = "# Changelog";
let name = source.project?.name let name = source.project?.name;
const links = {}; const links = {};
@ -17,16 +17,13 @@ const render_header = (source ) => {
if (name) header += ` for ${name}`; if (name) header += ` for ${name}`;
return { header, links } return { header, links };
}; };
function render_links(links) { function render_links(links) {
return Object.entries(links)
return Object.entries(links).map( .map(([name, url]) => ` [${name}]: ${url}`)
([name,url]) => ` [${name}]: ${url}` .join("\n");
).join( "\n")
} }
const render_change = (config, source) => (change) => { const render_change = (config, source) => (change) => {
@ -34,20 +31,23 @@ const render_change = (config,source)=>(change) => {
let links = {}; let links = {};
return { return {
body, links body,
} links,
};
}; };
export const render_release = (config, source) => (release) => { export const render_release = (config, source) => (release) => {
let links = {}; let links = {};
if( typeof release === 'string') return { if (typeof release === "string")
return {
body: release, body: release,
links links,
}; };
if(release.version === 'NEXT' && !config.next) return { if (release.version === "NEXT" && !config.next)
body: '', return {
body: "",
links, links,
}; };
@ -59,31 +59,38 @@ export const render_release = (config,source) => ( release ) => {
body += "\n\n"; body += "\n\n";
const type_map = Object.fromEntries(source.change_types.flatMap( const type_map = Object.fromEntries(
entry => entry.keywords.map( k => [ k, entry ]) source.change_types.flatMap((entry) =>
)); entry.keywords.map((k) => [k, entry])
)
);
const changes = release.changes.map( change => typeof change === 'string'? { desc: change, type: '' } : change ); const changes = release.changes.map((change) =>
typeof change === "string" ? { desc: change, type: "" } : change
);
const unknown = R.uniq( changes.map(R.prop('type')).map( const unknown = R.uniq(
t => t ?? '' changes
).filter( type => !type_map[type])); .map(R.prop("type"))
.map((t) => t ?? "")
.filter((type) => !type_map[type])
);
if (unknown.length) { if (unknown.length) {
throw new Error( throw new Error(
"unknown change types encountered: " + unknown.map(t => `'${t}'`).join(', ') "unknown change types encountered: " +
unknown.map((t) => `'${t}'`).join(", ")
); );
} }
for (const change_type of source.change_types) { for (const change_type of source.change_types) {
const type_changes = changes.filter( const type_changes = changes.filter(({ type }) =>
({type}) => change_type.keywords.includes(type) change_type.keywords.includes(type)
); );
if (type_changes.length === 0) continue; if (type_changes.length === 0) continue;
if( change_type.title ) if (change_type.title) body += "\n" + mkd.h3(change_type.title) + "\n\n";
body += mkd.h2( change_type.title) + "\n\n";
for (const c of type_changes) { for (const c of type_changes) {
const res = render_change(config, source)(c); const res = render_change(config, source)(c);
@ -96,9 +103,9 @@ export const render_release = (config,source) => ( release ) => {
}; };
const handler = async (config) => { const handler = async (config) => {
const source = await fs.readFile(config.source,'utf-8').then(yaml.parse); const source = await fs.readFile(config.source, "utf-8").then(yaml.parse);
let output = ''; let output = "";
let { header, links } = render_header(source); let { header, links } = render_header(source);
@ -112,20 +119,17 @@ const handler = async (config) => {
output += "\n\n\n\n" + render_links(links); output += "\n\n\n\n" + render_links(links);
config.consola.raw(output); config.consola.raw(output);
}; };
export default { export default {
command: 'print', command: "print",
desc : 'render the changelog', desc: "render the changelog",
builder: (yargs) => { builder: (yargs) => {
yargs yargs
//.boolean('json') //.boolean('json')
.boolean('next') .boolean("next")
// .default('json',false) // .default('json',false)
.default('next',true); .default("next", true);
}, },
handler, handler,
} };