-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathupdate-plugin.ts
41 lines (33 loc) · 1.19 KB
/
update-plugin.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
export class UpdatePluginCommand implements ICommand {
constructor(private $pluginsService: IPluginsService,
private $errors: IErrors) { }
execute(args: string[]): IFuture<void> {
return (() => {
let pluginNames = args;
if (!pluginNames || args.length === 0) {
let installedPlugins = this.$pluginsService.getAllInstalledPlugins().wait();
pluginNames = installedPlugins.map(p => p.name);
}
_.each(pluginNames, p => {
this.$pluginsService.remove(p).wait();
this.$pluginsService.add(p).wait();
});
}).future<void>()();
}
canExecute(args: string[]): IFuture<boolean> {
return (() => {
if (!args || args.length === 0) {
return true;
}
let installedPlugins = this.$pluginsService.getAllInstalledPlugins().wait();
let installedPluginNames: string[] = installedPlugins.map(pl => pl.name);
let pluginName = args[0].toLowerCase();
if (!_.some(installedPluginNames, name => name.toLowerCase() === pluginName)) {
this.$errors.failWithoutHelp(`Plugin "${pluginName}" is not installed.`);
}
return true;
}).future<boolean>()();
}
public allowedParameters: ICommandParameter[] = [];
}
$injector.registerCommand("plugin|update", UpdatePluginCommand);