install.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { program } from 'commander'
  2. import { isAbsolute } from 'path'
  3. import { initDatabaseModels } from '../../server/initializers/database'
  4. import { PluginManager } from '../../server/lib/plugins/plugin-manager'
  5. program
  6. .option('-n, --npm-name [npmName]', 'Plugin to install')
  7. .option('-v, --plugin-version [pluginVersion]', 'Plugin version to install')
  8. .option('-p, --plugin-path [pluginPath]', 'Path of the plugin you want to install')
  9. .parse(process.argv)
  10. const options = program.opts()
  11. if (!options.npmName && !options.pluginPath) {
  12. console.error('You need to specify a plugin name with the desired version, or a plugin path.')
  13. process.exit(-1)
  14. }
  15. if (options.pluginPath && !isAbsolute(options.pluginPath)) {
  16. console.error('Plugin path should be absolute.')
  17. process.exit(-1)
  18. }
  19. run()
  20. .then(() => process.exit(0))
  21. .catch(err => {
  22. console.error(err)
  23. process.exit(-1)
  24. })
  25. async function run () {
  26. await initDatabaseModels(true)
  27. const toInstall = options.npmName || options.pluginPath
  28. await PluginManager.Instance.install(toInstall, options.pluginVersion, !!options.pluginPath)
  29. }