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 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';
let header = "# Changelog";
let name = source.project?.name
let name = source.project?.name;
const links = {};
@ -17,16 +17,13 @@ const render_header = (source ) => {
if (name) header += ` for ${name}`;
return { header, links }
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) => {
@ -34,20 +31,23 @@ const render_change = (config,source)=>(change) => {
let links = {};
return {
body, links
}
body,
links,
};
};
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,
};
@ -59,31 +59,38 @@ export const render_release = (config,source) => ( release ) => {
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) {
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)
const type_changes = changes.filter(({ type }) =>
change_type.keywords.includes(type)
);
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);
@ -96,9 +103,9 @@ 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);
@ -112,20 +119,17 @@ const handler = async (config) => {
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')
.boolean("next")
// .default('json',false)
.default('next',true);
.default("next", true);
},
handler,
}
};