add more CR padding
This commit is contained in:
parent
8f8a16d025
commit
a326be7211
@ -1,94 +1,101 @@
|
|||||||
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 = {};
|
||||||
|
|
||||||
if( source?.project?.homepage) {
|
if (source?.project?.homepage) {
|
||||||
links.homepage = source?.project?.homepage;
|
links.homepage = source?.project?.homepage;
|
||||||
name = `[${name}][homepage]`;
|
name = `[${name}][homepage]`;
|
||||||
}
|
}
|
||||||
|
|
||||||
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) => {
|
||||||
let body = change.desc;
|
let body = change.desc;
|
||||||
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,
|
||||||
};
|
};
|
||||||
|
|
||||||
let body = "## " + release.version;
|
let body = "## " + release.version;
|
||||||
|
|
||||||
if( release.date) {
|
if (release.date) {
|
||||||
body += " " + release.date;
|
body += " " + release.date;
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
body += mkd.li(res.body,1)+"\n";
|
body += mkd.li(res.body, 1) + "\n";
|
||||||
links = { ...links, ...res.links};
|
links = { ...links, ...res.links };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,36 +103,33 @@ 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);
|
||||||
|
|
||||||
output += header + "\n\n";
|
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";
|
output += res.body + "\n\n";
|
||||||
links = {...links,...res.links};
|
links = { ...links, ...res.links };
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
||||||
}
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user