]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tools/peertube-repl.ts
Use grid to organise settings in admin, my-account
[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 { uuidv1, uuidv3, uuidv4, uuidv5 } from 'uuid'
6 import * as Sequelize from 'sequelize'
7 import * as YoutubeDL from 'youtube-dl'
8
9 import { initDatabaseModels, sequelizeTypescript } from '../initializers'
10 import * as cli from '../tools/cli'
11 import { logger } from '../helpers/logger'
12 import * as constants from '../initializers/constants'
13 import * as modelsUtils from '../models/utils'
14 import * as coreUtils from '../helpers/core-utils'
15 import * as ffmpegUtils from '../helpers/ffmpeg-utils'
16 import * as peertubeCryptoUtils from '../helpers/peertube-crypto'
17 import * as signupUtils from '../helpers/signup'
18 import * as utils from '../helpers/utils'
19 import * as YoutubeDLUtils from '../helpers/youtube-dl'
20
21 registerTSPaths()
22
23 const 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,
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(),
50 YoutubeDL,
51 coreUtils,
52 ffmpegUtils,
53 peertubeCryptoUtils,
54 signupUtils,
55 utils,
56 YoutubeDLUtils
57 }
58
59 for (const prop in properties) {
60 Object.defineProperty(context, prop, {
61 configurable: false,
62 enumerable: true,
63 value: properties[prop]
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))
75 replServer.on('exit', () => process.exit())
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
89 start()
90 .catch((err) => {
91 console.error(err)
92 })