install.ts 1.2 KB

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