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