1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Plugins: Add support for the JPL plugin format

This commit is contained in:
Laurent Cozic 2020-11-18 10:17:27 +00:00
parent 73571f1c48
commit 8e2daef144
134 changed files with 1101 additions and 323 deletions

View File

@ -35,6 +35,7 @@ module.exports = {
'/build/', '/build/',
'test-utils.js', 'test-utils.js',
'file_api_driver.js', 'file_api_driver.js',
'/tests\\/tmp/',
], ],
// To avoid this warning: // To avoid this warning:

View File

@ -45,7 +45,7 @@ describe('services_PluginService', function() {
const service = newPluginService(); const service = newPluginService();
await service.loadAndRunPlugins([`${testPluginDir}/simple`]); 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(); const allFolders = await Folder.all();
expect(allFolders.length).toBe(1); 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 () => { it('should load and run a simple plugin and handle trailing slash', asyncTest(async () => {
const service = newPluginService(); const service = newPluginService();
await service.loadAndRunPlugins([`${testPluginDir}/simple/`]); 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 () => { it('should load and run a plugin that uses external packages', asyncTest(async () => {
const service = newPluginService(); const service = newPluginService();
await service.loadAndRunPlugins([`${testPluginDir}/withExternalModules`]); await service.loadAndRunPlugins([`${testPluginDir}/withExternalModules`]);
const plugin = service.pluginById('withexternalmodules'); expect(() => service.pluginById('org.joplinapp.plugins.ExternalModuleDemo')).not.toThrowError();
expect(plugin.id).toBe('withexternalmodules');
const allFolders = await Folder.all(); const allFolders = await Folder.all();
expect(allFolders.length).toBe(1); expect(allFolders.length).toBe(1);
@ -81,8 +80,8 @@ describe('services_PluginService', function() {
const service = newPluginService(); const service = newPluginService();
await service.loadAndRunPlugins(`${testPluginDir}/multi_plugins`); await service.loadAndRunPlugins(`${testPluginDir}/multi_plugins`);
const plugin1 = service.pluginById('simple1'); const plugin1 = service.pluginById('org.joplinapp.plugins.MultiPluginDemo1');
const plugin2 = service.pluginById('simple2'); const plugin2 = service.pluginById('org.joplinapp.plugins.MultiPluginDemo2');
expect(!!plugin1).toBe(true); expect(!!plugin1).toBe(true);
expect(!!plugin2).toBe(true); expect(!!plugin2).toBe(true);
@ -94,9 +93,10 @@ describe('services_PluginService', function() {
it('should load plugins from JS bundles', asyncTest(async () => { it('should load plugins from JS bundles', asyncTest(async () => {
const service = newPluginService(); const service = newPluginService();
const plugin = await service.loadPluginFromJsBundle('example', '/tmp', ` const plugin = await service.loadPluginFromJsBundle('/tmp', `
/* joplin-manifest: /* joplin-manifest:
{ {
"id": "org.joplinapp.plugins.JsBundleTest",
"manifest_version": 1, "manifest_version": 1,
"app_min_version": "1.4", "app_min_version": "1.4",
"name": "JS Bundle test", "name": "JS Bundle test",
@ -126,7 +126,7 @@ describe('services_PluginService', function() {
it('should load plugins from JS bundle files', asyncTest(async () => { it('should load plugins from JS bundle files', asyncTest(async () => {
const service = newPluginService(); const service = newPluginService();
await service.loadAndRunPlugins(`${testPluginDir}/jsbundles`); 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); expect((await Folder.all()).length).toBe(1);
})); }));
@ -166,7 +166,7 @@ describe('services_PluginService', function() {
const service = newPluginService(); const service = newPluginService();
for (const jsBundle of invalidJsBundles) { 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 service = newPluginService();
const plugin = await service.loadPluginFromJsBundle('example', tempDir, ` const plugin = await service.loadPluginFromJsBundle(tempDir, `
/* joplin-manifest: /* joplin-manifest:
{ {
"id": "org.joplinapp.plugin.MarkdownItPluginTest",
"manifest_version": 1, "manifest_version": 1,
"app_min_version": "1.4", "app_min_version": "1.4",
"name": "JS Bundle test", "name": "JS Bundle test",
@ -225,6 +226,7 @@ describe('services_PluginService', function() {
const pluginScript = ` const pluginScript = `
/* joplin-manifest: /* joplin-manifest:
{ {
"id": "org.joplinapp.plugins.PluginTest",
"manifest_version": 1, "manifest_version": 1,
"app_min_version": "1.4", "app_min_version": "1.4",
"name": "JS Bundle test", "name": "JS Bundle test",
@ -247,7 +249,7 @@ describe('services_PluginService', function() {
for (const testCase of testCases) { for (const testCase of testCases) {
const [appVersion, expected] = testCase; 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); expect(plugin.enabled).toBe(expected as boolean);
} }
})); }));

View File

@ -1,2 +1,3 @@
dist/* dist/*
node_modules/ node_modules/
*.jpl

View File

@ -12,3 +12,11 @@ The plugin is built using webpack, which create the compiled code in `/dist`. Th
## Building the plugin ## Building the plugin
To build the plugin, simply run `npm run dist`. 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.

View File

@ -1,6 +1,6 @@
import Plugin from '../Plugin'; import Plugin from '../Plugin';
import Joplin from './Joplin'; import Joplin from './Joplin';
import Logger from 'lib/Logger'; import Logger from '../../../Logger';
/** /**
* @ignore * @ignore
*/ */

View File

@ -7,9 +7,21 @@ import JoplinCommands from './JoplinCommands';
import JoplinViews from './JoplinViews'; import JoplinViews from './JoplinViews';
import JoplinInterop from './JoplinInterop'; import JoplinInterop from './JoplinInterop';
import JoplinSettings from './JoplinSettings'; 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 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 { export default class Joplin {
private data_; private data_;

View File

@ -1,25 +1,35 @@
import { Command } from './types'; import { Command } from './types';
/** /**
* This class allows executing or registering new Joplin commands. Commands can be executed or associated with * This class allows executing or registering new Joplin commands. Commands
* {@link JoplinViewsToolbarButtons | toolbar buttons} or {@link JoplinViewsMenuItems | menu items}. * 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 * ## Executing Joplin's internal commands
* *
* It is also possible to execute internal Joplin's commands which, as of now, are not well documented. * It is also possible to execute internal Joplin's commands which, as of
* You can find the list directly on GitHub though at the following locations: * 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 * * [Main screen commands](https://github.com/laurent22/joplin/tree/dev/packages/app-desktop/gui/MainScreen/commands)
* https://github.com/laurent22/joplin/tree/dev/ElectronClient/commands * * [Global commands](https://github.com/laurent22/joplin/tree/dev/packages/app-desktop/commands)
* https://github.com/laurent22/joplin/tree/dev/ElectronClient/gui/NoteEditor/commands/editorCommandDeclarations.ts * * [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 { export default class JoplinCommands {
/** /**
* <span class="platform-desktop">desktop</span> Executes the given command. * <span class="platform-desktop">desktop</span> Executes the given
* The `props` are the arguments passed to the command, and they vary based on the command * 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 * ```typescript
* // Create a new note in the current notebook: * // Create a new note in the current notebook:
@ -30,8 +40,8 @@ export default class JoplinCommands {
* await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID");
* ``` * ```
*/ */
execute(commandName: string, ...args: any[]): Promise<any | void>; execute(commandName: string, ...args: any[]): Promise<any | void>;
/** /**
* <span class="platform-desktop">desktop</span> Registers a new command. * <span class="platform-desktop">desktop</span> Registers a new command.
* *
* ```typescript * ```typescript
@ -47,5 +57,5 @@ export default class JoplinCommands {
* }); * });
* ``` * ```
*/ */
register(command: Command): Promise<void>; register(command: Command): Promise<void>;
} }

View File

@ -6,7 +6,7 @@ import { Path } from './types';
* *
* This is also what you would use to search notes, via the `search` endpoint. * 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. * 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: * And each method takes these parameters:

View File

@ -5,6 +5,6 @@
* so for now disable filters. * so for now disable filters.
*/ */
export default class JoplinFilters { export default class JoplinFilters {
on(name: string, callback: Function): Promise<void>; on(name: string, callback: Function): Promise<void>;
off(name: string, callback: Function): Promise<void>; off(name: string, callback: Function): Promise<void>;
} }

View File

@ -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. * 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 * 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. * 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/ * 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 { export default class JoplinInterop {
registerExportModule(module: ExportModule): Promise<void>; registerExportModule(module: ExportModule): Promise<void>;
registerImportModule(module: ImportModule): Promise<void>; registerImportModule(module: ImportModule): Promise<void>;
} }

View File

@ -1,5 +1,5 @@
import Plugin from '../Plugin'; import Plugin from '../Plugin';
import Logger from 'lib/Logger'; import Logger from '../../../Logger';
import { ContentScriptType, Script } from './types'; import { ContentScriptType, Script } from './types';
/** /**
* This class provides access to plugin-related features. * 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 * 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. * (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 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. * @param id A unique ID for the content script.

View File

@ -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 * 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 { export default class JoplinSettings {
private plugin_; 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: * 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<any>; globalValue(key: string): Promise<any>;
} }

View File

@ -1,11 +1,12 @@
import Plugin from '../Plugin'; 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. * 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 * 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
* 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. * 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 { export default class JoplinViewsDialogs {
private store; private store;
@ -16,7 +17,7 @@ export default class JoplinViewsDialogs {
/** /**
* Creates a new dialog * Creates a new dialog
*/ */
create(): Promise<ViewHandle>; create(id: string): Promise<ViewHandle>;
/** /**
* Displays a message box with OK/Cancel buttons. Returns the button index that was clicked - "0" for OK and "1" for "Cancel" * 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 * Opens the dialog
*/ */
open(handle: ViewHandle): Promise<ButtonId>; open(handle: ViewHandle): Promise<DialogResult>;
} }

View File

@ -3,7 +3,7 @@ import Plugin from '../Plugin';
/** /**
* Allows creating and managing menu items. * 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 { export default class JoplinViewsMenuItems {
private store; 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. * 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<void>; create(id: string, commandName: string, location?: MenuItemLocation, options?: CreateMenuItemOptions): Promise<void>;
} }

View File

@ -3,7 +3,7 @@ import Plugin from '../Plugin';
/** /**
* Allows creating menus. * 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 { export default class JoplinViewsMenus {
private store; 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 * 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. * menu as a sub-menu of the application build-in menus.
*/ */
create(label: string, menuItems: MenuItem[], location?: MenuItemLocation): Promise<void>; create(id: string, label: string, menuItems: MenuItem[], location?: MenuItemLocation): Promise<void>;
} }

View File

@ -1,10 +1,13 @@
import Plugin from '../Plugin'; import Plugin from '../Plugin';
import { ViewHandle } from './types'; 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 * Allows creating and managing view panels. View panels currently are
* it could be used to display a table of content for the active note, or display various metadata or graph. * 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 { export default class JoplinViewsPanels {
private store; private store;
@ -14,7 +17,7 @@ export default class JoplinViewsPanels {
/** /**
* Creates a new panel * Creates a new panel
*/ */
create(): Promise<ViewHandle>; create(id: string): Promise<ViewHandle>;
/** /**
* Sets the panel webview HTML * Sets the panel webview HTML
*/ */

View File

@ -3,7 +3,7 @@ import Plugin from '../Plugin';
/** /**
* Allows creating and managing toolbar buttons. * 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 { export default class JoplinViewsToolbarButtons {
private store; private store;
@ -12,5 +12,5 @@ export default class JoplinViewsToolbarButtons {
/** /**
* Creates a new toolbar button and associate it with the given command. * Creates a new toolbar button and associate it with the given command.
*/ */
create(commandName: string, location: ToolbarButtonLocation): Promise<void>; create(id: string, commandName: string, location: ToolbarButtonLocation): Promise<void>;
} }

View File

@ -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 * 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. * 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 { export default class JoplinWorkspace {
private store; private store;

View File

@ -1,5 +1,5 @@
import type Joplin from './Joplin'; import type Joplin from './Joplin';
declare const joplin:Joplin; declare const joplin: Joplin;
export default joplin; export default joplin;

View File

@ -6,7 +6,7 @@ export interface Command {
/** /**
* Name of command - must be globally unique * Name of command - must be globally unique
*/ */
name: string name: string;
/** /**
* Label to be displayed on menu items or keyboard shortcut editor for example. * 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 * 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. * should not be used as a menu item.
*/ */
label?: string label?: string;
/** /**
* Icon to be used on toolbar buttons for example * 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. * Code to be ran when the command is executed. It may return a result.
*/ */
execute(...args:any[]):Promise<any | void> execute(...args: any[]): Promise<any | void>;
/** /**
* Defines whether the command should be enabled or disabled, which in turns affects * Defines whether the command should be enabled or disabled, which in turns affects
@ -40,13 +40,11 @@ export interface Command {
* Or | \|\| | "noteIsTodo \|\| noteTodoCompleted" * Or | \|\| | "noteIsTodo \|\| noteTodoCompleted"
* And | && | "oneNoteSelected && !inConflictFolder" * And | && | "oneNoteSelected && !inConflictFolder"
* *
* Currently the supported context variables aren't documented, but you can find the list there: * 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).
*
* https://github.com/laurent22/joplin/blob/dev/ReactNativeClient/lib/services/commands/stateToWhenClauseContext.ts
* *
* Note: Commands are enabled by default unless you use this property. * 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. * 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. * 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. * 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. * 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 * Only applies to single file exporters or importers
* It tells whether the format can package multiple notes into one file. * It tells whether the format can package multiple notes into one file.
* For example JEX or ENEX can, but HTML cannot. * 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. * 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. * Called when the export process starts.
*/ */
onInit(context:ExportContext): Promise<void>; onInit(context: ExportContext): Promise<void>;
/** /**
* Called when an item needs to be processed. An "item" can be any Joplin object, such as a note, a folder, a notebook, etc. * 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<void>; onProcessItem(context: ExportContext, itemType: number, item: any): Promise<void>;
/** /**
* Called when a resource file needs to be exported. * Called when a resource file needs to be exported.
*/ */
onProcessResource(context:ExportContext, resource:any, filePath:string):Promise<void>; onProcessResource(context: ExportContext, resource: any, filePath: string): Promise<void>;
/** /**
* Called when the export process is done. * Called when the export process is done.
*/ */
onClose(context:ExportContext):Promise<void>; onClose(context: ExportContext): Promise<void>;
} }
export interface ImportModule { export interface ImportModule {
/** /**
* The format to be exported, eg "enex", "jex", "json", etc. * 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. * 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 * Only applies to single file exporters or importers
* It tells whether the format can package multiple notes into one file. * It tells whether the format can package multiple notes into one file.
* For example JEX or ENEX can, but HTML cannot. * 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. * 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. * 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). * 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. * Called when the import process starts. There is only one event handler within which you should import the complete data.
*/ */
onExec(context:ImportContext): Promise<void>; onExec(context: ImportContext): Promise<void>;
} }
export interface ExportOptions { export interface ExportOptions {
format?: string, format?: string;
path?:string, path?: string;
sourceFolderIds?: string[], sourceFolderIds?: string[];
sourceNoteIds?: string[], sourceNoteIds?: string[];
modulePath?:string, modulePath?: string;
target?:FileSystemItem, target?: FileSystemItem;
} }
export interface ExportContext { export interface ExportContext {
destPath: string, destPath: string;
options: ExportOptions, 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. * 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 { export interface ImportContext {
sourcePath: string, sourcePath: string;
options: any, options: any;
warnings: string[], warnings: string[];
} }
// ================================================================= // =================================================================
@ -188,7 +186,7 @@ export interface ImportContext {
// ================================================================= // =================================================================
export interface Script { export interface Script {
onStart?(event:any):Promise<void>, onStart?(event: any): Promise<void>;
} }
// ================================================================= // =================================================================
@ -196,7 +194,7 @@ export interface Script {
// ================================================================= // =================================================================
export interface CreateMenuItemOptions { export interface CreateMenuItemOptions {
accelerator: string, accelerator: string;
} }
export enum MenuItemLocation { export enum MenuItemLocation {
@ -206,7 +204,12 @@ export enum MenuItemLocation {
Note = 'note', Note = 'note',
Tools = 'tools', Tools = 'tools',
Help = 'help', Help = 'help',
/**
* @deprecated Do not use - same as NoteListContextMenu
*/
Context = 'context', Context = 'context',
NoteListContextMenu = 'noteListContextMenu',
EditorContextMenu = 'editorContextMenu',
} }
export interface MenuItem { export interface MenuItem {
@ -214,22 +217,22 @@ export interface MenuItem {
* Command that should be associated with the menu item. All menu item should * 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. * have a command associated with them unless they are a sub-menu.
*/ */
commandName?: string, commandName?: string;
/** /**
* Accelerator associated with the menu item * Accelerator associated with the menu item
*/ */
accelerator?: string, accelerator?: string;
/** /**
* Menu items that should appear below this menu item. Allows creating a menu tree. * 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. * 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 { export interface ButtonSpec {
id: ButtonId, id: ButtonId;
title?: string, title?: string;
onClick?():void, onClick?(): void;
} }
export type ButtonId = string; export type ButtonId = string;
@ -263,6 +266,11 @@ export interface EditorCommand {
value?: any; value?: any;
} }
export interface DialogResult {
id: ButtonId;
formData?: any;
}
// ================================================================= // =================================================================
// Settings types // Settings types
// ================================================================= // =================================================================
@ -279,28 +287,28 @@ export enum SettingItemType {
// Redefine a simplified interface to mask internal details // Redefine a simplified interface to mask internal details
// and to remove function calls as they would have to be async. // and to remove function calls as they would have to be async.
export interface SettingItem { export interface SettingItem {
value: any, value: any;
type: SettingItemType, type: SettingItemType;
public: boolean, public: boolean;
label:string, label: string;
description?:string, description?: string;
isEnum?: boolean, isEnum?: boolean;
section?: string, section?: string;
options?:any, options?: any;
appTypes?:string[], appTypes?: string[];
secure?: boolean, secure?: boolean;
advanced?: boolean, advanced?: boolean;
minimum?: number, minimum?: number;
maximum?: number, maximum?: number;
step?: number, step?: number;
} }
export interface SettingSection { export interface SettingSection {
label: string, label: string;
iconName?: string, iconName?: string;
description?: string, description?: string;
name?: string, name?: string;
} }
// ================================================================= // =================================================================
@ -322,36 +330,30 @@ export type Path = string[];
export enum ContentScriptType { 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 * ```javascript
* // The module should export an object as below:
*
* module.exports = { * 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) { * default: function(context) {
* return { * 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) { * plugin: function(markdownIt, options) {
* // ... * // ...
* }, * },
* * assets: {
* // 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: {},
* } * }
* } * }
* } * }
* ``` * ```
* *
* To include a regular Markdown-It plugin, that doesn't make use of any Joplin-specific feature, you * - 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.
* would simply create a file such as this: *
* - 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 * ```javascript
* module.exports = { * module.exports = {

View File

@ -7,17 +7,17 @@
"postinstall": "npm run dist" "postinstall": "npm run dist"
}, },
"keywords": [], "keywords": [],
"author": "CalebJohn",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@types/node": "^14.0.14", "@types/node": "^14.0.14",
"copy-webpack-plugin": "^6.1.0", "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", "ts-loader": "^7.0.5",
"typescript": "^3.9.3", "typescript": "^3.9.3",
"webpack": "^4.43.0", "webpack": "^4.43.0",
"webpack-cli": "^3.3.11" "webpack-cli": "^3.3.11"
},
"dependencies": {
"codemirror": "^5.58.2"
} }
} }

View File

@ -1,4 +1,5 @@
{ {
"id": "org.joplinapp.plugins.MatchHighlighter",
"manifest_version": 1, "manifest_version": 1,
"name": "joplin-match-highlighter", "name": "joplin-match-highlighter",
"description": "Adds support for the Codemirror match highlighter to the Joplin CodeView editor.", "description": "Adds support for the Codemirror match highlighter to the Joplin CodeView editor.",

View File

@ -1,5 +1,42 @@
const path = require('path'); const path = require('path');
const fs = require('fs-extra');
const CopyPlugin = require('copy-webpack-plugin'); 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 = { module.exports = {
mode: 'production', mode: 'production',
@ -16,19 +53,19 @@ module.exports = {
}, },
resolve: { resolve: {
alias: { alias: {
api: path.resolve(__dirname, 'api') api: path.resolve(__dirname, 'api'),
}, },
extensions: [ '.tsx', '.ts', '.js' ], extensions: ['.tsx', '.ts', '.js'],
}, },
output: { output: {
filename: 'index.js', filename: 'index.js',
path: path.resolve(__dirname, 'dist'), path: distDir,
}, },
plugins: [ plugins: [
new CopyPlugin({ new CopyPlugin({
patterns: [ patterns: [
{ {
from: "**/*", from: '**/*',
context: path.resolve(__dirname, 'src'), context: path.resolve(__dirname, 'src'),
to: path.resolve(__dirname, 'dist'), to: path.resolve(__dirname, 'dist'),
globOptions: { globOptions: {
@ -40,5 +77,8 @@ module.exports = {
}, },
], ],
}), }),
new WebpackOnBuildPlugin(function() {
createPluginArchive(distDir, archiveFilePath);
}),
], ],
}; };

View File

@ -1,2 +1,3 @@
dist/* dist/*
node_modules/ node_modules/
*.jpl

View File

@ -12,3 +12,11 @@ The plugin is built using webpack, which create the compiled code in `/dist`. Th
## Building the plugin ## Building the plugin
To build the plugin, simply run `npm run dist`. 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.

View File

@ -21,7 +21,7 @@ import { Command } from './types';
* and look at the `execute()` command. * and look at the `execute()` command.
*/ */
export default class JoplinCommands { export default class JoplinCommands {
/** /**
* <span class="platform-desktop">desktop</span> Executes the given * <span class="platform-desktop">desktop</span> Executes the given
* command. * command.
* *
@ -40,8 +40,8 @@ export default class JoplinCommands {
* await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID");
* ``` * ```
*/ */
execute(commandName: string, ...args: any[]): Promise<any | void>; execute(commandName: string, ...args: any[]): Promise<any | void>;
/** /**
* <span class="platform-desktop">desktop</span> Registers a new command. * <span class="platform-desktop">desktop</span> Registers a new command.
* *
* ```typescript * ```typescript
@ -57,5 +57,5 @@ export default class JoplinCommands {
* }); * });
* ``` * ```
*/ */
register(command: Command): Promise<void>; register(command: Command): Promise<void>;
} }

View File

@ -5,6 +5,6 @@
* so for now disable filters. * so for now disable filters.
*/ */
export default class JoplinFilters { export default class JoplinFilters {
on(name: string, callback: Function): Promise<void>; on(name: string, callback: Function): Promise<void>;
off(name: string, callback: Function): Promise<void>; off(name: string, callback: Function): Promise<void>;
} }

View File

@ -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/ * 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 { export default class JoplinInterop {
registerExportModule(module: ExportModule): Promise<void>; registerExportModule(module: ExportModule): Promise<void>;
registerImportModule(module: ImportModule): Promise<void>; registerImportModule(module: ImportModule): Promise<void>;
} }

View File

@ -7,11 +7,14 @@
"postinstall": "npm run dist" "postinstall": "npm run dist"
}, },
"keywords": [], "keywords": [],
"author": "",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@types/node": "^14.0.14", "@types/node": "^14.0.14",
"copy-webpack-plugin": "^6.1.0", "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", "ts-loader": "^7.0.5",
"typescript": "^3.9.3", "typescript": "^3.9.3",
"webpack": "^4.43.0", "webpack": "^4.43.0",

View File

@ -1,4 +1,5 @@
{ {
"id": "org.joplinapp.plugins.ContentScriptDemo",
"manifest_version": 1, "manifest_version": 1,
"app_min_version": "1.4", "app_min_version": "1.4",
"name": "Content Script Test", "name": "Content Script Test",

View File

@ -1,5 +1,42 @@
const path = require('path'); const path = require('path');
const fs = require('fs-extra');
const CopyPlugin = require('copy-webpack-plugin'); 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 = { module.exports = {
mode: 'production', mode: 'production',
@ -22,7 +59,7 @@ module.exports = {
}, },
output: { output: {
filename: 'index.js', filename: 'index.js',
path: path.resolve(__dirname, 'dist'), path: distDir,
}, },
plugins: [ plugins: [
new CopyPlugin({ new CopyPlugin({
@ -40,5 +77,8 @@ module.exports = {
}, },
], ],
}), }),
new WebpackOnBuildPlugin(function() {
createPluginArchive(distDir, archiveFilePath);
}),
], ],
}; };

View File

@ -1,2 +1,3 @@
dist/* dist/*
node_modules/ node_modules/
*.jpl

View File

@ -12,3 +12,11 @@ The plugin is built using webpack, which create the compiled code in `/dist`. Th
## Building the plugin ## Building the plugin
To build the plugin, simply run `npm run dist`. 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.

View File

@ -21,7 +21,7 @@ import { Command } from './types';
* and look at the `execute()` command. * and look at the `execute()` command.
*/ */
export default class JoplinCommands { export default class JoplinCommands {
/** /**
* <span class="platform-desktop">desktop</span> Executes the given * <span class="platform-desktop">desktop</span> Executes the given
* command. * command.
* *
@ -40,8 +40,8 @@ export default class JoplinCommands {
* await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID");
* ``` * ```
*/ */
execute(commandName: string, ...args: any[]): Promise<any | void>; execute(commandName: string, ...args: any[]): Promise<any | void>;
/** /**
* <span class="platform-desktop">desktop</span> Registers a new command. * <span class="platform-desktop">desktop</span> Registers a new command.
* *
* ```typescript * ```typescript
@ -57,5 +57,5 @@ export default class JoplinCommands {
* }); * });
* ``` * ```
*/ */
register(command: Command): Promise<void>; register(command: Command): Promise<void>;
} }

View File

@ -5,6 +5,6 @@
* so for now disable filters. * so for now disable filters.
*/ */
export default class JoplinFilters { export default class JoplinFilters {
on(name: string, callback: Function): Promise<void>; on(name: string, callback: Function): Promise<void>;
off(name: string, callback: Function): Promise<void>; off(name: string, callback: Function): Promise<void>;
} }

View File

@ -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/ * 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 { export default class JoplinInterop {
registerExportModule(module: ExportModule): Promise<void>; registerExportModule(module: ExportModule): Promise<void>;
registerImportModule(module: ImportModule): Promise<void>; registerImportModule(module: ImportModule): Promise<void>;
} }

View File

@ -7,11 +7,14 @@
"postinstall": "npm run dist" "postinstall": "npm run dist"
}, },
"keywords": [], "keywords": [],
"author": "Laurent Cozic",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@types/node": "^14.0.14", "@types/node": "^14.0.14",
"copy-webpack-plugin": "^6.1.0", "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", "ts-loader": "^7.0.5",
"typescript": "^3.9.3", "typescript": "^3.9.3",
"webpack": "^4.43.0", "webpack": "^4.43.0",

View File

@ -1,4 +1,5 @@
{ {
"id": "org.joplinapp.plugins.DialogDemo",
"manifest_version": 1, "manifest_version": 1,
"app_min_version": "1.4", "app_min_version": "1.4",
"name": "Dialog Demo", "name": "Dialog Demo",

View File

@ -1,5 +1,42 @@
const path = require('path'); const path = require('path');
const fs = require('fs-extra');
const CopyPlugin = require('copy-webpack-plugin'); 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 = { module.exports = {
mode: 'production', mode: 'production',
@ -22,7 +59,7 @@ module.exports = {
}, },
output: { output: {
filename: 'index.js', filename: 'index.js',
path: path.resolve(__dirname, 'dist'), path: distDir,
}, },
plugins: [ plugins: [
new CopyPlugin({ new CopyPlugin({
@ -40,5 +77,8 @@ module.exports = {
}, },
], ],
}), }),
new WebpackOnBuildPlugin(function() {
createPluginArchive(distDir, archiveFilePath);
}),
], ],
}; };

View File

@ -1,2 +1,3 @@
dist/* dist/*
node_modules/ node_modules/
*.jpl

View File

@ -12,3 +12,11 @@ The plugin is built using webpack, which create the compiled code in `/dist`. Th
## Building the plugin ## Building the plugin
To build the plugin, simply run `npm run dist`. 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.

View File

@ -21,7 +21,7 @@ import { Command } from './types';
* and look at the `execute()` command. * and look at the `execute()` command.
*/ */
export default class JoplinCommands { export default class JoplinCommands {
/** /**
* <span class="platform-desktop">desktop</span> Executes the given * <span class="platform-desktop">desktop</span> Executes the given
* command. * command.
* *
@ -40,8 +40,8 @@ export default class JoplinCommands {
* await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID");
* ``` * ```
*/ */
execute(commandName: string, ...args: any[]): Promise<any | void>; execute(commandName: string, ...args: any[]): Promise<any | void>;
/** /**
* <span class="platform-desktop">desktop</span> Registers a new command. * <span class="platform-desktop">desktop</span> Registers a new command.
* *
* ```typescript * ```typescript
@ -57,5 +57,5 @@ export default class JoplinCommands {
* }); * });
* ``` * ```
*/ */
register(command: Command): Promise<void>; register(command: Command): Promise<void>;
} }

View File

@ -5,6 +5,6 @@
* so for now disable filters. * so for now disable filters.
*/ */
export default class JoplinFilters { export default class JoplinFilters {
on(name: string, callback: Function): Promise<void>; on(name: string, callback: Function): Promise<void>;
off(name: string, callback: Function): Promise<void>; off(name: string, callback: Function): Promise<void>;
} }

View File

@ -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/ * 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 { export default class JoplinInterop {
registerExportModule(module: ExportModule): Promise<void>; registerExportModule(module: ExportModule): Promise<void>;
registerImportModule(module: ImportModule): Promise<void>; registerImportModule(module: ImportModule): Promise<void>;
} }

View File

@ -7,11 +7,14 @@
"postinstall": "npm run dist" "postinstall": "npm run dist"
}, },
"keywords": [], "keywords": [],
"author": "",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@types/node": "^14.0.14", "@types/node": "^14.0.14",
"copy-webpack-plugin": "^6.1.0", "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", "ts-loader": "^7.0.5",
"typescript": "^3.9.3", "typescript": "^3.9.3",
"webpack": "^4.43.0", "webpack": "^4.43.0",

View File

@ -1,4 +1,5 @@
{ {
"id": "org.joplinapp.plugins.EditorContextMenuDemo",
"manifest_version": 1, "manifest_version": 1,
"app_min_version": "1.4", "app_min_version": "1.4",
"name": "Editor Context Menu Demo", "name": "Editor Context Menu Demo",

View File

@ -1,5 +1,42 @@
const path = require('path'); const path = require('path');
const fs = require('fs-extra');
const CopyPlugin = require('copy-webpack-plugin'); 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 = { module.exports = {
mode: 'production', mode: 'production',
@ -22,7 +59,7 @@ module.exports = {
}, },
output: { output: {
filename: 'index.js', filename: 'index.js',
path: path.resolve(__dirname, 'dist'), path: distDir,
}, },
plugins: [ plugins: [
new CopyPlugin({ new CopyPlugin({
@ -40,5 +77,8 @@ module.exports = {
}, },
], ],
}), }),
new WebpackOnBuildPlugin(function() {
createPluginArchive(distDir, archiveFilePath);
}),
], ],
}; };

View File

@ -1,2 +1,3 @@
dist/* dist/*
node_modules/ node_modules/
*.jpl

View File

@ -12,3 +12,11 @@ The plugin is built using webpack, which create the compiled code in `/dist`. Th
## Building the plugin ## Building the plugin
To build the plugin, simply run `npm run dist`. 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.

View File

@ -21,7 +21,7 @@ import { Command } from './types';
* and look at the `execute()` command. * and look at the `execute()` command.
*/ */
export default class JoplinCommands { export default class JoplinCommands {
/** /**
* <span class="platform-desktop">desktop</span> Executes the given * <span class="platform-desktop">desktop</span> Executes the given
* command. * command.
* *
@ -40,8 +40,8 @@ export default class JoplinCommands {
* await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID");
* ``` * ```
*/ */
execute(commandName: string, ...args: any[]): Promise<any | void>; execute(commandName: string, ...args: any[]): Promise<any | void>;
/** /**
* <span class="platform-desktop">desktop</span> Registers a new command. * <span class="platform-desktop">desktop</span> Registers a new command.
* *
* ```typescript * ```typescript
@ -57,5 +57,5 @@ export default class JoplinCommands {
* }); * });
* ``` * ```
*/ */
register(command: Command): Promise<void>; register(command: Command): Promise<void>;
} }

View File

@ -5,6 +5,6 @@
* so for now disable filters. * so for now disable filters.
*/ */
export default class JoplinFilters { export default class JoplinFilters {
on(name: string, callback: Function): Promise<void>; on(name: string, callback: Function): Promise<void>;
off(name: string, callback: Function): Promise<void>; off(name: string, callback: Function): Promise<void>;
} }

View File

@ -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/ * 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 { export default class JoplinInterop {
registerExportModule(module: ExportModule): Promise<void>; registerExportModule(module: ExportModule): Promise<void>;
registerImportModule(module: ImportModule): Promise<void>; registerImportModule(module: ImportModule): Promise<void>;
} }

View File

@ -7,11 +7,14 @@
"postinstall": "npm run dist" "postinstall": "npm run dist"
}, },
"keywords": [], "keywords": [],
"author": "Laurent Cozic",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@types/node": "^14.0.14", "@types/node": "^14.0.14",
"copy-webpack-plugin": "^6.1.0", "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", "ts-loader": "^7.0.5",
"typescript": "^3.9.3", "typescript": "^3.9.3",
"webpack": "^4.43.0", "webpack": "^4.43.0",

View File

@ -1,4 +1,5 @@
{ {
"id": "org.joplinapp.plugins.EventsDemo",
"manifest_version": 1, "manifest_version": 1,
"app_min_version": "1.4", "app_min_version": "1.4",
"name": "Event demo", "name": "Event demo",

View File

@ -1,5 +1,42 @@
const path = require('path'); const path = require('path');
const fs = require('fs-extra');
const CopyPlugin = require('copy-webpack-plugin'); 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 = { module.exports = {
mode: 'production', mode: 'production',
@ -22,7 +59,7 @@ module.exports = {
}, },
output: { output: {
filename: 'index.js', filename: 'index.js',
path: path.resolve(__dirname, 'dist'), path: distDir,
}, },
plugins: [ plugins: [
new CopyPlugin({ new CopyPlugin({
@ -40,5 +77,8 @@ module.exports = {
}, },
], ],
}), }),
new WebpackOnBuildPlugin(function() {
createPluginArchive(distDir, archiveFilePath);
}),
], ],
}; };

View File

@ -12,3 +12,11 @@ The plugin is built using webpack, which create the compiled code in `/dist`. Th
## Building the plugin ## Building the plugin
To build the plugin, simply run `npm run dist`. 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.

View File

@ -1,5 +1,5 @@
{ {
"name": "org.joplinapp.FirstJplPlugin", "name": "joplin_plugin",
"version": "1.0.0", "version": "1.0.0",
"description": "", "description": "",
"scripts": { "scripts": {
@ -7,7 +7,6 @@
"postinstall": "npm run dist" "postinstall": "npm run dist"
}, },
"keywords": [], "keywords": [],
"author": "",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@types/node": "^14.0.14", "@types/node": "^14.0.14",

View File

@ -1,5 +1,6 @@
/* joplin-manifest: /* joplin-manifest:
{ {
"id": "org.joplinapp.plugins.JsBundleDemo",
"manifest_version": 1, "manifest_version": 1,
"app_min_version": "1.4", "app_min_version": "1.4",
"name": "JS Bundle test", "name": "JS Bundle test",

View File

@ -1,2 +1,3 @@
dist/* dist/*
node_modules/ node_modules/
*.jpl

View File

@ -12,3 +12,11 @@ The plugin is built using webpack, which create the compiled code in `/dist`. Th
## Building the plugin ## Building the plugin
To build the plugin, simply run `npm run dist`. 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.

View File

@ -21,7 +21,7 @@ import { Command } from './types';
* and look at the `execute()` command. * and look at the `execute()` command.
*/ */
export default class JoplinCommands { export default class JoplinCommands {
/** /**
* <span class="platform-desktop">desktop</span> Executes the given * <span class="platform-desktop">desktop</span> Executes the given
* command. * command.
* *
@ -40,8 +40,8 @@ export default class JoplinCommands {
* await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID");
* ``` * ```
*/ */
execute(commandName: string, ...args: any[]): Promise<any | void>; execute(commandName: string, ...args: any[]): Promise<any | void>;
/** /**
* <span class="platform-desktop">desktop</span> Registers a new command. * <span class="platform-desktop">desktop</span> Registers a new command.
* *
* ```typescript * ```typescript
@ -57,5 +57,5 @@ export default class JoplinCommands {
* }); * });
* ``` * ```
*/ */
register(command: Command): Promise<void>; register(command: Command): Promise<void>;
} }

View File

@ -5,6 +5,6 @@
* so for now disable filters. * so for now disable filters.
*/ */
export default class JoplinFilters { export default class JoplinFilters {
on(name: string, callback: Function): Promise<void>; on(name: string, callback: Function): Promise<void>;
off(name: string, callback: Function): Promise<void>; off(name: string, callback: Function): Promise<void>;
} }

View File

@ -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/ * 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 { export default class JoplinInterop {
registerExportModule(module: ExportModule): Promise<void>; registerExportModule(module: ExportModule): Promise<void>;
registerImportModule(module: ImportModule): Promise<void>; registerImportModule(module: ImportModule): Promise<void>;
} }

View File

@ -1,5 +1,5 @@
{ {
"name": "test_plugin", "name": "joplin_plugin",
"version": "1.0.0", "version": "1.0.0",
"description": "", "description": "",
"scripts": { "scripts": {
@ -7,11 +7,14 @@
"postinstall": "npm run dist" "postinstall": "npm run dist"
}, },
"keywords": [], "keywords": [],
"author": "",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@types/node": "^14.0.14", "@types/node": "^14.0.14",
"copy-webpack-plugin": "^6.1.0", "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", "ts-loader": "^7.0.5",
"typescript": "^3.9.3", "typescript": "^3.9.3",
"webpack": "^4.43.0", "webpack": "^4.43.0",

View File

@ -1,4 +1,5 @@
{ {
"id": "org.joplinapp.plugins.JsonExportDemo",
"manifest_version": 1, "manifest_version": 1,
"app_min_version": "1.4", "app_min_version": "1.4",
"name": "Json Export Test", "name": "Json Export Test",

View File

@ -1,5 +1,42 @@
const path = require('path'); const path = require('path');
const fs = require('fs-extra');
const CopyPlugin = require('copy-webpack-plugin'); 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 = { module.exports = {
mode: 'production', mode: 'production',
@ -22,7 +59,7 @@ module.exports = {
}, },
output: { output: {
filename: 'index.js', filename: 'index.js',
path: path.resolve(__dirname, 'dist'), path: distDir,
}, },
plugins: [ plugins: [
new CopyPlugin({ new CopyPlugin({
@ -40,5 +77,8 @@ module.exports = {
}, },
], ],
}), }),
new WebpackOnBuildPlugin(function() {
createPluginArchive(distDir, archiveFilePath);
}),
], ],
}; };

View File

@ -1,2 +1,3 @@
dist/* dist/*
node_modules/ node_modules/
*.jpl

View File

@ -12,3 +12,11 @@ The plugin is built using webpack, which create the compiled code in `/dist`. Th
## Building the plugin ## Building the plugin
To build the plugin, simply run `npm run dist`. 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.

View File

@ -21,7 +21,7 @@ import { Command } from './types';
* and look at the `execute()` command. * and look at the `execute()` command.
*/ */
export default class JoplinCommands { export default class JoplinCommands {
/** /**
* <span class="platform-desktop">desktop</span> Executes the given * <span class="platform-desktop">desktop</span> Executes the given
* command. * command.
* *
@ -40,8 +40,8 @@ export default class JoplinCommands {
* await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID");
* ``` * ```
*/ */
execute(commandName: string, ...args: any[]): Promise<any | void>; execute(commandName: string, ...args: any[]): Promise<any | void>;
/** /**
* <span class="platform-desktop">desktop</span> Registers a new command. * <span class="platform-desktop">desktop</span> Registers a new command.
* *
* ```typescript * ```typescript
@ -57,5 +57,5 @@ export default class JoplinCommands {
* }); * });
* ``` * ```
*/ */
register(command: Command): Promise<void>; register(command: Command): Promise<void>;
} }

View File

@ -5,6 +5,6 @@
* so for now disable filters. * so for now disable filters.
*/ */
export default class JoplinFilters { export default class JoplinFilters {
on(name: string, callback: Function): Promise<void>; on(name: string, callback: Function): Promise<void>;
off(name: string, callback: Function): Promise<void>; off(name: string, callback: Function): Promise<void>;
} }

View File

@ -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/ * 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 { export default class JoplinInterop {
registerExportModule(module: ExportModule): Promise<void>; registerExportModule(module: ExportModule): Promise<void>;
registerImportModule(module: ImportModule): Promise<void>; registerImportModule(module: ImportModule): Promise<void>;
} }

View File

@ -7,11 +7,14 @@
"postinstall": "npm run dist" "postinstall": "npm run dist"
}, },
"keywords": [], "keywords": [],
"author": "",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@types/node": "^14.0.14", "@types/node": "^14.0.14",
"copy-webpack-plugin": "^6.1.0", "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", "ts-loader": "^7.0.5",
"typescript": "^3.9.3", "typescript": "^3.9.3",
"webpack": "^4.43.0", "webpack": "^4.43.0",

View File

@ -1,4 +1,5 @@
{ {
"id": "org.joplinapp.plugins.MenuDemo",
"manifest_version": 1, "manifest_version": 1,
"app_min_version": "1.4", "app_min_version": "1.4",
"name": "Menu Test", "name": "Menu Test",

View File

@ -1,5 +1,42 @@
const path = require('path'); const path = require('path');
const fs = require('fs-extra');
const CopyPlugin = require('copy-webpack-plugin'); 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 = { module.exports = {
mode: 'production', mode: 'production',
@ -22,7 +59,7 @@ module.exports = {
}, },
output: { output: {
filename: 'index.js', filename: 'index.js',
path: path.resolve(__dirname, 'dist'), path: distDir,
}, },
plugins: [ plugins: [
new CopyPlugin({ new CopyPlugin({
@ -40,5 +77,8 @@ module.exports = {
}, },
], ],
}), }),
new WebpackOnBuildPlugin(function() {
createPluginArchive(distDir, archiveFilePath);
}),
], ],
}; };

