diff options
Diffstat (limited to 'server/tools/repl.ts')
-rw-r--r-- | server/tools/repl.ts | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/server/tools/repl.ts b/server/tools/repl.ts new file mode 100644 index 000000000..6800ff8ab --- /dev/null +++ b/server/tools/repl.ts | |||
@@ -0,0 +1,79 @@ | |||
1 | import * as repl from 'repl' | ||
2 | import * as path from 'path' | ||
3 | import * as _ from 'lodash' | ||
4 | import * as uuidv1 from 'uuid/v1' | ||
5 | import * as uuidv3 from 'uuid/v3' | ||
6 | import * as uuidv4 from 'uuid/v4' | ||
7 | import * as uuidv5 from 'uuid/v5' | ||
8 | import * as Sequelize from 'sequelize' | ||
9 | import * as YoutubeDL from 'youtube-dl' | ||
10 | |||
11 | import { initDatabaseModels, sequelizeTypescript } from '../initializers' | ||
12 | import * as cli from '../tools/cli' | ||
13 | import { logger } from '../helpers/logger' | ||
14 | import * as constants from '../initializers/constants' | ||
15 | import * as modelsUtils from '../models/utils' | ||
16 | import * as coreUtils from '../helpers/core-utils' | ||
17 | import * as ffmpegUtils from '../helpers/ffmpeg-utils' | ||
18 | import * as peertubeCryptoUtils from '../helpers/peertube-crypto' | ||
19 | import * as signupUtils from '../helpers/signup' | ||
20 | import * as utils from '../helpers/utils' | ||
21 | import * as YoutubeDLUtils from '../helpers/youtube-dl' | ||
22 | |||
23 | let versionCommitHash | ||
24 | |||
25 | const start = async () => { | ||
26 | await initDatabaseModels(true) | ||
27 | |||
28 | await utils.getVersion().then((data) => { | ||
29 | versionCommitHash = data | ||
30 | }) | ||
31 | |||
32 | const initContext = (replServer) => { | ||
33 | return (context) => { | ||
34 | const properties = { | ||
35 | context, repl: replServer, env: process.env, | ||
36 | lodash: _, path, | ||
37 | uuidv1, uuidv3, uuidv4, uuidv5, | ||
38 | cli, logger, constants, | ||
39 | Sequelize, sequelizeTypescript, modelsUtils, | ||
40 | models: sequelizeTypescript.models, transaction: sequelizeTypescript.transaction, | ||
41 | query: sequelizeTypescript.query, queryInterface: sequelizeTypescript.getQueryInterface(), | ||
42 | YoutubeDL, | ||
43 | coreUtils, ffmpegUtils, peertubeCryptoUtils, signupUtils, utils, YoutubeDLUtils | ||
44 | } | ||
45 | |||
46 | for (let prop in properties) { | ||
47 | Object.defineProperty(context, prop, { | ||
48 | configurable: false, | ||
49 | enumerable: true, | ||
50 | value: properties[prop] | ||
51 | }) | ||
52 | } | ||
53 | } | ||
54 | } | ||
55 | |||
56 | const replServer = repl.start({ | ||
57 | prompt: `PeerTube [${cli.version}] (${versionCommitHash})> ` | ||
58 | }) | ||
59 | |||
60 | initContext(replServer)(replServer.context) | ||
61 | replServer.on('reset', initContext(replServer)) | ||
62 | |||
63 | const resetCommand = { | ||
64 | help: 'Reset REPL', | ||
65 | action () { | ||
66 | this.write('.clear\n') | ||
67 | this.displayPrompt() | ||
68 | } | ||
69 | } | ||
70 | replServer.defineCommand('reset', resetCommand) | ||
71 | replServer.defineCommand('r', resetCommand) | ||
72 | |||
73 | } | ||
74 | |||
75 | start().then((data) => { | ||
76 | // do nothing | ||
77 | }).catch((err) => { | ||
78 | console.error(err) | ||
79 | }) | ||