peertube-repl.ts 2.4 KB

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