aboutsummaryrefslogtreecommitdiffhomepage
path: root/support/doc/plugins/quickstart.md
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-23 11:23:25 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-07-24 10:58:16 +0200
commitd8e9a42c4b048b2669ab6a61704682ce23fbcf99 (patch)
treee54af7ea903ab04728832f1451141050f0986f54 /support/doc/plugins/quickstart.md
parent7c421bb19809c4b0223d9e082d52d125fbe95f2a (diff)
downloadPeerTube-d8e9a42c4b048b2669ab6a61704682ce23fbcf99.tar.gz
PeerTube-d8e9a42c4b048b2669ab6a61704682ce23fbcf99.tar.zst
PeerTube-d8e9a42c4b048b2669ab6a61704682ce23fbcf99.zip
Update plugin guide
Diffstat (limited to 'support/doc/plugins/quickstart.md')
-rw-r--r--support/doc/plugins/quickstart.md237
1 files changed, 0 insertions, 237 deletions
diff --git a/support/doc/plugins/quickstart.md b/support/doc/plugins/quickstart.md
deleted file mode 100644
index 0e125e707..000000000
--- a/support/doc/plugins/quickstart.md
+++ /dev/null
@@ -1,237 +0,0 @@
1# Plugins & Themes
2
3## Concepts
4
5Themes 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
9
10### Hooks
11
12A 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
17
18Example:
19
20```js
21// This register function is called by PeerTube, and **must** return a promise
22async function register ({ registerHook }) {
23 registerHook({
24 target: 'action:application.listening',
25 handler: () => displayHelloWorld()
26 })
27}
28```
29
30On server side, these hooks are registered by the `library` file defined in `package.json`.
31
32```json
33{
34 ...,
35 "library": "./main.js",
36 ...,
37}
38```
39
40
41On client side, these hooks are registered by the `clientScripts` files defined in `package.json`.
42All client scripts have scopes so PeerTube client only loads scripts it needs:
43
44```json
45{
46 ...,
47 "clientScripts": [
48 {
49 "script": "client/common-client-plugin.js",
50 "scopes": [ "common" ]
51 },
52 {
53 "script": "client/video-watch-client-plugin.js",
54 "scopes": [ "video-watch" ]
55 }
56 ],
57 ...
58}
59```
60
61### Static files
62
63Plugins can declare static directories that PeerTube will serve (images for example)
64from `/plugins/{plugin-name}/{plugin-version}/static/`
65or `/themes/{theme-name}/{theme-version}/static/` routes.
66
67### CSS
68
69Plugins can declare CSS files that PeerTube will automatically inject in the client.
70
71### Server helpers (only for plugins)
72
73#### Settings
74
75Plugins can register settings, that PeerTube will inject in the administration interface.
76
77Example:
78
79```js
80registerSetting({
81 name: 'admin-name',
82 label: 'Admin name',
83 type: 'input',
84 default: 'my super name'
85})
86
87const adminName = await settingsManager.getSetting('admin-name')
88```
89
90##### Storage
91
92Plugins can store/load JSON data, that PeerTube will store in its database (so don't put files in there).
93
94Example:
95
96```js
97const value = await storageManager.getData('mykey')
98await storageManager.storeData('mykey', { subkey: 'value' })
99```
100
101### Publishing
102
103PeerTube plugins and themes should be published on [NPM](https://www.npmjs.com/) so that PeerTube indexes
104take 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
106## Write a plugin/theme
107
108Steps:
109 * Find a name for your plugin or your theme (must not have spaces, it can only contain lowercase letters and `-`)
110 * Add the appropriate prefix:
111 * If you develop a plugin, add `peertube-plugin-` prefix to your plugin name (for example: `peertube-plugin-mysupername`)
112 * If you develop a theme, add `peertube-theme-` prefix to your theme name (for example: `peertube-theme-mysupertheme`)
113 * Clone the quickstart repository
114 * Configure your repository
115 * Update `README.md`
116 * Update `package.json`
117 * Register hooks, add CSS and static files
118 * Test your plugin/theme with a local PeerTube installation
119 * Publish your plugin/theme on NPM
120
121### Clone the quickstart repository
122
123If you develop a plugin, clone the `peertube-plugin-quickstart` repository:
124
125```
126$ git clone https://framagit.org/framasoft/peertube/peertube-plugin-quickstart.git peertube-plugin-mysupername
127```
128
129If you develop a theme, clone the `peertube-theme-quickstart` repository:
130
131```
132$ git clone https://framagit.org/framasoft/peertube/peertube-theme-quickstart.git peertube-theme-mysupername
133```
134
135### Configure your repository
136
137Set your repository URL:
138
139```
140$ cd peertube-plugin-mysupername # or cd peertube-theme-mysupername
141$ git remote set-url origin https://your-git-repo
142```
143
144### Update README
145
146Update `README.md` file:
147
148```
149$ $EDITOR README.md
150```
151
152### Update package.json
153
154Update the `package.json` fields:
155 * `name` (should start with `peertube-plugin-` or `peertube-theme-`)
156 * `description`
157 * `homepage`
158 * `author`
159 * `bugs`
160 * `engine.peertube` (the PeerTube version compatibility, must be `>=x.y.z` and nothing else)
161
162**Caution:** Don't update or remove other keys, or PeerTube will not be able to index/install your plugin.
163If you don't need static directories, use an empty `object`:
164
165```json
166{
167 ...,
168 "staticDirs": {},
169 ...
170}
171```
172
173And if you don't need CSS or client script files, use an empty `array`:
174
175```json
176{
177 ...,
178 "css": [],
179 "clientScripts": [],
180 ...
181}
182```
183
184### Write code
185
186Now you can register hooks or settings, write CSS and add static directories to your plugin or your theme :)
187
188**Caution:** It's up to you to check the code you write will be compatible with the PeerTube NodeJS version,
189and will be supported by web browsers.
190If you want to write modern JavaScript, please use a transpiler like [Babel](https://babeljs.io/).
191
192### Test your plugin/theme
193
194You'll need to have a local PeerTube instance:
195 * Follow the [dev prerequisites](https://github.com/Chocobozzz/PeerTube/blob/develop/.github/CONTRIBUTING.md#prerequisites)
196 (to clone the repository, install dependencies and prepare the database)
197 * Build PeerTube (`--light` to only build the english language):
198
199```
200$ npm run build -- --light
201```
202
203 * Build the CLI:
204
205```
206$ npm run setup:cli
207```
208
209 * Run PeerTube (you can access to your instance on http://localhost:9000):
210
211```
212$ NODE_ENV=test npm start
213```
214
215 * Register the instance via the CLI:
216
217```
218$ node ./dist/server/tools/peertube.js auth add -u 'http://localhost:9000' -U 'root' --password 'test'
219```
220
221Then, you can install or reinstall your local plugin/theme by running:
222
223```
224$ node ./dist/server/tools/peertube.js plugins install --path /your/absolute/plugin-or-theme/path
225```
226
227### Publish
228
229Go in your plugin/theme directory, and run:
230
231```
232$ npm publish
233```
234
235Every time you want to publish another version of your plugin/theme, just update the `version` key from the `package.json`
236and republish it on NPM. Remember that the PeerTube index will take into account your new plugin/theme version after ~24 hours.
237