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