View File

@ -1,4 +1,5 @@
{ {
"id": "org.joplinapp.plugins.MultiPluginDemo1",
"manifest_version": 1, "manifest_version": 1,
"app_min_version": "1.4", "app_min_version": "1.4",
"name": "Joplin Simple Plugin", "name": "Joplin Simple Plugin",

View File

@ -1,4 +1,5 @@
{ {
"id": "org.joplinapp.plugins.MultiPluginDemo2",
"manifest_version": 1, "manifest_version": 1,
"app_min_version": "1.4", "app_min_version": "1.4",
"name": "Joplin Simple Plugin", "name": "Joplin Simple Plugin",

View File

@ -1,2 +1,3 @@
dist/* dist/*
node_modules/ node_modules/
*.jpl

View File

@ -12,3 +12,11 @@ The plugin is built using webpack, which create the compiled code in `/dist`. Th
## Building the plugin ## Building the plugin
To build the plugin, simply run `npm run dist`. 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.

View File

@ -21,7 +21,7 @@ import { Command } from './types';
* and look at the `execute()` command. * and look at the `execute()` command.
*/ */
export default class JoplinCommands { export default class JoplinCommands {
/** /**
* <span class="platform-desktop">desktop</span> Executes the given * <span class="platform-desktop">desktop</span> Executes the given
* command. * command.
* *
@ -40,8 +40,8 @@ export default class JoplinCommands {
* await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID");
* ``` * ```
*/ */
execute(commandName: string, ...args: any[]): Promise<any | void>; execute(commandName: string, ...args: any[]): Promise<any | void>;
/** /**
* <span class="platform-desktop">desktop</span> Registers a new command. * <span class="platform-desktop">desktop</span> Registers a new command.
* *
* ```typescript * ```typescript
@ -57,5 +57,5 @@ export default class JoplinCommands {
* }); * });
* ``` * ```
*/ */
register(command: Command): Promise<void>; register(command: Command): Promise<void>;
} }

View File

@ -5,6 +5,6 @@
* so for now disable filters. * so for now disable filters.
*/ */
export default class JoplinFilters { export default class JoplinFilters {
on(name: string, callback: Function): Promise<void>; on(name: string, callback: Function): Promise<void>;
off(name: string, callback: Function): Promise<void>; off(name: string, callback: Function): Promise<void>;
} }

View File

@ -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/ * 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 { export default class JoplinInterop {
registerExportModule(module: ExportModule): Promise<void>; registerExportModule(module: ExportModule): Promise<void>;
registerImportModule(module: ImportModule): Promise<void>; registerImportModule(module: ImportModule): Promise<void>;
} }

View File

@ -7,11 +7,14 @@
"postinstall": "npm run dist" "postinstall": "npm run dist"
}, },
"keywords": [], "keywords": [],
"author": "Laurent Cozic",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@types/node": "^14.0.14", "@types/node": "^14.0.14",
"copy-webpack-plugin": "^6.1.0", "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", "ts-loader": "^7.0.5",
"typescript": "^3.9.3", "typescript": "^3.9.3",
"webpack": "^4.43.0", "webpack": "^4.43.0",

View File

@ -1,4 +1,5 @@
{ {
"id": "org.joplinapp.plugins.MultiSelection",
"manifest_version": 1, "manifest_version": 1,
"app_min_version": "1.4", "app_min_version": "1.4",
"name": "Multi Note Selection Demo", "name": "Multi Note Selection Demo",

View File

@ -1,5 +1,42 @@
const path = require('path'); const path = require('path');
const fs = require('fs-extra');
const CopyPlugin = require('copy-webpack-plugin'); 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 = { module.exports = {
mode: 'production', mode: 'production',
@ -22,7 +59,7 @@ module.exports = {
}, },
output: { output: {
filename: 'index.js', filename: 'index.js',
path: path.resolve(__dirname, 'dist'), path: distDir,
}, },
plugins: [ plugins: [
new CopyPlugin({ new CopyPlugin({
@ -40,5 +77,8 @@ module.exports = {
}, },
], ],
}), }),
new WebpackOnBuildPlugin(function() {
createPluginArchive(distDir, archiveFilePath);
}),
], ],
}; };

