]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
refactor(types): create dedicated folder for types package src
authorlutangar <johan.dufour@gmail.com>
Tue, 9 Nov 2021 12:49:08 +0000 (13:49 +0100)
committerChocobozzz <chocobozzz@cpy.re>
Thu, 16 Dec 2021 09:08:43 +0000 (10:08 +0100)
fix guide examples and add types package readme

refactor(tsconfig): move back base tsconfig to base directory

20 files changed:
.gitignore
client/src/index.ts [deleted file]
client/tsconfig.types.json
index.ts [deleted file]
package.json
server/tools/tsconfig.json
server/tsconfig.types.json
shared/tsconfig.json
shared/tsconfig.types.json
support/doc/plugins/guide.md
tsconfig.base.json
tsconfig.json
tsconfig.types.json [deleted file]
types/README.md [new file with mode: 0644]
types/generate-package.ts [moved from scripts/generate-types-package.ts with 67% similarity]
types/src/client/index.ts [new file with mode: 0644]
types/src/client/tsconfig.json [new file with mode: 0644]
types/src/index.ts [new file with mode: 0644]
types/tsconfig.dist.json [new file with mode: 0644]
types/tsconfig.json [new file with mode: 0644]

index ac1d6a99ad3a9efcab8efb882140a4914784216c..0ec17217d2b8f584b8c9f72069351f20157d2859 100644 (file)
@@ -53,4 +53,4 @@ yarn-error.log
 
 # TypeScript
 *.tsbuildinfo
-/types
+/types/dist/
diff --git a/client/src/index.ts b/client/src/index.ts
deleted file mode 100644 (file)
index c9f6f04..0000000
+++ /dev/null
@@ -1 +0,0 @@
-export * from './types'
index 35a5e92cc1fbd2876ed19f2fa864133f7bc080c8..1f5c86161346fd633bc980a345368dcfe7f71ef7 100644 (file)
@@ -4,15 +4,15 @@
     "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/**/*"]
 }
diff --git a/index.ts b/index.ts
deleted file mode 100644 (file)
index 4c65e3d..0000000
--- a/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from './server/types'
index 7bfe8aadc41e33f69c85c415f8e0bccfc93e8654..88d8329e625785850ad3a5f8fe9cc328a5df23b8 100644 (file)
@@ -29,7 +29,7 @@
     "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",
@@ -53,7 +53,7 @@
     "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)",
index 575133ec8c99bacbeb84bed577c6c6d3fd5cd726..61e6b87395e08217efe10fa24256d9cd43942c4e 100644 (file)
@@ -7,5 +7,6 @@
   "references": [
     { "path": "../" },
   ],
+  "files": [],
   "exclude": [ ] // Overwrite exclude property
 }
