diff options
author | Chocobozzz <me@florianbigard.com> | 2023-07-31 14:34:36 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-08-11 15:02:33 +0200 |
commit | 3a4992633ee62d5edfbb484d9c6bcb3cf158489d (patch) | |
tree | e4510b39bdac9c318fdb4b47018d08f15368b8f0 /apps/peertube-cli/src/peertube.ts | |
parent | 04d1da5621d25d59bd5fa1543b725c497bf5d9a8 (diff) | |
download | PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.gz PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.zst PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.zip |
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)
Diffstat (limited to 'apps/peertube-cli/src/peertube.ts')
-rw-r--r-- | apps/peertube-cli/src/peertube.ts | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/apps/peertube-cli/src/peertube.ts b/apps/peertube-cli/src/peertube.ts new file mode 100644 index 000000000..e3565bb1a --- /dev/null +++ b/apps/peertube-cli/src/peertube.ts | |||
@@ -0,0 +1,64 @@ | |||
1 | #!/usr/bin/env node | ||
2 | |||
3 | import { Command } from '@commander-js/extra-typings' | ||
4 | import { defineAuthProgram } from './peertube-auth.js' | ||
5 | import { defineGetAccessProgram } from './peertube-get-access-token.js' | ||
6 | import { definePluginsProgram } from './peertube-plugins.js' | ||
7 | import { defineRedundancyProgram } from './peertube-redundancy.js' | ||
8 | import { defineUploadProgram } from './peertube-upload.js' | ||
9 | import { getSettings, version } from './shared/index.js' | ||
10 | |||
11 | const program = new Command() | ||
12 | |||
13 | program | ||
14 | .version(version, '-v, --version') | ||
15 | .usage('[command] [options]') | ||
16 | |||
17 | program.addCommand(defineAuthProgram()) | ||
18 | program.addCommand(defineUploadProgram()) | ||
19 | program.addCommand(defineRedundancyProgram()) | ||
20 | program.addCommand(definePluginsProgram()) | ||
21 | program.addCommand(defineGetAccessProgram()) | ||
22 | |||
23 | // help on no command | ||
24 | if (!process.argv.slice(2).length) { | ||
25 | const logo = '░P░e░e░r░T░u░b░e░' | ||
26 | console.log(` | ||
27 | ___/),.._ ` + logo + ` | ||
28 | /' ,. ."'._ | ||
29 | ( "' '-.__"-._ ,- | ||
30 | \\'='='), "\\ -._-"-. -"/ | ||
31 | / ""/"\\,_\\,__"" _" /,- | ||
32 | / / -" _/"/ | ||
33 | / | ._\\\\ |\\ |_.".-" / | ||
34 | / | __\\)|)|),/|_." _,." | ||
35 | / \\_." " ") | ).-""---''-- | ||
36 | ( "/.""7__-""'' | ||
37 | | " ."._--._ | ||
38 | \\ \\ (_ __ "" ".,_ | ||
39 | \\.,. \\ "" -"".-" | ||
40 | ".,_, (",_-,,,-".- | ||
41 | "'-,\\_ __,-" | ||
42 | ",)" ") | ||
43 | /"\\-" | ||
44 | ,"\\/ | ||
45 | _,.__/"\\/_ (the CLI for red chocobos) | ||
46 | / \\) "./, ". | ||
47 | --/---"---" "-) )---- by Chocobozzz et al.\n`) | ||
48 | } | ||
49 | |||
50 | getSettings() | ||
51 | .then(settings => { | ||
52 | const state = (settings.default === undefined || settings.default === -1) | ||
53 | ? 'no instance selected, commands will require explicit arguments' | ||
54 | : 'instance ' + settings.remotes[settings.default] + ' selected' | ||
55 | |||
56 | program | ||
57 | .addHelpText('after', '\n\n State: ' + state + '\n\n' + | ||
58 | ' Examples:\n\n' + | ||
59 | ' $ peertube auth add -u "PEERTUBE_URL" -U "PEERTUBE_USER" --password "PEERTUBE_PASSWORD"\n' + | ||
60 | ' $ peertube up <videoFile>\n' | ||
61 | ) | ||
62 | .parse(process.argv) | ||
63 | }) | ||
64 | .catch(err => console.error(err)) | ||