add more CR padding
This commit is contained in:
parent
8f8a16d025
commit
a326be7211
@ -1,131 +1,135 @@
|
|||||||
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
|
|
||||||
|
|
||||||
const links = {};
|
let name = source.project?.name;
|
||||||
|
|
||||||
if( source?.project?.homepage) {
|
const links = {};
|
||||||
links.homepage = source?.project?.homepage;
|
|
||||||
name = `[${name}][homepage]`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(name) header += ` for ${name}`;
|
if (source?.project?.homepage) {
|
||||||
|
links.homepage = source?.project?.homepage;
|
||||||
|
name = `[${name}][homepage]`;
|
||||||
|
}
|
||||||
|
|
||||||
return { header, links }
|
if (name) header += ` for ${name}`;
|
||||||
|
|
||||||
|
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")
|
||||||
body: release,
|
return {
|
||||||
links
|
body: release,
|
||||||
|
links,
|
||||||
};
|
};
|
||||||
|
|
||||||
if(release.version === 'NEXT' && !config.next) return {
|
if (release.version === "NEXT" && !config.next)
|
||||||
body: '',
|
return {
|
||||||
links,
|
body: "",
|
||||||
|
links,
|
||||||
};
|
};
|
||||||
|
|
||||||
let body = "## " + release.version;
|
let body = "## " + release.version;
|
||||||
|
|
||||||
if( release.date) {
|
if (release.date) {
|
||||||
body += " " + 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 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])
|
||||||
|
);
|
||||||
|
|
||||||
|
if (unknown.length) {
|
||||||
|
throw new Error(
|
||||||
|
"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)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (type_changes.length === 0) continue;
|
||||||
|
|
||||||
|
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 };
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
body += "\n\n";
|
return { body, links };
|
||||||
|
|
||||||
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 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(', ')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
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( change_type.title )
|
|
||||||
body += mkd.h2( 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};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return { body, links };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
config.consola.raw(output);
|
|
||||||
|
|
||||||
|
output += "\n\n\n\n" + render_links(links);
|
||||||
|
|
||||||
|
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