View File

@ -1,2 +1,3 @@
dist/* dist/*
node_modules/ node_modules/
*.jpl

View File

@ -12,3 +12,11 @@ The plugin is built using webpack, which create the compiled code in `/dist`. Th
## Building the plugin ## Building the plugin
To build the plugin, simply run `npm run dist`. 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.

View File

@ -21,7 +21,7 @@ import { Command } from './types';
* and look at the `execute()` command. * and look at the `execute()` command.
*/ */
export default class JoplinCommands { export default class JoplinCommands {
/** /**
* <span class="platform-desktop">desktop</span> Executes the given * <span class="platform-desktop">desktop</span> Executes the given
* command. * command.
* *
@ -40,8 +40,8 @@ export default class JoplinCommands {
* await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID");
* ``` * ```
*/ */
execute(commandName: string, ...args: any[]): Promise<any | void>; execute(commandName: string, ...args: any[]): Promise<any | void>;
/** /**
* <span class="platform-desktop">desktop</span> Registers a new command. * <span class="platform-desktop">desktop</span> Registers a new command.
* *
* ```typescript * ```typescript
@ -57,5 +57,5 @@ export default class JoplinCommands {
* }); * });
* ``` * ```
*/ */
register(command: Command): Promise<void>; register(command: Command): Promise<void>;
} }

