aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tools/peertube-repl.ts
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2018-10-19 14:24:35 +0200
committerRigel Kent <sendmemail@rigelk.eu>2018-10-19 14:24:35 +0200
commitc141f68be14193fb92d3f5cfc82cd1e156823c17 (patch)
treecee21605c1401fce5a945f5d63f54661ccf19e86 /server/tools/peertube-repl.ts
parent6d8c8ea73a774c3568e6d28a4cbebcf7979d5c2a (diff)
downloadPeerTube-c141f68be14193fb92d3f5cfc82cd1e156823c17.tar.gz
PeerTube-c141f68be14193fb92d3f5cfc82cd1e156823c17.tar.zst
PeerTube-c141f68be14193fb92d3f5cfc82cd1e156823c17.zip
add repl to the cli wrapper, remove extraneous TOC in tools.md
Diffstat (limited to 'server/tools/peertube-repl.ts')
-rw-r--r--server/tools/peertube-repl.ts79
1 files changed, 79 insertions, 0 deletions
diff --git a/server/tools/peertube-repl.ts b/server/tools/peertube-repl.ts
new file mode 100644
index 000000000..6800ff8ab
--- /dev/null
+++ b/server/tools/peertube-repl.ts
@@ -0,0 +1,79 @@
1import * as repl from 'repl'
2import * as path from 'path'
3import * as _ from 'lodash'
4import * as uuidv1 from 'uuid/v1'
5import * as uuidv3 from 'uuid/v3'
6import * as uuidv4 from 'uuid/v4'
7import * as uuidv5 from 'uuid/v5'
8import * as Sequelize from 'sequelize'
9import * as YoutubeDL from 'youtube-dl'
10
11import { initDatabaseModels, sequelizeTypescript } from '../initializers'
12import * as cli from '../tools/cli'
13import { logger } from '../helpers/logger'
14import * as constants from '../initializers/constants'
15import * as modelsUtils from '../models/utils'
16import * as coreUtils from '../helpers/core-utils'
17import * as ffmpegUtils from '../helpers/ffmpeg-utils'
18import * as peertubeCryptoUtils from '../helpers/peertube-crypto'
19import * as signupUtils from '../helpers/signup'
20import * as utils from '../helpers/utils'
21import * as YoutubeDLUtils from '../helpers/youtube-dl'
22
23let versionCommitHash
24
25const start = async () => {
26 await initDatabaseModels(true)
27
28 await utils.getVersion().then((data) => {
29 versionCommitHash = data
30 })
31
32 const initContext = (replServer) => {
33 return (context) => {
34 const properties = {
35 context, repl: replServer, env: process.env,
36 lodash: _, path,
37 uuidv1, uuidv3, uuidv4, uuidv5,
38 cli, logger, constants,
39 Sequelize, sequelizeTypescript, modelsUtils,
40 models: sequelizeTypescript.models, transaction: sequelizeTypescript.transaction,
41 query: sequelizeTypescript.query, queryInterface: sequelizeTypescript.getQueryInterface(),
42 YoutubeDL,
43 coreUtils, ffmpegUtils, peertubeCryptoUtils, signupUtils, utils, YoutubeDLUtils
44 }
45
46 for (let prop in properties) {
47 Object.defineProperty(context, prop, {
48 configurable: false,
49 enumerable: true,
50 value: properties[prop]
51 })
52 }
53 }
54 }
55
56 const replServer = repl.start({
57 prompt: `PeerTube [${cli.version}] (${versionCommitHash})> `
58 })
59
60 initContext(replServer)(replServer.context)
61 replServer.on('reset', initContext(replServer))
62
63 const resetCommand = {
64 help: 'Reset REPL',
65 action () {
66 this.write('.clear\n')
67 this.displayPrompt()
68 }
69 }
70 replServer.defineCommand('reset', resetCommand)
71 replServer.defineCommand('r', resetCommand)
72
73}
74
75start().then((data) => {
76 // do nothing
77}).catch((err) => {
78 console.error(err)
79})