2
1

peertube-repl.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 { uuidv1, uuidv3, uuidv4, uuidv5 } from 'uuid'
  7. import * as Sequelize from 'sequelize'
  8. import * as YoutubeDL from 'youtube-dl'
  9. import { initDatabaseModels, sequelizeTypescript } from '../initializers/database'
  10. import * as cli from '../tools/cli'
  11. import { logger } from '../helpers/logger'
  12. import * as constants from '../initializers/constants'
  13. import * as modelsUtils from '../models/utils'
  14. import * as coreUtils from '../helpers/core-utils'
  15. import * as ffmpegUtils from '../helpers/ffmpeg-utils'
  16. import * as peertubeCryptoUtils from '../helpers/peertube-crypto'
  17. import * as signupUtils from '../helpers/signup'
  18. import * as utils from '../helpers/utils'
  19. import * as YoutubeDLUtils from '../helpers/youtube-dl'
  20. const start = async () => {
  21. await initDatabaseModels(true)
  22. const versionCommitHash = await utils.getServerCommit()
  23. const initContext = (replServer) => {
  24. return (context) => {
  25. const properties = {
  26. context,
  27. repl: replServer,
  28. env: process.env,
  29. lodash: _,
  30. path,
  31. uuidv1,
  32. uuidv3,
  33. uuidv4,
  34. uuidv5,
  35. cli,
  36. logger,
  37. constants,
  38. Sequelize,
  39. sequelizeTypescript,
  40. modelsUtils,
  41. models: sequelizeTypescript.models,
  42. transaction: sequelizeTypescript.transaction,
  43. query: sequelizeTypescript.query,
  44. queryInterface: sequelizeTypescript.getQueryInterface(),
  45. YoutubeDL,
  46. coreUtils,
  47. ffmpegUtils,
  48. peertubeCryptoUtils,
  49. signupUtils,
  50. utils,
  51. YoutubeDLUtils
  52. }
  53. for (const prop in properties) {
  54. Object.defineProperty(context, prop, {
  55. configurable: false,
  56. enumerable: true,
  57. value: properties[prop]
  58. })
  59. }
  60. }
  61. }
  62. const replServer = repl.start({
  63. prompt: `PeerTube [${cli.version}] (${versionCommitHash})> `
  64. })
  65. initContext(replServer)(replServer.context)
  66. replServer.on('reset', initContext(replServer))
  67. replServer.on('exit', () => process.exit())
  68. const resetCommand = {
  69. help: 'Reset REPL',
  70. action () {
  71. this.write('.clear\n')
  72. this.displayPrompt()
  73. }
  74. }
  75. replServer.defineCommand('reset', resetCommand)
  76. replServer.defineCommand('r', resetCommand)
  77. }
  78. start()
  79. .catch((err) => {
  80. console.error(err)
  81. })