View File

@ -5,6 +5,6 @@
* so for now disable filters. * so for now disable filters.
*/ */
export default class JoplinFilters { export default class JoplinFilters {
on(name: string, callback: Function): Promise<void>; on(name: string, callback: Function): Promise<void>;
off(name: string, callback: Function): Promise<void>; off(name: string, callback: Function): Promise<void>;
} }

View File

@ -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/ * 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 { export default class JoplinInterop {
registerExportModule(module: ExportModule): Promise<void>; registerExportModule(module: ExportModule): Promise<void>;
registerImportModule(module: ImportModule): Promise<void>; registerImportModule(module: ImportModule): Promise<void>;
} }

View File

@ -7,11 +7,14 @@
"postinstall": "npm run dist" "postinstall": "npm run dist"
}, },
"keywords": [], "keywords": [],
"author": "Laurent Cozic",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@types/node": "^14.0.14", "@types/node": "^14.0.14",
"copy-webpack-plugin": "^6.1.0", "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", "ts-loader": "^7.0.5",
"typescript": "^3.9.3", "typescript": "^3.9.3",
"webpack": "^4.43.0", "webpack": "^4.43.0",

View File

@ -1,4 +1,5 @@
{ {
"id": "org.joplinapp.plugins.RegisterCommandDemo",
"manifest_version": 1, "manifest_version": 1,
"app_min_version": "1.4", "app_min_version": "1.4",
"name": "Register Command Test", "name": "Register Command Test",

View File

@ -1,5 +1,42 @@
const path = require('path'); const path = require('path');
const fs = require('fs-extra');
const CopyPlugin = require('copy-webpack-plugin'); 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 = { module.exports = {
mode: 'production', mode: 'production',
@ -22,7 +59,7 @@ module.exports = {
}, },
output: { output: {
filename: 'index.js', filename: 'index.js',
path: path.resolve(__dirname, 'dist'), path: distDir,
}, },
plugins: [ plugins: [
new CopyPlugin({ new CopyPlugin({
@ -40,5 +77,8 @@ module.exports = {
}, },
], ],
}), }),
new WebpackOnBuildPlugin(function() {
createPluginArchive(distDir, archiveFilePath);
}),
], ],
}; };

