Federated video streaming platform using ActivityPub and P2P in the web browser with Angular. https://joinpeertube.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

166 lines
5.2 KiB

  1. import CliTable3 from 'cli-table3'
  2. import { Command, OptionValues, program } from 'commander'
  3. import { isAbsolute } from 'path'
  4. import { PluginType } from '../../shared/models'
  5. import { assignToken, buildServer, getServerCredentials } from './cli'
  6. program
  7. .name('plugins')
  8. .usage('[command] [options]')
  9. program
  10. .command('list')
  11. .description('List installed plugins')
  12. .option('-u, --url <url>', 'Server url')
  13. .option('-U, --username <username>', 'Username')
  14. .option('-p, --password <token>', 'Password')
  15. .option('-t, --only-themes', 'List themes only')
  16. .option('-P, --only-plugins', 'List plugins only')
  17. .action((options, command) => pluginsListCLI(command, options))
  18. program
  19. .command('install')
  20. .description('Install a plugin or a theme')
  21. .option('-u, --url <url>', 'Server url')
  22. .option('-U, --username <username>', 'Username')
  23. .option('-p, --password <token>', 'Password')
  24. .option('-P --path <path>', 'Install from a path')
  25. .option('-n, --npm-name <npmName>', 'Install from npm')
  26. .option('--plugin-version <pluginVersion>', 'Specify the plugin version to install (only available when installing from npm)')
  27. .action((options, command) => installPluginCLI(command, options))
  28. program
  29. .command('update')
  30. .description('Update a plugin or a theme')
  31. .option('-u, --url <url>', 'Server url')
  32. .option('-U, --username <username>', 'Username')
  33. .option('-p, --password <token>', 'Password')
  34. .option('-P --path <path>', 'Update from a path')
  35. .option('-n, --npm-name <npmName>', 'Update from npm')
  36. .action((options, command) => updatePluginCLI(command, options))
  37. program
  38. .command('uninstall')
  39. .description('Uninstall a plugin or a theme')
  40. .option('-u, --url <url>', 'Server url')
  41. .option('-U, --username <username>', 'Username')
  42. .option('-p, --password <token>', 'Password')
  43. .option('-n, --npm-name <npmName>', 'NPM plugin/theme name')
  44. .action((options, command) => uninstallPluginCLI(command, options))
  45. if (!process.argv.slice(2).length) {
  46. program.outputHelp()
  47. }
  48. program.parse(process.argv)
  49. // ----------------------------------------------------------------------------
  50. async function pluginsListCLI (command: Command, options: OptionValues) {
  51. const { url, username, password } = await getServerCredentials(command)
  52. const server = buildServer(url)
  53. await assignToken(server, username, password)
  54. let pluginType: PluginType
  55. if (options.onlyThemes) pluginType = PluginType.THEME
  56. if (options.onlyPlugins) pluginType = PluginType.PLUGIN
  57. const { data } = await server.plugins.list({ start: 0, count: 100, sort: 'name', pluginType })
  58. const table = new CliTable3({
  59. head: [ 'name', 'version', 'homepage' ],
  60. colWidths: [ 50, 10, 50 ]
  61. }) as any
  62. for (const plugin of data) {
  63. const npmName = plugin.type === PluginType.PLUGIN
  64. ? 'peertube-plugin-' + plugin.name
  65. : 'peertube-theme-' + plugin.name
  66. table.push([
  67. npmName,
  68. plugin.version,
  69. plugin.homepage
  70. ])
  71. }
  72. console.log(table.toString())
  73. process.exit(0)
  74. }
  75. async function installPluginCLI (command: Command, options: OptionValues) {
  76. if (!options.path && !options.npmName) {
  77. console.error('You need to specify the npm name or the path of the plugin you want to install.\n')
  78. program.outputHelp()
  79. process.exit(-1)
  80. }
  81. if (options.path && !isAbsolute(options.path)) {
  82. console.error('Path should be absolute.')
  83. process.exit(-1)
  84. }
  85. const { url, username, password } = await getServerCredentials(command)
  86. const server = buildServer(url)
  87. await assignToken(server, username, password)
  88. try {
  89. await server.plugins.install({ npmName: options.npmName, path: options.path, pluginVersion: options.pluginVersion })
  90. } catch (err) {
  91. console.error('Cannot install plugin.', err)
  92. process.exit(-1)
  93. }
  94. console.log('Plugin installed.')
  95. process.exit(0)
  96. }
  97. async function updatePluginCLI (command: Command, options: OptionValues) {
  98. if (!options.path && !options.npmName) {
  99. console.error('You need to specify the npm name or the path of the plugin you want to update.\n')
  100. program.outputHelp()
  101. process.exit(-1)
  102. }
  103. if (options.path && !isAbsolute(options.path)) {
  104. console.error('Path should be absolute.')
  105. process.exit(-1)
  106. }
  107. const { url, username, password } = await getServerCredentials(command)
  108. const server = buildServer(url)
  109. await assignToken(server, username, password)
  110. try {
  111. await server.plugins.update({ npmName: options.npmName, path: options.path })
  112. } catch (err) {
  113. console.error('Cannot update plugin.', err)
  114. process.exit(-1)
  115. }
  116. console.log('Plugin updated.')
  117. process.exit(0)
  118. }
  119. async function uninstallPluginCLI (command: Command, options: OptionValues) {
  120. if (!options.npmName) {
  121. console.error('You need to specify the npm name of the plugin/theme you want to uninstall.\n')
  122. program.outputHelp()
  123. process.exit(-1)
  124. }
  125. const { url, username, password } = await getServerCredentials(command)
  126. const server = buildServer(url)
  127. await assignToken(server, username, password)
  128. try {
  129. await server.plugins.uninstall({ npmName: options.npmName })
  130. } catch (err) {
  131. console.error('Cannot uninstall plugin.', err)
  132. process.exit(-1)
  133. }
  134. console.log('Plugin uninstalled.')
  135. process.exit(0)
  136. }