From 3a4992633ee62d5edfbb484d9c6bcb3cf158489d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 31 Jul 2023 14:34:36 +0200 Subject: Migrate server to ESM Sorry for the very big commit that may lead to git log issues and merge conflicts, but it's a major step forward: * Server can be faster at startup because imports() are async and we can easily lazy import big modules * Angular doesn't seem to support ES import (with .js extension), so we had to correctly organize peertube into a monorepo: * Use yarn workspace feature * Use typescript reference projects for dependencies * Shared projects have been moved into "packages", each one is now a node module (with a dedicated package.json/tsconfig.json) * server/tools have been moved into apps/ and is now a dedicated app bundled and published on NPM so users don't have to build peertube cli tools manually * server/tests have been moved into packages/ so we don't compile them every time we want to run the server * Use isolatedModule option: * Had to move from const enum to const (https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums) * Had to explictely specify "type" imports when used in decorators * Prefer tsx (that uses esbuild under the hood) instead of ts-node to load typescript files (tests with mocha or scripts): * To reduce test complexity as esbuild doesn't support decorator metadata, we only test server files that do not import server models * We still build tests files into js files for a faster CI * Remove unmaintained peertube CLI import script * Removed some barrels to speed up execution (less imports) --- support/doc/plugins/guide.md | 43 ++++++++++++++----------------------------- 1 file changed, 14 insertions(+), 29 deletions(-) (limited to 'support/doc/plugins') diff --git a/support/doc/plugins/guide.md b/support/doc/plugins/guide.md index ff08ce8c4..07f484934 100644 --- a/support/doc/plugins/guide.md +++ b/support/doc/plugins/guide.md @@ -387,7 +387,7 @@ function register (...) { displayName: 'User display name', // Custom admin flags (bypass video auto moderation etc.) - // https://github.com/Chocobozzz/PeerTube/blob/develop/shared/models/users/user-flag.model.ts + // https://github.com/Chocobozzz/PeerTube/blob/develop/packages/models/users/user-flag.model.ts // PeerTube >= 5.1 adminFlags: 0, // Quota in bytes @@ -977,7 +977,7 @@ 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.js' export async function register ({ registerHook }: RegisterServerOptions) { registerHook({ @@ -989,8 +989,8 @@ export async function register ({ registerHook }: RegisterServerOptions) { But it also exposes client types and various models used in __PeerTube__: ```ts -import { Video } from '@peertube/peertube-types'; -import { RegisterClientOptions } from '@peertube/peertube-types/client'; +import { Video } from '@peertube/peertube-types.js'; +import { RegisterClientOptions } from '@peertube/peertube-types/client.js'; function register({ registerHook, peertubeHelpers }: RegisterClientOptions) { registerHook({ @@ -1032,7 +1032,7 @@ If you want to translate strings of your plugin (like labels of your registered } ``` -The key should be one of the locales defined in [i18n.ts](https://github.com/Chocobozzz/PeerTube/blob/develop/shared/models/i18n/i18n.ts). +The key should be one of the locales defined in [i18n.ts](https://github.com/Chocobozzz/PeerTube/blob/develop/packages/models/i18n/i18n.ts). Translation files are just objects, with the english sentence as the key and the translation as the value. `fr.json` could contain for example: @@ -1070,40 +1070,25 @@ You built files are in the `dist/` directory. Check `package.json` to correctly ### Test your plugin/theme -PeerTube dev server (ran with `npm run dev` on `localhost:3000`) can't inject plugin CSS. -It's the reason why we don't use the dev mode but build PeerTube instead. +You need to have a running PeerTube instance with an administrator account. +If you're using dev server on your local computer, test your plugin on `localhost:9000` using `npm run dev` because plugin CSS is not injected in Angular webserver (`localhost:3000`). -You'll need to have a local PeerTube instance: - * Follow the [dev prerequisites](https://github.com/Chocobozzz/PeerTube/blob/develop/.github/CONTRIBUTING.md#prerequisites) - (to clone the repository, install dependencies and prepare the database) - * Build PeerTube: +Install PeerTube CLI (can be installed on another computer/server than the PeerTube instance): -```sh -npm run build -``` - - * Build the CLI: - -```sh -npm run setup:cli -``` - - * Run PeerTube (you can access to your instance on `localhost:9000`): - -```sh -NODE_ENV=dev npm start +```bash +npm install -g @peertube/peertube-cli ``` - * Register the instance via the CLI: +Register the PeerTube instance via the CLI: ```sh -node ./dist/server/tools/peertube.js auth add -u 'http://localhost:9000' -U 'root' --password 'test' +peertube-cli auth add -u 'https://peertube.example.com' -U 'root' --password 'test' ``` -Then, you can install or reinstall your local plugin/theme by running: +Then, you can install your local plugin/theme by running: ```sh -node ./dist/server/tools/peertube.js plugins install --path /your/absolute/plugin-or-theme/path +peertube-cli plugins install --path /your/absolute/plugin-or-theme/path ``` ### Publish -- cgit v1.2.3