-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathremove-plugin.ts
50 lines (42 loc) · 1.62 KB
/
remove-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
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 RemovePluginCommand implements ICommand {
public allowedParameters: ICommandParameter[] = [];
constructor(
private $pluginsService: IPluginsService,
private $errors: IErrors,
private $logger: ILogger,
private $projectData: IProjectData
) {
this.$projectData.initializeProjectData();
}
public async execute(args: string[]): Promise<void> {
return this.$pluginsService.remove(args[0], this.$projectData);
}
public async canExecute(args: string[]): Promise<boolean> {
if (!args[0]) {
this.$errors.failWithHelp("You must specify plugin name.");
}
let pluginNames: string[] = [];
try {
// try installing the plugins, so we can get information from node_modules about their native code, libs, etc.
const installedPlugins = await this.$pluginsService.getAllInstalledPlugins(
this.$projectData
);
pluginNames = installedPlugins.map((pl) => pl.name);
} catch (err) {
this.$logger.trace("Error while installing plugins. Error is:", err);
pluginNames = _.keys(this.$projectData.dependencies);
}
const pluginName = args[0].toLowerCase();
if (!_.some(pluginNames, (name) => name.toLowerCase() === pluginName)) {
this.$errors.fail(`Plugin "${pluginName}" is not installed.`);
}
return true;
}
}
injector.registerCommand("plugin|remove", RemovePluginCommand);