1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-18 09:35:20 +02:00
joplin/readme/api/get_started/plugins.md

3.5 KiB

Getting started with plugin development

In this article you will learn the basic steps to build and test a plugin in Joplin.

Setting up your environment

First you need to setup your environment:

But first install Yeoman and the Joplin Plugin Generator:

npm install -g yo generator-joplin

Then, in the directory where you plan to develop the plugin, run:

yo joplin

This will generate the basic scaffolding of the plugin. At the root of it, there are a number of configuration files which you normally won't need to change. Then the src/ directory will contain your code. By default, the project uses TypeScript, but you are free to use plain JavaScript too - eventually the project is compiled to plain JS in any case.

The src/ directory also contains a manifest.json file, which contains the various information about the plugin that was set in the initial generation of the scaffolding, such as its name, homepage URL, etc. You can edit this at any time, but editing it after it has been published may cause users to have to download it again.

Setup Source Control

In your plugin directory, run:

git init 

This will setup source control.

Run Joplin in Development Mode

You should test your plugin in Development Mode. Doing so means that Joplin will run using a different profile, so you can experiment with the plugin without risking to accidentally change or delete your data.

Building the plugin

From the scaffolding, src/index.ts now contains the basic code for a Hello World plugin.

Two things to note:

  1. It contains a call to joplin.plugins.register. All plugins call this to register the plugin in the app.
  2. An onStart() event handler method, which is called when the plugin starts.

To try this basic plugin, compile the app by running the following from the root of the project:

npm run dist

Doing so should compile all the files into the dist/ directory. This is where Joplin will load the plugin.

Install the plugin

Open Joplin Configuration > Plugins section. Under Advanced Settings, add the plugin path in the Development plugins text field. This should be the path to your main plugin directory, i.e. path/to/your/root/plugin/directory.

Test the Plugin, Hello World!

Restart the Development app from the command line/terminal, and Joplin should load the plugin and execute its onStart handler. If all went well you should see the test message in the plugin console: "Hello world. Test plugin started!". You will also be able to see the information from the manifest in the Settings > Plugins

Next steps

Great, you now have the basics of a working plugin!