diff --git a/.eslintignore b/.eslintignore index 27b2a4722..7b08025c0 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1584,6 +1584,9 @@ packages/plugin-repo-cli/lib/types.js.map packages/plugin-repo-cli/lib/updateReadme.d.ts packages/plugin-repo-cli/lib/updateReadme.js packages/plugin-repo-cli/lib/updateReadme.js.map +packages/plugin-repo-cli/lib/updateReadme.test.d.ts +packages/plugin-repo-cli/lib/updateReadme.test.js +packages/plugin-repo-cli/lib/updateReadme.test.js.map packages/plugins/ToggleSidebars/api/index.d.ts packages/plugins/ToggleSidebars/api/index.js packages/plugins/ToggleSidebars/api/index.js.map diff --git a/.gitignore b/.gitignore index a655bb7a2..2296a886b 100644 --- a/.gitignore +++ b/.gitignore @@ -1569,6 +1569,9 @@ packages/plugin-repo-cli/lib/types.js.map packages/plugin-repo-cli/lib/updateReadme.d.ts packages/plugin-repo-cli/lib/updateReadme.js packages/plugin-repo-cli/lib/updateReadme.js.map +packages/plugin-repo-cli/lib/updateReadme.test.d.ts +packages/plugin-repo-cli/lib/updateReadme.test.js +packages/plugin-repo-cli/lib/updateReadme.test.js.map packages/plugins/ToggleSidebars/api/index.d.ts packages/plugins/ToggleSidebars/api/index.js packages/plugins/ToggleSidebars/api/index.js.map diff --git a/packages/plugin-repo-cli/README.md b/packages/plugin-repo-cli/README.md index dfbf351f4..76578d8f6 100644 --- a/packages/plugin-repo-cli/README.md +++ b/packages/plugin-repo-cli/README.md @@ -2,6 +2,14 @@ This tool is used to build the plugin repository at https://github.com/joplin/plugins -# Publishing +## Testing + +To test the tool with existing packages, the best is to: + +- Create a separate copy of the plugin repo +- Reset back a few commits +- Run with the --dry-run option: `plugin-repo-cli build ~/src/joplin-plugins-test/ --dry-run` + +## Publishing To publish it, run `npm run publishAll` from the root. \ No newline at end of file diff --git a/packages/plugin-repo-cli/index.ts b/packages/plugin-repo-cli/index.ts index 5401fcbdb..dbcb04c27 100644 --- a/packages/plugin-repo-cli/index.ts +++ b/packages/plugin-repo-cli/index.ts @@ -1,11 +1,5 @@ #!/usr/bin/env node -// To test the tool with existing packages, the best is to: -// -// - Create a separate copy of the plugin repo -// - Reset back a few commits -// - Run with the --dry-run option: `plugin-repo-cli build ~/src/joplin-plugins-test/ --dry-run` - import * as fs from 'fs-extra'; import * as path from 'path'; import * as process from 'process'; diff --git a/packages/plugin-repo-cli/lib/updateReadme.test.ts b/packages/plugin-repo-cli/lib/updateReadme.test.ts new file mode 100644 index 000000000..0243af088 --- /dev/null +++ b/packages/plugin-repo-cli/lib/updateReadme.test.ts @@ -0,0 +1,68 @@ +import * as fs from 'fs-extra'; +import updateReadme from './updateReadme'; + +describe('updateReadme', () => { + + test('should update the README file', async () => { + const manifests: any = { + 'io.github.jackgruber.copytags': { + 'manifest_version': 1, + 'id': 'io.github.jackgruber.copytags', + 'app_min_version': '1.6.2', + 'version': '1.0.1', + 'name': 'Tagging', + 'description': 'Plugin to extend the Joplin tagging menu with a coppy all tags and a tagging dialog with more control. (Formerly Copy Tags).', + 'author': 'JackGruber', + 'homepage_url': 'https://github.com/JackGruber/joplin-plugin-tagging/blob/master/README.md', + 'repository_url': 'https://github.com/JackGruber/joplin-plugin-tagging', + 'keywords': [ + 'duplicate', + 'copy', + 'tags', + 'tagging', + 'tag', + ], + '_publish_hash': 'sha256:88daaf234a9b47e5644a8de6f830a801d12edbe41ea5364d994773e89eeafeef', + '_publish_commit': 'master:64c0510e3236df7788a8d10ec28dcfbb4c2bdbb7', + '_npm_package_name': 'joplin-plugin-copytags', + }, + 'joplin.plugin.ambrt.backlinksToNote': { + 'manifest_version': 1, + 'id': 'joplin.plugin.ambrt.backlinksToNote', + 'app_min_version': '1.7', + 'version': '2.0.10', + 'name': 'Automatic Backlinks to note', + 'description': 'Creates backlinks to opened note, also in automatic way', + 'author': 'ambrt', + 'homepage_url': 'https://discourse.joplinapp.org/t/insert-referencing-notes-backlinks-plugin/13632', + '_publish_hash': 'sha256:b5dec8d00f19e34c4fe1dc0ed380b6743aa7debfd8f600ead0d6866ba21466f1', + '_publish_commit': 'master:05020664a6a7f567c466e3fbad1d7e7ec64dc369', + '_npm_package_name': 'joplin-plugin-backlinks', + }, + }; + + const tempFilePath = `${__dirname}/test_README.md`; + await fs.writeFile(tempFilePath, '\n'); + + await updateReadme(tempFilePath, manifests); + + const content = await fs.readFile(tempFilePath, 'utf8'); + + // Check header + expect(content.includes('|   |   | Name | Version | Description | Author |')).toBe(true); + + // Check plugin content + expect(content.includes('https://github.com/JackGruber/joplin-plugin-tagging/blob/master/README.md')).toBe(true); + expect(content.includes('https://github.com/joplin/plugins/raw/master/plugins/joplin.plugin.ambrt.backlinksToNote/plugin.jpl')).toBe(true); + expect(content.includes('Automatic Backlinks to note')).toBe(true); + expect(content.includes('2.0.10')).toBe(true); + expect(content.includes('Creates backlinks to opened note, also in automatic way')).toBe(true); + expect(content.includes('ambrt')).toBe(true); + + // Check that it keeps the markers + expect(content.split('').length - 1).toBe(2); + + await fs.remove(tempFilePath); + }); + +}); diff --git a/packages/plugin-repo-cli/lib/updateReadme.ts b/packages/plugin-repo-cli/lib/updateReadme.ts index b60446194..b63c31eec 100644 --- a/packages/plugin-repo-cli/lib/updateReadme.ts +++ b/packages/plugin-repo-cli/lib/updateReadme.ts @@ -2,20 +2,36 @@ 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[] = []; + let rows: MarkdownTableRow[] = []; for (const pluginId in manifests) { rows.push(manifests[pluginId]); } + rows = rows.map(row => { + return { + ...row, + download_url: `https://github.com/joplin/plugins/raw/master/plugins/${row.id}/plugin.jpl`, + }; + }); + const headers: MarkdownTableHeader[] = [ { name: 'homepage_url', label: ' ', filter: (value: string) => { + if (!value) return '-'; return `[🏠](${markdownUtils.escapeLinkUrl(value)})`; }, }, + { + name: 'download_url', + label: ' ', + filter: (value: string) => { + if (!value) return '-'; + return `[⬇️](${markdownUtils.escapeLinkUrl(value)})`; + }, + }, { name: 'name', label: 'Name',