fix: insert a record after pm.add

This commit is contained in:
chenos 2023-08-27 10:04:32 +08:00
parent 4eada322ef
commit f5a4413a9a
2 changed files with 13 additions and 2 deletions

View File

@ -12,7 +12,7 @@ export default (app: Application) => {
pm.command('add') pm.command('add')
.arguments('plugin') .arguments('plugin')
.action(async (plugin) => { .action(async (plugin) => {
await app.pm.add(plugin); await app.pm.add(plugin, {}, true);
}); });
pm.command('enable') pm.command('enable')

View File

@ -189,7 +189,7 @@ export class PluginManager {
await run('yarn', ['install']); await run('yarn', ['install']);
} }
async add(plugin?: any, options: any = {}) { async add(plugin?: any, options: any = {}, insert = false) {
if (this.has(plugin)) { if (this.has(plugin)) {
const name = typeof plugin === 'string' ? plugin : plugin.name; const name = typeof plugin === 'string' ? plugin : plugin.name;
this.app.log.warn(`plugin [${name}] added`); this.app.log.warn(`plugin [${name}] added`);
@ -211,6 +211,17 @@ export class PluginManager {
if (options.name) { if (options.name) {
this.pluginAliases.set(options.name, instance); this.pluginAliases.set(options.name, instance);
} }
if (insert && options.name) {
const packageName = PluginManager.getPackageName(options.name);
const packageJson = PluginManager.getPackageJson(packageName);
await this.repository.updateOrCreate({
values: {
...options,
version: packageJson.version,
},
filterKeys: ['name'],
});
}
await instance.afterAdd(); await instance.afterAdd();
} }