View File

@ -1,2 +1,3 @@
dist/* dist/*
node_modules/ node_modules/
*.jpl

View File

@ -12,3 +12,11 @@ The plugin is built using webpack, which create the compiled code in `/dist`. Th
## Building the plugin ## Building the plugin
To build the plugin, simply run `npm run dist`. 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.

View File

@ -21,7 +21,7 @@ import { Command } from './types';
* and look at the `execute()` command. * and look at the `execute()` command.
*/ */
export default class JoplinCommands { export default class JoplinCommands {
/** /**
* <span class="platform-desktop">desktop</span> Executes the given * <span class="platform-desktop">desktop</span> Executes the given
* command. * command.
* *
@ -40,8 +40,8 @@ export default class JoplinCommands {
* await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID");
* ``` * ```
*/ */
execute(commandName: string, ...args: any[]): Promise<any | void>; execute(commandName: string, ...args: any[]): Promise<any | void>;
/** /**
* <span class="platform-desktop">desktop</span> Registers a new command. * <span class="platform-desktop">desktop</span> Registers a new command.
* *
* ```typescript * ```typescript
@ -57,5 +57,5 @@ export default class JoplinCommands {
* }); * });
* ``` * ```
*/ */
register(command: Command): Promise<void>; register(command: Command): Promise<void>;
} }

