2021-06-25 11:39:27 -04:00
|
|
|
import { program } from 'commander'
|
2019-07-12 05:39:58 -04:00
|
|
|
import { isAbsolute } from 'path'
|
2023-10-04 09:13:25 -04:00
|
|
|
import { initDatabaseModels } from '../../core/initializers/database.js'
|
|
|
|
import { PluginManager } from '../../core/lib/plugins/plugin-manager.js'
|
2019-07-12 05:39:58 -04:00
|
|
|
|
|
|
|
program
|
2019-07-19 04:37:35 -04:00
|
|
|
.option('-n, --npm-name [npmName]', 'Plugin to install')
|
2019-07-12 05:39:58 -04:00
|
|
|
.option('-v, --plugin-version [pluginVersion]', 'Plugin version to install')
|
|
|
|
.option('-p, --plugin-path [pluginPath]', 'Path of the plugin you want to install')
|
|
|
|
.parse(process.argv)
|
|
|
|
|
2021-02-03 03:33:05 -05:00
|
|
|
const options = program.opts()
|
|
|
|
|
|
|
|
if (!options.npmName && !options.pluginPath) {
|
2019-07-12 05:39:58 -04:00
|
|
|
console.error('You need to specify a plugin name with the desired version, or a plugin path.')
|
|
|
|
process.exit(-1)
|
|
|
|
}
|
|
|
|
|
2021-02-03 03:33:05 -05:00
|
|
|
if (options.pluginPath && !isAbsolute(options.pluginPath)) {
|
2019-07-12 05:39:58 -04:00
|
|
|
console.error('Plugin path should be absolute.')
|
|
|
|
process.exit(-1)
|
|
|
|
}
|
|
|
|
|
|
|
|
run()
|
|
|
|
.then(() => process.exit(0))
|
|
|
|
.catch(err => {
|
|
|
|
console.error(err)
|
|
|
|
process.exit(-1)
|
|
|
|
})
|
|
|
|
|
|
|
|
async function run () {
|
|
|
|
await initDatabaseModels(true)
|
|
|
|
|
2021-02-03 03:33:05 -05:00
|
|
|
const toInstall = options.npmName || options.pluginPath
|
2023-05-05 08:14:26 -04:00
|
|
|
await PluginManager.Instance.install({
|
|
|
|
toInstall,
|
|
|
|
version: options.pluginVersion,
|
|
|
|
fromDisk: !!options.pluginPath,
|
|
|
|
register: false
|
|
|
|
})
|
2019-07-12 05:39:58 -04:00
|
|
|
}
|