]>
Commit | Line | Data |
---|---|---|
2aaa1a3f C |
1 | import { registerTSPaths } from '../helpers/register-ts-paths' |
2 | registerTSPaths() | |
3 | ||
1e59ca3b BY |
4 | import * as repl from 'repl' |
5 | import * as path from 'path' | |
6 | import * as _ from 'lodash' | |
7 | import * as uuidv1 from 'uuid/v1' | |
8 | import * as uuidv3 from 'uuid/v3' | |
9 | import * as uuidv4 from 'uuid/v4' | |
10 | import * as uuidv5 from 'uuid/v5' | |
11 | import * as Sequelize from 'sequelize' | |
12 | import * as YoutubeDL from 'youtube-dl' | |
13 | ||
14 | import { initDatabaseModels, sequelizeTypescript } from '../initializers' | |
15 | import * as cli from '../tools/cli' | |
16 | import { logger } from '../helpers/logger' | |
17 | import * as constants from '../initializers/constants' | |
18 | import * as modelsUtils from '../models/utils' | |
19 | import * as coreUtils from '../helpers/core-utils' | |
20 | import * as ffmpegUtils from '../helpers/ffmpeg-utils' | |
21 | import * as peertubeCryptoUtils from '../helpers/peertube-crypto' | |
22 | import * as signupUtils from '../helpers/signup' | |
23 | import * as utils from '../helpers/utils' | |
24 | import * as YoutubeDLUtils from '../helpers/youtube-dl' | |
25 | ||
1e59ca3b BY |
26 | const start = async () => { |
27 | await initDatabaseModels(true) | |
28 | ||
1b5e2d72 | 29 | const versionCommitHash = await utils.getServerCommit() |
1e59ca3b BY |
30 | |
31 | const initContext = (replServer) => { | |
32 | return (context) => { | |
33 | const properties = { | |
34 | context, repl: replServer, env: process.env, | |
35 | lodash: _, path, | |
36 | uuidv1, uuidv3, uuidv4, uuidv5, | |
37 | cli, logger, constants, | |
38 | Sequelize, sequelizeTypescript, modelsUtils, | |
39 | models: sequelizeTypescript.models, transaction: sequelizeTypescript.transaction, | |
40 | query: sequelizeTypescript.query, queryInterface: sequelizeTypescript.getQueryInterface(), | |
41 | YoutubeDL, | |
42 | coreUtils, ffmpegUtils, peertubeCryptoUtils, signupUtils, utils, YoutubeDLUtils | |
43 | } | |
44 | ||
45 | for (let prop in properties) { | |
46 | Object.defineProperty(context, prop, { | |
47 | configurable: false, | |
48 | enumerable: true, | |
1a12f66d | 49 | value: properties[ prop ] |
1e59ca3b BY |
50 | }) |
51 | } | |
52 | } | |
53 | } | |
54 | ||
55 | const replServer = repl.start({ | |
56 | prompt: `PeerTube [${cli.version}] (${versionCommitHash})> ` | |
57 | }) | |
58 | ||
59 | initContext(replServer)(replServer.context) | |
60 | replServer.on('reset', initContext(replServer)) | |
1b5e2d72 | 61 | replServer.on('exit', () => process.exit()) |
1e59ca3b BY |
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 | ||
1a12f66d C |
75 | start() |
76 | .catch((err) => { | |
77 | console.error(err) | |
78 | }) |