aboutsummaryrefslogtreecommitdiffhomepage
path: root/apps/peertube-cli/src/peertube.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-07-31 14:34:36 +0200
committerChocobozzz <me@florianbigard.com>2023-08-11 15:02:33 +0200
commit3a4992633ee62d5edfbb484d9c6bcb3cf158489d (patch)
treee4510b39bdac9c318fdb4b47018d08f15368b8f0 /apps/peertube-cli/src/peertube.ts
parent04d1da5621d25d59bd5fa1543b725c497bf5d9a8 (diff)
downloadPeerTube-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.ts64
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
3import { Command } from '@commander-js/extra-typings'
4import { defineAuthProgram } from './peertube-auth.js'
5import { defineGetAccessProgram } from './peertube-get-access-token.js'
6import { definePluginsProgram } from './peertube-plugins.js'
7import { defineRedundancyProgram } from './peertube-redundancy.js'
8import { defineUploadProgram } from './peertube-upload.js'
9import { getSettings, version } from './shared/index.js'
10
11const program = new Command()
12
13program
14 .version(version, '-v, --version')
15 .usage('[command] [options]')
16
17program.addCommand(defineAuthProgram())
18program.addCommand(defineUploadProgram())
19program.addCommand(defineRedundancyProgram())
20program.addCommand(definePluginsProgram())
21program.addCommand(defineGetAccessProgram())
22
23// help on no command
24if (!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
50getSettings()
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))