diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | client/src/index.ts | 1 | ||||
-rw-r--r-- | client/tsconfig.types.json | 8 | ||||
-rw-r--r-- | index.ts | 1 | ||||
-rw-r--r-- | package.json | 4 | ||||
-rw-r--r-- | server/tools/tsconfig.json | 1 | ||||
-rw-r--r-- | server/tsconfig.types.json | 2 | ||||
-rw-r--r-- | shared/tsconfig.json | 3 | ||||
-rw-r--r-- | shared/tsconfig.types.json | 2 | ||||
-rw-r--r-- | support/doc/plugins/guide.md | 33 | ||||
-rw-r--r-- | tsconfig.base.json | 4 | ||||
-rw-r--r-- | tsconfig.json | 6 | ||||
-rw-r--r-- | tsconfig.types.json | 16 | ||||
-rw-r--r-- | types/README.md | 19 | ||||
-rw-r--r-- | types/generate-package.ts (renamed from scripts/generate-types-package.ts) | 31 | ||||
-rw-r--r-- | types/src/client/index.ts | 1 | ||||
-rw-r--r-- | types/src/client/tsconfig.json | 12 | ||||
-rw-r--r-- | types/src/index.ts | 1 | ||||
-rw-r--r-- | types/tsconfig.dist.json | 16 | ||||
-rw-r--r-- | types/tsconfig.json | 23 |
20 files changed, 131 insertions, 55 deletions
diff --git a/.gitignore b/.gitignore index ac1d6a99a..0ec17217d 100644 --- a/.gitignore +++ b/.gitignore | |||
@@ -53,4 +53,4 @@ yarn-error.log | |||
53 | 53 | ||
54 | # TypeScript | 54 | # TypeScript |
55 | *.tsbuildinfo | 55 | *.tsbuildinfo |
56 | /types | 56 | /types/dist/ |
diff --git a/client/src/index.ts b/client/src/index.ts deleted file mode 100644 index c9f6f047d..000000000 --- a/client/src/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './types' | ||
diff --git a/client/tsconfig.types.json b/client/tsconfig.types.json index 35a5e92cc..1f5c86161 100644 --- a/client/tsconfig.types.json +++ b/client/tsconfig.types.json | |||
@@ -4,15 +4,15 @@ | |||
4 | "stripInternal": true, | 4 | "stripInternal": true, |
5 | "removeComments": false, | 5 | "removeComments": false, |
6 | "declaration": true, | 6 | "declaration": true, |
7 | "outDir": "../types/client/", | 7 | "outDir": "../types/dist/client/", |
8 | "emitDeclarationOnly": true, | 8 | "emitDeclarationOnly": true, |
9 | "composite": true, | 9 | "composite": true, |
10 | "rootDir": "src/", | 10 | "rootDir": "src/", |
11 | "tsBuildInfoFile": "../types/client.tsbuildinfo" | 11 | "tsBuildInfoFile": "../types/dist/tsconfig.client.tsbuildinfo" |
12 | }, | 12 | }, |
13 | "references": [ | 13 | "references": [ |
14 | { "path": "../shared/tsconfig.types.json" } | 14 | { "path": "../shared/tsconfig.types.json" } |
15 | ], | 15 | ], |
16 | "files": ["src/index.ts"], | 16 | "files": ["src/types/index.ts"], |
17 | "include": ["src/index.ts", "src/types/**/*"] | 17 | "include": ["src/**/*", "src/types/**/*"] |
18 | } | 18 | } |
diff --git a/index.ts b/index.ts deleted file mode 100644 index 4c65e3d02..000000000 --- a/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './server/types' | ||
diff --git a/package.json b/package.json index 7bfe8aadc..88d8329e6 100644 --- a/package.json +++ b/package.json | |||
@@ -29,7 +29,7 @@ | |||
29 | "build:embed": "bash ./scripts/build/embed.sh", | 29 | "build:embed": "bash ./scripts/build/embed.sh", |
30 | "build:server": "bash ./scripts/build/server.sh", | 30 | "build:server": "bash ./scripts/build/server.sh", |
31 | "build:client": "bash ./scripts/build/client.sh", | 31 | "build:client": "bash ./scripts/build/client.sh", |
32 | "build:types": "tsc -b --verbose tsconfig.types.json", | 32 | "build:types": "tsc -b --verbose types", |
33 | "clean:client": "bash ./scripts/clean/client/index.sh", | 33 | "clean:client": "bash ./scripts/clean/client/index.sh", |
34 | "clean:server:test": "bash ./scripts/clean/server/test.sh", | 34 | "clean:server:test": "bash ./scripts/clean/server/test.sh", |
35 | "i18n:update": "bash ./scripts/i18n/update.sh", | 35 | "i18n:update": "bash ./scripts/i18n/update.sh", |
@@ -53,7 +53,7 @@ | |||
53 | "test": "bash ./scripts/test.sh", | 53 | "test": "bash ./scripts/test.sh", |
54 | "help": "bash ./scripts/help.sh", | 54 | "help": "bash ./scripts/help.sh", |
55 | "generate-cli-doc": "bash ./scripts/generate-cli-doc.sh", | 55 | "generate-cli-doc": "bash ./scripts/generate-cli-doc.sh", |
56 | "generate-types-package": "ts-node ./scripts/generate-types-package.ts", | 56 | "generate-types-package": "ts-node ./types/generate-package.ts", |
57 | "parse-log": "node ./dist/scripts/parse-log.js", | 57 | "parse-log": "node ./dist/scripts/parse-log.js", |
58 | "prune-storage": "node ./dist/scripts/prune-storage.js", | 58 | "prune-storage": "node ./dist/scripts/prune-storage.js", |
59 | "postinstall": "test -n \"$NOCLIENT\" || (cd client && yarn install --pure-lockfile)", | 59 | "postinstall": "test -n \"$NOCLIENT\" || (cd client && yarn install --pure-lockfile)", |
diff --git a/server/tools/tsconfig.json b/server/tools/tsconfig.json index 575133ec8..61e6b8739 100644 --- a/server/tools/tsconfig.json +++ b/server/tools/tsconfig.json | |||
@@ -7,5 +7,6 @@ | |||
7 | "references": [ | 7 | "references": [ |
8 | { "path": "../" }, | 8 | { "path": "../" }, |
9 | ], | 9 | ], |
10 | "files": [], | ||
10 | "exclude": [ ] // Overwrite exclude property | 11 | "exclude": [ ] // Overwrite exclude property |
11 | } | 12 | } |
diff --git a/server/tsconfig.types.json b/server/tsconfig.types.json index 26697bd45..824834066 100644 --- a/server/tsconfig.types.json +++ b/server/tsconfig.types.json | |||
@@ -1,7 +1,7 @@ | |||
1 | { | 1 | { |
2 | "extends": "./tsconfig.json", | 2 | "extends": "./tsconfig.json", |
3 | "compilerOptions": { | 3 | "compilerOptions": { |
4 | "outDir": "../types/server", | 4 | "outDir": "../types/dist/server", |
5 | "stripInternal": true, | 5 | "stripInternal": true, |
6 | "removeComments": false, | 6 | "removeComments": false, |
7 | "emitDeclarationOnly": true | 7 | "emitDeclarationOnly": true |
diff --git a/shared/tsconfig.json b/shared/tsconfig.json index 95892077b..88107e27f 100644 --- a/shared/tsconfig.json +++ b/shared/tsconfig.json | |||
@@ -1,6 +1,7 @@ | |||
1 | { | 1 | { |
2 | "extends": "../tsconfig.base.json", | 2 | "extends": "../tsconfig.base.json", |
3 | "compilerOptions": { | 3 | "compilerOptions": { |
4 | "outDir": "../dist/shared" | 4 | "outDir": "../dist/shared", |
5 | |||
5 | } | 6 | } |
6 | } | 7 | } |
diff --git a/shared/tsconfig.types.json b/shared/tsconfig.types.json index 18c470059..b01d12e53 100644 --- a/shared/tsconfig.types.json +++ b/shared/tsconfig.types.json | |||
@@ -1,7 +1,7 @@ | |||
1 | { | 1 | { |
2 | "extends": "./tsconfig.json", | 2 | "extends": "./tsconfig.json", |
3 | "compilerOptions": { | 3 | "compilerOptions": { |
4 | "outDir": "../types/shared", | 4 | "outDir": "../types/dist/shared", |
5 | "stripInternal": true, | 5 | "stripInternal": true, |
6 | "removeComments": false, | 6 | "removeComments": false, |
7 | "emitDeclarationOnly": true | 7 | "emitDeclarationOnly": true |
diff --git a/support/doc/plugins/guide.md b/support/doc/plugins/guide.md index 5c96d1b03..92cc20db0 100644 --- a/support/doc/plugins/guide.md +++ b/support/doc/plugins/guide.md | |||
@@ -889,12 +889,12 @@ If you want to use __Typescript__ see section below. | |||
889 | 889 | ||
890 | You can add __PeerTube__ types as dev dependencies: | 890 | You can add __PeerTube__ types as dev dependencies: |
891 | ``` | 891 | ``` |
892 | npm install --dev @peertube/peertube-types | 892 | npm install --save-dev @peertube/peertube-types |
893 | ``` | 893 | ``` |
894 | 894 | ||
895 | This package exposes *server* definition files by default: | 895 | This package exposes *server* definition files by default: |
896 | ```ts | 896 | ```ts |
897 | import { RegisterServerOptions } from '@peertube/peertube-types' | 897 | import { RegisterServerOptions } from '@peertube/peertube-types/server/types' |
898 | 898 | ||
899 | export async function register ({ registerHook }: RegisterServerOptions) { | 899 | export async function register ({ registerHook }: RegisterServerOptions) { |
900 | registerHook({ | 900 | registerHook({ |
@@ -906,14 +906,33 @@ export async function register ({ registerHook }: RegisterServerOptions) { | |||
906 | 906 | ||
907 | But it also exposes client types and various models used in __PeerTube__: | 907 | But it also exposes client types and various models used in __PeerTube__: |
908 | ```ts | 908 | ```ts |
909 | import { RegisterClientOptions } from '@peertube/peertube-types/client' | 909 | import { RegisterClientOptions } from '@larriereguichet/peertube-types/client/types'; |
910 | import { Video } from '@larriereguichet/peertube-types/shared'; | ||
910 | 911 | ||
911 | export function register ({ registerHook, peertubeHelpers }: RegisterClientOptions) { | 912 | function register({ registerHook, peertubeHelpers }: RegisterClientOptions) { |
912 | registerHook({ | 913 | registerHook({ |
913 | target: 'action:application.init', | 914 | target: 'action:admin-plugin-settings.init', |
914 | handler: () => onApplicationInit(peertubeHelpers) | 915 | handler: ({ npmName }: { npmName: string }) => { |
915 | }) | 916 | if ('peertube-plugin-transcription' !== npmName) { |
917 | return; | ||
918 | } | ||
919 | }, | ||
920 | }); | ||
921 | |||
922 | registerHook({ | ||
923 | target: 'action:video-watch.video.loaded', | ||
924 | handler: ({ video }: { video: Video }) => { | ||
925 | fetch(`${peertubeHelpers.getBaseRouterRoute()}/videos/${video.uuid}/captions`, { | ||
926 | method: 'PUT', | ||
927 | headers: peertubeHelpers.getAuthHeader(), | ||
928 | }) | ||
929 | .then((res) => res.json()) | ||
930 | .then((data) => console.log('Hi %s.', data)); | ||
931 | }, | ||
932 | }); | ||
916 | } | 933 | } |
934 | |||
935 | export { register }; | ||
917 | ``` | 936 | ``` |
918 | > Other types are accessible from the shared path `@peertube/peertube-types/shared`. | 937 | > Other types are accessible from the shared path `@peertube/peertube-types/shared`. |
919 | 938 | ||
diff --git a/tsconfig.base.json b/tsconfig.base.json index 349c4de6c..f579c703a 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json | |||
@@ -24,10 +24,10 @@ | |||
24 | "client/node_modules/@types" | 24 | "client/node_modules/@types" |
25 | ], | 25 | ], |
26 | "baseUrl": "./", | 26 | "baseUrl": "./", |
27 | "outDir": "./dist/", | ||
28 | "paths": { | 27 | "paths": { |
29 | "@server/*": [ "server/*" ], | 28 | "@server/*": [ "server/*" ], |
30 | "@shared/*": [ "shared/*" ] | 29 | "@shared/*": [ "shared/*" ], |
30 | "@client/*": [ "client/src/*" ], | ||
31 | }, | 31 | }, |
32 | "resolveJsonModule": true, | 32 | "resolveJsonModule": true, |
33 | "strict": false, | 33 | "strict": false, |
diff --git a/tsconfig.json b/tsconfig.json index 8f1d5b6fb..cb7937f99 100644 --- a/tsconfig.json +++ b/tsconfig.json | |||
@@ -6,7 +6,11 @@ | |||
6 | "paths": { | 6 | "paths": { |
7 | "@server/*": [ "server/*" ], | 7 | "@server/*": [ "server/*" ], |
8 | "@shared/*": [ "shared/*" ] | 8 | "@shared/*": [ "shared/*" ] |
9 | } | 9 | }, |
10 | "typeRoots": [ | ||
11 | "server/typings", | ||
12 | "node_modules/@types" | ||
13 | ] | ||
10 | }, | 14 | }, |
11 | "references": [ | 15 | "references": [ |
12 | { "path": "./shared" }, | 16 | { "path": "./shared" }, |
diff --git a/tsconfig.types.json b/tsconfig.types.json deleted file mode 100644 index b6898e294..000000000 --- a/tsconfig.types.json +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | { | ||
2 | "extends": "./tsconfig.base.json", | ||
3 | "compilerOptions": { | ||
4 | "stripInternal": true, | ||
5 | "removeComments": false, | ||
6 | "emitDeclarationOnly": true, | ||
7 | "outDir": "./types/" | ||
8 | }, | ||
9 | "references": [ | ||
10 | { "path": "./shared/tsconfig.types.json" }, | ||
11 | { "path": "./server/tsconfig.types.json" }, | ||
12 | { "path": "./client/tsconfig.types.json" } | ||
13 | ], | ||
14 | "files": ["./index.ts"], | ||
15 | } | ||
16 | |||
diff --git a/types/README.md b/types/README.md new file mode 100644 index 000000000..adeca48e5 --- /dev/null +++ b/types/README.md | |||
@@ -0,0 +1,19 @@ | |||
1 | # PeerTube typings | ||
2 | |||
3 | These **Typescript** *types* are mainly used to write **PeerTube** plugins. | ||
4 | |||
5 | ## Installation | ||
6 | |||
7 | Npm: | ||
8 | ``` | ||
9 | npm install --save-dev @peertube/peertube-types | ||
10 | ``` | ||
11 | |||
12 | Yarn: | ||
13 | ``` | ||
14 | yarn add --dev @peertube/peertube-types | ||
15 | ``` | ||
16 | |||
17 | ## Usage | ||
18 | |||
19 | > See [contribute-plugins](https://docs.joinpeertube.org/contribute-plugins?id=typescript) **Typescript** section of the doc. | ||
diff --git a/scripts/generate-types-package.ts b/types/generate-package.ts index 3543fa472..e0bdd721a 100644 --- a/scripts/generate-types-package.ts +++ b/types/generate-package.ts | |||
@@ -14,11 +14,12 @@ run() | |||
14 | async function run () { | 14 | async function run () { |
15 | execSync('npm run build:types', { stdio: 'inherit' }) | 15 | execSync('npm run build:types', { stdio: 'inherit' }) |
16 | const typesPath = resolve(cwd(), './types/') | 16 | const typesPath = resolve(cwd(), './types/') |
17 | const typesPackageJsonPath = resolve(typesPath, './package.json') | 17 | const typesDistPath = resolve(cwd(), typesPath, './dist/') |
18 | const typesGitIgnorePath = resolve(typesPath, './.gitignore') | 18 | const typesDistPackageJsonPath = resolve(typesDistPath, './package.json') |
19 | const typesDistGitIgnorePath = resolve(typesDistPath, './.gitignore') | ||
19 | const mainPackageJson = await readJson(resolve(cwd(), './package.json')) | 20 | const mainPackageJson = await readJson(resolve(cwd(), './package.json')) |
20 | const tsConfigPath = resolve(cwd(), './tsconfig.json') | 21 | const distTsConfigPath = resolve(cwd(), typesPath, './tsconfig.dist.json') |
21 | const tsConfig = await readJson(tsConfigPath) | 22 | const distTsConfig = await readJson(distTsConfigPath) |
22 | const clientPackageJson = await readJson(resolve(cwd(), './client/package.json')) | 23 | const clientPackageJson = await readJson(resolve(cwd(), './client/package.json')) |
23 | 24 | ||
24 | const allDependencies = Object.assign( | 25 | const allDependencies = Object.assign( |
@@ -34,7 +35,7 @@ async function run () { | |||
34 | depcheck.detector.requireCallExpression, | 35 | depcheck.detector.requireCallExpression, |
35 | depcheck.detector.importDeclaration | 36 | depcheck.detector.importDeclaration |
36 | ], | 37 | ], |
37 | ignoreMatches: Object.keys(tsConfig?.compilerOptions?.paths || []), | 38 | ignoreMatches: Object.keys(distTsConfig?.compilerOptions?.paths || []), |
38 | package: { dependencies: allDependencies } | 39 | package: { dependencies: allDependencies } |
39 | } | 40 | } |
40 | 41 | ||
@@ -60,19 +61,15 @@ async function run () { | |||
60 | repository, | 61 | repository, |
61 | dependencies | 62 | dependencies |
62 | } | 63 | } |
63 | console.log(`Writing package.json to ${typesPackageJsonPath}`) | 64 | console.log(`Writing package.json to ${typesDistPackageJsonPath}`) |
64 | await writeJSON(typesPackageJsonPath, typesPackageJson, { spaces: 2 }) | 65 | await writeJSON(typesDistPackageJsonPath, typesPackageJson, { spaces: 2 }) |
65 | 66 | ||
66 | console.log(`Writing git ignore to ${typesGitIgnorePath}`) | 67 | console.log(`Writing git ignore to ${typesDistGitIgnorePath}`) |
67 | await writeFile(typesGitIgnorePath, '*.tsbuildinfo') | 68 | await writeFile(typesDistGitIgnorePath, '*.tsbuildinfo') |
68 | 69 | ||
69 | console.log('Copying tsconfig files') | 70 | console.log('Copying tsconfig files') |
70 | await copyFile(tsConfigPath, resolve(typesPath, './tsconfig.json')) | 71 | await copyFile(distTsConfigPath, resolve(typesDistPath, './tsconfig.json')) |
71 | await copyFile(resolve(cwd(), './tsconfig.base.json'), resolve(typesPath, './tsconfig.base.json')) | 72 | await copyFile(resolve(cwd(), './tsconfig.base.json'), resolve(typesDistPath, './tsconfig.base.json')) |
72 | tsConfig.references.map(({ path }) => path).forEach((path) => { | 73 | |
73 | const src = resolve(cwd(), path, '/tsconfig.json') | 74 | await copyFile(resolve(typesPath, './README.md'), resolve(typesDistPath, './README.md')) |
74 | const dest = resolve(typesPath, path, './tsconfig.json') | ||
75 | console.log(`${src} -> ${dest}`) | ||
76 | copyFile(src, dest).catch((e) => console.error(e)) | ||
77 | }) | ||
78 | } | 75 | } |
diff --git a/types/src/client/index.ts b/types/src/client/index.ts new file mode 100644 index 000000000..5ee10ecb8 --- /dev/null +++ b/types/src/client/index.ts | |||
@@ -0,0 +1 @@ | |||
export * from '@client/types' | |||
diff --git a/types/src/client/tsconfig.json b/types/src/client/tsconfig.json new file mode 100644 index 000000000..199273538 --- /dev/null +++ b/types/src/client/tsconfig.json | |||
@@ -0,0 +1,12 @@ | |||
1 | { | ||
2 | "extends": "../../../tsconfig.base.json", | ||
3 | "compilerOptions": { | ||
4 | "outDir": "../../dist/client/", | ||
5 | "rootDir": "./", | ||
6 | "tsBuildInfoFile": "../../dist/tsconfig.client.types.tsbuildinfo" | ||
7 | }, | ||
8 | "references": [ | ||
9 | { "path": "../../../client/tsconfig.types.json" } | ||
10 | ], | ||
11 | "files": ["index.ts"] | ||
12 | } | ||
diff --git a/types/src/index.ts b/types/src/index.ts new file mode 100644 index 000000000..f1325777f --- /dev/null +++ b/types/src/index.ts | |||
@@ -0,0 +1 @@ | |||
export * from '@server/types' | |||
diff --git a/types/tsconfig.dist.json b/types/tsconfig.dist.json new file mode 100644 index 000000000..d9c3fdfc3 --- /dev/null +++ b/types/tsconfig.dist.json | |||
@@ -0,0 +1,16 @@ | |||
1 | { | ||
2 | "extends": "./tsconfig.base.json", | ||
3 | "compilerOptions": { | ||
4 | "typeRoots": [ | ||
5 | "node_modules/@types", | ||
6 | "client/node_modules/@types" | ||
7 | ], | ||
8 | "baseUrl": "./", | ||
9 | "paths": { | ||
10 | "@server/*": [ "server/*" ], | ||
11 | "@shared/*": [ "shared/*" ], | ||
12 | "@client/*": [ "client/*" ] | ||
13 | } | ||
14 | } | ||
15 | } | ||
16 | |||
diff --git a/types/tsconfig.json b/types/tsconfig.json new file mode 100644 index 000000000..8f09c4a83 --- /dev/null +++ b/types/tsconfig.json | |||
@@ -0,0 +1,23 @@ | |||
1 | { | ||
2 | "extends": "../tsconfig.base.json", | ||
3 | "compilerOptions": { | ||
4 | "stripInternal": true, | ||
5 | "removeComments": false, | ||
6 | "emitDeclarationOnly": true, | ||
7 | "outDir": "./dist/", | ||
8 | "baseUrl": "./src/", | ||
9 | "rootDir": "./src/", | ||
10 | "paths": { | ||
11 | "@server/*": [ "../../server/*" ], | ||
12 | "@shared/*": [ "../../shared/*" ], | ||
13 | "@client/*": [ "../../client/src/*" ], | ||
14 | } | ||
15 | }, | ||
16 | "references": [ | ||
17 | { "path": "../shared/tsconfig.types.json" }, | ||
18 | { "path": "../server/tsconfig.types.json" }, | ||
19 | { "path": "./src/client/tsconfig.json" } | ||
20 | ], | ||
21 | "files": ["./src/index.ts"], | ||
22 | } | ||
23 | |||