aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tools/peertube-repl.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tools/peertube-repl.ts')
-rw-r--r--server/tools/peertube-repl.ts76
1 files changed, 76 insertions, 0 deletions
diff --git a/server/tools/peertube-repl.ts b/server/tools/peertube-repl.ts
new file mode 100644
index 000000000..04d8b95a3
--- /dev/null
+++ b/server/tools/peertube-repl.ts
@@ -0,0 +1,76 @@
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
23const start = async () => {
24 await initDatabaseModels(true)
25
26 const versionCommitHash = await utils.getServerCommit()
27
28 const initContext = (replServer) => {
29 return (context) => {
30 const properties = {
31 context, repl: replServer, env: process.env,
32 lodash: _, path,
33 uuidv1, uuidv3, uuidv4, uuidv5,
34 cli, logger, constants,
35 Sequelize, sequelizeTypescript, modelsUtils,
36 models: sequelizeTypescript.models, transaction: sequelizeTypescript.transaction,
37 query: sequelizeTypescript.query, queryInterface: sequelizeTypescript.getQueryInterface(),
38 YoutubeDL,
39 coreUtils, ffmpegUtils, peertubeCryptoUtils, signupUtils, utils, YoutubeDLUtils
40 }
41
42 for (let prop in properties) {
43 Object.defineProperty(context, prop, {
44 configurable: false,
45 enumerable: true,
46 value: properties[prop]
47 })
48 }
49 }
50 }
51
52 const replServer = repl.start({
53 prompt: `PeerTube [${cli.version}] (${versionCommitHash})> `
54 })
55
56 initContext(replServer)(replServer.context)
57 replServer.on('reset', initContext(replServer))
58 replServer.on('exit', () => process.exit())
59
60 const resetCommand = {
61 help: 'Reset REPL',
62 action () {
63 this.write('.clear\n')
64 this.displayPrompt()
65 }
66 }
67 replServer.defineCommand('reset', resetCommand)
68 replServer.defineCommand('r', resetCommand)
69
70}
71
72start().then((data) => {
73 // do nothing
74}).catch((err) => {
75 console.error(err)
76})