strategy:
fail-fast: false
matrix:
- test_suite: [ client, api-1, api-2, api-3, api-4, cli-plugin, lint, external-plugins ]
+ test_suite: [ types, client, api-1, api-2, api-3, api-4, cli-plugin, lint, external-plugins ]
env:
PGUSER: peertube
"nodemon": "nodemon",
"ts-node": "ts-node",
"eslint": "eslint",
+ "resolve-tspaths": "resolve-tspaths",
"concurrently": "concurrently",
"mocha": "mocha",
"ci": "bash ./scripts/ci.sh",
"mocha": "^9.0.0",
"nodemon": "^2.0.1",
"proxy": "^1.0.2",
+ "resolve-tspaths": "^0.1.2",
"socket.io-client": "^4.0.1",
"source-map-support": "^0.5.0",
"supertest": "^6.0.1",
find $1 -type f -name "*.js" $exception | xargs echo
}
-if [ "$1" = "client" ]; then
+if [ "$1" = "types" ]; then
+ npm run generate-types-package
+ npm run tsc -- --noEmit --esModuleInterop types/tests/test.ts
+elif [ "$1" = "client" ]; then
npm run build
feedsFiles=$(findTestFiles ./dist/server/tests/feeds)
# Release types package
npm run generate-types-package
-cd types
+cd types/dist
npm publish --access public
set -eu
+npm run ci -- types
npm run ci -- client
npm run ci -- cli-plugin
npm run ci -- api-1
- [Update README](#update-readme)
- [Update package.json](#update-packagejson)
- [Write code](#write-code)
- - [Typescript](#typescript)
- [Add translations](#add-translations)
- [Build your plugin](#build-your-plugin)
- [Test your plugin/theme](#test-your-plugintheme)
### Write code
Now you can register hooks or settings, write CSS and add static directories to your plugin or your theme :)
+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.
+
+**JavaScript**
-**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
+**Typescript**
+
+If you want to use __Typescript__, you can add __PeerTube__ types as dev dependencies:
-You can add __PeerTube__ types as dev dependencies:
```
npm install --save-dev @peertube/peertube-types
```
This package exposes *server* definition files by default:
```ts
-import { RegisterServerOptions } from '@peertube/peertube-types/server/types'
+import { RegisterServerOptions } from '@peertube/peertube-types'
export async function register ({ registerHook }: RegisterServerOptions) {
registerHook({
But it also exposes client types and various models used in __PeerTube__:
```ts
-import { RegisterClientOptions } from '@larriereguichet/peertube-types/client/types';
-import { Video } from '@larriereguichet/peertube-types/shared';
+import { Video } from '@peertube/peertube-types';
+import { RegisterClientOptions } from '@peertube/peertube-types/client';
function register({ registerHook, peertubeHelpers }: RegisterClientOptions) {
registerHook({
fetch(`${peertubeHelpers.getBaseRouterRoute()}/videos/${video.uuid}/captions`, {
method: 'PUT',
headers: peertubeHelpers.getAuthHeader(),
- })
- .then((res) => res.json())
- .then((data) => console.log('Hi %s.', data));
+ }).then((res) => res.json())
+ .then((data) => console.log('Hi %s.', data));
},
});
}
export { register };
```
-> Other types are accessible from the shared path `@peertube/peertube-types/shared`.
### Add translations
"paths": {
"@server/*": [ "server/*" ],
"@shared/*": [ "shared/*" ],
- "@client/*": [ "client/src/*" ],
+ "@client/*": [ "client/src/*" ]
},
"resolveJsonModule": true,
"strict": false,
await remove(typesDistPath)
execSync('npm run tsc -- -b --verbose types', { stdio: 'inherit' })
+ execSync(`npm run resolve-tspaths -- --project ${distTsConfigPath} --src ${typesDistPath} --out ${typesDistPath}`, { stdio: 'inherit' })
const allDependencies = Object.assign(
mainPackageJson.dependencies,
console.log(`Writing git ignore to ${typesDistGitIgnorePath}`)
await writeFile(typesDistGitIgnorePath, '*.tsbuildinfo')
- console.log('Copying tsconfig files')
- await copyFile(distTsConfigPath, resolve(typesDistPath, './tsconfig.json'))
- await copyFile(resolve(cwd(), './tsconfig.base.json'), resolve(typesDistPath, './tsconfig.base.json'))
-
await copyFile(resolve(typesPath, './README.md'), resolve(typesDistPath, './README.md'))
}
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
+ "stripInternal": true,
+ "removeComments": false,
+ "emitDeclarationOnly": true,
"outDir": "../../dist/client/",
"rootDir": "./",
"tsBuildInfoFile": "../../dist/tsconfig.client.types.tsbuildinfo"
export * from '@server/types'
+export * from '@server/types/models'
+export * from '@shared/models'
--- /dev/null
+import { RegisterServerOptions, Video } from '../dist'
+import { RegisterClientOptions } from '../dist/client'
+
+function register1 ({ registerHook }: RegisterServerOptions) {
+ registerHook({
+ target: 'action:application.listening',
+ handler: () => console.log('hello')
+ })
+}
+
+function register2 ({ registerHook, peertubeHelpers }: RegisterClientOptions) {
+ registerHook({
+ target: 'action:admin-plugin-settings.init',
+ handler: ({ npmName }: { npmName: string }) => {
+ if ('peertube-plugin-transcription' !== npmName) {
+ return
+ }
+ },
+ })
+
+ registerHook({
+ target: 'action:video-watch.video.loaded',
+ handler: ({ video }: { video: Video }) => {
+ fetch(`${peertubeHelpers.getBaseRouterRoute()}/videos/${video.uuid}/captions`, {
+ method: 'PUT',
+ headers: peertubeHelpers.getAuthHeader(),
+ })
+ .then((res) => res.json())
+ .then((data) => console.log('Hi %s.', data))
+ },
+ })
+}
"node_modules/@types",
"client/node_modules/@types"
],
- "baseUrl": "./",
+ "baseUrl": "./dist",
"paths": {
"@server/*": [ "server/*" ],
"@shared/*": [ "shared/*" ],
"outDir": "./dist/",
"baseUrl": "./src/",
"rootDir": "./src/",
+ "tsBuildInfoFile": "./dist/tsconfig.server.types.tsbuildinfo",
"paths": {
"@server/*": [ "../../server/*" ],
"@shared/*": [ "../../shared/*" ],
- "@client/*": [ "../../client/src/*" ],
+ "@client/*": [ "../../client/src/*" ]
}
},
"references": [
{ "path": "../server/tsconfig.types.json" },
{ "path": "./src/client/tsconfig.json" }
],
- "files": ["./src/index.ts"],
+ "files": ["./src/index.ts"]
}
-
dependencies:
delayed-stream "~1.0.0"
+commander@8.2.0:
+ version "8.2.0"
+ resolved "https://registry.yarnpkg.com/commander/-/commander-8.2.0.tgz#37fe2bde301d87d47a53adeff8b5915db1381ca8"
+ integrity sha512-LLKxDvHeL91/8MIyTAD5BFMNtoIwztGPMiM/7Bl8rIPmHCZXRxmSWr91h57dpOpnQ6jIUqEWdXE/uBYMfiVZDA==
+
commander@^2.19.0, commander@^2.7.1:
version "2.20.3"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
resolved "https://registry.yarnpkg.com/fast-fifo/-/fast-fifo-1.0.0.tgz#9bc72e6860347bb045a876d1c5c0af11e9b984e7"
integrity sha512-4VEXmjxLj7sbs8J//cn2qhRap50dGzF5n8fjay8mau+Jn4hxSeR3xPFwxMaQq/pDaq7+KQk0PAbC2+nWDkJrmQ==
-fast-glob@^3.1.1:
+fast-glob@3.2.7, fast-glob@^3.1.1:
version "3.2.7"
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.7.tgz#fd6cb7a2d7e9aa7a7846111e85a196d6b2f766a1"
integrity sha512-rYGMRwip6lUMvYD3BTScMwT1HtAs2d71SMv66Vrxs0IekGZEjhM0pcMfjQPnknBt2zeCwQMEupiN02ZP4DiT1Q==
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-4.0.0.tgz#4abcd852ad32dd7baabfe9b40e00a36db5f392e6"
integrity sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==
+resolve-tspaths@^0.1.2:
+ version "0.1.2"
+ resolved "https://registry.yarnpkg.com/resolve-tspaths/-/resolve-tspaths-0.1.2.tgz#621c78f2372dea919f7cecf4f228e7fd6dbd8d45"
+ integrity sha512-HBU+9gBL/CWzCXudGVJAOGph9xspBShW2Ay8cngXMB8fLBkv8Oz/yoe/LC9cCAzuZouul9YNRyKQKdr/GEFR3w==
+ dependencies:
+ ansi-colors "4.1.1"
+ commander "8.2.0"
+ fast-glob "3.2.7"
+
resolve@^1.10.1, resolve@^1.15.1, resolve@^1.18.1, resolve@^1.20.0:
version "1.20.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.20.0.tgz#629a013fb3f70755d6f0b7935cc1c2c5378b1975"