Add client hook/register typings
authorChocobozzz <me@florianbigard.com>
Wed, 24 Jul 2019 09:55:08 +0000 (11:55 +0200)
committerChocobozzz <me@florianbigard.com>
Wed, 24 Jul 2019 09:55:08 +0000 (11:55 +0200)
.github/CONTRIBUTING.md
client/src/app/core/plugins/plugin.service.ts
client/src/types/client-script.model.ts [new file with mode: 0644]
client/src/types/register-client-option.model.ts [new file with mode: 0644]
support/doc/plugins/guide.md

index 1672ebfa9b7523eee8982f9f6cb9b32f6b6650c0..6fc80b6aa2d695332492ba3bee4b0bc031c01db1 100644 (file)
@@ -7,8 +7,9 @@ Interested in contributing? Awesome!
   * [Translate](#translate)
   * [Give your feedback](#give-your-feedback)
   * [Write documentation](#write-documentation)
-  * [Develop](#develop)
   * [Improve the website](#improve-the-website)
+  * [Develop](#develop)
+  * [Write a plugin or a theme](#plugins--themes)
 
 ## Translate
 
@@ -199,3 +200,7 @@ $ npm run mocha -- --exit --require ts-node/register/type-check --bail server/te
 
 Instance configurations are in `config/test-{1,2,3,4,5,6}.yaml`.
 Note that only instance 2 has transcoding enabled.
+
+## Plugins & Themes
+
+See the dedicated documentation: https://docs.joinpeertube.org/#/contribute-plugins
index e4a73de81d2de717f0823b3a60ff7c3a56025bc1..1294edd7d2375987299f7a63de4e32548795abbc 100644 (file)
@@ -3,6 +3,7 @@ import { Router } from '@angular/router'
 import { ServerConfigPlugin } from '@shared/models'
 import { ServerService } from '@app/core/server/server.service'
 import { ClientScript } from '@shared/models/plugins/plugin-package-json.model'
+import { ClientScript as ClientScriptModule } from '../../../types/client-script.model'
 import { environment } from '../../../environments/environment'
 import { ReplaySubject } from 'rxjs'
 import { first, shareReplay } from 'rxjs/operators'
@@ -186,7 +187,7 @@ export class PluginService implements ClientHook {
     console.log('Loading script %s of plugin %s.', clientScript.script, plugin.name)
 
     return import(/* webpackIgnore: true */ clientScript.script)
-      .then(script => script.register({ registerHook, peertubeHelpers }))
+      .then((script: ClientScriptModule) => script.register({ registerHook, peertubeHelpers }))
       .then(() => this.sortHooksByPriority())
   }
 
diff --git a/client/src/types/client-script.model.ts b/client/src/types/client-script.model.ts
new file mode 100644 (file)
index 0000000..6197fca
--- /dev/null
@@ -0,0 +1,7 @@
+import { RegisterClientOptions } from './register-client-option.model'
+
+export interface ClientScript {
+  register: (options: RegisterClientOptions) => Promise<any>
+
+  unregister: () => Promise<any>
+}
diff --git a/client/src/types/register-client-option.model.ts b/client/src/types/register-client-option.model.ts
new file mode 100644 (file)
index 0000000..42d6894
--- /dev/null
@@ -0,0 +1,9 @@
+import { RegisterClientHookOptions } from '@shared/models/plugins/register-client-hook.model'
+
+export type RegisterClientOptions = {
+  registerHook: (options: RegisterClientHookOptions) => void
+
+  peertubeHelpers: {
+    getBaseStaticRoute: () => string
+  }
+}
index 0b2d337eb95d1e0723defff4c8258bf0ac6c298e..8f8884d005eda6619c7b282167e47d1d4b41589d 100644 (file)
@@ -262,6 +262,11 @@ Every time you want to publish another version of your plugin/theme, just update
 and republish it on NPM. Remember that the PeerTube index will take into account your new plugin/theme version after ~24 hours.
 
 
+## Plugin & Theme hooks/helpers API
+
+See the dedicated documentation: https://docs.joinpeertube.org/#/api-plugins
+
+
 ## Tips
 
 ### Compatibility with PeerTube