await initDatabaseModels(true)
const toInstall = options.npmName || options.pluginPath
- await PluginManager.Instance.install(toInstall, options.pluginVersion, !!options.pluginPath)
+ await PluginManager.Instance.install({
+ toInstall,
+ version: options.pluginVersion,
+ fromDisk: !!options.pluginPath,
+ register: false
+ })
}
: undefined
try {
- const plugin = await PluginManager.Instance.install(toInstall, pluginVersion, fromDisk)
+ const plugin = await PluginManager.Instance.install({ toInstall, version: pluginVersion, fromDisk })
return res.json(plugin.toFormattedJSON())
} catch (err) {
async function uninstallPlugin (req: express.Request, res: express.Response) {
const body: ManagePlugin = req.body
- await PluginManager.Instance.uninstall(body.npmName)
+ await PluginManager.Instance.uninstall({ npmName: body.npmName })
return res.status(HttpStatusCode.NO_CONTENT_204).end()
}
// ###################### Installation ######################
- async install (toInstall: string, version?: string, fromDisk = false) {
+ async install (options: {
+ toInstall: string
+ version?: string
+ fromDisk?: boolean // default false
+ register?: boolean // default true
+ }) {
+ const { toInstall, version, fromDisk = false, register = true } = options
+
let plugin: PluginModel
let npmName: string
logger.info('Successful installation of plugin %s.', toInstall)
- await this.registerPluginOrTheme(plugin)
+ if (register) {
+ await this.registerPluginOrTheme(plugin)
+ }
} catch (rootErr) {
logger.error('Cannot install plugin %s, removing it...', toInstall, { err: rootErr })
try {
- await this.uninstall(npmName)
+ await this.uninstall({ npmName })
} catch (err) {
logger.error('Cannot uninstall plugin %s after failed installation.', toInstall, { err })
// Unregister old hooks
await this.unregister(npmName)
- return this.install(toUpdate, version, fromDisk)
+ return this.install({ toInstall: toUpdate, version, fromDisk })
}
- async uninstall (npmName: string) {
+ async uninstall (options: {
+ npmName: string
+ unregister?: boolean // default true
+ }) {
+ const { npmName, unregister } = options
+
logger.info('Uninstalling plugin %s.', npmName)
- try {
- await this.unregister(npmName)
- } catch (err) {
- logger.warn('Cannot unregister plugin %s.', npmName, { err })
+ if (unregister) {
+ try {
+ await this.unregister(npmName)
+ } catch (err) {
+ logger.warn('Cannot unregister plugin %s.', npmName, { err })
+ }
}
const plugin = await PluginModel.loadByNpmName(npmName)