index 26697bd4598ac1353064fd3fd002f37862ce8c4d..824834066ec6b2e8f4344985d388d572c594b40b 100644 (file)
@@ -1,7 +1,7 @@
 {
   "extends": "./tsconfig.json",
   "compilerOptions": {
-    "outDir": "../types/server",
+    "outDir": "../types/dist/server",
     "stripInternal": true,
     "removeComments": false,
     "emitDeclarationOnly": true
index 95892077b84a7dd9273c104d41c7bcdc9806abb6..88107e27f5e94d36397d16df98a65dd55099683a 100644 (file)
@@ -1,6 +1,7 @@
 {
   "extends": "../tsconfig.base.json",
   "compilerOptions": {
-    "outDir": "../dist/shared"
+    "outDir": "../dist/shared",
+
   }
 }
index 18c470059c90bd9f49ccbf8282b216bef13d26f8..b01d12e539228a21ff94ed359b23f75c18b948b2 100644 (file)
@@ -1,7 +1,7 @@
 {
   "extends": "./tsconfig.json",
   "compilerOptions": {
-    "outDir": "../types/shared",
+    "outDir": "../types/dist/shared",
     "stripInternal": true,
     "removeComments": false,
     "emitDeclarationOnly": true
index 5c96d1b03aed7ca87e82410230abdf58ab04222d..92cc20db0922b188066d61169f9bc180027bb14f 100644 (file)
@@ -889,12 +889,12 @@ If you want to use __Typescript__ see section below.
 
 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({
@@ -906,14 +906,33 @@ export async function register ({ registerHook }: RegisterServerOptions) {
 
 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`.
 
index 349c4de6c4685cacd3e7dd32460ce60cc8ab4ba3..f579c703a7495a552270bbd12893aebc6e0ed5a1 100644 (file)
       "client/node_modules/@types"
     ],
     "baseUrl": "./",
-    "outDir": "./dist/",
     "paths": {
       "@server/*": [ "server/*" ],
-      "@shared/*": [ "shared/*" ]
+      "@shared/*": [ "shared/*" ],
+      "@client/*": [ "client/src/*" ],
     },
     "resolveJsonModule": true,
     "strict": false,
index 8f1d5b6fb6e327761ed7163d67be15ba0083f4ee..cb7937f9967cddab3c16f574db8488f0d28cbc6b 100644 (file)
@@ -6,7 +6,11 @@
     "paths": {
       "@server/*": [ "server/*" ],
       "@shared/*": [ "shared/*" ]
-    }
+    },
+    "typeRoots": [
+      "server/typings",
+      "node_modules/@types"
+    ]
   },
   "references": [
     { "path": "./shared" },
diff --git a/tsconfig.types.json b/tsconfig.types.json
deleted file mode 100644 (file)
index b6898e2..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-{
-  "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"],
-}
-
diff --git a/types/README.md b/types/README.md
new file mode 100644 (file)
index 0000000..adeca48
--- /dev/null
@@ -0,0 +1,19 @@
+# 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.
similarity index 67%
rename from scripts/generate-types-package.ts
rename to types/generate-package.ts
index 3543fa4720691480e3143c2620919c863799ccd6..e0bdd721ab73b3e8e942210798129414faaf45a5 100644 (file)
@@ -14,11 +14,12 @@ run()
 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(
@@ -34,7 +35,7 @@ async function run () {
       depcheck.detector.requireCallExpression,
       depcheck.detector.importDeclaration
     ],
-    ignoreMatches: Object.keys(tsConfig?.compilerOptions?.paths || []),
+    ignoreMatches: Object.keys(distTsConfig?.compilerOptions?.paths || []),
     package: { dependencies: allDependencies }
   }
 
@@ -60,19 +61,15 @@ async function run () {
     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'))
 }
diff --git a/types/src/client/index.ts b/types/src/client/index.ts
new file mode 100644 (file)
index 0000000..5ee10ec
--- /dev/null
@@ -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 (file)
index 0000000..1992735
--- /dev/null
@@ -0,0 +1,12 @@
+{
+  "extends": "../../../tsconfig.base.json",
+  "compilerOptions": {
+    "outDir": "../../dist/client/",
+    "rootDir": "./",
+    "tsBuildInfoFile": "../../dist/tsconfig.client.types.tsbuildinfo"
+  },
+  "references": [
+    { "path": "../../../client/tsconfig.types.json" }
+  ],
+  "files": ["index.ts"]
+}
diff --git a/types/src/index.ts b/types/src/index.ts
new file mode 100644 (file)
index 0000000..f132577
--- /dev/null
@@ -0,0 +1 @@
+export * from '@server/types'
diff --git a/types/tsconfig.dist.json b/types/tsconfig.dist.json
new file mode 100644 (file)
index 0000000..d9c3fdf
--- /dev/null
@@ -0,0 +1,16 @@
+{
+  "extends": "./tsconfig.base.json",
+  "compilerOptions": {
+    "typeRoots": [
+      "node_modules/@types",
+      "client/node_modules/@types"
+    ],
+    "baseUrl": "./",
+    "paths": {
+      "@server/*": [ "server/*" ],
+      "@shared/*": [ "shared/*" ],
+      "@client/*": [ "client/*" ]
+    }
+  }
+}
+
diff --git a/types/tsconfig.json b/types/tsconfig.json
new file mode 100644 (file)
index 0000000..8f09c4a
--- /dev/null
@@ -0,0 +1,23 @@
+{
+  "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"],
+}
+