]>
Commit | Line | Data |
---|---|---|
2aaa1a3f | 1 | import { registerTSPaths } from '../helpers/register-ts-paths' |
1e59ca3b BY |
2 | import * as repl from 'repl' |
3 | import * as path from 'path' | |
4 | import * as _ from 'lodash' | |
bdd428a6 | 5 | import { uuidv1, uuidv3, uuidv4, uuidv5 } from 'uuid' |
1e59ca3b BY |
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 | ||
a1587156 C |
21 | registerTSPaths() |
22 | ||
1e59ca3b BY |
23 | const 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 |
89 | start() |
90 | .catch((err) => { | |
91 | console.error(err) | |
92 | }) |