peertube-repl.ts 2.3 KB

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