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