fix: insert a record after pm.add
This commit is contained in:
		
							parent
							
								
									4eada322ef
								
							
						
					
					
						commit
						f5a4413a9a
					
				@ -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')
 | 
				
			||||||
 | 
				
			|||||||
@ -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();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user