]>
Commit | Line | Data |
---|---|---|
2aaa1a3f | 1 | import { registerTSPaths } from '../helpers/register-ts-paths' |
00c22836 C |
2 | registerTSPaths() |
3 | ||
1e59ca3b BY |
4 | import * as repl from 'repl' |
5 | import * as path from 'path' | |
6 | import * as _ from 'lodash' | |
1e59ca3b BY |
7 | import * as Sequelize from 'sequelize' |
8 | import * as YoutubeDL from 'youtube-dl' | |
faf174d0 | 9 | import { initDatabaseModels, sequelizeTypescript } from '../initializers/database' |
1e59ca3b BY |
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' | |
1e59ca3b BY |
17 | import * as utils from '../helpers/utils' |
18 | import * as YoutubeDLUtils from '../helpers/youtube-dl' | |
19 | ||
1e59ca3b BY |
20 | const start = async () => { |
21 | await initDatabaseModels(true) | |
22 | ||
1b5e2d72 | 23 | const versionCommitHash = await utils.getServerCommit() |
1e59ca3b BY |
24 | |
25 | const initContext = (replServer) => { | |
26 | return (context) => { | |
27 | const properties = { | |
a1587156 C |
28 | context, |
29 | repl: replServer, | |
30 | env: process.env, | |
31 | lodash: _, | |
32 | path, | |
a1587156 C |
33 | cli, |
34 | logger, | |
35 | constants, | |
36 | Sequelize, | |
37 | sequelizeTypescript, | |
38 | modelsUtils, | |
39 | models: sequelizeTypescript.models, | |
40 | transaction: sequelizeTypescript.transaction, | |
41 | query: sequelizeTypescript.query, | |
42 | queryInterface: sequelizeTypescript.getQueryInterface(), | |
1e59ca3b | 43 | YoutubeDL, |
a1587156 C |
44 | coreUtils, |
45 | ffmpegUtils, | |
46 | peertubeCryptoUtils, | |
a1587156 C |
47 | utils, |
48 | YoutubeDLUtils | |
1e59ca3b BY |
49 | } |
50 | ||
a1587156 | 51 | for (const prop in properties) { |
1e59ca3b BY |
52 | Object.defineProperty(context, prop, { |
53 | configurable: false, | |
54 | enumerable: true, | |
a1587156 | 55 | value: properties[prop] |
1e59ca3b BY |
56 | }) |
57 | } | |
58 | } | |
59 | } | |
60 | ||
61 | const replServer = repl.start({ | |
62 | prompt: `PeerTube [${cli.version}] (${versionCommitHash})> ` | |
63 | }) | |
64 | ||
65 | initContext(replServer)(replServer.context) | |
66 | replServer.on('reset', initContext(replServer)) | |
1b5e2d72 | 67 | replServer.on('exit', () => process.exit()) |
1e59ca3b BY |
68 | |
69 | const resetCommand = { | |
70 | help: 'Reset REPL', | |
71 | action () { | |
72 | this.write('.clear\n') | |
73 | this.displayPrompt() | |
74 | } | |
75 | } | |
76 | replServer.defineCommand('reset', resetCommand) | |
77 | replServer.defineCommand('r', resetCommand) | |
1e59ca3b BY |
78 | } |
79 | ||
1a12f66d C |
80 | start() |
81 | .catch((err) => { | |
82 | console.error(err) | |
83 | }) |