From 5aa5089ae0d52c6d60e70f8ac7785c299e0a2527 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Tue, 12 Jan 2021 15:34:59 +0000 Subject: [PATCH] Plugins: Add support for "keywords" manifest field --- .eslintignore | 6 +++--- .gitignore | 6 +++--- packages/app-cli/tests/support/plugins/toc/package.json | 2 +- .../app-cli/tests/support/plugins/toc/src/manifest.json | 4 +--- .../generators/app/templates/src/manifest.json | 3 ++- packages/lib/services/plugins/utils/manifestFromObject.ts | 8 ++++++++ packages/lib/services/plugins/utils/types.ts | 1 + readme/api/references/plugin_manifest.md | 2 ++ 8 files changed, 21 insertions(+), 11 deletions(-) diff --git a/.eslintignore b/.eslintignore index 732147a89..b7facce7d 100644 --- a/.eslintignore +++ b/.eslintignore @@ -452,9 +452,9 @@ packages/app-desktop/gui/MainScreen/commands/toggleLayoutMoveMode.js.map packages/app-desktop/gui/MainScreen/commands/toggleNoteList.d.ts packages/app-desktop/gui/MainScreen/commands/toggleNoteList.js packages/app-desktop/gui/MainScreen/commands/toggleNoteList.js.map -packages/app-desktop/gui/MainScreen/commands/toggleSidebar.d.ts -packages/app-desktop/gui/MainScreen/commands/toggleSidebar.js -packages/app-desktop/gui/MainScreen/commands/toggleSidebar.js.map +packages/app-desktop/gui/MainScreen/commands/toggleSideBar.d.ts +packages/app-desktop/gui/MainScreen/commands/toggleSideBar.js +packages/app-desktop/gui/MainScreen/commands/toggleSideBar.js.map packages/app-desktop/gui/MainScreen/commands/toggleVisiblePanes.d.ts packages/app-desktop/gui/MainScreen/commands/toggleVisiblePanes.js packages/app-desktop/gui/MainScreen/commands/toggleVisiblePanes.js.map diff --git a/.gitignore b/.gitignore index 3dcd4042d..f98ce2686 100644 --- a/.gitignore +++ b/.gitignore @@ -441,9 +441,9 @@ packages/app-desktop/gui/MainScreen/commands/toggleLayoutMoveMode.js.map packages/app-desktop/gui/MainScreen/commands/toggleNoteList.d.ts packages/app-desktop/gui/MainScreen/commands/toggleNoteList.js packages/app-desktop/gui/MainScreen/commands/toggleNoteList.js.map -packages/app-desktop/gui/MainScreen/commands/toggleSidebar.d.ts -packages/app-desktop/gui/MainScreen/commands/toggleSidebar.js -packages/app-desktop/gui/MainScreen/commands/toggleSidebar.js.map +packages/app-desktop/gui/MainScreen/commands/toggleSideBar.d.ts +packages/app-desktop/gui/MainScreen/commands/toggleSideBar.js +packages/app-desktop/gui/MainScreen/commands/toggleSideBar.js.map packages/app-desktop/gui/MainScreen/commands/toggleVisiblePanes.d.ts packages/app-desktop/gui/MainScreen/commands/toggleVisiblePanes.js packages/app-desktop/gui/MainScreen/commands/toggleVisiblePanes.js.map diff --git a/packages/app-cli/tests/support/plugins/toc/package.json b/packages/app-cli/tests/support/plugins/toc/package.json index 77d04017c..abb434bb0 100644 --- a/packages/app-cli/tests/support/plugins/toc/package.json +++ b/packages/app-cli/tests/support/plugins/toc/package.json @@ -27,4 +27,4 @@ "dependencies": { "uslug": "^1.0.4" } -} \ No newline at end of file +} diff --git a/packages/app-cli/tests/support/plugins/toc/src/manifest.json b/packages/app-cli/tests/support/plugins/toc/src/manifest.json index 11eb07e18..4e988c8de 100644 --- a/packages/app-cli/tests/support/plugins/toc/src/manifest.json +++ b/packages/app-cli/tests/support/plugins/toc/src/manifest.json @@ -5,7 +5,5 @@ "name": "Webview test", "version": "1.0.0", "homepage_url": "https://joplinapp.org", - "permissions": [ - "model" - ] + "keywords": ["table of content", "toc"] } \ No newline at end of file diff --git a/packages/generator-joplin/generators/app/templates/src/manifest.json b/packages/generator-joplin/generators/app/templates/src/manifest.json index be5003803..b8f87cf0d 100644 --- a/packages/generator-joplin/generators/app/templates/src/manifest.json +++ b/packages/generator-joplin/generators/app/templates/src/manifest.json @@ -7,5 +7,6 @@ "description": "<%= pluginDescription %>", "author": "<%= pluginAuthor %>", "homepage_url": "<%= pluginHomepageUrl %>", - "repository_url": "<%= pluginRepositoryUrl %>" + "repository_url": "<%= pluginRepositoryUrl %>", + "keywords": [] } \ No newline at end of file diff --git a/packages/lib/services/plugins/utils/manifestFromObject.ts b/packages/lib/services/plugins/utils/manifestFromObject.ts index e4ff50760..0f9f786f2 100644 --- a/packages/lib/services/plugins/utils/manifestFromObject.ts +++ b/packages/lib/services/plugins/utils/manifestFromObject.ts @@ -17,6 +17,13 @@ export default function manifestFromObject(o: any): PluginManifest { return o[name]; }; + const getStrings = (name: string, required: boolean = true, defaultValue: string[] = []): string[] => { + if (required && !o[name]) throw new Error(`Missing required field: ${name}`); + if (!o[name]) return defaultValue; + if (!Array.isArray(o[name])) throw new Error(`Field must be an array: ${name}`); + return o[name]; + }; + const permissions: PluginPermission[] = []; const manifest: PluginManifest = { @@ -30,6 +37,7 @@ export default function manifestFromObject(o: any): PluginManifest { description: getString('description', false), homepage_url: getString('homepage_url', false), repository_url: getString('repository_url', false), + keywords: getStrings('keywords', false), permissions: permissions, }; diff --git a/packages/lib/services/plugins/utils/types.ts b/packages/lib/services/plugins/utils/types.ts index 77151c464..eb854e2e9 100644 --- a/packages/lib/services/plugins/utils/types.ts +++ b/packages/lib/services/plugins/utils/types.ts @@ -12,6 +12,7 @@ export interface PluginManifest { description?: string; homepage_url?: string; repository_url?: string; + keywords?: string[]; permissions?: PluginPermission[]; // Private keys diff --git a/readme/api/references/plugin_manifest.md b/readme/api/references/plugin_manifest.md index 676f19221..4e8d2881f 100644 --- a/readme/api/references/plugin_manifest.md +++ b/readme/api/references/plugin_manifest.md @@ -10,7 +10,9 @@ Name | Type | Required? | Description `app_min_version` | string | **Yes** | Minimum version of Joplin that the plugin is compatible with. In general it should be whatever version you are using to develop the plugin. `description` | string | No | Detailed description of the plugin. `author` | string | No | Plugin author name. +`keywords` | string[] | No | Keywords associated with the plugins. They are used in search in particular. `homepage_url` | string | No | Homepage URL of the plugin. It can also be, for example, a link to a GitHub repository. +`repository_url` | string | No | Repository URL where the plugin source code is hosted. ## Manifest example