# TypeScript
*.tsbuildinfo
-/types
+/types/dist/
+++ /dev/null
-export * from './types'
"stripInternal": true,
"removeComments": false,
"declaration": true,
- "outDir": "../types/client/",
+ "outDir": "../types/dist/client/",
"emitDeclarationOnly": true,
"composite": true,
"rootDir": "src/",
- "tsBuildInfoFile": "../types/client.tsbuildinfo"
+ "tsBuildInfoFile": "../types/dist/tsconfig.client.tsbuildinfo"
},
"references": [
{ "path": "../shared/tsconfig.types.json" }
],
- "files": ["src/index.ts"],
- "include": ["src/index.ts", "src/types/**/*"]
+ "files": ["src/types/index.ts"],
+ "include": ["src/**/*", "src/types/**/*"]
}
+++ /dev/null
-export * from './server/types'
"build:embed": "bash ./scripts/build/embed.sh",
"build:server": "bash ./scripts/build/server.sh",
"build:client": "bash ./scripts/build/client.sh",
- "build:types": "tsc -b --verbose tsconfig.types.json",
+ "build:types": "tsc -b --verbose types",
"clean:client": "bash ./scripts/clean/client/index.sh",
"clean:server:test": "bash ./scripts/clean/server/test.sh",
"i18n:update": "bash ./scripts/i18n/update.sh",
"test": "bash ./scripts/test.sh",
"help": "bash ./scripts/help.sh",
"generate-cli-doc": "bash ./scripts/generate-cli-doc.sh",
- "generate-types-package": "ts-node ./scripts/generate-types-package.ts",
+ "generate-types-package": "ts-node ./types/generate-package.ts",
"parse-log": "node ./dist/scripts/parse-log.js",
"prune-storage": "node ./dist/scripts/prune-storage.js",
"postinstall": "test -n \"$NOCLIENT\" || (cd client && yarn install --pure-lockfile)",
"references": [
{ "path": "../" },
],
+ "files": [],
"exclude": [ ] // Overwrite exclude property
}
{
"extends": "./tsconfig.json",
"compilerOptions": {
- "outDir": "../types/server",
+ "outDir": "../types/dist/server",
"stripInternal": true,
"removeComments": false,
"emitDeclarationOnly": true
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
- "outDir": "../dist/shared"
+ "outDir": "../dist/shared",
+
}
}
{
"extends": "./tsconfig.json",
"compilerOptions": {
- "outDir": "../types/shared",
+ "outDir": "../types/dist/shared",
"stripInternal": true,
"removeComments": false,
"emitDeclarationOnly": true
You can add __PeerTube__ types as dev dependencies:
```
-npm install --dev @peertube/peertube-types
+npm install --save-dev @peertube/peertube-types
```
This package exposes *server* definition files by default:
```ts
-import { RegisterServerOptions } from '@peertube/peertube-types'
+import { RegisterServerOptions } from '@peertube/peertube-types/server/types'
export async function register ({ registerHook }: RegisterServerOptions) {
registerHook({
But it also exposes client types and various models used in __PeerTube__:
```ts
-import { RegisterClientOptions } from '@peertube/peertube-types/client'
+import { RegisterClientOptions } from '@larriereguichet/peertube-types/client/types';
+import { Video } from '@larriereguichet/peertube-types/shared';
-export function register ({ registerHook, peertubeHelpers }: RegisterClientOptions) {
+function register({ registerHook, peertubeHelpers }: RegisterClientOptions) {
registerHook({
- target: 'action:application.init',
- handler: () => onApplicationInit(peertubeHelpers)
- })
+ 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));
+ },
+ });
}
+
+export { register };
```
> Other types are accessible from the shared path `@peertube/peertube-types/shared`.
"client/node_modules/@types"
],
"baseUrl": "./",
- "outDir": "./dist/",
"paths": {
"@server/*": [ "server/*" ],
- "@shared/*": [ "shared/*" ]
+ "@shared/*": [ "shared/*" ],
+ "@client/*": [ "client/src/*" ],
},
"resolveJsonModule": true,
"strict": false,
"paths": {
"@server/*": [ "server/*" ],
"@shared/*": [ "shared/*" ]
- }
+ },
+ "typeRoots": [
+ "server/typings",
+ "node_modules/@types"
+ ]
},
"references": [
{ "path": "./shared" },
+++ /dev/null
-{
- "extends": "./tsconfig.base.json",
- "compilerOptions": {
- "stripInternal": true,
- "removeComments": false,
- "emitDeclarationOnly": true,
- "outDir": "./types/"
- },
- "references": [
- { "path": "./shared/tsconfig.types.json" },
- { "path": "./server/tsconfig.types.json" },
- { "path": "./client/tsconfig.types.json" }
- ],
- "files": ["./index.ts"],
-}
-
--- /dev/null
+# PeerTube typings
+
+These **Typescript** *types* are mainly used to write **PeerTube** plugins.
+
+## Installation
+
+Npm:
+```
+npm install --save-dev @peertube/peertube-types
+```
+
+Yarn:
+```
+yarn add --dev @peertube/peertube-types
+```
+
+## Usage
+
+> See [contribute-plugins](https://docs.joinpeertube.org/contribute-plugins?id=typescript) **Typescript** section of the doc.
async function run () {
execSync('npm run build:types', { stdio: 'inherit' })
const typesPath = resolve(cwd(), './types/')
- const typesPackageJsonPath = resolve(typesPath, './package.json')
- const typesGitIgnorePath = resolve(typesPath, './.gitignore')
+ const typesDistPath = resolve(cwd(), typesPath, './dist/')
+ const typesDistPackageJsonPath = resolve(typesDistPath, './package.json')
+ const typesDistGitIgnorePath = resolve(typesDistPath, './.gitignore')
const mainPackageJson = await readJson(resolve(cwd(), './package.json'))
- const tsConfigPath = resolve(cwd(), './tsconfig.json')
- const tsConfig = await readJson(tsConfigPath)
+ const distTsConfigPath = resolve(cwd(), typesPath, './tsconfig.dist.json')
+ const distTsConfig = await readJson(distTsConfigPath)
const clientPackageJson = await readJson(resolve(cwd(), './client/package.json'))
const allDependencies = Object.assign(
depcheck.detector.requireCallExpression,
depcheck.detector.importDeclaration
],
- ignoreMatches: Object.keys(tsConfig?.compilerOptions?.paths || []),
+ ignoreMatches: Object.keys(distTsConfig?.compilerOptions?.paths || []),
package: { dependencies: allDependencies }
}
repository,
dependencies
}
- console.log(`Writing package.json to ${typesPackageJsonPath}`)
- await writeJSON(typesPackageJsonPath, typesPackageJson, { spaces: 2 })
+ console.log(`Writing package.json to ${typesDistPackageJsonPath}`)
+ await writeJSON(typesDistPackageJsonPath, typesPackageJson, { spaces: 2 })
- console.log(`Writing git ignore to ${typesGitIgnorePath}`)
- await writeFile(typesGitIgnorePath, '*.tsbuildinfo')
+ console.log(`Writing git ignore to ${typesDistGitIgnorePath}`)
+ await writeFile(typesDistGitIgnorePath, '*.tsbuildinfo')
console.log('Copying tsconfig files')
- await copyFile(tsConfigPath, resolve(typesPath, './tsconfig.json'))
- await copyFile(resolve(cwd(), './tsconfig.base.json'), resolve(typesPath, './tsconfig.base.json'))
- tsConfig.references.map(({ path }) => path).forEach((path) => {
- const src = resolve(cwd(), path, '/tsconfig.json')
- const dest = resolve(typesPath, path, './tsconfig.json')
- console.log(`${src} -> ${dest}`)
- copyFile(src, dest).catch((e) => console.error(e))
- })
+ 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'))
}
--- /dev/null
+export * from '@client/types'
--- /dev/null
+{
+ "extends": "../../../tsconfig.base.json",
+ "compilerOptions": {
+ "outDir": "../../dist/client/",
+ "rootDir": "./",
+ "tsBuildInfoFile": "../../dist/tsconfig.client.types.tsbuildinfo"
+ },
+ "references": [
+ { "path": "../../../client/tsconfig.types.json" }
+ ],
+ "files": ["index.ts"]
+}
--- /dev/null
+export * from '@server/types'
--- /dev/null
+{
+ "extends": "./tsconfig.base.json",
+ "compilerOptions": {
+ "typeRoots": [
+ "node_modules/@types",
+ "client/node_modules/@types"
+ ],
+ "baseUrl": "./",
+ "paths": {
+ "@server/*": [ "server/*" ],
+ "@shared/*": [ "shared/*" ],
+ "@client/*": [ "client/*" ]
+ }
+ }
+}
+
--- /dev/null
+{
+ "extends": "../tsconfig.base.json",
+ "compilerOptions": {
+ "stripInternal": true,
+ "removeComments": false,
+ "emitDeclarationOnly": true,
+ "outDir": "./dist/",
+ "baseUrl": "./src/",
+ "rootDir": "./src/",
+ "paths": {
+ "@server/*": [ "../../server/*" ],
+ "@shared/*": [ "../../shared/*" ],
+ "@client/*": [ "../../client/src/*" ],
+ }
+ },
+ "references": [
+ { "path": "../shared/tsconfig.types.json" },
+ { "path": "../server/tsconfig.types.json" },
+ { "path": "./src/client/tsconfig.json" }
+ ],
+ "files": ["./src/index.ts"],
+}
+