2019-10-21 17:13:07 +02:00
|
|
|
import { registerTSPaths } from '../helpers/register-ts-paths'
|
2020-04-09 08:39:44 +02:00
|
|
|
registerTSPaths()
|
|
|
|
|
2018-10-14 19:48:08 +02:00
|
|
|
import * as repl from 'repl'
|
|
|
|
import * as path from 'path'
|
|
|
|
import * as _ from 'lodash'
|
|
|
|
import * as Sequelize from 'sequelize'
|
|
|
|
import * as YoutubeDL from 'youtube-dl'
|
2020-05-07 15:40:22 +02:00
|
|
|
import { initDatabaseModels, sequelizeTypescript } from '../initializers/database'
|
2018-10-14 19:48:08 +02:00
|
|
|
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 utils from '../helpers/utils'
|
|
|
|
import * as YoutubeDLUtils from '../helpers/youtube-dl'
|
|
|
|
|
|
|
|
const start = async () => {
|
|
|
|
await initDatabaseModels(true)
|
|
|
|
|
2018-11-23 11:06:10 +01:00
|
|
|
const versionCommitHash = await utils.getServerCommit()
|
2018-10-14 19:48:08 +02:00
|
|
|
|
|
|
|
const initContext = (replServer) => {
|
|
|
|
return (context) => {
|
|
|
|
const properties = {
|
2020-01-31 16:56:52 +01:00
|
|
|
context,
|
|
|
|
repl: replServer,
|
|
|
|
env: process.env,
|
|
|
|
lodash: _,
|
|
|
|
path,
|
|
|
|
cli,
|
|
|
|
logger,
|
|
|
|
constants,
|
|
|
|
Sequelize,
|
|
|
|
sequelizeTypescript,
|
|
|
|
modelsUtils,
|
|
|
|
models: sequelizeTypescript.models,
|
|
|
|
transaction: sequelizeTypescript.transaction,
|
|
|
|
query: sequelizeTypescript.query,
|
|
|
|
queryInterface: sequelizeTypescript.getQueryInterface(),
|
2018-10-14 19:48:08 +02:00
|
|
|
YoutubeDL,
|
2020-01-31 16:56:52 +01:00
|
|
|
coreUtils,
|
|
|
|
ffmpegUtils,
|
|
|
|
peertubeCryptoUtils,
|
|
|
|
utils,
|
|
|
|
YoutubeDLUtils
|
2018-10-14 19:48:08 +02:00
|
|
|
}
|
|
|
|
|
2020-01-31 16:56:52 +01:00
|
|
|
for (const prop in properties) {
|
2018-10-14 19:48:08 +02:00
|
|
|
Object.defineProperty(context, prop, {
|
|
|
|
configurable: false,
|
|
|
|
enumerable: true,
|
2020-01-31 16:56:52 +01:00
|
|
|
value: properties[prop]
|
2018-10-14 19:48:08 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const replServer = repl.start({
|
|
|
|
prompt: `PeerTube [${cli.version}] (${versionCommitHash})> `
|
|
|
|
})
|
|
|
|
|
|
|
|
initContext(replServer)(replServer.context)
|
|
|
|
replServer.on('reset', initContext(replServer))
|
2018-11-23 11:06:10 +01:00
|
|
|
replServer.on('exit', () => process.exit())
|
2018-10-14 19:48:08 +02:00
|
|
|
|
|
|
|
const resetCommand = {
|
|
|
|
help: 'Reset REPL',
|
|
|
|
action () {
|
|
|
|
this.write('.clear\n')
|
|
|
|
this.displayPrompt()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
replServer.defineCommand('reset', resetCommand)
|
|
|
|
replServer.defineCommand('r', resetCommand)
|
|
|
|
}
|
|
|
|
|
2019-06-13 11:09:38 +02:00
|
|
|
start()
|
|
|
|
.catch((err) => {
|
|
|
|
console.error(err)
|
|
|
|
})
|