2
1

install.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { registerTSPaths } from '../../server/helpers/register-ts-paths'
  2. registerTSPaths()
  3. import { initDatabaseModels } from '../../server/initializers/database'
  4. import * as 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. if (!program['npmName'] && !program['pluginPath']) {
  13. console.error('You need to specify a plugin name with the desired version, or a plugin path.')
  14. process.exit(-1)
  15. }
  16. if (program['pluginPath'] && !isAbsolute(program['pluginPath'])) {
  17. console.error('Plugin path should be absolute.')
  18. process.exit(-1)
  19. }
  20. run()
  21. .then(() => process.exit(0))
  22. .catch(err => {
  23. console.error(err)
  24. process.exit(-1)
  25. })
  26. async function run () {
  27. await initDatabaseModels(true)
  28. const toInstall = program['npmName'] || program['pluginPath']
  29. await PluginManager.Instance.install(toInstall, program['pluginVersion'], !!program['pluginPath'])
  30. }