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,94 +1,101 @@
import * as R from 'remeda';
import fs from 'fs-extra';
import yaml from 'yaml';
import mkd from 'markdown-utils';
import * as R from "remeda";
import fs from "fs-extra";
import yaml from "yaml";
import mkd from "markdown-utils";
const render_header = (source ) => {
let header = '# Changelog';
const render_header = (source) => {
let header = "# Changelog";
let name = source.project?.name
let name = source.project?.name;
const links = {};
if( source?.project?.homepage) {
if (source?.project?.homepage) {
links.homepage = source?.project?.homepage;
name = `[${name}][homepage]`;
}
if(name) header += ` for ${name}`;
return { header, links }
if (name) header += ` for ${name}`;
return { header, links };
};
function render_links(links) {
return Object.entries(links).map(
([name,url]) => ` [${name}]: ${url}`
).join( "\n")
return Object.entries(links)
.map(([name, url]) => ` [${name}]: ${url}`)
.join("\n");
}
const render_change = (config,source)=>(change) => {
const render_change = (config, source) => (change) => {
let body = change.desc;
let links = {};
return {
body, links
}
body,
links,
};
};
export const render_release = (config,source) => ( release ) => {
export const render_release = (config, source) => (release) => {
let links = {};
if( typeof release === 'string') return {
if (typeof release === "string")
return {
body: release,
links
links,
};
if(release.version === 'NEXT' && !config.next) return {
body: '',
if (release.version === "NEXT" && !config.next)
return {
body: "",
links,
};
let body = "## " + release.version;
if( release.date) {
if (release.date) {
body += " " + release.date;
}
body += "\n\n";
const type_map = Object.fromEntries(source.change_types.flatMap(
entry => entry.keywords.map( k => [ k, entry ])
));
const type_map = Object.fromEntries(
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(
t => t ?? ''
).filter( type => !type_map[type]));
const unknown = R.uniq(
changes
.map(R.prop("type"))
.map((t) => t ?? "")
.filter((type) => !type_map[type])
);
if( unknown.length ) {
if (unknown.length) {
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 ) {
const type_changes = changes.filter(
({type}) => change_type.keywords.includes(type)
for (const change_type of source.change_types) {
const type_changes = changes.filter(({ type }) =>
change_type.keywords.includes(type)
);
if( type_changes.length === 0) continue;
if (type_changes.length === 0) continue;
if( change_type.title )
body += mkd.h2( change_type.title) + "\n\n";
if (change_type.title) body += "\n" + mkd.h3(change_type.title) + "\n\n";
for( const c of type_changes ) {
const res = render_change(config,source)(c);
body += mkd.li(res.body,1)+"\n";
links = { ...links, ...res.links};
for (const c of type_changes) {
const res = render_change(config, source)(c);
body += mkd.li(res.body, 1) + "\n";
links = { ...links, ...res.links };
}
}
@ -96,36 +103,33 @@ export const render_release = (config,source) => ( release ) => {
};
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);
output += header + "\n\n";
for ( const res of source.releases.map( render_release(config,source) )) {
for (const res of source.releases.map(render_release(config, source))) {
output += res.body + "\n\n";
links = {...links,...res.links};
links = { ...links, ...res.links };
}
output += "\n\n\n\n" + render_links(links);
config.consola.raw(output);
};
export default {
command: 'print',
desc : 'render the changelog',
command: "print",
desc: "render the changelog",
builder: (yargs) => {
yargs
//.boolean('json')
.boolean('next')
// .default('json',false)
.default('next',true);
.boolean("next")
// .default('json',false)
.default("next", true);
},
handler,
}
};