5 Themes are exactly the same than plugins, except that:
6 * Their name starts with `peertube-theme-` instead of `peertube-plugin-`
7 * They cannot declare server code (so they cannot register server hooks or settings)
8 * CSS files are loaded by client only if the theme is chosen by the administrator or the user
12 A plugin registers functions in JavaScript to execute when PeerTube (server and client) fires events. There are 3 types of hooks:
13 * `filter`: used to filter functions parameters or return values.
14 For example to replace words in video comments, or change the videos list behaviour
15 * `action`: used to do something after a certain trigger. For example to send a hook every time a video is published
16 * `static`: same than `action` but PeerTube waits their execution
22 target: 'action:application.listening',
23 handler: () => displayHelloWorld()
27 On server side, these hooks are registered by the `library` file defined in `package.json`.
32 "library": "./main.js",
38 On client side, these hooks are registered by the `clientScripts` files defined in `package.json`.
39 All client scripts have scopes so PeerTube client only loads scripts it needs:
46 "script": "client/common-client-plugin.js",
47 "scopes": [ "common" ]
50 "script": "client/video-watch-client-plugin.js",
51 "scopes": [ "video-watch" ]
60 Plugins can declare static directories that PeerTube will serve (images for example)
61 from `/plugins/{plugin-name}/{plugin-version}/static/`
62 or `/themes/{theme-name}/{theme-version}/static/` routes.
66 Plugins can declare CSS files that PeerTube will automatically inject in the client.
74 Plugins can register settings, that PeerTube will inject in the administration interface.
83 default: 'my super name'
86 const adminName = await settingsManager.getSetting('admin-name')
91 Plugins can store/load JSON data, that PeerTube will store in its database (so don't put files in there).
96 const value = await storageManager.getData('mykey')
97 await storageManager.storeData('mykey', 'myvalue')
102 PeerTube plugins and themes should be published on [NPM](https://www.npmjs.com/) so that PeerTube indexes
103 take into account your plugin (after ~ 1 day). An official PeerTube index is available on https://packages.joinpeertube.org/ (it's just a REST API, so don't expect a beautiful website).
105 ## Write a plugin/theme
108 * Find a name for your plugin or your theme (must not have spaces, it can only contain lowercase letters and `-`)
109 * Add the appropriate prefix:
110 * If you develop a plugin, add `peertube-plugin-` prefix to your plugin name (for example: `peertube-plugin-mysupername`)
111 * If you develop a theme, add `peertube-theme-` prefix to your theme name (for example: `peertube-theme-mysupertheme`)
112 * Clone the quickstart repository
113 * Configure your repository
115 * Update `package.json`
116 * Register hooks, add CSS and static files
117 * Test your plugin/theme with a local PeerTube installation
118 * Publish your plugin/theme on NPM
120 ### Clone the quickstart repository
122 If you develop a plugin, clone the `peertube-plugin-quickstart` repository:
125 $ git clone https://framagit.org/framasoft/peertube/peertube-plugin-quickstart.git peertube-plugin-mysupername
128 If you develop a theme, clone the `peertube-theme-quickstart` repository:
131 $ git clone https://framagit.org/framasoft/peertube/peertube-theme-quickstart.git peertube-theme-mysupername
134 ### Configure your repository
136 Set your repository URL:
139 $ cd peertube-plugin-mysupername # or cd peertube-theme-mysupername
140 $ git remote set-url origin https://your-git-repo
145 Update `README.md` file:
151 ### Update package.json
153 Update the `package.json` fields:
154 * `name` (should start with `peertube-plugin-` or `peertube-theme-`)
159 * `engine.peertube` (the PeerTube version compatibility, must be `>=x.y.z` and nothing else)
161 **Caution:** Don't update or remove other keys, or PeerTube will not be able to index/install your plugin.
162 If you don't need static directories, use an empty `object`:
172 And if you don't need CSS files, use an empty `array`:
184 Now you can register hooks or settings, write CSS and add static directories to your plugin or your theme :)
186 **Caution:** It's up to you to check the code you write will be compatible with the PeerTube NodeJS version,
187 and will be supported by web browsers.
188 If you want to write modern JavaScript, please use a transpiler like [Babel](https://babeljs.io/).
190 ### Test your plugin/theme
192 You'll need to have a local PeerTube instance:
193 * Follow the [dev prerequisites](https://github.com/Chocobozzz/PeerTube/blob/develop/.github/CONTRIBUTING.md#prerequisites)
194 (to clone the repository, install dependencies and prepare the database)
195 * Build PeerTube (`--light` to only build the english language):
198 $ npm run build -- --light
201 * Run it (you can access to your instance on http://localhost:9000):
204 $ NODE_ENV=test npm start
207 * Register the instance via the CLI:
210 $ node ./dist/server/tools/peertube.js auth add -u 'http://localhost:9000' -U 'root' --password 'test'
213 Then, you can install or reinstall your local plugin/theme by running:
216 $ node ./dist/server/tools/peertube.js plugins install --path /your/absolute/plugin-or-theme/path
221 Go in your plugin/theme directory, and run:
227 Every time you want to publish another version of your plugin/theme, just update the `version` key from the `package.json`
228 and republish it on NPM. Remember that the PeerTube index will take into account your new plugin/theme version after ~24 hours.