-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathupdate-plugin.ts
58 lines (48 loc) · 1.65 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import * as _ from "lodash";
import { IProjectData } from "../../definitions/project";
import { IPluginsService } from "../../definitions/plugins";
import { ICommand, ICommandParameter } from "../../common/definitions/commands";
import { IErrors } from "../../common/declarations";
import { injector } from "../../common/yok";
export class UpdatePluginCommand implements ICommand {
constructor(
private $pluginsService: IPluginsService,
private $projectData: IProjectData,
private $errors: IErrors
) {
this.$projectData.initializeProjectData();
}
public async execute(args: string[]): Promise<void> {
let pluginNames = args;
if (!pluginNames || args.length === 0) {
const installedPlugins = await this.$pluginsService.getAllInstalledPlugins(
this.$projectData
);
pluginNames = installedPlugins.map((p) => p.name);
}
for (const pluginName of pluginNames) {
await this.$pluginsService.remove(pluginName, this.$projectData);
await this.$pluginsService.add(pluginName, this.$projectData);
}
}
public async canExecute(args: string[]): Promise<boolean> {
if (!args || args.length === 0) {
return true;
}
const installedPlugins = await this.$pluginsService.getAllInstalledPlugins(
this.$projectData
);
const installedPluginNames: string[] = installedPlugins.map(
(pl) => pl.name
);
const pluginName = args[0].toLowerCase();
if (
!_.some(installedPluginNames, (name) => name.toLowerCase() === pluginName)
) {
this.$errors.fail(`Plugin "${pluginName}" is not installed.`);
}
return true;
}
public allowedParameters: ICommandParameter[] = [];
}
injector.registerCommand("plugin|update", UpdatePluginCommand);