1
0
Fork 0
peertube/server/tools/peertube-repl.ts

92 lines
2.4 KiB
TypeScript
Raw Normal View History

import { registerTSPaths } from '../helpers/register-ts-paths'
2020-04-09 02:39:44 -04:00
registerTSPaths()
import * as repl from 'repl'
import * as path from 'path'
import * as _ from 'lodash'
2020-02-28 10:03:39 -05:00
import { uuidv1, uuidv3, uuidv4, uuidv5 } from 'uuid'
import * as Sequelize from 'sequelize'
import * as YoutubeDL from 'youtube-dl'
import { initDatabaseModels, sequelizeTypescript } from '../initializers'
import * as cli from '../tools/cli'
import { logger } from '../helpers/logger'
import * as constants from '../initializers/constants'
import * as modelsUtils from '../models/utils'
import * as coreUtils from '../helpers/core-utils'
import * as ffmpegUtils from '../helpers/ffmpeg-utils'
import * as peertubeCryptoUtils from '../helpers/peertube-crypto'
import * as signupUtils from '../helpers/signup'
import * as utils from '../helpers/utils'
import * as YoutubeDLUtils from '../helpers/youtube-dl'
const start = async () => {
await initDatabaseModels(true)
2018-11-23 05:06:10 -05:00
const versionCommitHash = await utils.getServerCommit()
const initContext = (replServer) => {
return (context) => {
const properties = {
2020-01-31 10:56:52 -05:00
context,
repl: replServer,
env: process.env,
lodash: _,
path,
uuidv1,
uuidv3,
uuidv4,
uuidv5,
cli,
logger,
constants,
Sequelize,
sequelizeTypescript,
modelsUtils,
models: sequelizeTypescript.models,
transaction: sequelizeTypescript.transaction,
query: sequelizeTypescript.query,
queryInterface: sequelizeTypescript.getQueryInterface(),
YoutubeDL,
2020-01-31 10:56:52 -05:00
coreUtils,
ffmpegUtils,
peertubeCryptoUtils,
signupUtils,
utils,
YoutubeDLUtils
}
2020-01-31 10:56:52 -05:00
for (const prop in properties) {
Object.defineProperty(context, prop, {
configurable: false,
enumerable: true,
2020-01-31 10:56:52 -05:00
value: properties[prop]
})
}
}
}
const replServer = repl.start({
prompt: `PeerTube [${cli.version}] (${versionCommitHash})> `
})
initContext(replServer)(replServer.context)
replServer.on('reset', initContext(replServer))
2018-11-23 05:06:10 -05:00
replServer.on('exit', () => process.exit())
const resetCommand = {
help: 'Reset REPL',
action () {
this.write('.clear\n')
this.displayPrompt()
}
}
replServer.defineCommand('reset', resetCommand)
replServer.defineCommand('r', resetCommand)
}
2019-06-13 05:09:38 -04:00
start()
.catch((err) => {
console.error(err)
})