You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-06-15 23:00:36 +02:00
Tools: Various improvements on plugin-repo-cli
This commit is contained in:
49
packages/plugin-repo-cli/lib/updateReadme.ts
Normal file
49
packages/plugin-repo-cli/lib/updateReadme.ts
Normal file
@ -0,0 +1,49 @@
|
||||
import * as fs from 'fs-extra';
|
||||
import markdownUtils, { MarkdownTableHeader, MarkdownTableRow } from '@joplin/lib/markdownUtils';
|
||||
|
||||
export default async function(readmePath: string, manifests: any) {
|
||||
const rows: MarkdownTableRow[] = [];
|
||||
|
||||
for (const pluginId in manifests) {
|
||||
rows.push(manifests[pluginId]);
|
||||
}
|
||||
|
||||
const headers: MarkdownTableHeader[] = [
|
||||
{
|
||||
name: 'homepage_url',
|
||||
label: ' ',
|
||||
filter: (value: string) => {
|
||||
return `[🏠](${markdownUtils.escapeLinkUrl(value)})`;
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'name',
|
||||
label: 'Name',
|
||||
},
|
||||
{
|
||||
name: 'version',
|
||||
label: 'Version',
|
||||
},
|
||||
{
|
||||
name: 'description',
|
||||
label: 'Description',
|
||||
},
|
||||
{
|
||||
name: 'author',
|
||||
label: 'Author',
|
||||
},
|
||||
];
|
||||
|
||||
rows.sort((a: any, b: any) => {
|
||||
return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : +1;
|
||||
});
|
||||
|
||||
const mdTable = markdownUtils.createMarkdownTable(headers, rows);
|
||||
|
||||
const tableRegex = /<!-- PLUGIN_LIST -->([^]*)<!-- PLUGIN_LIST -->/;
|
||||
|
||||
const content = await fs.pathExists(readmePath) ? await fs.readFile(readmePath, 'utf8') : '<!-- PLUGIN_LIST -->\n<!-- PLUGIN_LIST -->';
|
||||
const newContent = content.replace(tableRegex, `<!-- PLUGIN_LIST -->\n${mdTable}\n<!-- PLUGIN_LIST -->`);
|
||||
|
||||
await fs.writeFile(readmePath, newContent, 'utf8');
|
||||
}
|
Reference in New Issue
Block a user