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 /packages/peertube-runner/peertube-runner.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 'packages/peertube-runner/peertube-runner.ts')
-rw-r--r-- | packages/peertube-runner/peertube-runner.ts | 93 |
1 files changed, 0 insertions, 93 deletions
diff --git a/packages/peertube-runner/peertube-runner.ts b/packages/peertube-runner/peertube-runner.ts deleted file mode 100644 index 32586c4d9..000000000 --- a/packages/peertube-runner/peertube-runner.ts +++ /dev/null | |||
@@ -1,93 +0,0 @@ | |||
1 | #!/usr/bin/env node | ||
2 | |||
3 | import { Command, InvalidArgumentError } from '@commander-js/extra-typings' | ||
4 | import { listRegistered, registerRunner, unregisterRunner } from './register' | ||
5 | import { RunnerServer } from './server' | ||
6 | import { ConfigManager, logger } from './shared' | ||
7 | |||
8 | const packageJSON = require('./package.json') | ||
9 | |||
10 | const program = new Command() | ||
11 | .version(packageJSON.version) | ||
12 | .option( | ||
13 | '--id <id>', | ||
14 | 'Runner server id, so you can run multiple PeerTube server runners with different configurations on the same machine', | ||
15 | 'default' | ||
16 | ) | ||
17 | .option('--verbose', 'Run in verbose mode') | ||
18 | .hook('preAction', thisCommand => { | ||
19 | const options = thisCommand.opts() | ||
20 | |||
21 | ConfigManager.Instance.init(options.id) | ||
22 | |||
23 | if (options.verbose === true) { | ||
24 | logger.level = 'debug' | ||
25 | } | ||
26 | }) | ||
27 | |||
28 | program.command('server') | ||
29 | .description('Run in server mode, to execute remote jobs of registered PeerTube instances') | ||
30 | .action(async () => { | ||
31 | try { | ||
32 | await RunnerServer.Instance.run() | ||
33 | } catch (err) { | ||
34 | logger.error(err, 'Cannot run PeerTube runner as server mode') | ||
35 | process.exit(-1) | ||
36 | } | ||
37 | }) | ||
38 | |||
39 | program.command('register') | ||
40 | .description('Register a new PeerTube instance to process runner jobs') | ||
41 | .requiredOption('--url <url>', 'PeerTube instance URL', parseUrl) | ||
42 | .requiredOption('--registration-token <token>', 'Runner registration token (can be found in PeerTube instance administration') | ||
43 | .requiredOption('--runner-name <name>', 'Runner name') | ||
44 | .option('--runner-description <description>', 'Runner description') | ||
45 | .action(async options => { | ||
46 | try { | ||
47 | await registerRunner(options) | ||
48 | } catch (err) { | ||
49 | console.error('Cannot register this PeerTube runner.') | ||
50 | console.error(err) | ||
51 | process.exit(-1) | ||
52 | } | ||
53 | }) | ||
54 | |||
55 | program.command('unregister') | ||
56 | .description('Unregister the runner from PeerTube instance') | ||
57 | .requiredOption('--url <url>', 'PeerTube instance URL', parseUrl) | ||
58 | .requiredOption('--runner-name <name>', 'Runner name') | ||
59 | .action(async options => { | ||
60 | try { | ||
61 | await unregisterRunner(options) | ||
62 | } catch (err) { | ||
63 | console.error('Cannot unregister this PeerTube runner.') | ||
64 | console.error(err) | ||
65 | process.exit(-1) | ||
66 | } | ||
67 | }) | ||
68 | |||
69 | program.command('list-registered') | ||
70 | .description('List registered PeerTube instances') | ||
71 | .action(async () => { | ||
72 | try { | ||
73 | await listRegistered() | ||
74 | } catch (err) { | ||
75 | console.error('Cannot list registered PeerTube instances.') | ||
76 | console.error(err) | ||
77 | process.exit(-1) | ||
78 | } | ||
79 | }) | ||
80 | |||
81 | program.parse() | ||
82 | |||
83 | // --------------------------------------------------------------------------- | ||
84 | // Private | ||
85 | // --------------------------------------------------------------------------- | ||
86 | |||
87 | function parseUrl (url: string) { | ||
88 | if (url.startsWith('http://') !== true && url.startsWith('https://') !== true) { | ||
89 | throw new InvalidArgumentError('URL should start with a http:// or https://') | ||
90 | } | ||
91 | |||
92 | return url | ||
93 | } | ||