View File

@ -5,6 +5,6 @@
* so for now disable filters. * so for now disable filters.
*/ */
export default class JoplinFilters { export default class JoplinFilters {
on(name: string, callback: Function): Promise<void>; on(name: string, callback: Function): Promise<void>;
off(name: string, callback: Function): Promise<void>; off(name: string, callback: Function): Promise<void>;
} }

View File

@ -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/ * 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 { export default class JoplinInterop {
registerExportModule(module: ExportModule): Promise<void>; registerExportModule(module: ExportModule): Promise<void>;
registerImportModule(module: ImportModule): Promise<void>; registerImportModule(module: ImportModule): Promise<void>;
} }

View File

@ -7,11 +7,14 @@
"postinstall": "npm run dist" "postinstall": "npm run dist"
}, },
"keywords": [], "keywords": [],
"author": "Laurent Cozic",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@types/node": "^14.0.14", "@types/node": "^14.0.14",
"copy-webpack-plugin": "^6.1.0", "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", "ts-loader": "^7.0.5",
"typescript": "^3.9.3", "typescript": "^3.9.3",
"webpack": "^4.43.0", "webpack": "^4.43.0",

View File

@ -1,4 +1,5 @@
{ {
"id": "org.joplinapp.plugins.SelectedTextDemo",
"manifest_version": 1, "manifest_version": 1,
"app_min_version": "1.4", "app_min_version": "1.4",
"name": "Selected Text Test", "name": "Selected Text Test",

View File

@ -1,5 +1,42 @@
const path = require('path'); const path = require('path');
const fs = require('fs-extra');
const CopyPlugin = require('copy-webpack-plugin'); 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 = { module.exports = {
mode: 'production', mode: 'production',
@ -22,7 +59,7 @@ module.exports = {
}, },
output: { output: {
filename: 'index.js', filename: 'index.js',
path: path.resolve(__dirname, 'dist'), path: distDir,
}, },
plugins: [ plugins: [
new CopyPlugin({ new CopyPlugin({
@ -40,5 +77,8 @@ module.exports = {
}, },
], ],
}), }),
new WebpackOnBuildPlugin(function() {
createPluginArchive(distDir, archiveFilePath);
}),
], ],
}; };

Some files were not shown because too many files have changed in this diff Show More