]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tools/peertube-repl.ts
Merge branch 'release/2.1.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tools / peertube-repl.ts
1 import { registerTSPaths } from '../helpers/register-ts-paths'
2 import * as repl from 'repl'
3 import * as path from 'path'
4 import * as _ from 'lodash'
5 import * as uuidv1 from 'uuid/v1'
6 import * as uuidv3 from 'uuid/v3'
7 import * as uuidv4 from 'uuid/v4'
8 import * as uuidv5 from 'uuid/v5'
9 import * as Sequelize from 'sequelize'
10 import * as YoutubeDL from 'youtube-dl'
11
12 import { initDatabaseModels, sequelizeTypescript } from '../initializers'
13 import * as cli from '../tools/cli'
14 import { logger } from '../helpers/logger'
15 import * as constants from '../initializers/constants'
16 import * as modelsUtils from '../models/utils'
17 import * as coreUtils from '../helpers/core-utils'
18 import * as ffmpegUtils from '../helpers/ffmpeg-utils'
19 import * as peertubeCryptoUtils from '../helpers/peertube-crypto'
20 import * as signupUtils from '../helpers/signup'
21 import * as utils from '../helpers/utils'
22 import * as YoutubeDLUtils from '../helpers/youtube-dl'
23
24 registerTSPaths()
25
26 const start = async () => {
27 await initDatabaseModels(true)
28
29 const versionCommitHash = await utils.getServerCommit()
30
31 const initContext = (replServer) => {
32 return (context) => {
33 const properties = {
34 context,
35 repl: replServer,
36 env: process.env,
37 lodash: _,
38 path,
39 uuidv1,
40 uuidv3,
41 uuidv4,
42 uuidv5,
43 cli,
44 logger,
45 constants,
46 Sequelize,
47 sequelizeTypescript,
48 modelsUtils,
49 models: sequelizeTypescript.models,
50 transaction: sequelizeTypescript.transaction,
51 query: sequelizeTypescript.query,
52 queryInterface: sequelizeTypescript.getQueryInterface(),
53 YoutubeDL,
54 coreUtils,
55 ffmpegUtils,
56 peertubeCryptoUtils,
57 signupUtils,
58 utils,
59 YoutubeDLUtils
60 }
61
62 for (const prop in properties) {
63 Object.defineProperty(context, prop, {
64 configurable: false,
65 enumerable: true,
66 value: properties[prop]
67 })
68 }
69 }
70 }
71
72 const replServer = repl.start({
73 prompt: `PeerTube [${cli.version}] (${versionCommitHash})> `
74 })
75
76 initContext(replServer)(replServer.context)
77 replServer.on('reset', initContext(replServer))
78 replServer.on('exit', () => process.exit())
79
80 const resetCommand = {
81 help: 'Reset REPL',
82 action () {
83 this.write('.clear\n')
84 this.displayPrompt()
85 }
86 }
87 replServer.defineCommand('reset', resetCommand)
88 replServer.defineCommand('r', resetCommand)
89
90 }
91
92 start()
93 .catch((err) => {
94 console.error(err)
95 })