From 8e2daef14439f8e319d0a99ef2eec5bcf2308554 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Wed, 18 Nov 2020 10:17:27 +0000 Subject: [PATCH] Plugins: Add support for the JPL plugin format --- packages/app-cli/jest.config.js | 1 + .../app-cli/tests/services_PluginService.ts | 24 +-- .../codemirror_content_script/.gitignore | 3 +- .../codemirror_content_script/README.md | 8 + .../codemirror_content_script/api/Global.d.ts | 2 +- .../codemirror_content_script/api/Joplin.d.ts | 14 +- .../api/JoplinCommands.d.ts | 40 +++-- .../api/JoplinData.d.ts | 2 +- .../api/JoplinFilters.d.ts | 4 +- .../api/JoplinInterop.d.ts | 6 +- .../api/JoplinPlugins.d.ts | 4 +- .../api/JoplinSettings.d.ts | 4 +- .../api/JoplinViewsDialogs.d.ts | 13 +- .../api/JoplinViewsMenuItems.d.ts | 4 +- .../api/JoplinViewsMenus.d.ts | 4 +- .../api/JoplinViewsPanels.d.ts | 11 +- .../api/JoplinViewsToolbarButtons.d.ts | 4 +- .../api/JoplinWorkspace.d.ts | 2 +- .../codemirror_content_script/api/index.ts | 4 +- .../codemirror_content_script/api/types.ts | 164 +++++++++--------- .../codemirror_content_script/package.json | 8 +- .../src/manifest.json | 1 + .../webpack.config.js | 48 ++++- .../support/plugins/content_script/.gitignore | 3 +- .../support/plugins/content_script/README.md | 8 + .../content_script/api/JoplinCommands.d.ts | 8 +- .../content_script/api/JoplinFilters.d.ts | 4 +- .../content_script/api/JoplinInterop.d.ts | 4 +- .../plugins/content_script/package.json | 5 +- .../plugins/content_script/src/manifest.json | 1 + .../plugins/content_script/webpack.config.js | 42 ++++- .../tests/support/plugins/dialog/.gitignore | 3 +- .../tests/support/plugins/dialog/README.md | 8 + .../plugins/dialog/api/JoplinCommands.d.ts | 8 +- .../plugins/dialog/api/JoplinFilters.d.ts | 4 +- .../plugins/dialog/api/JoplinInterop.d.ts | 4 +- .../tests/support/plugins/dialog/package.json | 5 +- .../support/plugins/dialog/src/manifest.json | 1 + .../support/plugins/dialog/webpack.config.js | 42 ++++- .../plugins/editor_context_menu/.gitignore | 3 +- .../plugins/editor_context_menu/README.md | 8 + .../api/JoplinCommands.d.ts | 8 +- .../api/JoplinFilters.d.ts | 4 +- .../api/JoplinInterop.d.ts | 4 +- .../plugins/editor_context_menu/package.json | 5 +- .../editor_context_menu/src/manifest.json | 1 + .../editor_context_menu/webpack.config.js | 42 ++++- .../tests/support/plugins/events/.gitignore | 3 +- .../tests/support/plugins/events/README.md | 8 + .../plugins/events/api/JoplinCommands.d.ts | 8 +- .../plugins/events/api/JoplinFilters.d.ts | 4 +- .../plugins/events/api/JoplinInterop.d.ts | 4 +- .../tests/support/plugins/events/package.json | 5 +- .../support/plugins/events/src/manifest.json | 1 + .../support/plugins/events/webpack.config.js | 42 ++++- .../tests/support/plugins/jpl_test/.gitignore | 2 +- .../tests/support/plugins/jpl_test/README.md | 8 + .../support/plugins/jpl_test/package.json | 3 +- .../support/plugins/jsbundles/example.js | 1 + .../support/plugins/json_export/.gitignore | 3 +- .../support/plugins/json_export/README.md | 8 + .../json_export/api/JoplinCommands.d.ts | 8 +- .../json_export/api/JoplinFilters.d.ts | 4 +- .../json_export/api/JoplinInterop.d.ts | 4 +- .../support/plugins/json_export/package.json | 7 +- .../plugins/json_export/src/manifest.json | 1 + .../plugins/json_export/webpack.config.js | 42 ++++- .../tests/support/plugins/menu/.gitignore | 3 +- .../tests/support/plugins/menu/README.md | 8 + .../plugins/menu/api/JoplinCommands.d.ts | 8 +- .../plugins/menu/api/JoplinFilters.d.ts | 4 +- .../plugins/menu/api/JoplinInterop.d.ts | 4 +- .../tests/support/plugins/menu/package.json | 5 +- .../support/plugins/menu/src/manifest.json | 1 + .../support/plugins/menu/webpack.config.js | 42 ++++- .../multi_plugins/simple1/manifest.json | 1 + .../multi_plugins/simple2/manifest.json | 1 + .../plugins/multi_selection/.gitignore | 3 +- .../support/plugins/multi_selection/README.md | 8 + .../multi_selection/api/JoplinCommands.d.ts | 8 +- .../multi_selection/api/JoplinFilters.d.ts | 4 +- .../multi_selection/api/JoplinInterop.d.ts | 4 +- .../plugins/multi_selection/package.json | 5 +- .../plugins/multi_selection/src/manifest.json | 1 + .../plugins/multi_selection/webpack.config.js | 42 ++++- .../plugins/register_command/.gitignore | 3 +- .../plugins/register_command/README.md | 8 + .../register_command/api/JoplinCommands.d.ts | 8 +- .../register_command/api/JoplinFilters.d.ts | 4 +- .../register_command/api/JoplinInterop.d.ts | 4 +- .../plugins/register_command/package.json | 5 +- .../register_command/src/manifest.json | 1 + .../register_command/webpack.config.js | 42 ++++- .../support/plugins/selected_text/.gitignore | 3 +- .../support/plugins/selected_text/README.md | 8 + .../selected_text/api/JoplinCommands.d.ts | 8 +- .../selected_text/api/JoplinFilters.d.ts | 4 +- .../selected_text/api/JoplinInterop.d.ts | 4 +- .../plugins/selected_text/package.json | 5 +- .../plugins/selected_text/src/manifest.json | 1 + .../plugins/selected_text/webpack.config.js | 42 ++++- .../tests/support/plugins/settings/.gitignore | 3 +- .../tests/support/plugins/settings/README.md | 8 + .../plugins/settings/api/JoplinCommands.d.ts | 8 +- .../plugins/settings/api/JoplinFilters.d.ts | 4 +- .../plugins/settings/api/JoplinInterop.d.ts | 4 +- .../support/plugins/settings/package.json | 5 +- .../plugins/settings/src/manifest.json | 1 + .../plugins/settings/webpack.config.js | 42 ++++- .../support/plugins/simple/manifest.json | 1 + .../support/plugins/testImport/manifest.json | 1 + .../tests/support/plugins/toc/.gitignore | 3 +- .../tests/support/plugins/toc/README.md | 8 + .../plugins/toc/api/JoplinCommands.d.ts | 8 +- .../plugins/toc/api/JoplinFilters.d.ts | 4 +- .../plugins/toc/api/JoplinInterop.d.ts | 4 +- .../tests/support/plugins/toc/package.json | 14 +- .../support/plugins/toc/src/manifest.json | 1 + .../support/plugins/toc/webpack.config.js | 42 ++++- .../tests/support/plugins/updatePlugins.sh | 35 ++-- .../plugins/withExternalModules/.gitignore | 3 +- .../plugins/withExternalModules/README.md | 8 + .../api/JoplinCommands.d.ts | 8 +- .../api/JoplinFilters.d.ts | 4 +- .../api/JoplinInterop.d.ts | 4 +- .../withExternalModules/dist/manifest.json | 1 + .../plugins/withExternalModules/package.json | 8 +- .../withExternalModules/src/manifest.json | 1 + .../withExternalModules/webpack.config.js | 42 ++++- .../generator-joplin/generators/app/index.js | 60 ++++++- .../app/templates/.gitignore_TEMPLATE | 2 +- .../generators/app/templates/README.md | 14 +- .../app/templates/package_TEMPLATE.json | 3 +- .../lib/services/plugins/PluginService.ts | 2 +- 134 files changed, 1101 insertions(+), 323 deletions(-) diff --git a/packages/app-cli/jest.config.js b/packages/app-cli/jest.config.js index 5fc45534d..cfdd0d56e 100644 --- a/packages/app-cli/jest.config.js +++ b/packages/app-cli/jest.config.js @@ -35,6 +35,7 @@ module.exports = { '/build/', 'test-utils.js', 'file_api_driver.js', + '/tests\\/tmp/', ], // To avoid this warning: diff --git a/packages/app-cli/tests/services_PluginService.ts b/packages/app-cli/tests/services_PluginService.ts index 3670115e7..6930073a1 100644 --- a/packages/app-cli/tests/services_PluginService.ts +++ b/packages/app-cli/tests/services_PluginService.ts @@ -45,7 +45,7 @@ describe('services_PluginService', function() { const service = newPluginService(); await service.loadAndRunPlugins([`${testPluginDir}/simple`]); - expect(() => service.pluginById('simple')).not.toThrowError(); + expect(() => service.pluginById('org.joplinapp.plugins.Simple')).not.toThrowError(); const allFolders = await Folder.all(); expect(allFolders.length).toBe(1); @@ -60,14 +60,13 @@ describe('services_PluginService', function() { it('should load and run a simple plugin and handle trailing slash', asyncTest(async () => { const service = newPluginService(); await service.loadAndRunPlugins([`${testPluginDir}/simple/`]); - expect(() => service.pluginById('simple')).not.toThrowError(); + expect(() => service.pluginById('org.joplinapp.plugins.Simple')).not.toThrowError(); })); it('should load and run a plugin that uses external packages', asyncTest(async () => { const service = newPluginService(); await service.loadAndRunPlugins([`${testPluginDir}/withExternalModules`]); - const plugin = service.pluginById('withexternalmodules'); - expect(plugin.id).toBe('withexternalmodules'); + expect(() => service.pluginById('org.joplinapp.plugins.ExternalModuleDemo')).not.toThrowError(); const allFolders = await Folder.all(); expect(allFolders.length).toBe(1); @@ -81,8 +80,8 @@ describe('services_PluginService', function() { const service = newPluginService(); await service.loadAndRunPlugins(`${testPluginDir}/multi_plugins`); - const plugin1 = service.pluginById('simple1'); - const plugin2 = service.pluginById('simple2'); + const plugin1 = service.pluginById('org.joplinapp.plugins.MultiPluginDemo1'); + const plugin2 = service.pluginById('org.joplinapp.plugins.MultiPluginDemo2'); expect(!!plugin1).toBe(true); expect(!!plugin2).toBe(true); @@ -94,9 +93,10 @@ describe('services_PluginService', function() { it('should load plugins from JS bundles', asyncTest(async () => { const service = newPluginService(); - const plugin = await service.loadPluginFromJsBundle('example', '/tmp', ` + const plugin = await service.loadPluginFromJsBundle('/tmp', ` /* joplin-manifest: { + "id": "org.joplinapp.plugins.JsBundleTest", "manifest_version": 1, "app_min_version": "1.4", "name": "JS Bundle test", @@ -126,7 +126,7 @@ describe('services_PluginService', function() { it('should load plugins from JS bundle files', asyncTest(async () => { const service = newPluginService(); await service.loadAndRunPlugins(`${testPluginDir}/jsbundles`); - expect(!!service.pluginById('example')).toBe(true); + expect(!!service.pluginById('org.joplinapp.plugins.JsBundleDemo')).toBe(true); expect((await Folder.all()).length).toBe(1); })); @@ -166,7 +166,7 @@ describe('services_PluginService', function() { const service = newPluginService(); for (const jsBundle of invalidJsBundles) { - await expectThrow(async () => await service.loadPluginFromJsBundle('example', '/tmp', jsBundle)); + await expectThrow(async () => await service.loadPluginFromJsBundle('/tmp', jsBundle)); } })); @@ -178,9 +178,10 @@ describe('services_PluginService', function() { const service = newPluginService(); - const plugin = await service.loadPluginFromJsBundle('example', tempDir, ` + const plugin = await service.loadPluginFromJsBundle(tempDir, ` /* joplin-manifest: { + "id": "org.joplinapp.plugin.MarkdownItPluginTest", "manifest_version": 1, "app_min_version": "1.4", "name": "JS Bundle test", @@ -225,6 +226,7 @@ describe('services_PluginService', function() { const pluginScript = ` /* joplin-manifest: { + "id": "org.joplinapp.plugins.PluginTest", "manifest_version": 1, "app_min_version": "1.4", "name": "JS Bundle test", @@ -247,7 +249,7 @@ describe('services_PluginService', function() { for (const testCase of testCases) { const [appVersion, expected] = testCase; - const plugin = await newPluginService(appVersion as string).loadPluginFromJsBundle('example', '', pluginScript); + const plugin = await newPluginService(appVersion as string).loadPluginFromJsBundle('', pluginScript); expect(plugin.enabled).toBe(expected as boolean); } })); diff --git a/packages/app-cli/tests/support/plugins/codemirror_content_script/.gitignore b/packages/app-cli/tests/support/plugins/codemirror_content_script/.gitignore index 2195be3d8..4efef4740 100644 --- a/packages/app-cli/tests/support/plugins/codemirror_content_script/.gitignore +++ b/packages/app-cli/tests/support/plugins/codemirror_content_script/.gitignore @@ -1,2 +1,3 @@ dist/* -node_modules/ \ No newline at end of file +node_modules/ +*.jpl diff --git a/packages/app-cli/tests/support/plugins/codemirror_content_script/README.md b/packages/app-cli/tests/support/plugins/codemirror_content_script/README.md index afbea1bd1..4618fa796 100644 --- a/packages/app-cli/tests/support/plugins/codemirror_content_script/README.md +++ b/packages/app-cli/tests/support/plugins/codemirror_content_script/README.md @@ -12,3 +12,11 @@ The plugin is built using webpack, which create the compiled code in `/dist`. Th ## Building the plugin To build the plugin, simply run `npm run dist`. + +## Updating the plugin framework + +To update the plugin framework, run `yo joplin --update` + +Keep in mind that doing so will overwrite all the framework-related files **outside of the "src/" directory** (your source code will not be touched). So if you have modified any of the framework-related files, such as package.json or .gitignore, make sure your code is under version control so that you can check the diff and re-apply your changes. + +For that reason, it's generally best not to change any of the framework files or to do so in a way that minimises the number of changes. For example, if you want to modify the Webpack config, create a new separate JavaScript file and include it in webpack.config.js. That way, when you update, you only have to restore the line that include your file. \ No newline at end of file diff --git a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/Global.d.ts b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/Global.d.ts index 011fe0daf..f6a0078fa 100644 --- a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/Global.d.ts +++ b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/Global.d.ts @@ -1,6 +1,6 @@ import Plugin from '../Plugin'; import Joplin from './Joplin'; -import Logger from 'lib/Logger'; +import Logger from '../../../Logger'; /** * @ignore */ diff --git a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/Joplin.d.ts b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/Joplin.d.ts index e12babda2..74494aea0 100644 --- a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/Joplin.d.ts +++ b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/Joplin.d.ts @@ -7,9 +7,21 @@ import JoplinCommands from './JoplinCommands'; import JoplinViews from './JoplinViews'; import JoplinInterop from './JoplinInterop'; import JoplinSettings from './JoplinSettings'; -import Logger from 'lib/Logger'; +import Logger from '../../../Logger'; /** * This is the main entry point to the Joplin API. You can access various services using the provided accessors. + * + * **This is a beta API** + * + * Please note that the plugin API is relatively new and should be considered Beta state. Besides possible bugs, what it means is that there might be necessary breaking changes from one version to the next. Whenever such change is needed, best effort will be done to: + * + * - Maintain backward compatibility; + * - When possible, deprecate features instead of removing them; + * - Document breaking changes in the changelog; + * + * So if you are developing a plugin, please keep an eye on the changelog as everything will be in there with information about how to update your code. There won't be any major API rewrite or architecture changes, but possibly small tweaks like function signature change, type change, etc. + * + * Eventually, the plugin API will be versioned to make this process smoother. */ export default class Joplin { private data_; diff --git a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinCommands.d.ts b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinCommands.d.ts index 0dc680e3b..e175d2e14 100644 --- a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinCommands.d.ts +++ b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinCommands.d.ts @@ -1,25 +1,35 @@ import { Command } from './types'; /** - * This class allows executing or registering new Joplin commands. Commands can be executed or associated with - * {@link JoplinViewsToolbarButtons | toolbar buttons} or {@link JoplinViewsMenuItems | menu items}. + * This class allows executing or registering new Joplin commands. Commands + * can be executed or associated with + * {@link JoplinViewsToolbarButtons | toolbar buttons} or + * {@link JoplinViewsMenuItems | menu items}. * - * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/CliClient/tests/support/plugins/register_command) + * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/register_command) * * ## Executing Joplin's internal commands * - * It is also possible to execute internal Joplin's commands which, as of now, are not well documented. - * You can find the list directly on GitHub though at the following locations: + * It is also possible to execute internal Joplin's commands which, as of + * now, are not well documented. You can find the list directly on GitHub + * though at the following locations: * - * https://github.com/laurent22/joplin/tree/dev/ElectronClient/gui/MainScreen/commands - * https://github.com/laurent22/joplin/tree/dev/ElectronClient/commands - * https://github.com/laurent22/joplin/tree/dev/ElectronClient/gui/NoteEditor/commands/editorCommandDeclarations.ts + * * [Main screen commands](https://github.com/laurent22/joplin/tree/dev/packages/app-desktop/gui/MainScreen/commands) + * * [Global commands](https://github.com/laurent22/joplin/tree/dev/packages/app-desktop/commands) + * * [Editor commands](https://github.com/laurent22/joplin/tree/dev/packages/app-desktop/gui/NoteEditor/commands/editorCommandDeclarations.ts) * - * To view what arguments are supported, you can open any of these files and look at the `execute()` command. + * To view what arguments are supported, you can open any of these files + * and look at the `execute()` command. */ export default class JoplinCommands { - /** - * desktop Executes the given command. - * The `props` are the arguments passed to the command, and they vary based on the command + /** + * desktop Executes the given + * command. + * + * The command can take any number of arguments, and the supported + * arguments will vary based on the command. For custom commands, this + * is the `args` passed to the `execute()` function. For built-in + * commands, you can find the supported arguments by checking the links + * above. * * ```typescript * // Create a new note in the current notebook: @@ -30,8 +40,8 @@ export default class JoplinCommands { * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * ``` */ - execute(commandName: string, ...args: any[]): Promise; - /** + execute(commandName: string, ...args: any[]): Promise; + /** * desktop Registers a new command. * * ```typescript @@ -47,5 +57,5 @@ export default class JoplinCommands { * }); * ``` */ - register(command: Command): Promise; + register(command: Command): Promise; } diff --git a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinData.d.ts b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinData.d.ts index 213d576ed..fbde6ff9a 100644 --- a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinData.d.ts +++ b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinData.d.ts @@ -6,7 +6,7 @@ import { Path } from './types'; * * This is also what you would use to search notes, via the `search` endpoint. * - * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/CliClient/tests/support/plugins/simple) + * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/simple) * * In general you would use the methods in this class as if you were using a REST API. There are four methods that map to GET, POST, PUT and DELETE calls. * And each method takes these parameters: diff --git a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinFilters.d.ts b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinFilters.d.ts index 43bc1b2b7..e086a720e 100644 --- a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinFilters.d.ts +++ b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinFilters.d.ts @@ -5,6 +5,6 @@ * so for now disable filters. */ export default class JoplinFilters { - on(name: string, callback: Function): Promise; - off(name: string, callback: Function): Promise; + on(name: string, callback: Function): Promise; + off(name: string, callback: Function): Promise; } diff --git a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinInterop.d.ts b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinInterop.d.ts index 142c01ddf..1304c7512 100644 --- a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinInterop.d.ts +++ b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinInterop.d.ts @@ -2,7 +2,7 @@ import { ExportModule, ImportModule } from './types'; /** * Provides a way to create modules to import external data into Joplin or to export notes into any arbitrary format. * - * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/CliClient/tests/support/plugins/json_export) + * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/json_export) * * To implement an import or export module, you would simply define an object with various event handlers that are called * by the application during the import/export process. @@ -12,6 +12,6 @@ import { ExportModule, ImportModule } from './types'; * You may also want to refer to the Joplin API documentation to see the list of properties for each item (note, notebook, etc.) - https://joplinapp.org/api/references/rest_api/ */ export default class JoplinInterop { - registerExportModule(module: ExportModule): Promise; - registerImportModule(module: ImportModule): Promise; + registerExportModule(module: ExportModule): Promise; + registerImportModule(module: ImportModule): Promise; } diff --git a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinPlugins.d.ts b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinPlugins.d.ts index 4b7d0c72e..fc9fda6a3 100644 --- a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinPlugins.d.ts +++ b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinPlugins.d.ts @@ -1,5 +1,5 @@ import Plugin from '../Plugin'; -import Logger from 'lib/Logger'; +import Logger from '../../../Logger'; import { ContentScriptType, Script } from './types'; /** * This class provides access to plugin-related features. @@ -28,7 +28,7 @@ export default class JoplinPlugins { * Note that registering a content script in itself will do nothing - it will only be loaded in specific cases by the relevant app modules * (eg. the Markdown renderer or the code editor). So it is not a way to inject and run arbitrary code in the app, which for safety and performance reasons is not supported. * - * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/CliClient/tests/support/plugins/content_script) + * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) * * @param type Defines how the script will be used. See the type definition for more information about each supported type. * @param id A unique ID for the content script. diff --git a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinSettings.d.ts b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinSettings.d.ts index 4deaae636..0fa39d964 100644 --- a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinSettings.d.ts +++ b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinSettings.d.ts @@ -7,7 +7,7 @@ import { SettingItem, SettingSection } from './types'; * * Note: Currently this API does **not** provide access to Joplin's built-in settings. This is by design as plugins that modify user settings could give unexpected results * - * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/CliClient/tests/support/plugins/settings) + * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/settings) */ export default class JoplinSettings { private plugin_; @@ -37,7 +37,7 @@ export default class JoplinSettings { * * The list of available settings is not documented yet, but can be found by looking at the source code: * - * https://github.com/laurent22/joplin/blob/3539a452a359162c461d2849829d2d42973eab50/ReactNativeClient/lib/models/Setting.ts#L142 + * https://github.com/laurent22/joplin/blob/3539a452a359162c461d2849829d2d42973eab50/packages/app-mobile/lib/models/Setting.ts#L142 */ globalValue(key: string): Promise; } diff --git a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinViewsDialogs.d.ts b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinViewsDialogs.d.ts index e76f8a41b..5956c0eca 100644 --- a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinViewsDialogs.d.ts +++ b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinViewsDialogs.d.ts @@ -1,11 +1,12 @@ import Plugin from '../Plugin'; -import { ButtonSpec, ViewHandle, ButtonId } from './types'; +import { ButtonSpec, ViewHandle, DialogResult } from './types'; /** * Allows creating and managing dialogs. A dialog is modal window that contains a webview and a row of buttons. You can update the update the webview using the `setHtml` method. - * Dialogs are hidden by default and you need to call `open()` to open them. Once the user clicks on a button, the `open` call will return and provide the button ID that was - * clicked on. There is currently no "close" method since the dialog should be thought as a modal one and thus can only be closed by clicking on one of the buttons. + * Dialogs are hidden by default and you need to call `open()` to open them. Once the user clicks on a button, the `open` call will return an object indicating what button was clicked + * on. If your HTML content included one or more form, a `formData` object will also be included with the key/value for each form. + * There is currently no "close" method since the dialog should be thought as a modal one and thus can only be closed by clicking on one of the buttons. * - * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/CliClient/tests/support/plugins/dialog) + * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/dialog) */ export default class JoplinViewsDialogs { private store; @@ -16,7 +17,7 @@ export default class JoplinViewsDialogs { /** * Creates a new dialog */ - create(): Promise; + create(id: string): Promise; /** * Displays a message box with OK/Cancel buttons. Returns the button index that was clicked - "0" for OK and "1" for "Cancel" */ @@ -32,5 +33,5 @@ export default class JoplinViewsDialogs { /** * Opens the dialog */ - open(handle: ViewHandle): Promise; + open(handle: ViewHandle): Promise; } diff --git a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinViewsMenuItems.d.ts b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinViewsMenuItems.d.ts index d2fb8d994..69e2a8f18 100644 --- a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinViewsMenuItems.d.ts +++ b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinViewsMenuItems.d.ts @@ -3,7 +3,7 @@ import Plugin from '../Plugin'; /** * Allows creating and managing menu items. * - * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/CliClient/tests/support/plugins/register_command) + * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/register_command) */ export default class JoplinViewsMenuItems { private store; @@ -12,5 +12,5 @@ export default class JoplinViewsMenuItems { /** * Creates a new menu item and associate it with the given command. You can specify under which menu the item should appear using the `location` parameter. */ - create(commandName: string, location?: MenuItemLocation, options?: CreateMenuItemOptions): Promise; + create(id: string, commandName: string, location?: MenuItemLocation, options?: CreateMenuItemOptions): Promise; } diff --git a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinViewsMenus.d.ts b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinViewsMenus.d.ts index 866486a08..f5f803cb1 100644 --- a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinViewsMenus.d.ts +++ b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinViewsMenus.d.ts @@ -3,7 +3,7 @@ import Plugin from '../Plugin'; /** * Allows creating menus. * - * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/CliClient/tests/support/plugins/menu) + * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/menu) */ export default class JoplinViewsMenus { private store; @@ -14,5 +14,5 @@ export default class JoplinViewsMenus { * Creates a new menu from the provided menu items and place it at the given location. As of now, it is only possible to place the * menu as a sub-menu of the application build-in menus. */ - create(label: string, menuItems: MenuItem[], location?: MenuItemLocation): Promise; + create(id: string, label: string, menuItems: MenuItem[], location?: MenuItemLocation): Promise; } diff --git a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinViewsPanels.d.ts b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinViewsPanels.d.ts index 98458e401..3646269ee 100644 --- a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinViewsPanels.d.ts +++ b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinViewsPanels.d.ts @@ -1,10 +1,13 @@ import Plugin from '../Plugin'; import { ViewHandle } from './types'; /** - * Allows creating and managing view panels. View panels currently are displayed at the right of the sidebar and allows displaying any HTML content (within a webview) and update it in real-time. For example - * it could be used to display a table of content for the active note, or display various metadata or graph. + * Allows creating and managing view panels. View panels currently are + * displayed at the right of the sidebar and allows displaying any HTML + * content (within a webview) and update it in real-time. For example it + * could be used to display a table of content for the active note, or + * display various metadata or graph. * - * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/CliClient/tests/support/plugins/toc) + * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/toc) */ export default class JoplinViewsPanels { private store; @@ -14,7 +17,7 @@ export default class JoplinViewsPanels { /** * Creates a new panel */ - create(): Promise; + create(id: string): Promise; /** * Sets the panel webview HTML */ diff --git a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinViewsToolbarButtons.d.ts b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinViewsToolbarButtons.d.ts index d937b50b4..ba17c83e3 100644 --- a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinViewsToolbarButtons.d.ts +++ b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinViewsToolbarButtons.d.ts @@ -3,7 +3,7 @@ import Plugin from '../Plugin'; /** * Allows creating and managing toolbar buttons. * - * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/CliClient/tests/support/plugins/register_command) + * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/register_command) */ export default class JoplinViewsToolbarButtons { private store; @@ -12,5 +12,5 @@ export default class JoplinViewsToolbarButtons { /** * Creates a new toolbar button and associate it with the given command. */ - create(commandName: string, location: ToolbarButtonLocation): Promise; + create(id: string, commandName: string, location: ToolbarButtonLocation): Promise; } diff --git a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinWorkspace.d.ts b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinWorkspace.d.ts index 361eb3a67..0686d32a9 100644 --- a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinWorkspace.d.ts +++ b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinWorkspace.d.ts @@ -2,7 +2,7 @@ * The workspace service provides access to all the parts of Joplin that are being worked on - i.e. the currently selected notes or notebooks as well * as various related events, such as when a new note is selected, or when the note content changes. * - * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/CliClient/tests/support/plugins) + * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins) */ export default class JoplinWorkspace { private store; diff --git a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/index.ts b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/index.ts index 1158f1ed4..10ff6555e 100644 --- a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/index.ts +++ b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/index.ts @@ -1,5 +1,5 @@ import type Joplin from './Joplin'; -declare const joplin:Joplin; +declare const joplin: Joplin; -export default joplin; +export default joplin; diff --git a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/types.ts b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/types.ts index a0636920c..d58bca6c3 100644 --- a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/types.ts +++ b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/types.ts @@ -6,7 +6,7 @@ export interface Command { /** * Name of command - must be globally unique */ - name: string + name: string; /** * Label to be displayed on menu items or keyboard shortcut editor for example. @@ -14,17 +14,17 @@ export interface Command { * In that case the command will not appear in the shortcut editor or command panel, and logically * should not be used as a menu item. */ - label?: string + label?: string; /** * Icon to be used on toolbar buttons for example */ - iconName?: string, + iconName?: string; /** * Code to be ran when the command is executed. It may return a result. */ - execute(...args:any[]):Promise + execute(...args: any[]): Promise; /** * Defines whether the command should be enabled or disabled, which in turns affects @@ -40,13 +40,11 @@ export interface Command { * Or | \|\| | "noteIsTodo \|\| noteTodoCompleted" * And | && | "oneNoteSelected && !inConflictFolder" * - * Currently the supported context variables aren't documented, but you can find the list there: - * - * https://github.com/laurent22/joplin/blob/dev/ReactNativeClient/lib/services/commands/stateToWhenClauseContext.ts + * Currently the supported context variables aren't documented, but you can [find the list here](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/services/commands/stateToWhenClauseContext.ts). * * Note: Commands are enabled by default unless you use this property. */ - enabledCondition?: string + enabledCondition?: string; } // ================================================================= @@ -64,7 +62,7 @@ export enum ImportModuleOutputFormat { } /** - * Used to implement a module to export data from Joplin. [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/CliClient/tests/support/plugins/json_export) for an example. + * Used to implement a module to export data from Joplin. [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/json_export) for an example. * * In general, all the event handlers you'll need to implement take a `context` object as a first argument. This object will contain the export or import path as well as various optional properties, such as which notes or notebooks need to be exported. * @@ -74,113 +72,113 @@ export interface ExportModule { /** * The format to be exported, eg "enex", "jex", "json", etc. */ - format: string, + format: string; /** * The description that will appear in the UI, for example in the menu item. */ - description: string, + description: string; /** * Whether the module will export a single file or multiple files in a directory. It affects the open dialog that will be presented to the user when using your exporter. */ - target: FileSystemItem, + target: FileSystemItem; /** * Only applies to single file exporters or importers * It tells whether the format can package multiple notes into one file. * For example JEX or ENEX can, but HTML cannot. */ - isNoteArchive: boolean, + isNoteArchive: boolean; /** * The extensions of the files exported by your module. For example, it is `["htm", "html"]` for the HTML module, and just `["jex"]` for the JEX module. */ - fileExtensions?: string[], + fileExtensions?: string[]; /** * Called when the export process starts. */ - onInit(context:ExportContext): Promise; + onInit(context: ExportContext): Promise; /** * Called when an item needs to be processed. An "item" can be any Joplin object, such as a note, a folder, a notebook, etc. */ - onProcessItem(context:ExportContext, itemType:number, item:any):Promise; + onProcessItem(context: ExportContext, itemType: number, item: any): Promise; /** * Called when a resource file needs to be exported. */ - onProcessResource(context:ExportContext, resource:any, filePath:string):Promise; + onProcessResource(context: ExportContext, resource: any, filePath: string): Promise; /** * Called when the export process is done. */ - onClose(context:ExportContext):Promise; + onClose(context: ExportContext): Promise; } export interface ImportModule { /** * The format to be exported, eg "enex", "jex", "json", etc. */ - format: string, + format: string; /** * The description that will appear in the UI, for example in the menu item. */ - description: string, + description: string; /** * Only applies to single file exporters or importers * It tells whether the format can package multiple notes into one file. * For example JEX or ENEX can, but HTML cannot. */ - isNoteArchive: boolean, + isNoteArchive: boolean; /** * The type of sources that are supported by the module. Tells whether the module can import files or directories or both. */ - sources: FileSystemItem[], + sources: FileSystemItem[]; /** * Tells the file extensions of the exported files. */ - fileExtensions?: string[], + fileExtensions?: string[]; /** * Tells the type of notes that will be generated, either HTML or Markdown (default). */ - outputFormat?: ImportModuleOutputFormat, + outputFormat?: ImportModuleOutputFormat; /** * Called when the import process starts. There is only one event handler within which you should import the complete data. */ - onExec(context:ImportContext): Promise; + onExec(context: ImportContext): Promise; } export interface ExportOptions { - format?: string, - path?:string, - sourceFolderIds?: string[], - sourceNoteIds?: string[], - modulePath?:string, - target?:FileSystemItem, + format?: string; + path?: string; + sourceFolderIds?: string[]; + sourceNoteIds?: string[]; + modulePath?: string; + target?: FileSystemItem; } export interface ExportContext { - destPath: string, - options: ExportOptions, + destPath: string; + options: ExportOptions; /** * You can attach your own custom data using this propery - it will then be passed to each event handler, allowing you to keep state from one event to the next. */ - userData?: any, + userData?: any; } export interface ImportContext { - sourcePath: string, - options: any, - warnings: string[], + sourcePath: string; + options: any; + warnings: string[]; } // ================================================================= @@ -188,7 +186,7 @@ export interface ImportContext { // ================================================================= export interface Script { - onStart?(event:any):Promise, + onStart?(event: any): Promise; } // ================================================================= @@ -196,7 +194,7 @@ export interface Script { // ================================================================= export interface CreateMenuItemOptions { - accelerator: string, + accelerator: string; } export enum MenuItemLocation { @@ -206,7 +204,12 @@ export enum MenuItemLocation { Note = 'note', Tools = 'tools', Help = 'help', + /** + * @deprecated Do not use - same as NoteListContextMenu + */ Context = 'context', + NoteListContextMenu = 'noteListContextMenu', + EditorContextMenu = 'editorContextMenu', } export interface MenuItem { @@ -214,22 +217,22 @@ export interface MenuItem { * Command that should be associated with the menu item. All menu item should * have a command associated with them unless they are a sub-menu. */ - commandName?: string, + commandName?: string; /** * Accelerator associated with the menu item */ - accelerator?: string, + accelerator?: string; /** * Menu items that should appear below this menu item. Allows creating a menu tree. */ - submenu?: MenuItem[], + submenu?: MenuItem[]; /** * Menu item label. If not specified, the command label will be used instead. */ - label?: string, + label?: string; } // ================================================================= @@ -237,9 +240,9 @@ export interface MenuItem { // ================================================================= export interface ButtonSpec { - id: ButtonId, - title?: string, - onClick?():void, + id: ButtonId; + title?: string; + onClick?(): void; } export type ButtonId = string; @@ -263,6 +266,11 @@ export interface EditorCommand { value?: any; } +export interface DialogResult { + id: ButtonId; + formData?: any; +} + // ================================================================= // Settings types // ================================================================= @@ -279,28 +287,28 @@ export enum SettingItemType { // Redefine a simplified interface to mask internal details // and to remove function calls as they would have to be async. export interface SettingItem { - value: any, - type: SettingItemType, - public: boolean, - label:string, + value: any; + type: SettingItemType; + public: boolean; + label: string; - description?:string, - isEnum?: boolean, - section?: string, - options?:any, - appTypes?:string[], - secure?: boolean, - advanced?: boolean, - minimum?: number, - maximum?: number, - step?: number, + description?: string; + isEnum?: boolean; + section?: string; + options?: any; + appTypes?: string[]; + secure?: boolean; + advanced?: boolean; + minimum?: number; + maximum?: number; + step?: number; } export interface SettingSection { - label: string, - iconName?: string, - description?: string, - name?: string, + label: string; + iconName?: string; + description?: string; + name?: string; } // ================================================================= @@ -322,36 +330,30 @@ export type Path = string[]; export enum ContentScriptType { /** - * Registers a new Markdown-It plugin, which should follow this template: + * Registers a new Markdown-It plugin, which should follow the template below. * * ```javascript - * // The module should export an object as below: - * * module.exports = { - * - * // The "context" variable is currently unused but could be used later on to provide - * // access to your own plugin so that the content script and plugin can communicate. * default: function(context) { * return { - * - * // This is the actual Markdown-It plugin - check the [official doc](https://github.com/markdown-it/markdown-it) for more information - * // The `options` parameter is of type [RuleOptions](https://github.com/laurent22/joplin/blob/dev/ReactNativeClient/lib/joplin-renderer/MdToHtml.ts), which - * // contains a number of options, mostly useful for Joplin's internal code. * plugin: function(markdownIt, options) { * // ... * }, - * - * // You may also specify additional assets such as JS or CSS that should be loaded in the rendered HTML document. - * // Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/ReactNativeClient/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to - * // see how the data should be structured. - * assets: {}, + * assets: { + * // ... + * }, * } * } * } * ``` * - * To include a regular Markdown-It plugin, that doesn't make use of any Joplin-specific feature, you - * would simply create a file such as this: + * - The `context` argument is currently unused but could be used later on to provide access to your own plugin so that the content script and plugin can communicate. + * + * - The **required** `plugin` key is the actual Markdown-It plugin - check the [official doc](https://github.com/markdown-it/markdown-it) for more information. The `options` parameter is of type [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml.ts), which contains a number of options, mostly useful for Joplin's internal code. + * + * - Using the **optional** `assets` key you may specify assets such as JS or CSS that should be loaded in the rendered HTML document. Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to see how the data should be structured. + * + * To include a regular Markdown-It plugin, that doesn't make use of any Joplin-specific features, you would simply create a file such as this: * * ```javascript * module.exports = { diff --git a/packages/app-cli/tests/support/plugins/codemirror_content_script/package.json b/packages/app-cli/tests/support/plugins/codemirror_content_script/package.json index 5ae5fa09a..ebc25dcb4 100644 --- a/packages/app-cli/tests/support/plugins/codemirror_content_script/package.json +++ b/packages/app-cli/tests/support/plugins/codemirror_content_script/package.json @@ -7,17 +7,17 @@ "postinstall": "npm run dist" }, "keywords": [], - "author": "CalebJohn", "license": "MIT", "devDependencies": { "@types/node": "^14.0.14", "copy-webpack-plugin": "^6.1.0", + "fs-extra": "^9.0.1", + "glob": "^7.1.6", + "on-build-webpack": "^0.1.0", + "tar": "^6.0.5", "ts-loader": "^7.0.5", "typescript": "^3.9.3", "webpack": "^4.43.0", "webpack-cli": "^3.3.11" - }, - "dependencies": { - "codemirror": "^5.58.2" } } diff --git a/packages/app-cli/tests/support/plugins/codemirror_content_script/src/manifest.json b/packages/app-cli/tests/support/plugins/codemirror_content_script/src/manifest.json index 45d000286..2d0deff34 100644 --- a/packages/app-cli/tests/support/plugins/codemirror_content_script/src/manifest.json +++ b/packages/app-cli/tests/support/plugins/codemirror_content_script/src/manifest.json @@ -1,4 +1,5 @@ { + "id": "org.joplinapp.plugins.MatchHighlighter", "manifest_version": 1, "name": "joplin-match-highlighter", "description": "Adds support for the Codemirror match highlighter to the Joplin CodeView editor.", diff --git a/packages/app-cli/tests/support/plugins/codemirror_content_script/webpack.config.js b/packages/app-cli/tests/support/plugins/codemirror_content_script/webpack.config.js index c3d740c88..5c86b05c6 100644 --- a/packages/app-cli/tests/support/plugins/codemirror_content_script/webpack.config.js +++ b/packages/app-cli/tests/support/plugins/codemirror_content_script/webpack.config.js @@ -1,5 +1,42 @@ const path = require('path'); +const fs = require('fs-extra'); const CopyPlugin = require('copy-webpack-plugin'); +const WebpackOnBuildPlugin = require('on-build-webpack'); +const tar = require('tar'); +const glob = require('glob'); + +function readManifest(manifestPath) { + const content = fs.readFileSync(manifestPath, 'utf8'); + const output = JSON.parse(content); + if (!output.id) throw new Error(`Manifest plugin ID is not set in ${manifestPath}`); + return output; +} + +function createPluginArchive(sourceDir, destPath) { + const distFiles = glob.sync(`${sourceDir}/**/*`) + .map(f => f.substr(sourceDir.length + 1)); + + fs.removeSync(destPath); + + tar.create( + { + strict: true, + portable: true, + file: destPath, + cwd: sourceDir, + sync: true, + }, + distFiles + ); + + console.info(`Plugin archive has been created in ${destPath}`); +} + +const distDir = path.resolve(__dirname, 'dist'); +const srcDir = path.resolve(__dirname, 'src'); +const manifestPath = `${srcDir}/manifest.json`; +const manifest = readManifest(manifestPath); +const archiveFilePath = path.resolve(__dirname, `${manifest.id}.jpl`); module.exports = { mode: 'production', @@ -16,19 +53,19 @@ module.exports = { }, resolve: { alias: { - api: path.resolve(__dirname, 'api') + api: path.resolve(__dirname, 'api'), }, - extensions: [ '.tsx', '.ts', '.js' ], + extensions: ['.tsx', '.ts', '.js'], }, output: { filename: 'index.js', - path: path.resolve(__dirname, 'dist'), + path: distDir, }, plugins: [ new CopyPlugin({ patterns: [ { - from: "**/*", + from: '**/*', context: path.resolve(__dirname, 'src'), to: path.resolve(__dirname, 'dist'), globOptions: { @@ -40,5 +77,8 @@ module.exports = { }, ], }), + new WebpackOnBuildPlugin(function() { + createPluginArchive(distDir, archiveFilePath); + }), ], }; diff --git a/packages/app-cli/tests/support/plugins/content_script/.gitignore b/packages/app-cli/tests/support/plugins/content_script/.gitignore index 2195be3d8..4efef4740 100644 --- a/packages/app-cli/tests/support/plugins/content_script/.gitignore +++ b/packages/app-cli/tests/support/plugins/content_script/.gitignore @@ -1,2 +1,3 @@ dist/* -node_modules/ \ No newline at end of file +node_modules/ +*.jpl diff --git a/packages/app-cli/tests/support/plugins/content_script/README.md b/packages/app-cli/tests/support/plugins/content_script/README.md index afbea1bd1..4618fa796 100644 --- a/packages/app-cli/tests/support/plugins/content_script/README.md +++ b/packages/app-cli/tests/support/plugins/content_script/README.md @@ -12,3 +12,11 @@ The plugin is built using webpack, which create the compiled code in `/dist`. Th ## Building the plugin To build the plugin, simply run `npm run dist`. + +## Updating the plugin framework + +To update the plugin framework, run `yo joplin --update` + +Keep in mind that doing so will overwrite all the framework-related files **outside of the "src/" directory** (your source code will not be touched). So if you have modified any of the framework-related files, such as package.json or .gitignore, make sure your code is under version control so that you can check the diff and re-apply your changes. + +For that reason, it's generally best not to change any of the framework files or to do so in a way that minimises the number of changes. For example, if you want to modify the Webpack config, create a new separate JavaScript file and include it in webpack.config.js. That way, when you update, you only have to restore the line that include your file. \ No newline at end of file diff --git a/packages/app-cli/tests/support/plugins/content_script/api/JoplinCommands.d.ts b/packages/app-cli/tests/support/plugins/content_script/api/JoplinCommands.d.ts index 8a9f30451..e175d2e14 100644 --- a/packages/app-cli/tests/support/plugins/content_script/api/JoplinCommands.d.ts +++ b/packages/app-cli/tests/support/plugins/content_script/api/JoplinCommands.d.ts @@ -21,7 +21,7 @@ import { Command } from './types'; * and look at the `execute()` command. */ export default class JoplinCommands { - /** + /** * desktop Executes the given * command. * @@ -40,8 +40,8 @@ export default class JoplinCommands { * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * ``` */ - execute(commandName: string, ...args: any[]): Promise; - /** + execute(commandName: string, ...args: any[]): Promise; + /** * desktop Registers a new command. * * ```typescript @@ -57,5 +57,5 @@ export default class JoplinCommands { * }); * ``` */ - register(command: Command): Promise; + register(command: Command): Promise; } diff --git a/packages/app-cli/tests/support/plugins/content_script/api/JoplinFilters.d.ts b/packages/app-cli/tests/support/plugins/content_script/api/JoplinFilters.d.ts index 43bc1b2b7..e086a720e 100644 --- a/packages/app-cli/tests/support/plugins/content_script/api/JoplinFilters.d.ts +++ b/packages/app-cli/tests/support/plugins/content_script/api/JoplinFilters.d.ts @@ -5,6 +5,6 @@ * so for now disable filters. */ export default class JoplinFilters { - on(name: string, callback: Function): Promise; - off(name: string, callback: Function): Promise; + on(name: string, callback: Function): Promise; + off(name: string, callback: Function): Promise; } diff --git a/packages/app-cli/tests/support/plugins/content_script/api/JoplinInterop.d.ts b/packages/app-cli/tests/support/plugins/content_script/api/JoplinInterop.d.ts index 8de655c83..1304c7512 100644 --- a/packages/app-cli/tests/support/plugins/content_script/api/JoplinInterop.d.ts +++ b/packages/app-cli/tests/support/plugins/content_script/api/JoplinInterop.d.ts @@ -12,6 +12,6 @@ import { ExportModule, ImportModule } from './types'; * You may also want to refer to the Joplin API documentation to see the list of properties for each item (note, notebook, etc.) - https://joplinapp.org/api/references/rest_api/ */ export default class JoplinInterop { - registerExportModule(module: ExportModule): Promise; - registerImportModule(module: ImportModule): Promise; + registerExportModule(module: ExportModule): Promise; + registerImportModule(module: ImportModule): Promise; } diff --git a/packages/app-cli/tests/support/plugins/content_script/package.json b/packages/app-cli/tests/support/plugins/content_script/package.json index 2d9b8a3e8..ebc25dcb4 100644 --- a/packages/app-cli/tests/support/plugins/content_script/package.json +++ b/packages/app-cli/tests/support/plugins/content_script/package.json @@ -7,11 +7,14 @@ "postinstall": "npm run dist" }, "keywords": [], - "author": "", "license": "MIT", "devDependencies": { "@types/node": "^14.0.14", "copy-webpack-plugin": "^6.1.0", + "fs-extra": "^9.0.1", + "glob": "^7.1.6", + "on-build-webpack": "^0.1.0", + "tar": "^6.0.5", "ts-loader": "^7.0.5", "typescript": "^3.9.3", "webpack": "^4.43.0", diff --git a/packages/app-cli/tests/support/plugins/content_script/src/manifest.json b/packages/app-cli/tests/support/plugins/content_script/src/manifest.json index d874097e7..48e33eab7 100644 --- a/packages/app-cli/tests/support/plugins/content_script/src/manifest.json +++ b/packages/app-cli/tests/support/plugins/content_script/src/manifest.json @@ -1,4 +1,5 @@ { + "id": "org.joplinapp.plugins.ContentScriptDemo", "manifest_version": 1, "app_min_version": "1.4", "name": "Content Script Test", diff --git a/packages/app-cli/tests/support/plugins/content_script/webpack.config.js b/packages/app-cli/tests/support/plugins/content_script/webpack.config.js index 86f38111d..5c86b05c6 100644 --- a/packages/app-cli/tests/support/plugins/content_script/webpack.config.js +++ b/packages/app-cli/tests/support/plugins/content_script/webpack.config.js @@ -1,5 +1,42 @@ const path = require('path'); +const fs = require('fs-extra'); const CopyPlugin = require('copy-webpack-plugin'); +const WebpackOnBuildPlugin = require('on-build-webpack'); +const tar = require('tar'); +const glob = require('glob'); + +function readManifest(manifestPath) { + const content = fs.readFileSync(manifestPath, 'utf8'); + const output = JSON.parse(content); + if (!output.id) throw new Error(`Manifest plugin ID is not set in ${manifestPath}`); + return output; +} + +function createPluginArchive(sourceDir, destPath) { + const distFiles = glob.sync(`${sourceDir}/**/*`) + .map(f => f.substr(sourceDir.length + 1)); + + fs.removeSync(destPath); + + tar.create( + { + strict: true, + portable: true, + file: destPath, + cwd: sourceDir, + sync: true, + }, + distFiles + ); + + console.info(`Plugin archive has been created in ${destPath}`); +} + +const distDir = path.resolve(__dirname, 'dist'); +const srcDir = path.resolve(__dirname, 'src'); +const manifestPath = `${srcDir}/manifest.json`; +const manifest = readManifest(manifestPath); +const archiveFilePath = path.resolve(__dirname, `${manifest.id}.jpl`); module.exports = { mode: 'production', @@ -22,7 +59,7 @@ module.exports = { }, output: { filename: 'index.js', - path: path.resolve(__dirname, 'dist'), + path: distDir, }, plugins: [ new CopyPlugin({ @@ -40,5 +77,8 @@ module.exports = { }, ], }), + new WebpackOnBuildPlugin(function() { + createPluginArchive(distDir, archiveFilePath); + }), ], }; diff --git a/packages/app-cli/tests/support/plugins/dialog/.gitignore b/packages/app-cli/tests/support/plugins/dialog/.gitignore index 2195be3d8..4efef4740 100644 --- a/packages/app-cli/tests/support/plugins/dialog/.gitignore +++ b/packages/app-cli/tests/support/plugins/dialog/.gitignore @@ -1,2 +1,3 @@ dist/* -node_modules/ \ No newline at end of file +node_modules/ +*.jpl diff --git a/packages/app-cli/tests/support/plugins/dialog/README.md b/packages/app-cli/tests/support/plugins/dialog/README.md index afbea1bd1..4618fa796 100644 --- a/packages/app-cli/tests/support/plugins/dialog/README.md +++ b/packages/app-cli/tests/support/plugins/dialog/README.md @@ -12,3 +12,11 @@ The plugin is built using webpack, which create the compiled code in `/dist`. Th ## Building the plugin To build the plugin, simply run `npm run dist`. + +## Updating the plugin framework + +To update the plugin framework, run `yo joplin --update` + +Keep in mind that doing so will overwrite all the framework-related files **outside of the "src/" directory** (your source code will not be touched). So if you have modified any of the framework-related files, such as package.json or .gitignore, make sure your code is under version control so that you can check the diff and re-apply your changes. + +For that reason, it's generally best not to change any of the framework files or to do so in a way that minimises the number of changes. For example, if you want to modify the Webpack config, create a new separate JavaScript file and include it in webpack.config.js. That way, when you update, you only have to restore the line that include your file. \ No newline at end of file diff --git a/packages/app-cli/tests/support/plugins/dialog/api/JoplinCommands.d.ts b/packages/app-cli/tests/support/plugins/dialog/api/JoplinCommands.d.ts index 8a9f30451..e175d2e14 100644 --- a/packages/app-cli/tests/support/plugins/dialog/api/JoplinCommands.d.ts +++ b/packages/app-cli/tests/support/plugins/dialog/api/JoplinCommands.d.ts @@ -21,7 +21,7 @@ import { Command } from './types'; * and look at the `execute()` command. */ export default class JoplinCommands { - /** + /** * desktop Executes the given * command. * @@ -40,8 +40,8 @@ export default class JoplinCommands { * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * ``` */ - execute(commandName: string, ...args: any[]): Promise; - /** + execute(commandName: string, ...args: any[]): Promise; + /** * desktop Registers a new command. * * ```typescript @@ -57,5 +57,5 @@ export default class JoplinCommands { * }); * ``` */ - register(command: Command): Promise; + register(command: Command): Promise; } diff --git a/packages/app-cli/tests/support/plugins/dialog/api/JoplinFilters.d.ts b/packages/app-cli/tests/support/plugins/dialog/api/JoplinFilters.d.ts index 43bc1b2b7..e086a720e 100644 --- a/packages/app-cli/tests/support/plugins/dialog/api/JoplinFilters.d.ts +++ b/packages/app-cli/tests/support/plugins/dialog/api/JoplinFilters.d.ts @@ -5,6 +5,6 @@ * so for now disable filters. */ export default class JoplinFilters { - on(name: string, callback: Function): Promise; - off(name: string, callback: Function): Promise; + on(name: string, callback: Function): Promise; + off(name: string, callback: Function): Promise; } diff --git a/packages/app-cli/tests/support/plugins/dialog/api/JoplinInterop.d.ts b/packages/app-cli/tests/support/plugins/dialog/api/JoplinInterop.d.ts index 8de655c83..1304c7512 100644 --- a/packages/app-cli/tests/support/plugins/dialog/api/JoplinInterop.d.ts +++ b/packages/app-cli/tests/support/plugins/dialog/api/JoplinInterop.d.ts @@ -12,6 +12,6 @@ import { ExportModule, ImportModule } from './types'; * You may also want to refer to the Joplin API documentation to see the list of properties for each item (note, notebook, etc.) - https://joplinapp.org/api/references/rest_api/ */ export default class JoplinInterop { - registerExportModule(module: ExportModule): Promise; - registerImportModule(module: ImportModule): Promise; + registerExportModule(module: ExportModule): Promise; + registerImportModule(module: ImportModule): Promise; } diff --git a/packages/app-cli/tests/support/plugins/dialog/package.json b/packages/app-cli/tests/support/plugins/dialog/package.json index f065077e6..ebc25dcb4 100644 --- a/packages/app-cli/tests/support/plugins/dialog/package.json +++ b/packages/app-cli/tests/support/plugins/dialog/package.json @@ -7,11 +7,14 @@ "postinstall": "npm run dist" }, "keywords": [], - "author": "Laurent Cozic", "license": "MIT", "devDependencies": { "@types/node": "^14.0.14", "copy-webpack-plugin": "^6.1.0", + "fs-extra": "^9.0.1", + "glob": "^7.1.6", + "on-build-webpack": "^0.1.0", + "tar": "^6.0.5", "ts-loader": "^7.0.5", "typescript": "^3.9.3", "webpack": "^4.43.0", diff --git a/packages/app-cli/tests/support/plugins/dialog/src/manifest.json b/packages/app-cli/tests/support/plugins/dialog/src/manifest.json index 7fd29ff04..952ef5019 100644 --- a/packages/app-cli/tests/support/plugins/dialog/src/manifest.json +++ b/packages/app-cli/tests/support/plugins/dialog/src/manifest.json @@ -1,4 +1,5 @@ { + "id": "org.joplinapp.plugins.DialogDemo", "manifest_version": 1, "app_min_version": "1.4", "name": "Dialog Demo", diff --git a/packages/app-cli/tests/support/plugins/dialog/webpack.config.js b/packages/app-cli/tests/support/plugins/dialog/webpack.config.js index 86f38111d..5c86b05c6 100644 --- a/packages/app-cli/tests/support/plugins/dialog/webpack.config.js +++ b/packages/app-cli/tests/support/plugins/dialog/webpack.config.js @@ -1,5 +1,42 @@ const path = require('path'); +const fs = require('fs-extra'); const CopyPlugin = require('copy-webpack-plugin'); +const WebpackOnBuildPlugin = require('on-build-webpack'); +const tar = require('tar'); +const glob = require('glob'); + +function readManifest(manifestPath) { + const content = fs.readFileSync(manifestPath, 'utf8'); + const output = JSON.parse(content); + if (!output.id) throw new Error(`Manifest plugin ID is not set in ${manifestPath}`); + return output; +} + +function createPluginArchive(sourceDir, destPath) { + const distFiles = glob.sync(`${sourceDir}/**/*`) + .map(f => f.substr(sourceDir.length + 1)); + + fs.removeSync(destPath); + + tar.create( + { + strict: true, + portable: true, + file: destPath, + cwd: sourceDir, + sync: true, + }, + distFiles + ); + + console.info(`Plugin archive has been created in ${destPath}`); +} + +const distDir = path.resolve(__dirname, 'dist'); +const srcDir = path.resolve(__dirname, 'src'); +const manifestPath = `${srcDir}/manifest.json`; +const manifest = readManifest(manifestPath); +const archiveFilePath = path.resolve(__dirname, `${manifest.id}.jpl`); module.exports = { mode: 'production', @@ -22,7 +59,7 @@ module.exports = { }, output: { filename: 'index.js', - path: path.resolve(__dirname, 'dist'), + path: distDir, }, plugins: [ new CopyPlugin({ @@ -40,5 +77,8 @@ module.exports = { }, ], }), + new WebpackOnBuildPlugin(function() { + createPluginArchive(distDir, archiveFilePath); + }), ], }; diff --git a/packages/app-cli/tests/support/plugins/editor_context_menu/.gitignore b/packages/app-cli/tests/support/plugins/editor_context_menu/.gitignore index 2195be3d8..4efef4740 100644 --- a/packages/app-cli/tests/support/plugins/editor_context_menu/.gitignore +++ b/packages/app-cli/tests/support/plugins/editor_context_menu/.gitignore @@ -1,2 +1,3 @@ dist/* -node_modules/ \ No newline at end of file +node_modules/ +*.jpl diff --git a/packages/app-cli/tests/support/plugins/editor_context_menu/README.md b/packages/app-cli/tests/support/plugins/editor_context_menu/README.md index afbea1bd1..4618fa796 100644 --- a/packages/app-cli/tests/support/plugins/editor_context_menu/README.md +++ b/packages/app-cli/tests/support/plugins/editor_context_menu/README.md @@ -12,3 +12,11 @@ The plugin is built using webpack, which create the compiled code in `/dist`. Th ## Building the plugin To build the plugin, simply run `npm run dist`. + +## Updating the plugin framework + +To update the plugin framework, run `yo joplin --update` + +Keep in mind that doing so will overwrite all the framework-related files **outside of the "src/" directory** (your source code will not be touched). So if you have modified any of the framework-related files, such as package.json or .gitignore, make sure your code is under version control so that you can check the diff and re-apply your changes. + +For that reason, it's generally best not to change any of the framework files or to do so in a way that minimises the number of changes. For example, if you want to modify the Webpack config, create a new separate JavaScript file and include it in webpack.config.js. That way, when you update, you only have to restore the line that include your file. \ No newline at end of file diff --git a/packages/app-cli/tests/support/plugins/editor_context_menu/api/JoplinCommands.d.ts b/packages/app-cli/tests/support/plugins/editor_context_menu/api/JoplinCommands.d.ts index 8a9f30451..e175d2e14 100644 --- a/packages/app-cli/tests/support/plugins/editor_context_menu/api/JoplinCommands.d.ts +++ b/packages/app-cli/tests/support/plugins/editor_context_menu/api/JoplinCommands.d.ts @@ -21,7 +21,7 @@ import { Command } from './types'; * and look at the `execute()` command. */ export default class JoplinCommands { - /** + /** * desktop Executes the given * command. * @@ -40,8 +40,8 @@ export default class JoplinCommands { * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * ``` */ - execute(commandName: string, ...args: any[]): Promise; - /** + execute(commandName: string, ...args: any[]): Promise; + /** * desktop Registers a new command. * * ```typescript @@ -57,5 +57,5 @@ export default class JoplinCommands { * }); * ``` */ - register(command: Command): Promise; + register(command: Command): Promise; } diff --git a/packages/app-cli/tests/support/plugins/editor_context_menu/api/JoplinFilters.d.ts b/packages/app-cli/tests/support/plugins/editor_context_menu/api/JoplinFilters.d.ts index 43bc1b2b7..e086a720e 100644 --- a/packages/app-cli/tests/support/plugins/editor_context_menu/api/JoplinFilters.d.ts +++ b/packages/app-cli/tests/support/plugins/editor_context_menu/api/JoplinFilters.d.ts @@ -5,6 +5,6 @@ * so for now disable filters. */ export default class JoplinFilters { - on(name: string, callback: Function): Promise; - off(name: string, callback: Function): Promise; + on(name: string, callback: Function): Promise; + off(name: string, callback: Function): Promise; } diff --git a/packages/app-cli/tests/support/plugins/editor_context_menu/api/JoplinInterop.d.ts b/packages/app-cli/tests/support/plugins/editor_context_menu/api/JoplinInterop.d.ts index 8de655c83..1304c7512 100644 --- a/packages/app-cli/tests/support/plugins/editor_context_menu/api/JoplinInterop.d.ts +++ b/packages/app-cli/tests/support/plugins/editor_context_menu/api/JoplinInterop.d.ts @@ -12,6 +12,6 @@ import { ExportModule, ImportModule } from './types'; * You may also want to refer to the Joplin API documentation to see the list of properties for each item (note, notebook, etc.) - https://joplinapp.org/api/references/rest_api/ */ export default class JoplinInterop { - registerExportModule(module: ExportModule): Promise; - registerImportModule(module: ImportModule): Promise; + registerExportModule(module: ExportModule): Promise; + registerImportModule(module: ImportModule): Promise; } diff --git a/packages/app-cli/tests/support/plugins/editor_context_menu/package.json b/packages/app-cli/tests/support/plugins/editor_context_menu/package.json index 2d9b8a3e8..ebc25dcb4 100644 --- a/packages/app-cli/tests/support/plugins/editor_context_menu/package.json +++ b/packages/app-cli/tests/support/plugins/editor_context_menu/package.json @@ -7,11 +7,14 @@ "postinstall": "npm run dist" }, "keywords": [], - "author": "", "license": "MIT", "devDependencies": { "@types/node": "^14.0.14", "copy-webpack-plugin": "^6.1.0", + "fs-extra": "^9.0.1", + "glob": "^7.1.6", + "on-build-webpack": "^0.1.0", + "tar": "^6.0.5", "ts-loader": "^7.0.5", "typescript": "^3.9.3", "webpack": "^4.43.0", diff --git a/packages/app-cli/tests/support/plugins/editor_context_menu/src/manifest.json b/packages/app-cli/tests/support/plugins/editor_context_menu/src/manifest.json index 3f402a3a7..d7ffb63dc 100644 --- a/packages/app-cli/tests/support/plugins/editor_context_menu/src/manifest.json +++ b/packages/app-cli/tests/support/plugins/editor_context_menu/src/manifest.json @@ -1,4 +1,5 @@ { + "id": "org.joplinapp.plugins.EditorContextMenuDemo", "manifest_version": 1, "app_min_version": "1.4", "name": "Editor Context Menu Demo", diff --git a/packages/app-cli/tests/support/plugins/editor_context_menu/webpack.config.js b/packages/app-cli/tests/support/plugins/editor_context_menu/webpack.config.js index 86f38111d..5c86b05c6 100644 --- a/packages/app-cli/tests/support/plugins/editor_context_menu/webpack.config.js +++ b/packages/app-cli/tests/support/plugins/editor_context_menu/webpack.config.js @@ -1,5 +1,42 @@ const path = require('path'); +const fs = require('fs-extra'); const CopyPlugin = require('copy-webpack-plugin'); +const WebpackOnBuildPlugin = require('on-build-webpack'); +const tar = require('tar'); +const glob = require('glob'); + +function readManifest(manifestPath) { + const content = fs.readFileSync(manifestPath, 'utf8'); + const output = JSON.parse(content); + if (!output.id) throw new Error(`Manifest plugin ID is not set in ${manifestPath}`); + return output; +} + +function createPluginArchive(sourceDir, destPath) { + const distFiles = glob.sync(`${sourceDir}/**/*`) + .map(f => f.substr(sourceDir.length + 1)); + + fs.removeSync(destPath); + + tar.create( + { + strict: true, + portable: true, + file: destPath, + cwd: sourceDir, + sync: true, + }, + distFiles + ); + + console.info(`Plugin archive has been created in ${destPath}`); +} + +const distDir = path.resolve(__dirname, 'dist'); +const srcDir = path.resolve(__dirname, 'src'); +const manifestPath = `${srcDir}/manifest.json`; +const manifest = readManifest(manifestPath); +const archiveFilePath = path.resolve(__dirname, `${manifest.id}.jpl`); module.exports = { mode: 'production', @@ -22,7 +59,7 @@ module.exports = { }, output: { filename: 'index.js', - path: path.resolve(__dirname, 'dist'), + path: distDir, }, plugins: [ new CopyPlugin({ @@ -40,5 +77,8 @@ module.exports = { }, ], }), + new WebpackOnBuildPlugin(function() { + createPluginArchive(distDir, archiveFilePath); + }), ], }; diff --git a/packages/app-cli/tests/support/plugins/events/.gitignore b/packages/app-cli/tests/support/plugins/events/.gitignore index 2195be3d8..4efef4740 100644 --- a/packages/app-cli/tests/support/plugins/events/.gitignore +++ b/packages/app-cli/tests/support/plugins/events/.gitignore @@ -1,2 +1,3 @@ dist/* -node_modules/ \ No newline at end of file +node_modules/ +*.jpl diff --git a/packages/app-cli/tests/support/plugins/events/README.md b/packages/app-cli/tests/support/plugins/events/README.md index afbea1bd1..4618fa796 100644 --- a/packages/app-cli/tests/support/plugins/events/README.md +++ b/packages/app-cli/tests/support/plugins/events/README.md @@ -12,3 +12,11 @@ The plugin is built using webpack, which create the compiled code in `/dist`. Th ## Building the plugin To build the plugin, simply run `npm run dist`. + +## Updating the plugin framework + +To update the plugin framework, run `yo joplin --update` + +Keep in mind that doing so will overwrite all the framework-related files **outside of the "src/" directory** (your source code will not be touched). So if you have modified any of the framework-related files, such as package.json or .gitignore, make sure your code is under version control so that you can check the diff and re-apply your changes. + +For that reason, it's generally best not to change any of the framework files or to do so in a way that minimises the number of changes. For example, if you want to modify the Webpack config, create a new separate JavaScript file and include it in webpack.config.js. That way, when you update, you only have to restore the line that include your file. \ No newline at end of file diff --git a/packages/app-cli/tests/support/plugins/events/api/JoplinCommands.d.ts b/packages/app-cli/tests/support/plugins/events/api/JoplinCommands.d.ts index 8a9f30451..e175d2e14 100644 --- a/packages/app-cli/tests/support/plugins/events/api/JoplinCommands.d.ts +++ b/packages/app-cli/tests/support/plugins/events/api/JoplinCommands.d.ts @@ -21,7 +21,7 @@ import { Command } from './types'; * and look at the `execute()` command. */ export default class JoplinCommands { - /** + /** * desktop Executes the given * command. * @@ -40,8 +40,8 @@ export default class JoplinCommands { * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * ``` */ - execute(commandName: string, ...args: any[]): Promise; - /** + execute(commandName: string, ...args: any[]): Promise; + /** * desktop Registers a new command. * * ```typescript @@ -57,5 +57,5 @@ export default class JoplinCommands { * }); * ``` */ - register(command: Command): Promise; + register(command: Command): Promise; } diff --git a/packages/app-cli/tests/support/plugins/events/api/JoplinFilters.d.ts b/packages/app-cli/tests/support/plugins/events/api/JoplinFilters.d.ts index 43bc1b2b7..e086a720e 100644 --- a/packages/app-cli/tests/support/plugins/events/api/JoplinFilters.d.ts +++ b/packages/app-cli/tests/support/plugins/events/api/JoplinFilters.d.ts @@ -5,6 +5,6 @@ * so for now disable filters. */ export default class JoplinFilters { - on(name: string, callback: Function): Promise; - off(name: string, callback: Function): Promise; + on(name: string, callback: Function): Promise; + off(name: string, callback: Function): Promise; } diff --git a/packages/app-cli/tests/support/plugins/events/api/JoplinInterop.d.ts b/packages/app-cli/tests/support/plugins/events/api/JoplinInterop.d.ts index 8de655c83..1304c7512 100644 --- a/packages/app-cli/tests/support/plugins/events/api/JoplinInterop.d.ts +++ b/packages/app-cli/tests/support/plugins/events/api/JoplinInterop.d.ts @@ -12,6 +12,6 @@ import { ExportModule, ImportModule } from './types'; * You may also want to refer to the Joplin API documentation to see the list of properties for each item (note, notebook, etc.) - https://joplinapp.org/api/references/rest_api/ */ export default class JoplinInterop { - registerExportModule(module: ExportModule): Promise; - registerImportModule(module: ImportModule): Promise; + registerExportModule(module: ExportModule): Promise; + registerImportModule(module: ImportModule): Promise; } diff --git a/packages/app-cli/tests/support/plugins/events/package.json b/packages/app-cli/tests/support/plugins/events/package.json index f065077e6..ebc25dcb4 100644 --- a/packages/app-cli/tests/support/plugins/events/package.json +++ b/packages/app-cli/tests/support/plugins/events/package.json @@ -7,11 +7,14 @@ "postinstall": "npm run dist" }, "keywords": [], - "author": "Laurent Cozic", "license": "MIT", "devDependencies": { "@types/node": "^14.0.14", "copy-webpack-plugin": "^6.1.0", + "fs-extra": "^9.0.1", + "glob": "^7.1.6", + "on-build-webpack": "^0.1.0", + "tar": "^6.0.5", "ts-loader": "^7.0.5", "typescript": "^3.9.3", "webpack": "^4.43.0", diff --git a/packages/app-cli/tests/support/plugins/events/src/manifest.json b/packages/app-cli/tests/support/plugins/events/src/manifest.json index c28fabbf3..3b88f4751 100644 --- a/packages/app-cli/tests/support/plugins/events/src/manifest.json +++ b/packages/app-cli/tests/support/plugins/events/src/manifest.json @@ -1,4 +1,5 @@ { + "id": "org.joplinapp.plugins.EventsDemo", "manifest_version": 1, "app_min_version": "1.4", "name": "Event demo", diff --git a/packages/app-cli/tests/support/plugins/events/webpack.config.js b/packages/app-cli/tests/support/plugins/events/webpack.config.js index 86f38111d..5c86b05c6 100644 --- a/packages/app-cli/tests/support/plugins/events/webpack.config.js +++ b/packages/app-cli/tests/support/plugins/events/webpack.config.js @@ -1,5 +1,42 @@ const path = require('path'); +const fs = require('fs-extra'); const CopyPlugin = require('copy-webpack-plugin'); +const WebpackOnBuildPlugin = require('on-build-webpack'); +const tar = require('tar'); +const glob = require('glob'); + +function readManifest(manifestPath) { + const content = fs.readFileSync(manifestPath, 'utf8'); + const output = JSON.parse(content); + if (!output.id) throw new Error(`Manifest plugin ID is not set in ${manifestPath}`); + return output; +} + +function createPluginArchive(sourceDir, destPath) { + const distFiles = glob.sync(`${sourceDir}/**/*`) + .map(f => f.substr(sourceDir.length + 1)); + + fs.removeSync(destPath); + + tar.create( + { + strict: true, + portable: true, + file: destPath, + cwd: sourceDir, + sync: true, + }, + distFiles + ); + + console.info(`Plugin archive has been created in ${destPath}`); +} + +const distDir = path.resolve(__dirname, 'dist'); +const srcDir = path.resolve(__dirname, 'src'); +const manifestPath = `${srcDir}/manifest.json`; +const manifest = readManifest(manifestPath); +const archiveFilePath = path.resolve(__dirname, `${manifest.id}.jpl`); module.exports = { mode: 'production', @@ -22,7 +59,7 @@ module.exports = { }, output: { filename: 'index.js', - path: path.resolve(__dirname, 'dist'), + path: distDir, }, plugins: [ new CopyPlugin({ @@ -40,5 +77,8 @@ module.exports = { }, ], }), + new WebpackOnBuildPlugin(function() { + createPluginArchive(distDir, archiveFilePath); + }), ], }; diff --git a/packages/app-cli/tests/support/plugins/jpl_test/.gitignore b/packages/app-cli/tests/support/plugins/jpl_test/.gitignore index 2195be3d8..34112f8f2 100644 --- a/packages/app-cli/tests/support/plugins/jpl_test/.gitignore +++ b/packages/app-cli/tests/support/plugins/jpl_test/.gitignore @@ -1,2 +1,2 @@ dist/* -node_modules/ \ No newline at end of file +node_modules/ diff --git a/packages/app-cli/tests/support/plugins/jpl_test/README.md b/packages/app-cli/tests/support/plugins/jpl_test/README.md index afbea1bd1..4618fa796 100644 --- a/packages/app-cli/tests/support/plugins/jpl_test/README.md +++ b/packages/app-cli/tests/support/plugins/jpl_test/README.md @@ -12,3 +12,11 @@ The plugin is built using webpack, which create the compiled code in `/dist`. Th ## Building the plugin To build the plugin, simply run `npm run dist`. + +## Updating the plugin framework + +To update the plugin framework, run `yo joplin --update` + +Keep in mind that doing so will overwrite all the framework-related files **outside of the "src/" directory** (your source code will not be touched). So if you have modified any of the framework-related files, such as package.json or .gitignore, make sure your code is under version control so that you can check the diff and re-apply your changes. + +For that reason, it's generally best not to change any of the framework files or to do so in a way that minimises the number of changes. For example, if you want to modify the Webpack config, create a new separate JavaScript file and include it in webpack.config.js. That way, when you update, you only have to restore the line that include your file. \ No newline at end of file diff --git a/packages/app-cli/tests/support/plugins/jpl_test/package.json b/packages/app-cli/tests/support/plugins/jpl_test/package.json index 171374ff9..ebc25dcb4 100644 --- a/packages/app-cli/tests/support/plugins/jpl_test/package.json +++ b/packages/app-cli/tests/support/plugins/jpl_test/package.json @@ -1,5 +1,5 @@ { - "name": "org.joplinapp.FirstJplPlugin", + "name": "joplin_plugin", "version": "1.0.0", "description": "", "scripts": { @@ -7,7 +7,6 @@ "postinstall": "npm run dist" }, "keywords": [], - "author": "", "license": "MIT", "devDependencies": { "@types/node": "^14.0.14", diff --git a/packages/app-cli/tests/support/plugins/jsbundles/example.js b/packages/app-cli/tests/support/plugins/jsbundles/example.js index 84852c8ab..83e32e91c 100644 --- a/packages/app-cli/tests/support/plugins/jsbundles/example.js +++ b/packages/app-cli/tests/support/plugins/jsbundles/example.js @@ -1,5 +1,6 @@ /* joplin-manifest: { + "id": "org.joplinapp.plugins.JsBundleDemo", "manifest_version": 1, "app_min_version": "1.4", "name": "JS Bundle test", diff --git a/packages/app-cli/tests/support/plugins/json_export/.gitignore b/packages/app-cli/tests/support/plugins/json_export/.gitignore index 2195be3d8..4efef4740 100644 --- a/packages/app-cli/tests/support/plugins/json_export/.gitignore +++ b/packages/app-cli/tests/support/plugins/json_export/.gitignore @@ -1,2 +1,3 @@ dist/* -node_modules/ \ No newline at end of file +node_modules/ +*.jpl diff --git a/packages/app-cli/tests/support/plugins/json_export/README.md b/packages/app-cli/tests/support/plugins/json_export/README.md index afbea1bd1..4618fa796 100644 --- a/packages/app-cli/tests/support/plugins/json_export/README.md +++ b/packages/app-cli/tests/support/plugins/json_export/README.md @@ -12,3 +12,11 @@ The plugin is built using webpack, which create the compiled code in `/dist`. Th ## Building the plugin To build the plugin, simply run `npm run dist`. + +## Updating the plugin framework + +To update the plugin framework, run `yo joplin --update` + +Keep in mind that doing so will overwrite all the framework-related files **outside of the "src/" directory** (your source code will not be touched). So if you have modified any of the framework-related files, such as package.json or .gitignore, make sure your code is under version control so that you can check the diff and re-apply your changes. + +For that reason, it's generally best not to change any of the framework files or to do so in a way that minimises the number of changes. For example, if you want to modify the Webpack config, create a new separate JavaScript file and include it in webpack.config.js. That way, when you update, you only have to restore the line that include your file. \ No newline at end of file diff --git a/packages/app-cli/tests/support/plugins/json_export/api/JoplinCommands.d.ts b/packages/app-cli/tests/support/plugins/json_export/api/JoplinCommands.d.ts index 8a9f30451..e175d2e14 100644 --- a/packages/app-cli/tests/support/plugins/json_export/api/JoplinCommands.d.ts +++ b/packages/app-cli/tests/support/plugins/json_export/api/JoplinCommands.d.ts @@ -21,7 +21,7 @@ import { Command } from './types'; * and look at the `execute()` command. */ export default class JoplinCommands { - /** + /** * desktop Executes the given * command. * @@ -40,8 +40,8 @@ export default class JoplinCommands { * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * ``` */ - execute(commandName: string, ...args: any[]): Promise; - /** + execute(commandName: string, ...args: any[]): Promise; + /** * desktop Registers a new command. * * ```typescript @@ -57,5 +57,5 @@ export default class JoplinCommands { * }); * ``` */ - register(command: Command): Promise; + register(command: Command): Promise; } diff --git a/packages/app-cli/tests/support/plugins/json_export/api/JoplinFilters.d.ts b/packages/app-cli/tests/support/plugins/json_export/api/JoplinFilters.d.ts index 43bc1b2b7..e086a720e 100644 --- a/packages/app-cli/tests/support/plugins/json_export/api/JoplinFilters.d.ts +++ b/packages/app-cli/tests/support/plugins/json_export/api/JoplinFilters.d.ts @@ -5,6 +5,6 @@ * so for now disable filters. */ export default class JoplinFilters { - on(name: string, callback: Function): Promise; - off(name: string, callback: Function): Promise; + on(name: string, callback: Function): Promise; + off(name: string, callback: Function): Promise; } diff --git a/packages/app-cli/tests/support/plugins/json_export/api/JoplinInterop.d.ts b/packages/app-cli/tests/support/plugins/json_export/api/JoplinInterop.d.ts index 8de655c83..1304c7512 100644 --- a/packages/app-cli/tests/support/plugins/json_export/api/JoplinInterop.d.ts +++ b/packages/app-cli/tests/support/plugins/json_export/api/JoplinInterop.d.ts @@ -12,6 +12,6 @@ import { ExportModule, ImportModule } from './types'; * You may also want to refer to the Joplin API documentation to see the list of properties for each item (note, notebook, etc.) - https://joplinapp.org/api/references/rest_api/ */ export default class JoplinInterop { - registerExportModule(module: ExportModule): Promise; - registerImportModule(module: ImportModule): Promise; + registerExportModule(module: ExportModule): Promise; + registerImportModule(module: ImportModule): Promise; } diff --git a/packages/app-cli/tests/support/plugins/json_export/package.json b/packages/app-cli/tests/support/plugins/json_export/package.json index bd9f258be..ebc25dcb4 100644 --- a/packages/app-cli/tests/support/plugins/json_export/package.json +++ b/packages/app-cli/tests/support/plugins/json_export/package.json @@ -1,5 +1,5 @@ { - "name": "test_plugin", + "name": "joplin_plugin", "version": "1.0.0", "description": "", "scripts": { @@ -7,11 +7,14 @@ "postinstall": "npm run dist" }, "keywords": [], - "author": "", "license": "MIT", "devDependencies": { "@types/node": "^14.0.14", "copy-webpack-plugin": "^6.1.0", + "fs-extra": "^9.0.1", + "glob": "^7.1.6", + "on-build-webpack": "^0.1.0", + "tar": "^6.0.5", "ts-loader": "^7.0.5", "typescript": "^3.9.3", "webpack": "^4.43.0", diff --git a/packages/app-cli/tests/support/plugins/json_export/src/manifest.json b/packages/app-cli/tests/support/plugins/json_export/src/manifest.json index 2d484dc98..ef8f8225f 100644 --- a/packages/app-cli/tests/support/plugins/json_export/src/manifest.json +++ b/packages/app-cli/tests/support/plugins/json_export/src/manifest.json @@ -1,4 +1,5 @@ { + "id": "org.joplinapp.plugins.JsonExportDemo", "manifest_version": 1, "app_min_version": "1.4", "name": "Json Export Test", diff --git a/packages/app-cli/tests/support/plugins/json_export/webpack.config.js b/packages/app-cli/tests/support/plugins/json_export/webpack.config.js index 86f38111d..5c86b05c6 100644 --- a/packages/app-cli/tests/support/plugins/json_export/webpack.config.js +++ b/packages/app-cli/tests/support/plugins/json_export/webpack.config.js @@ -1,5 +1,42 @@ const path = require('path'); +const fs = require('fs-extra'); const CopyPlugin = require('copy-webpack-plugin'); +const WebpackOnBuildPlugin = require('on-build-webpack'); +const tar = require('tar'); +const glob = require('glob'); + +function readManifest(manifestPath) { + const content = fs.readFileSync(manifestPath, 'utf8'); + const output = JSON.parse(content); + if (!output.id) throw new Error(`Manifest plugin ID is not set in ${manifestPath}`); + return output; +} + +function createPluginArchive(sourceDir, destPath) { + const distFiles = glob.sync(`${sourceDir}/**/*`) + .map(f => f.substr(sourceDir.length + 1)); + + fs.removeSync(destPath); + + tar.create( + { + strict: true, + portable: true, + file: destPath, + cwd: sourceDir, + sync: true, + }, + distFiles + ); + + console.info(`Plugin archive has been created in ${destPath}`); +} + +const distDir = path.resolve(__dirname, 'dist'); +const srcDir = path.resolve(__dirname, 'src'); +const manifestPath = `${srcDir}/manifest.json`; +const manifest = readManifest(manifestPath); +const archiveFilePath = path.resolve(__dirname, `${manifest.id}.jpl`); module.exports = { mode: 'production', @@ -22,7 +59,7 @@ module.exports = { }, output: { filename: 'index.js', - path: path.resolve(__dirname, 'dist'), + path: distDir, }, plugins: [ new CopyPlugin({ @@ -40,5 +77,8 @@ module.exports = { }, ], }), + new WebpackOnBuildPlugin(function() { + createPluginArchive(distDir, archiveFilePath); + }), ], }; diff --git a/packages/app-cli/tests/support/plugins/menu/.gitignore b/packages/app-cli/tests/support/plugins/menu/.gitignore index 2195be3d8..4efef4740 100644 --- a/packages/app-cli/tests/support/plugins/menu/.gitignore +++ b/packages/app-cli/tests/support/plugins/menu/.gitignore @@ -1,2 +1,3 @@ dist/* -node_modules/ \ No newline at end of file +node_modules/ +*.jpl diff --git a/packages/app-cli/tests/support/plugins/menu/README.md b/packages/app-cli/tests/support/plugins/menu/README.md index afbea1bd1..4618fa796 100644 --- a/packages/app-cli/tests/support/plugins/menu/README.md +++ b/packages/app-cli/tests/support/plugins/menu/README.md @@ -12,3 +12,11 @@ The plugin is built using webpack, which create the compiled code in `/dist`. Th ## Building the plugin To build the plugin, simply run `npm run dist`. + +## Updating the plugin framework + +To update the plugin framework, run `yo joplin --update` + +Keep in mind that doing so will overwrite all the framework-related files **outside of the "src/" directory** (your source code will not be touched). So if you have modified any of the framework-related files, such as package.json or .gitignore, make sure your code is under version control so that you can check the diff and re-apply your changes. + +For that reason, it's generally best not to change any of the framework files or to do so in a way that minimises the number of changes. For example, if you want to modify the Webpack config, create a new separate JavaScript file and include it in webpack.config.js. That way, when you update, you only have to restore the line that include your file. \ No newline at end of file diff --git a/packages/app-cli/tests/support/plugins/menu/api/JoplinCommands.d.ts b/packages/app-cli/tests/support/plugins/menu/api/JoplinCommands.d.ts index 8a9f30451..e175d2e14 100644 --- a/packages/app-cli/tests/support/plugins/menu/api/JoplinCommands.d.ts +++ b/packages/app-cli/tests/support/plugins/menu/api/JoplinCommands.d.ts @@ -21,7 +21,7 @@ import { Command } from './types'; * and look at the `execute()` command. */ export default class JoplinCommands { - /** + /** * desktop Executes the given * command. * @@ -40,8 +40,8 @@ export default class JoplinCommands { * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * ``` */ - execute(commandName: string, ...args: any[]): Promise; - /** + execute(commandName: string, ...args: any[]): Promise; + /** * desktop Registers a new command. * * ```typescript @@ -57,5 +57,5 @@ export default class JoplinCommands { * }); * ``` */ - register(command: Command): Promise; + register(command: Command): Promise; } diff --git a/packages/app-cli/tests/support/plugins/menu/api/JoplinFilters.d.ts b/packages/app-cli/tests/support/plugins/menu/api/JoplinFilters.d.ts index 43bc1b2b7..e086a720e 100644 --- a/packages/app-cli/tests/support/plugins/menu/api/JoplinFilters.d.ts +++ b/packages/app-cli/tests/support/plugins/menu/api/JoplinFilters.d.ts @@ -5,6 +5,6 @@ * so for now disable filters. */ export default class JoplinFilters { - on(name: string, callback: Function): Promise; - off(name: string, callback: Function): Promise; + on(name: string, callback: Function): Promise; + off(name: string, callback: Function): Promise; } diff --git a/packages/app-cli/tests/support/plugins/menu/api/JoplinInterop.d.ts b/packages/app-cli/tests/support/plugins/menu/api/JoplinInterop.d.ts index 8de655c83..1304c7512 100644 --- a/packages/app-cli/tests/support/plugins/menu/api/JoplinInterop.d.ts +++ b/packages/app-cli/tests/support/plugins/menu/api/JoplinInterop.d.ts @@ -12,6 +12,6 @@ import { ExportModule, ImportModule } from './types'; * You may also want to refer to the Joplin API documentation to see the list of properties for each item (note, notebook, etc.) - https://joplinapp.org/api/references/rest_api/ */ export default class JoplinInterop { - registerExportModule(module: ExportModule): Promise; - registerImportModule(module: ImportModule): Promise; + registerExportModule(module: ExportModule): Promise; + registerImportModule(module: ImportModule): Promise; } diff --git a/packages/app-cli/tests/support/plugins/menu/package.json b/packages/app-cli/tests/support/plugins/menu/package.json index 2d9b8a3e8..ebc25dcb4 100644 --- a/packages/app-cli/tests/support/plugins/menu/package.json +++ b/packages/app-cli/tests/support/plugins/menu/package.json @@ -7,11 +7,14 @@ "postinstall": "npm run dist" }, "keywords": [], - "author": "", "license": "MIT", "devDependencies": { "@types/node": "^14.0.14", "copy-webpack-plugin": "^6.1.0", + "fs-extra": "^9.0.1", + "glob": "^7.1.6", + "on-build-webpack": "^0.1.0", + "tar": "^6.0.5", "ts-loader": "^7.0.5", "typescript": "^3.9.3", "webpack": "^4.43.0", diff --git a/packages/app-cli/tests/support/plugins/menu/src/manifest.json b/packages/app-cli/tests/support/plugins/menu/src/manifest.json index 1a7da2707..ed47d2573 100644 --- a/packages/app-cli/tests/support/plugins/menu/src/manifest.json +++ b/packages/app-cli/tests/support/plugins/menu/src/manifest.json @@ -1,4 +1,5 @@ { + "id": "org.joplinapp.plugins.MenuDemo", "manifest_version": 1, "app_min_version": "1.4", "name": "Menu Test", diff --git a/packages/app-cli/tests/support/plugins/menu/webpack.config.js b/packages/app-cli/tests/support/plugins/menu/webpack.config.js index 86f38111d..5c86b05c6 100644 --- a/packages/app-cli/tests/support/plugins/menu/webpack.config.js +++ b/packages/app-cli/tests/support/plugins/menu/webpack.config.js @@ -1,5 +1,42 @@ const path = require('path'); +const fs = require('fs-extra'); const CopyPlugin = require('copy-webpack-plugin'); +const WebpackOnBuildPlugin = require('on-build-webpack'); +const tar = require('tar'); +const glob = require('glob'); + +function readManifest(manifestPath) { + const content = fs.readFileSync(manifestPath, 'utf8'); + const output = JSON.parse(content); + if (!output.id) throw new Error(`Manifest plugin ID is not set in ${manifestPath}`); + return output; +} + +function createPluginArchive(sourceDir, destPath) { + const distFiles = glob.sync(`${sourceDir}/**/*`) + .map(f => f.substr(sourceDir.length + 1)); + + fs.removeSync(destPath); + + tar.create( + { + strict: true, + portable: true, + file: destPath, + cwd: sourceDir, + sync: true, + }, + distFiles + ); + + console.info(`Plugin archive has been created in ${destPath}`); +} + +const distDir = path.resolve(__dirname, 'dist'); +const srcDir = path.resolve(__dirname, 'src'); +const manifestPath = `${srcDir}/manifest.json`; +const manifest = readManifest(manifestPath); +const archiveFilePath = path.resolve(__dirname, `${manifest.id}.jpl`); module.exports = { mode: 'production', @@ -22,7 +59,7 @@ module.exports = { }, output: { filename: 'index.js', - path: path.resolve(__dirname, 'dist'), + path: distDir, }, plugins: [ new CopyPlugin({ @@ -40,5 +77,8 @@ module.exports = { }, ], }), + new WebpackOnBuildPlugin(function() { + createPluginArchive(distDir, archiveFilePath); + }), ], }; diff --git a/packages/app-cli/tests/support/plugins/multi_plugins/simple1/manifest.json b/packages/app-cli/tests/support/plugins/multi_plugins/simple1/manifest.json index 5a96977da..7697c2b9b 100644 --- a/packages/app-cli/tests/support/plugins/multi_plugins/simple1/manifest.json +++ b/packages/app-cli/tests/support/plugins/multi_plugins/simple1/manifest.json @@ -1,4 +1,5 @@ { + "id": "org.joplinapp.plugins.MultiPluginDemo1", "manifest_version": 1, "app_min_version": "1.4", "name": "Joplin Simple Plugin", diff --git a/packages/app-cli/tests/support/plugins/multi_plugins/simple2/manifest.json b/packages/app-cli/tests/support/plugins/multi_plugins/simple2/manifest.json index 5a96977da..6af3d1dce 100644 --- a/packages/app-cli/tests/support/plugins/multi_plugins/simple2/manifest.json +++ b/packages/app-cli/tests/support/plugins/multi_plugins/simple2/manifest.json @@ -1,4 +1,5 @@ { + "id": "org.joplinapp.plugins.MultiPluginDemo2", "manifest_version": 1, "app_min_version": "1.4", "name": "Joplin Simple Plugin", diff --git a/packages/app-cli/tests/support/plugins/multi_selection/.gitignore b/packages/app-cli/tests/support/plugins/multi_selection/.gitignore index 2195be3d8..4efef4740 100644 --- a/packages/app-cli/tests/support/plugins/multi_selection/.gitignore +++ b/packages/app-cli/tests/support/plugins/multi_selection/.gitignore @@ -1,2 +1,3 @@ dist/* -node_modules/ \ No newline at end of file +node_modules/ +*.jpl diff --git a/packages/app-cli/tests/support/plugins/multi_selection/README.md b/packages/app-cli/tests/support/plugins/multi_selection/README.md index afbea1bd1..4618fa796 100644 --- a/packages/app-cli/tests/support/plugins/multi_selection/README.md +++ b/packages/app-cli/tests/support/plugins/multi_selection/README.md @@ -12,3 +12,11 @@ The plugin is built using webpack, which create the compiled code in `/dist`. Th ## Building the plugin To build the plugin, simply run `npm run dist`. + +## Updating the plugin framework + +To update the plugin framework, run `yo joplin --update` + +Keep in mind that doing so will overwrite all the framework-related files **outside of the "src/" directory** (your source code will not be touched). So if you have modified any of the framework-related files, such as package.json or .gitignore, make sure your code is under version control so that you can check the diff and re-apply your changes. + +For that reason, it's generally best not to change any of the framework files or to do so in a way that minimises the number of changes. For example, if you want to modify the Webpack config, create a new separate JavaScript file and include it in webpack.config.js. That way, when you update, you only have to restore the line that include your file. \ No newline at end of file diff --git a/packages/app-cli/tests/support/plugins/multi_selection/api/JoplinCommands.d.ts b/packages/app-cli/tests/support/plugins/multi_selection/api/JoplinCommands.d.ts index 8a9f30451..e175d2e14 100644 --- a/packages/app-cli/tests/support/plugins/multi_selection/api/JoplinCommands.d.ts +++ b/packages/app-cli/tests/support/plugins/multi_selection/api/JoplinCommands.d.ts @@ -21,7 +21,7 @@ import { Command } from './types'; * and look at the `execute()` command. */ export default class JoplinCommands { - /** + /** * desktop Executes the given * command. * @@ -40,8 +40,8 @@ export default class JoplinCommands { * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * ``` */ - execute(commandName: string, ...args: any[]): Promise; - /** + execute(commandName: string, ...args: any[]): Promise; + /** * desktop Registers a new command. * * ```typescript @@ -57,5 +57,5 @@ export default class JoplinCommands { * }); * ``` */ - register(command: Command): Promise; + register(command: Command): Promise; } diff --git a/packages/app-cli/tests/support/plugins/multi_selection/api/JoplinFilters.d.ts b/packages/app-cli/tests/support/plugins/multi_selection/api/JoplinFilters.d.ts index 43bc1b2b7..e086a720e 100644 --- a/packages/app-cli/tests/support/plugins/multi_selection/api/JoplinFilters.d.ts +++ b/packages/app-cli/tests/support/plugins/multi_selection/api/JoplinFilters.d.ts @@ -5,6 +5,6 @@ * so for now disable filters. */ export default class JoplinFilters { - on(name: string, callback: Function): Promise; - off(name: string, callback: Function): Promise; + on(name: string, callback: Function): Promise; + off(name: string, callback: Function): Promise; } diff --git a/packages/app-cli/tests/support/plugins/multi_selection/api/JoplinInterop.d.ts b/packages/app-cli/tests/support/plugins/multi_selection/api/JoplinInterop.d.ts index 8de655c83..1304c7512 100644 --- a/packages/app-cli/tests/support/plugins/multi_selection/api/JoplinInterop.d.ts +++ b/packages/app-cli/tests/support/plugins/multi_selection/api/JoplinInterop.d.ts @@ -12,6 +12,6 @@ import { ExportModule, ImportModule } from './types'; * You may also want to refer to the Joplin API documentation to see the list of properties for each item (note, notebook, etc.) - https://joplinapp.org/api/references/rest_api/ */ export default class JoplinInterop { - registerExportModule(module: ExportModule): Promise; - registerImportModule(module: ImportModule): Promise; + registerExportModule(module: ExportModule): Promise; + registerImportModule(module: ImportModule): Promise; } diff --git a/packages/app-cli/tests/support/plugins/multi_selection/package.json b/packages/app-cli/tests/support/plugins/multi_selection/package.json index f065077e6..ebc25dcb4 100644 --- a/packages/app-cli/tests/support/plugins/multi_selection/package.json +++ b/packages/app-cli/tests/support/plugins/multi_selection/package.json @@ -7,11 +7,14 @@ "postinstall": "npm run dist" }, "keywords": [], - "author": "Laurent Cozic", "license": "MIT", "devDependencies": { "@types/node": "^14.0.14", "copy-webpack-plugin": "^6.1.0", + "fs-extra": "^9.0.1", + "glob": "^7.1.6", + "on-build-webpack": "^0.1.0", + "tar": "^6.0.5", "ts-loader": "^7.0.5", "typescript": "^3.9.3", "webpack": "^4.43.0", diff --git a/packages/app-cli/tests/support/plugins/multi_selection/src/manifest.json b/packages/app-cli/tests/support/plugins/multi_selection/src/manifest.json index 35f4eb5e5..26a14e184 100644 --- a/packages/app-cli/tests/support/plugins/multi_selection/src/manifest.json +++ b/packages/app-cli/tests/support/plugins/multi_selection/src/manifest.json @@ -1,4 +1,5 @@ { + "id": "org.joplinapp.plugins.MultiSelection", "manifest_version": 1, "app_min_version": "1.4", "name": "Multi Note Selection Demo", diff --git a/packages/app-cli/tests/support/plugins/multi_selection/webpack.config.js b/packages/app-cli/tests/support/plugins/multi_selection/webpack.config.js index 86f38111d..5c86b05c6 100644 --- a/packages/app-cli/tests/support/plugins/multi_selection/webpack.config.js +++ b/packages/app-cli/tests/support/plugins/multi_selection/webpack.config.js @@ -1,5 +1,42 @@ const path = require('path'); +const fs = require('fs-extra'); const CopyPlugin = require('copy-webpack-plugin'); +const WebpackOnBuildPlugin = require('on-build-webpack'); +const tar = require('tar'); +const glob = require('glob'); + +function readManifest(manifestPath) { + const content = fs.readFileSync(manifestPath, 'utf8'); + const output = JSON.parse(content); + if (!output.id) throw new Error(`Manifest plugin ID is not set in ${manifestPath}`); + return output; +} + +function createPluginArchive(sourceDir, destPath) { + const distFiles = glob.sync(`${sourceDir}/**/*`) + .map(f => f.substr(sourceDir.length + 1)); + + fs.removeSync(destPath); + + tar.create( + { + strict: true, + portable: true, + file: destPath, + cwd: sourceDir, + sync: true, + }, + distFiles + ); + + console.info(`Plugin archive has been created in ${destPath}`); +} + +const distDir = path.resolve(__dirname, 'dist'); +const srcDir = path.resolve(__dirname, 'src'); +const manifestPath = `${srcDir}/manifest.json`; +const manifest = readManifest(manifestPath); +const archiveFilePath = path.resolve(__dirname, `${manifest.id}.jpl`); module.exports = { mode: 'production', @@ -22,7 +59,7 @@ module.exports = { }, output: { filename: 'index.js', - path: path.resolve(__dirname, 'dist'), + path: distDir, }, plugins: [ new CopyPlugin({ @@ -40,5 +77,8 @@ module.exports = { }, ], }), + new WebpackOnBuildPlugin(function() { + createPluginArchive(distDir, archiveFilePath); + }), ], }; diff --git a/packages/app-cli/tests/support/plugins/register_command/.gitignore b/packages/app-cli/tests/support/plugins/register_command/.gitignore index 2195be3d8..4efef4740 100644 --- a/packages/app-cli/tests/support/plugins/register_command/.gitignore +++ b/packages/app-cli/tests/support/plugins/register_command/.gitignore @@ -1,2 +1,3 @@ dist/* -node_modules/ \ No newline at end of file +node_modules/ +*.jpl diff --git a/packages/app-cli/tests/support/plugins/register_command/README.md b/packages/app-cli/tests/support/plugins/register_command/README.md index afbea1bd1..4618fa796 100644 --- a/packages/app-cli/tests/support/plugins/register_command/README.md +++ b/packages/app-cli/tests/support/plugins/register_command/README.md @@ -12,3 +12,11 @@ The plugin is built using webpack, which create the compiled code in `/dist`. Th ## Building the plugin To build the plugin, simply run `npm run dist`. + +## Updating the plugin framework + +To update the plugin framework, run `yo joplin --update` + +Keep in mind that doing so will overwrite all the framework-related files **outside of the "src/" directory** (your source code will not be touched). So if you have modified any of the framework-related files, such as package.json or .gitignore, make sure your code is under version control so that you can check the diff and re-apply your changes. + +For that reason, it's generally best not to change any of the framework files or to do so in a way that minimises the number of changes. For example, if you want to modify the Webpack config, create a new separate JavaScript file and include it in webpack.config.js. That way, when you update, you only have to restore the line that include your file. \ No newline at end of file diff --git a/packages/app-cli/tests/support/plugins/register_command/api/JoplinCommands.d.ts b/packages/app-cli/tests/support/plugins/register_command/api/JoplinCommands.d.ts index 8a9f30451..e175d2e14 100644 --- a/packages/app-cli/tests/support/plugins/register_command/api/JoplinCommands.d.ts +++ b/packages/app-cli/tests/support/plugins/register_command/api/JoplinCommands.d.ts @@ -21,7 +21,7 @@ import { Command } from './types'; * and look at the `execute()` command. */ export default class JoplinCommands { - /** + /** * desktop Executes the given * command. * @@ -40,8 +40,8 @@ export default class JoplinCommands { * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * ``` */ - execute(commandName: string, ...args: any[]): Promise; - /** + execute(commandName: string, ...args: any[]): Promise; + /** * desktop Registers a new command. * * ```typescript @@ -57,5 +57,5 @@ export default class JoplinCommands { * }); * ``` */ - register(command: Command): Promise; + register(command: Command): Promise; } diff --git a/packages/app-cli/tests/support/plugins/register_command/api/JoplinFilters.d.ts b/packages/app-cli/tests/support/plugins/register_command/api/JoplinFilters.d.ts index 43bc1b2b7..e086a720e 100644 --- a/packages/app-cli/tests/support/plugins/register_command/api/JoplinFilters.d.ts +++ b/packages/app-cli/tests/support/plugins/register_command/api/JoplinFilters.d.ts @@ -5,6 +5,6 @@ * so for now disable filters. */ export default class JoplinFilters { - on(name: string, callback: Function): Promise; - off(name: string, callback: Function): Promise; + on(name: string, callback: Function): Promise; + off(name: string, callback: Function): Promise; } diff --git a/packages/app-cli/tests/support/plugins/register_command/api/JoplinInterop.d.ts b/packages/app-cli/tests/support/plugins/register_command/api/JoplinInterop.d.ts index 8de655c83..1304c7512 100644 --- a/packages/app-cli/tests/support/plugins/register_command/api/JoplinInterop.d.ts +++ b/packages/app-cli/tests/support/plugins/register_command/api/JoplinInterop.d.ts @@ -12,6 +12,6 @@ import { ExportModule, ImportModule } from './types'; * You may also want to refer to the Joplin API documentation to see the list of properties for each item (note, notebook, etc.) - https://joplinapp.org/api/references/rest_api/ */ export default class JoplinInterop { - registerExportModule(module: ExportModule): Promise; - registerImportModule(module: ImportModule): Promise; + registerExportModule(module: ExportModule): Promise; + registerImportModule(module: ImportModule): Promise; } diff --git a/packages/app-cli/tests/support/plugins/register_command/package.json b/packages/app-cli/tests/support/plugins/register_command/package.json index f065077e6..ebc25dcb4 100644 --- a/packages/app-cli/tests/support/plugins/register_command/package.json +++ b/packages/app-cli/tests/support/plugins/register_command/package.json @@ -7,11 +7,14 @@ "postinstall": "npm run dist" }, "keywords": [], - "author": "Laurent Cozic", "license": "MIT", "devDependencies": { "@types/node": "^14.0.14", "copy-webpack-plugin": "^6.1.0", + "fs-extra": "^9.0.1", + "glob": "^7.1.6", + "on-build-webpack": "^0.1.0", + "tar": "^6.0.5", "ts-loader": "^7.0.5", "typescript": "^3.9.3", "webpack": "^4.43.0", diff --git a/packages/app-cli/tests/support/plugins/register_command/src/manifest.json b/packages/app-cli/tests/support/plugins/register_command/src/manifest.json index 19169ef44..d5550c6e8 100644 --- a/packages/app-cli/tests/support/plugins/register_command/src/manifest.json +++ b/packages/app-cli/tests/support/plugins/register_command/src/manifest.json @@ -1,4 +1,5 @@ { + "id": "org.joplinapp.plugins.RegisterCommandDemo", "manifest_version": 1, "app_min_version": "1.4", "name": "Register Command Test", diff --git a/packages/app-cli/tests/support/plugins/register_command/webpack.config.js b/packages/app-cli/tests/support/plugins/register_command/webpack.config.js index 86f38111d..5c86b05c6 100644 --- a/packages/app-cli/tests/support/plugins/register_command/webpack.config.js +++ b/packages/app-cli/tests/support/plugins/register_command/webpack.config.js @@ -1,5 +1,42 @@ const path = require('path'); +const fs = require('fs-extra'); const CopyPlugin = require('copy-webpack-plugin'); +const WebpackOnBuildPlugin = require('on-build-webpack'); +const tar = require('tar'); +const glob = require('glob'); + +function readManifest(manifestPath) { + const content = fs.readFileSync(manifestPath, 'utf8'); + const output = JSON.parse(content); + if (!output.id) throw new Error(`Manifest plugin ID is not set in ${manifestPath}`); + return output; +} + +function createPluginArchive(sourceDir, destPath) { + const distFiles = glob.sync(`${sourceDir}/**/*`) + .map(f => f.substr(sourceDir.length + 1)); + + fs.removeSync(destPath); + + tar.create( + { + strict: true, + portable: true, + file: destPath, + cwd: sourceDir, + sync: true, + }, + distFiles + ); + + console.info(`Plugin archive has been created in ${destPath}`); +} + +const distDir = path.resolve(__dirname, 'dist'); +const srcDir = path.resolve(__dirname, 'src'); +const manifestPath = `${srcDir}/manifest.json`; +const manifest = readManifest(manifestPath); +const archiveFilePath = path.resolve(__dirname, `${manifest.id}.jpl`); module.exports = { mode: 'production', @@ -22,7 +59,7 @@ module.exports = { }, output: { filename: 'index.js', - path: path.resolve(__dirname, 'dist'), + path: distDir, }, plugins: [ new CopyPlugin({ @@ -40,5 +77,8 @@ module.exports = { }, ], }), + new WebpackOnBuildPlugin(function() { + createPluginArchive(distDir, archiveFilePath); + }), ], }; diff --git a/packages/app-cli/tests/support/plugins/selected_text/.gitignore b/packages/app-cli/tests/support/plugins/selected_text/.gitignore index 2195be3d8..4efef4740 100644 --- a/packages/app-cli/tests/support/plugins/selected_text/.gitignore +++ b/packages/app-cli/tests/support/plugins/selected_text/.gitignore @@ -1,2 +1,3 @@ dist/* -node_modules/ \ No newline at end of file +node_modules/ +*.jpl diff --git a/packages/app-cli/tests/support/plugins/selected_text/README.md b/packages/app-cli/tests/support/plugins/selected_text/README.md index afbea1bd1..4618fa796 100644 --- a/packages/app-cli/tests/support/plugins/selected_text/README.md +++ b/packages/app-cli/tests/support/plugins/selected_text/README.md @@ -12,3 +12,11 @@ The plugin is built using webpack, which create the compiled code in `/dist`. Th ## Building the plugin To build the plugin, simply run `npm run dist`. + +## Updating the plugin framework + +To update the plugin framework, run `yo joplin --update` + +Keep in mind that doing so will overwrite all the framework-related files **outside of the "src/" directory** (your source code will not be touched). So if you have modified any of the framework-related files, such as package.json or .gitignore, make sure your code is under version control so that you can check the diff and re-apply your changes. + +For that reason, it's generally best not to change any of the framework files or to do so in a way that minimises the number of changes. For example, if you want to modify the Webpack config, create a new separate JavaScript file and include it in webpack.config.js. That way, when you update, you only have to restore the line that include your file. \ No newline at end of file diff --git a/packages/app-cli/tests/support/plugins/selected_text/api/JoplinCommands.d.ts b/packages/app-cli/tests/support/plugins/selected_text/api/JoplinCommands.d.ts index 8a9f30451..e175d2e14 100644 --- a/packages/app-cli/tests/support/plugins/selected_text/api/JoplinCommands.d.ts +++ b/packages/app-cli/tests/support/plugins/selected_text/api/JoplinCommands.d.ts @@ -21,7 +21,7 @@ import { Command } from './types'; * and look at the `execute()` command. */ export default class JoplinCommands { - /** + /** * desktop Executes the given * command. * @@ -40,8 +40,8 @@ export default class JoplinCommands { * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * ``` */ - execute(commandName: string, ...args: any[]): Promise; - /** + execute(commandName: string, ...args: any[]): Promise; + /** * desktop Registers a new command. * * ```typescript @@ -57,5 +57,5 @@ export default class JoplinCommands { * }); * ``` */ - register(command: Command): Promise; + register(command: Command): Promise; } diff --git a/packages/app-cli/tests/support/plugins/selected_text/api/JoplinFilters.d.ts b/packages/app-cli/tests/support/plugins/selected_text/api/JoplinFilters.d.ts index 43bc1b2b7..e086a720e 100644 --- a/packages/app-cli/tests/support/plugins/selected_text/api/JoplinFilters.d.ts +++ b/packages/app-cli/tests/support/plugins/selected_text/api/JoplinFilters.d.ts @@ -5,6 +5,6 @@ * so for now disable filters. */ export default class JoplinFilters { - on(name: string, callback: Function): Promise; - off(name: string, callback: Function): Promise; + on(name: string, callback: Function): Promise; + off(name: string, callback: Function): Promise; } diff --git a/packages/app-cli/tests/support/plugins/selected_text/api/JoplinInterop.d.ts b/packages/app-cli/tests/support/plugins/selected_text/api/JoplinInterop.d.ts index 8de655c83..1304c7512 100644 --- a/packages/app-cli/tests/support/plugins/selected_text/api/JoplinInterop.d.ts +++ b/packages/app-cli/tests/support/plugins/selected_text/api/JoplinInterop.d.ts @@ -12,6 +12,6 @@ import { ExportModule, ImportModule } from './types'; * You may also want to refer to the Joplin API documentation to see the list of properties for each item (note, notebook, etc.) - https://joplinapp.org/api/references/rest_api/ */ export default class JoplinInterop { - registerExportModule(module: ExportModule): Promise; - registerImportModule(module: ImportModule): Promise; + registerExportModule(module: ExportModule): Promise; + registerImportModule(module: ImportModule): Promise; } diff --git a/packages/app-cli/tests/support/plugins/selected_text/package.json b/packages/app-cli/tests/support/plugins/selected_text/package.json index f065077e6..ebc25dcb4 100644 --- a/packages/app-cli/tests/support/plugins/selected_text/package.json +++ b/packages/app-cli/tests/support/plugins/selected_text/package.json @@ -7,11 +7,14 @@ "postinstall": "npm run dist" }, "keywords": [], - "author": "Laurent Cozic", "license": "MIT", "devDependencies": { "@types/node": "^14.0.14", "copy-webpack-plugin": "^6.1.0", + "fs-extra": "^9.0.1", + "glob": "^7.1.6", + "on-build-webpack": "^0.1.0", + "tar": "^6.0.5", "ts-loader": "^7.0.5", "typescript": "^3.9.3", "webpack": "^4.43.0", diff --git a/packages/app-cli/tests/support/plugins/selected_text/src/manifest.json b/packages/app-cli/tests/support/plugins/selected_text/src/manifest.json index d927b6578..e1db7fe1c 100644 --- a/packages/app-cli/tests/support/plugins/selected_text/src/manifest.json +++ b/packages/app-cli/tests/support/plugins/selected_text/src/manifest.json @@ -1,4 +1,5 @@ { + "id": "org.joplinapp.plugins.SelectedTextDemo", "manifest_version": 1, "app_min_version": "1.4", "name": "Selected Text Test", diff --git a/packages/app-cli/tests/support/plugins/selected_text/webpack.config.js b/packages/app-cli/tests/support/plugins/selected_text/webpack.config.js index 86f38111d..5c86b05c6 100644 --- a/packages/app-cli/tests/support/plugins/selected_text/webpack.config.js +++ b/packages/app-cli/tests/support/plugins/selected_text/webpack.config.js @@ -1,5 +1,42 @@ const path = require('path'); +const fs = require('fs-extra'); const CopyPlugin = require('copy-webpack-plugin'); +const WebpackOnBuildPlugin = require('on-build-webpack'); +const tar = require('tar'); +const glob = require('glob'); + +function readManifest(manifestPath) { + const content = fs.readFileSync(manifestPath, 'utf8'); + const output = JSON.parse(content); + if (!output.id) throw new Error(`Manifest plugin ID is not set in ${manifestPath}`); + return output; +} + +function createPluginArchive(sourceDir, destPath) { + const distFiles = glob.sync(`${sourceDir}/**/*`) + .map(f => f.substr(sourceDir.length + 1)); + + fs.removeSync(destPath); + + tar.create( + { + strict: true, + portable: true, + file: destPath, + cwd: sourceDir, + sync: true, + }, + distFiles + ); + + console.info(`Plugin archive has been created in ${destPath}`); +} + +const distDir = path.resolve(__dirname, 'dist'); +const srcDir = path.resolve(__dirname, 'src'); +const manifestPath = `${srcDir}/manifest.json`; +const manifest = readManifest(manifestPath); +const archiveFilePath = path.resolve(__dirname, `${manifest.id}.jpl`); module.exports = { mode: 'production', @@ -22,7 +59,7 @@ module.exports = { }, output: { filename: 'index.js', - path: path.resolve(__dirname, 'dist'), + path: distDir, }, plugins: [ new CopyPlugin({ @@ -40,5 +77,8 @@ module.exports = { }, ], }), + new WebpackOnBuildPlugin(function() { + createPluginArchive(distDir, archiveFilePath); + }), ], }; diff --git a/packages/app-cli/tests/support/plugins/settings/.gitignore b/packages/app-cli/tests/support/plugins/settings/.gitignore index 2195be3d8..4efef4740 100644 --- a/packages/app-cli/tests/support/plugins/settings/.gitignore +++ b/packages/app-cli/tests/support/plugins/settings/.gitignore @@ -1,2 +1,3 @@ dist/* -node_modules/ \ No newline at end of file +node_modules/ +*.jpl diff --git a/packages/app-cli/tests/support/plugins/settings/README.md b/packages/app-cli/tests/support/plugins/settings/README.md index afbea1bd1..4618fa796 100644 --- a/packages/app-cli/tests/support/plugins/settings/README.md +++ b/packages/app-cli/tests/support/plugins/settings/README.md @@ -12,3 +12,11 @@ The plugin is built using webpack, which create the compiled code in `/dist`. Th ## Building the plugin To build the plugin, simply run `npm run dist`. + +## Updating the plugin framework + +To update the plugin framework, run `yo joplin --update` + +Keep in mind that doing so will overwrite all the framework-related files **outside of the "src/" directory** (your source code will not be touched). So if you have modified any of the framework-related files, such as package.json or .gitignore, make sure your code is under version control so that you can check the diff and re-apply your changes. + +For that reason, it's generally best not to change any of the framework files or to do so in a way that minimises the number of changes. For example, if you want to modify the Webpack config, create a new separate JavaScript file and include it in webpack.config.js. That way, when you update, you only have to restore the line that include your file. \ No newline at end of file diff --git a/packages/app-cli/tests/support/plugins/settings/api/JoplinCommands.d.ts b/packages/app-cli/tests/support/plugins/settings/api/JoplinCommands.d.ts index 8a9f30451..e175d2e14 100644 --- a/packages/app-cli/tests/support/plugins/settings/api/JoplinCommands.d.ts +++ b/packages/app-cli/tests/support/plugins/settings/api/JoplinCommands.d.ts @@ -21,7 +21,7 @@ import { Command } from './types'; * and look at the `execute()` command. */ export default class JoplinCommands { - /** + /** * desktop Executes the given * command. * @@ -40,8 +40,8 @@ export default class JoplinCommands { * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * ``` */ - execute(commandName: string, ...args: any[]): Promise; - /** + execute(commandName: string, ...args: any[]): Promise; + /** * desktop Registers a new command. * * ```typescript @@ -57,5 +57,5 @@ export default class JoplinCommands { * }); * ``` */ - register(command: Command): Promise; + register(command: Command): Promise; } diff --git a/packages/app-cli/tests/support/plugins/settings/api/JoplinFilters.d.ts b/packages/app-cli/tests/support/plugins/settings/api/JoplinFilters.d.ts index 43bc1b2b7..e086a720e 100644 --- a/packages/app-cli/tests/support/plugins/settings/api/JoplinFilters.d.ts +++ b/packages/app-cli/tests/support/plugins/settings/api/JoplinFilters.d.ts @@ -5,6 +5,6 @@ * so for now disable filters. */ export default class JoplinFilters { - on(name: string, callback: Function): Promise; - off(name: string, callback: Function): Promise; + on(name: string, callback: Function): Promise; + off(name: string, callback: Function): Promise; } diff --git a/packages/app-cli/tests/support/plugins/settings/api/JoplinInterop.d.ts b/packages/app-cli/tests/support/plugins/settings/api/JoplinInterop.d.ts index 8de655c83..1304c7512 100644 --- a/packages/app-cli/tests/support/plugins/settings/api/JoplinInterop.d.ts +++ b/packages/app-cli/tests/support/plugins/settings/api/JoplinInterop.d.ts @@ -12,6 +12,6 @@ import { ExportModule, ImportModule } from './types'; * You may also want to refer to the Joplin API documentation to see the list of properties for each item (note, notebook, etc.) - https://joplinapp.org/api/references/rest_api/ */ export default class JoplinInterop { - registerExportModule(module: ExportModule): Promise; - registerImportModule(module: ImportModule): Promise; + registerExportModule(module: ExportModule): Promise; + registerImportModule(module: ImportModule): Promise; } diff --git a/packages/app-cli/tests/support/plugins/settings/package.json b/packages/app-cli/tests/support/plugins/settings/package.json index f065077e6..ebc25dcb4 100644 --- a/packages/app-cli/tests/support/plugins/settings/package.json +++ b/packages/app-cli/tests/support/plugins/settings/package.json @@ -7,11 +7,14 @@ "postinstall": "npm run dist" }, "keywords": [], - "author": "Laurent Cozic", "license": "MIT", "devDependencies": { "@types/node": "^14.0.14", "copy-webpack-plugin": "^6.1.0", + "fs-extra": "^9.0.1", + "glob": "^7.1.6", + "on-build-webpack": "^0.1.0", + "tar": "^6.0.5", "ts-loader": "^7.0.5", "typescript": "^3.9.3", "webpack": "^4.43.0", diff --git a/packages/app-cli/tests/support/plugins/settings/src/manifest.json b/packages/app-cli/tests/support/plugins/settings/src/manifest.json index 0a4d026c1..4bfda5471 100644 --- a/packages/app-cli/tests/support/plugins/settings/src/manifest.json +++ b/packages/app-cli/tests/support/plugins/settings/src/manifest.json @@ -1,4 +1,5 @@ { + "id": "org.joplinapp.plugins.SettingsDemo", "manifest_version": 1, "app_min_version": "1.4", "name": "Setting Demo", diff --git a/packages/app-cli/tests/support/plugins/settings/webpack.config.js b/packages/app-cli/tests/support/plugins/settings/webpack.config.js index 86f38111d..5c86b05c6 100644 --- a/packages/app-cli/tests/support/plugins/settings/webpack.config.js +++ b/packages/app-cli/tests/support/plugins/settings/webpack.config.js @@ -1,5 +1,42 @@ const path = require('path'); +const fs = require('fs-extra'); const CopyPlugin = require('copy-webpack-plugin'); +const WebpackOnBuildPlugin = require('on-build-webpack'); +const tar = require('tar'); +const glob = require('glob'); + +function readManifest(manifestPath) { + const content = fs.readFileSync(manifestPath, 'utf8'); + const output = JSON.parse(content); + if (!output.id) throw new Error(`Manifest plugin ID is not set in ${manifestPath}`); + return output; +} + +function createPluginArchive(sourceDir, destPath) { + const distFiles = glob.sync(`${sourceDir}/**/*`) + .map(f => f.substr(sourceDir.length + 1)); + + fs.removeSync(destPath); + + tar.create( + { + strict: true, + portable: true, + file: destPath, + cwd: sourceDir, + sync: true, + }, + distFiles + ); + + console.info(`Plugin archive has been created in ${destPath}`); +} + +const distDir = path.resolve(__dirname, 'dist'); +const srcDir = path.resolve(__dirname, 'src'); +const manifestPath = `${srcDir}/manifest.json`; +const manifest = readManifest(manifestPath); +const archiveFilePath = path.resolve(__dirname, `${manifest.id}.jpl`); module.exports = { mode: 'production', @@ -22,7 +59,7 @@ module.exports = { }, output: { filename: 'index.js', - path: path.resolve(__dirname, 'dist'), + path: distDir, }, plugins: [ new CopyPlugin({ @@ -40,5 +77,8 @@ module.exports = { }, ], }), + new WebpackOnBuildPlugin(function() { + createPluginArchive(distDir, archiveFilePath); + }), ], }; diff --git a/packages/app-cli/tests/support/plugins/simple/manifest.json b/packages/app-cli/tests/support/plugins/simple/manifest.json index 5a96977da..28799b356 100644 --- a/packages/app-cli/tests/support/plugins/simple/manifest.json +++ b/packages/app-cli/tests/support/plugins/simple/manifest.json @@ -1,4 +1,5 @@ { + "id": "org.joplinapp.plugins.Simple", "manifest_version": 1, "app_min_version": "1.4", "name": "Joplin Simple Plugin", diff --git a/packages/app-cli/tests/support/plugins/testImport/manifest.json b/packages/app-cli/tests/support/plugins/testImport/manifest.json index b817f168c..272f2d331 100644 --- a/packages/app-cli/tests/support/plugins/testImport/manifest.json +++ b/packages/app-cli/tests/support/plugins/testImport/manifest.json @@ -1,4 +1,5 @@ { + "id": "org.joplinapp.plugins.ImportDemo", "manifest_version": 1, "app_min_version": "1.4", "name": "Joplin Test Plugin", diff --git a/packages/app-cli/tests/support/plugins/toc/.gitignore b/packages/app-cli/tests/support/plugins/toc/.gitignore index 2195be3d8..4efef4740 100644 --- a/packages/app-cli/tests/support/plugins/toc/.gitignore +++ b/packages/app-cli/tests/support/plugins/toc/.gitignore @@ -1,2 +1,3 @@ dist/* -node_modules/ \ No newline at end of file +node_modules/ +*.jpl diff --git a/packages/app-cli/tests/support/plugins/toc/README.md b/packages/app-cli/tests/support/plugins/toc/README.md index afbea1bd1..4618fa796 100644 --- a/packages/app-cli/tests/support/plugins/toc/README.md +++ b/packages/app-cli/tests/support/plugins/toc/README.md @@ -12,3 +12,11 @@ The plugin is built using webpack, which create the compiled code in `/dist`. Th ## Building the plugin To build the plugin, simply run `npm run dist`. + +## Updating the plugin framework + +To update the plugin framework, run `yo joplin --update` + +Keep in mind that doing so will overwrite all the framework-related files **outside of the "src/" directory** (your source code will not be touched). So if you have modified any of the framework-related files, such as package.json or .gitignore, make sure your code is under version control so that you can check the diff and re-apply your changes. + +For that reason, it's generally best not to change any of the framework files or to do so in a way that minimises the number of changes. For example, if you want to modify the Webpack config, create a new separate JavaScript file and include it in webpack.config.js. That way, when you update, you only have to restore the line that include your file. \ No newline at end of file diff --git a/packages/app-cli/tests/support/plugins/toc/api/JoplinCommands.d.ts b/packages/app-cli/tests/support/plugins/toc/api/JoplinCommands.d.ts index 8a9f30451..e175d2e14 100644 --- a/packages/app-cli/tests/support/plugins/toc/api/JoplinCommands.d.ts +++ b/packages/app-cli/tests/support/plugins/toc/api/JoplinCommands.d.ts @@ -21,7 +21,7 @@ import { Command } from './types'; * and look at the `execute()` command. */ export default class JoplinCommands { - /** + /** * desktop Executes the given * command. * @@ -40,8 +40,8 @@ export default class JoplinCommands { * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * ``` */ - execute(commandName: string, ...args: any[]): Promise; - /** + execute(commandName: string, ...args: any[]): Promise; + /** * desktop Registers a new command. * * ```typescript @@ -57,5 +57,5 @@ export default class JoplinCommands { * }); * ``` */ - register(command: Command): Promise; + register(command: Command): Promise; } diff --git a/packages/app-cli/tests/support/plugins/toc/api/JoplinFilters.d.ts b/packages/app-cli/tests/support/plugins/toc/api/JoplinFilters.d.ts index 43bc1b2b7..e086a720e 100644 --- a/packages/app-cli/tests/support/plugins/toc/api/JoplinFilters.d.ts +++ b/packages/app-cli/tests/support/plugins/toc/api/JoplinFilters.d.ts @@ -5,6 +5,6 @@ * so for now disable filters. */ export default class JoplinFilters { - on(name: string, callback: Function): Promise; - off(name: string, callback: Function): Promise; + on(name: string, callback: Function): Promise; + off(name: string, callback: Function): Promise; } diff --git a/packages/app-cli/tests/support/plugins/toc/api/JoplinInterop.d.ts b/packages/app-cli/tests/support/plugins/toc/api/JoplinInterop.d.ts index 8de655c83..1304c7512 100644 --- a/packages/app-cli/tests/support/plugins/toc/api/JoplinInterop.d.ts +++ b/packages/app-cli/tests/support/plugins/toc/api/JoplinInterop.d.ts @@ -12,6 +12,6 @@ import { ExportModule, ImportModule } from './types'; * You may also want to refer to the Joplin API documentation to see the list of properties for each item (note, notebook, etc.) - https://joplinapp.org/api/references/rest_api/ */ export default class JoplinInterop { - registerExportModule(module: ExportModule): Promise; - registerImportModule(module: ImportModule): Promise; + registerExportModule(module: ExportModule): Promise; + registerImportModule(module: ImportModule): Promise; } diff --git a/packages/app-cli/tests/support/plugins/toc/package.json b/packages/app-cli/tests/support/plugins/toc/package.json index d921a3537..ebc25dcb4 100644 --- a/packages/app-cli/tests/support/plugins/toc/package.json +++ b/packages/app-cli/tests/support/plugins/toc/package.json @@ -1,25 +1,23 @@ { - "name": "test_webview", + "name": "joplin_plugin", "version": "1.0.0", "description": "", - "private": true, "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", "dist": "webpack", "postinstall": "npm run dist" }, "keywords": [], - "author": "", - "license": "ISC", + "license": "MIT", "devDependencies": { "@types/node": "^14.0.14", "copy-webpack-plugin": "^6.1.0", + "fs-extra": "^9.0.1", + "glob": "^7.1.6", + "on-build-webpack": "^0.1.0", + "tar": "^6.0.5", "ts-loader": "^7.0.5", "typescript": "^3.9.3", "webpack": "^4.43.0", "webpack-cli": "^3.3.11" - }, - "dependencies": { - "uslug": "git+https://github.com/laurent22/uslug.git#emoji-support" } } 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 899861d27..11eb07e18 100644 --- a/packages/app-cli/tests/support/plugins/toc/src/manifest.json +++ b/packages/app-cli/tests/support/plugins/toc/src/manifest.json @@ -1,4 +1,5 @@ { + "id": "org.joplinapp.plugins.TocDemo", "manifest_version": 1, "app_min_version": "1.4", "name": "Webview test", diff --git a/packages/app-cli/tests/support/plugins/toc/webpack.config.js b/packages/app-cli/tests/support/plugins/toc/webpack.config.js index 86f38111d..5c86b05c6 100644 --- a/packages/app-cli/tests/support/plugins/toc/webpack.config.js +++ b/packages/app-cli/tests/support/plugins/toc/webpack.config.js @@ -1,5 +1,42 @@ const path = require('path'); +const fs = require('fs-extra'); const CopyPlugin = require('copy-webpack-plugin'); +const WebpackOnBuildPlugin = require('on-build-webpack'); +const tar = require('tar'); +const glob = require('glob'); + +function readManifest(manifestPath) { + const content = fs.readFileSync(manifestPath, 'utf8'); + const output = JSON.parse(content); + if (!output.id) throw new Error(`Manifest plugin ID is not set in ${manifestPath}`); + return output; +} + +function createPluginArchive(sourceDir, destPath) { + const distFiles = glob.sync(`${sourceDir}/**/*`) + .map(f => f.substr(sourceDir.length + 1)); + + fs.removeSync(destPath); + + tar.create( + { + strict: true, + portable: true, + file: destPath, + cwd: sourceDir, + sync: true, + }, + distFiles + ); + + console.info(`Plugin archive has been created in ${destPath}`); +} + +const distDir = path.resolve(__dirname, 'dist'); +const srcDir = path.resolve(__dirname, 'src'); +const manifestPath = `${srcDir}/manifest.json`; +const manifest = readManifest(manifestPath); +const archiveFilePath = path.resolve(__dirname, `${manifest.id}.jpl`); module.exports = { mode: 'production', @@ -22,7 +59,7 @@ module.exports = { }, output: { filename: 'index.js', - path: path.resolve(__dirname, 'dist'), + path: distDir, }, plugins: [ new CopyPlugin({ @@ -40,5 +77,8 @@ module.exports = { }, ], }), + new WebpackOnBuildPlugin(function() { + createPluginArchive(distDir, archiveFilePath); + }), ], }; diff --git a/packages/app-cli/tests/support/plugins/updatePlugins.sh b/packages/app-cli/tests/support/plugins/updatePlugins.sh index ae315cc19..76487354c 100755 --- a/packages/app-cli/tests/support/plugins/updatePlugins.sh +++ b/packages/app-cli/tests/support/plugins/updatePlugins.sh @@ -1,24 +1,19 @@ #!/bin/bash SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -TEMP_DIR="$SCRIPT_DIR/_temp" -rm -rf "$TEMP_DIR" -mkdir -p "$TEMP_DIR" -cd "$TEMP_DIR" +cd "$SCRIPT_DIR/jpl_test/" && yo joplin --update --skip-install --silent +sed -i /*.jpl/d .gitignore -yo joplin - -rsync -a --delete --exclude "src/" --exclude "package.json" --exclude "package-lock.json" --exclude "node_modules/" --exclude "dist/" "$TEMP_DIR/" "$SCRIPT_DIR/dialog/" -rsync -a --delete --exclude "src/" --exclude "package.json" --exclude "package-lock.json" --exclude "node_modules/" --exclude "dist/" "$TEMP_DIR/" "$SCRIPT_DIR/events/" -rsync -a --delete --exclude "src/" --exclude "package.json" --exclude "package-lock.json" --exclude "node_modules/" --exclude "dist/" "$TEMP_DIR/" "$SCRIPT_DIR/json_export/" -rsync -a --delete --exclude "src/" --exclude "package.json" --exclude "package-lock.json" --exclude "node_modules/" --exclude "dist/" "$TEMP_DIR/" "$SCRIPT_DIR/menu/" -rsync -a --delete --exclude "src/" --exclude "package.json" --exclude "package-lock.json" --exclude "node_modules/" --exclude "dist/" "$TEMP_DIR/" "$SCRIPT_DIR/multi_selection/" -rsync -a --delete --exclude "src/" --exclude "package.json" --exclude "package-lock.json" --exclude "node_modules/" --exclude "dist/" "$TEMP_DIR/" "$SCRIPT_DIR/register_command/" -rsync -a --delete --exclude "src/" --exclude "package.json" --exclude "package-lock.json" --exclude "node_modules/" --exclude "dist/" "$TEMP_DIR/" "$SCRIPT_DIR/selected_text/" -rsync -a --delete --exclude "src/" --exclude "package.json" --exclude "package-lock.json" --exclude "node_modules/" --exclude "dist/" "$TEMP_DIR/" "$SCRIPT_DIR/editor_context_menu/" -rsync -a --delete --exclude "src/" --exclude "package.json" --exclude "package-lock.json" --exclude "node_modules/" --exclude "dist/" "$TEMP_DIR/" "$SCRIPT_DIR/settings/" -rsync -a --delete --exclude "src/" --exclude "package.json" --exclude "package-lock.json" --exclude "node_modules/" --exclude "dist/" "$TEMP_DIR/" "$SCRIPT_DIR/toc/" -rsync -a --delete --exclude "src/" --exclude "package.json" --exclude "package-lock.json" --exclude "node_modules/" --exclude "dist/" "$TEMP_DIR/" "$SCRIPT_DIR/withExternalModules/" -rsync -a --delete --exclude "src/" --exclude "package.json" --exclude "package-lock.json" --exclude "node_modules/" --exclude "dist/" "$TEMP_DIR/" "$SCRIPT_DIR/content_script/" - -rm -rf "$TEMP_DIR" +cd "$SCRIPT_DIR/codemirror_content_script/" && yo joplin --update --skip-install --silent +cd "$SCRIPT_DIR/content_script/" && yo joplin --update --skip-install --silent +cd "$SCRIPT_DIR/dialog/" && yo joplin --update --skip-install --silent +cd "$SCRIPT_DIR/editor_context_menu/" && yo joplin --update --skip-install --silent +cd "$SCRIPT_DIR/events/" && yo joplin --update --skip-install --silent +cd "$SCRIPT_DIR/json_export/" && yo joplin --update --skip-install --silent +cd "$SCRIPT_DIR/menu/" && yo joplin --update --skip-install --silent +cd "$SCRIPT_DIR/multi_selection/" && yo joplin --update --skip-install --silent +cd "$SCRIPT_DIR/register_command/" && yo joplin --update --skip-install --silent +cd "$SCRIPT_DIR/selected_text/" && yo joplin --update --skip-install --silent +cd "$SCRIPT_DIR/settings/" && yo joplin --update --skip-install --silent +cd "$SCRIPT_DIR/toc/" && yo joplin --update --skip-install --silent +cd "$SCRIPT_DIR/withExternalModules/" && yo joplin --update --skip-install --silent diff --git a/packages/app-cli/tests/support/plugins/withExternalModules/.gitignore b/packages/app-cli/tests/support/plugins/withExternalModules/.gitignore index 2195be3d8..4efef4740 100644 --- a/packages/app-cli/tests/support/plugins/withExternalModules/.gitignore +++ b/packages/app-cli/tests/support/plugins/withExternalModules/.gitignore @@ -1,2 +1,3 @@ dist/* -node_modules/ \ No newline at end of file +node_modules/ +*.jpl diff --git a/packages/app-cli/tests/support/plugins/withExternalModules/README.md b/packages/app-cli/tests/support/plugins/withExternalModules/README.md index afbea1bd1..4618fa796 100644 --- a/packages/app-cli/tests/support/plugins/withExternalModules/README.md +++ b/packages/app-cli/tests/support/plugins/withExternalModules/README.md @@ -12,3 +12,11 @@ The plugin is built using webpack, which create the compiled code in `/dist`. Th ## Building the plugin To build the plugin, simply run `npm run dist`. + +## Updating the plugin framework + +To update the plugin framework, run `yo joplin --update` + +Keep in mind that doing so will overwrite all the framework-related files **outside of the "src/" directory** (your source code will not be touched). So if you have modified any of the framework-related files, such as package.json or .gitignore, make sure your code is under version control so that you can check the diff and re-apply your changes. + +For that reason, it's generally best not to change any of the framework files or to do so in a way that minimises the number of changes. For example, if you want to modify the Webpack config, create a new separate JavaScript file and include it in webpack.config.js. That way, when you update, you only have to restore the line that include your file. \ No newline at end of file diff --git a/packages/app-cli/tests/support/plugins/withExternalModules/api/JoplinCommands.d.ts b/packages/app-cli/tests/support/plugins/withExternalModules/api/JoplinCommands.d.ts index 8a9f30451..e175d2e14 100644 --- a/packages/app-cli/tests/support/plugins/withExternalModules/api/JoplinCommands.d.ts +++ b/packages/app-cli/tests/support/plugins/withExternalModules/api/JoplinCommands.d.ts @@ -21,7 +21,7 @@ import { Command } from './types'; * and look at the `execute()` command. */ export default class JoplinCommands { - /** + /** * desktop Executes the given * command. * @@ -40,8 +40,8 @@ export default class JoplinCommands { * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * ``` */ - execute(commandName: string, ...args: any[]): Promise; - /** + execute(commandName: string, ...args: any[]): Promise; + /** * desktop Registers a new command. * * ```typescript @@ -57,5 +57,5 @@ export default class JoplinCommands { * }); * ``` */ - register(command: Command): Promise; + register(command: Command): Promise; } diff --git a/packages/app-cli/tests/support/plugins/withExternalModules/api/JoplinFilters.d.ts b/packages/app-cli/tests/support/plugins/withExternalModules/api/JoplinFilters.d.ts index 43bc1b2b7..e086a720e 100644 --- a/packages/app-cli/tests/support/plugins/withExternalModules/api/JoplinFilters.d.ts +++ b/packages/app-cli/tests/support/plugins/withExternalModules/api/JoplinFilters.d.ts @@ -5,6 +5,6 @@ * so for now disable filters. */ export default class JoplinFilters { - on(name: string, callback: Function): Promise; - off(name: string, callback: Function): Promise; + on(name: string, callback: Function): Promise; + off(name: string, callback: Function): Promise; } diff --git a/packages/app-cli/tests/support/plugins/withExternalModules/api/JoplinInterop.d.ts b/packages/app-cli/tests/support/plugins/withExternalModules/api/JoplinInterop.d.ts index 8de655c83..1304c7512 100644 --- a/packages/app-cli/tests/support/plugins/withExternalModules/api/JoplinInterop.d.ts +++ b/packages/app-cli/tests/support/plugins/withExternalModules/api/JoplinInterop.d.ts @@ -12,6 +12,6 @@ import { ExportModule, ImportModule } from './types'; * You may also want to refer to the Joplin API documentation to see the list of properties for each item (note, notebook, etc.) - https://joplinapp.org/api/references/rest_api/ */ export default class JoplinInterop { - registerExportModule(module: ExportModule): Promise; - registerImportModule(module: ImportModule): Promise; + registerExportModule(module: ExportModule): Promise; + registerImportModule(module: ImportModule): Promise; } diff --git a/packages/app-cli/tests/support/plugins/withExternalModules/dist/manifest.json b/packages/app-cli/tests/support/plugins/withExternalModules/dist/manifest.json index 9f226cc69..32fbb9aa5 100644 --- a/packages/app-cli/tests/support/plugins/withExternalModules/dist/manifest.json +++ b/packages/app-cli/tests/support/plugins/withExternalModules/dist/manifest.json @@ -1,4 +1,5 @@ { + "id": "org.joplinapp.plugins.ExternalModuleDemo", "manifest_version": 1, "app_min_version": "1.4", "name": "withExternalModules", diff --git a/packages/app-cli/tests/support/plugins/withExternalModules/package.json b/packages/app-cli/tests/support/plugins/withExternalModules/package.json index 4f594b108..ebc25dcb4 100644 --- a/packages/app-cli/tests/support/plugins/withExternalModules/package.json +++ b/packages/app-cli/tests/support/plugins/withExternalModules/package.json @@ -7,17 +7,17 @@ "postinstall": "npm run dist" }, "keywords": [], - "author": "Laurent Cozic", "license": "MIT", "devDependencies": { "@types/node": "^14.0.14", "copy-webpack-plugin": "^6.1.0", + "fs-extra": "^9.0.1", + "glob": "^7.1.6", + "on-build-webpack": "^0.1.0", + "tar": "^6.0.5", "ts-loader": "^7.0.5", "typescript": "^3.9.3", "webpack": "^4.43.0", "webpack-cli": "^3.3.11" - }, - "dependencies": { - "left-pad": "^1.3.0" } } diff --git a/packages/app-cli/tests/support/plugins/withExternalModules/src/manifest.json b/packages/app-cli/tests/support/plugins/withExternalModules/src/manifest.json index 9f226cc69..32fbb9aa5 100644 --- a/packages/app-cli/tests/support/plugins/withExternalModules/src/manifest.json +++ b/packages/app-cli/tests/support/plugins/withExternalModules/src/manifest.json @@ -1,4 +1,5 @@ { + "id": "org.joplinapp.plugins.ExternalModuleDemo", "manifest_version": 1, "app_min_version": "1.4", "name": "withExternalModules", diff --git a/packages/app-cli/tests/support/plugins/withExternalModules/webpack.config.js b/packages/app-cli/tests/support/plugins/withExternalModules/webpack.config.js index 86f38111d..5c86b05c6 100644 --- a/packages/app-cli/tests/support/plugins/withExternalModules/webpack.config.js +++ b/packages/app-cli/tests/support/plugins/withExternalModules/webpack.config.js @@ -1,5 +1,42 @@ const path = require('path'); +const fs = require('fs-extra'); const CopyPlugin = require('copy-webpack-plugin'); +const WebpackOnBuildPlugin = require('on-build-webpack'); +const tar = require('tar'); +const glob = require('glob'); + +function readManifest(manifestPath) { + const content = fs.readFileSync(manifestPath, 'utf8'); + const output = JSON.parse(content); + if (!output.id) throw new Error(`Manifest plugin ID is not set in ${manifestPath}`); + return output; +} + +function createPluginArchive(sourceDir, destPath) { + const distFiles = glob.sync(`${sourceDir}/**/*`) + .map(f => f.substr(sourceDir.length + 1)); + + fs.removeSync(destPath); + + tar.create( + { + strict: true, + portable: true, + file: destPath, + cwd: sourceDir, + sync: true, + }, + distFiles + ); + + console.info(`Plugin archive has been created in ${destPath}`); +} + +const distDir = path.resolve(__dirname, 'dist'); +const srcDir = path.resolve(__dirname, 'src'); +const manifestPath = `${srcDir}/manifest.json`; +const manifest = readManifest(manifestPath); +const archiveFilePath = path.resolve(__dirname, `${manifest.id}.jpl`); module.exports = { mode: 'production', @@ -22,7 +59,7 @@ module.exports = { }, output: { filename: 'index.js', - path: path.resolve(__dirname, 'dist'), + path: distDir, }, plugins: [ new CopyPlugin({ @@ -40,5 +77,8 @@ module.exports = { }, ], }), + new WebpackOnBuildPlugin(function() { + createPluginArchive(distDir, archiveFilePath); + }), ], }; diff --git a/packages/generator-joplin/generators/app/index.js b/packages/generator-joplin/generators/app/index.js index 818f2efaa..042ea5e01 100644 --- a/packages/generator-joplin/generators/app/index.js +++ b/packages/generator-joplin/generators/app/index.js @@ -5,9 +5,45 @@ const chalk = require('chalk'); const yosay = require('yosay'); module.exports = class extends Generator { - prompting() { + + constructor(args, opts) { + super(args, opts); + + this.option('silent'); + this.option('update'); + + if (this.options.update) { + // When updating, overwrite files without prompting + this.conflicter.force = true; + } + } + + + + async prompting() { this.log(yosay(`Welcome to the fine ${chalk.red('generator-joplin')} generator!`)); + if (this.options.update && !this.options.silent) { + const answers = await this.prompt([ + { + type: 'confirm', + name: 'proceed', + message: [ + 'Updating will overwrite all the generator files **except for the', + 'src/ directory**. So if you have made any changes outside of src/', + 'make sure your code is under version control so that you can inspect', + 'the diff and re-apply your changes if needed. Do you want to proceed?', + ].join('\n'), + }, + ]); + + if (!answers.proceed) { + this.log(''); + this.log('Operation was cancelled and no changes was made'); + process.exit(0); + } + } + const prompts = [ { type: 'input', @@ -36,9 +72,17 @@ module.exports = class extends Generator { }, ]; - return this.prompt(prompts).then(props => { + if (this.options.update) { + const props = {}; + for (const prompt of prompts) { + props[prompt.name] = ''; + } this.props = props; - }); + } else { + return this.prompt(prompts).then(props => { + this.props = props; + }); + } } writing() { @@ -53,12 +97,20 @@ module.exports = class extends Generator { 'README.md', 'tsconfig.json', 'webpack.config.js', + ]; + + const noUpdateFiles = [ 'src/index.ts', 'src/manifest.json', ]; - for (const file of files) { + const allFiles = files.concat(noUpdateFiles); + + for (const file of allFiles) { + if (this.options.update && noUpdateFiles.includes(file)) continue; + const destFile = file.replace(/_TEMPLATE/, ''); + this.fs.copyTpl( this.templatePath(file), this.destinationPath(destFile), diff --git a/packages/generator-joplin/generators/app/templates/.gitignore_TEMPLATE b/packages/generator-joplin/generators/app/templates/.gitignore_TEMPLATE index 06b9a61b5..4efef4740 100644 --- a/packages/generator-joplin/generators/app/templates/.gitignore_TEMPLATE +++ b/packages/generator-joplin/generators/app/templates/.gitignore_TEMPLATE @@ -1,3 +1,3 @@ dist/* node_modules/ -*.jpl \ No newline at end of file +*.jpl diff --git a/packages/generator-joplin/generators/app/templates/README.md b/packages/generator-joplin/generators/app/templates/README.md index afbea1bd1..884120872 100644 --- a/packages/generator-joplin/generators/app/templates/README.md +++ b/packages/generator-joplin/generators/app/templates/README.md @@ -7,8 +7,18 @@ The main two files you will want to look at are: - `/src/index.ts`, which contains the entry point for the plugin source code. - `/src/manifest.json`, which is the plugin manifest. It contains information such as the plugin a name, version, etc. -The plugin is built using webpack, which create the compiled code in `/dist`. The project is setup to use TypeScript, although you can change the configuration to use plain JavaScript. - ## Building the plugin +The plugin is built using Webpack, which creates the compiled code in `/dist`. A JPL archive will also be created at the root, which can use to distribute the plugin. + To build the plugin, simply run `npm run dist`. + +The project is setup to use TypeScript, although you can change the configuration to use plain JavaScript. + +## Updating the plugin framework + +To update the plugin framework, run `yo joplin --update` + +Keep in mind that doing so will overwrite all the framework-related files **outside of the "src/" directory** (your source code will not be touched). So if you have modified any of the framework-related files, such as package.json or .gitignore, make sure your code is under version control so that you can check the diff and re-apply your changes. + +For that reason, it's generally best not to change any of the framework files or to do so in a way that minimises the number of changes. For example, if you want to modify the Webpack config, create a new separate JavaScript file and include it in webpack.config.js. That way, when you update, you only have to restore the line that include your file. \ No newline at end of file diff --git a/packages/generator-joplin/generators/app/templates/package_TEMPLATE.json b/packages/generator-joplin/generators/app/templates/package_TEMPLATE.json index e4b0d91b1..ebc25dcb4 100644 --- a/packages/generator-joplin/generators/app/templates/package_TEMPLATE.json +++ b/packages/generator-joplin/generators/app/templates/package_TEMPLATE.json @@ -1,5 +1,5 @@ { - "name": "<%= pluginId %>", + "name": "joplin_plugin", "version": "1.0.0", "description": "", "scripts": { @@ -7,7 +7,6 @@ "postinstall": "npm run dist" }, "keywords": [], - "author": "<%= pluginAuthor %>", "license": "MIT", "devDependencies": { "@types/node": "^14.0.14", diff --git a/packages/lib/services/plugins/PluginService.ts b/packages/lib/services/plugins/PluginService.ts index 16e40e917..21dde5256 100644 --- a/packages/lib/services/plugins/PluginService.ts +++ b/packages/lib/services/plugins/PluginService.ts @@ -95,7 +95,7 @@ export default class PluginService extends BaseService { }; } - public async loadPluginFromJsBundle(baseDir: string, jsBundleString: string, pluginIdIfNotSpecified: string): Promise { + public async loadPluginFromJsBundle(baseDir: string, jsBundleString: string, pluginIdIfNotSpecified: string = ''): Promise { baseDir = rtrimSlashes(baseDir); const r = await this.parsePluginJsBundle(jsBundleString);