feat(types): create peertube-types package

Create dedicated Typescript "types" configuration file for each "projects".
Create a types folder which includes every useful ts definition:
- client
- server
- shared
Add tooling to create a proper package, extract dependencies, etc...
Add CI Github task.

refactor(types): publish types package in release script
This commit is contained in:
lutangar
2021-11-09 13:49:08 +01:00
committed by Chocobozzz
parent 06aad80165
commit 8b03e2ce1a
18 changed files with 544 additions and 18 deletions

View File

@@ -8,3 +8,16 @@
$ cd client/src/standalone/player/
$ npm run build
```
## @peertube/peertube-types
Typescript definition files generation is controlled by the various `tsconfig.types.json` files, see:
```
yarn tsc -b --verbose tsconfig.types.json
```
But the complete types package is generated via:
```
yarn generate-types-package
```
> See [scripts/generate-types-package.ts](scripts/generate-types-package.ts) for details.

View File

@@ -883,6 +883,39 @@ Now you can register hooks or settings, write CSS and add static directories to
**Caution:** It's up to you to check the code you write will be compatible with the PeerTube NodeJS version,
and will be supported by web browsers.
If you want to write modern JavaScript, please use a transpiler like [Babel](https://babeljs.io/).
If you want to use __Typescript__ see section below.
### Typescript
You can add __PeerTube__ types as dev dependencies:
```
npm install --dev @peertube/peertube-types
```
This package exposes *server* definition files by default:
```ts
import { RegisterServerOptions } from '@peertube/peertube-types'
export async function register ({ registerHook }: RegisterServerOptions) {
registerHook({
target: 'action:application.listening',
handler: () => displayHelloWorld()
})
}
```
But it also exposes client types and various models used in __PeerTube__:
```ts
import { RegisterClientOptions } from '@peertube/peertube-types/client'
export function register ({ registerHook, peertubeHelpers }: RegisterClientOptions) {
registerHook({
target: 'action:application.init',
handler: () => onApplicationInit(peertubeHelpers)
})
}
```
> Other types are accessible from the shared path `@peertube/peertube-types/shared`.
### Add translations