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