-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathlist-plugins.ts
77 lines (65 loc) · 2.29 KB
/
list-plugins.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { createTable } from "../../common/helpers";
import { IProjectData } from "../../definitions/project";
import {
IPluginsService,
IPackageJsonDepedenciesResult,
IBasePluginData,
} from "../../definitions/plugins";
import { ICommand, ICommandParameter } from "../../common/definitions/commands";
import { injector } from "../../common/yok";
import { color } from "../../color";
export class ListPluginsCommand implements ICommand {
public allowedParameters: ICommandParameter[] = [];
constructor(
private $pluginsService: IPluginsService,
private $projectData: IProjectData,
private $logger: ILogger
) {
this.$projectData.initializeProjectData();
}
public async execute(args: string[]): Promise<void> {
const installedPlugins: IPackageJsonDepedenciesResult = this.$pluginsService.getDependenciesFromPackageJson(
this.$projectData.projectDir
);
const headers: string[] = ["Plugin", "Version"];
const dependenciesData: string[][] = this.createTableCells(
installedPlugins.dependencies
);
const dependenciesTable: any = createTable(headers, dependenciesData);
this.$logger.info("Dependencies:");
this.$logger.info(dependenciesTable.toString());
if (
installedPlugins.devDependencies &&
installedPlugins.devDependencies.length
) {
const devDependenciesData: string[][] = this.createTableCells(
installedPlugins.devDependencies
);
const devDependenciesTable: any = createTable(
headers,
devDependenciesData
);
this.$logger.info("Dev Dependencies:");
this.$logger.info(devDependenciesTable.toString());
} else {
this.$logger.info("There are no dev dependencies.");
}
const viewDependenciesCommand: string = color.cyan(
"npm view <pluginName> grep dependencies"
);
const viewDevDependenciesCommand: string = color.cyan(
"npm view <pluginName> grep devDependencies"
);
this.$logger.warn("NOTE:");
this.$logger.warn(
`If you want to check the dependencies of installed plugin use ${viewDependenciesCommand}`
);
this.$logger.warn(
`If you want to check the dev dependencies of installed plugin use ${viewDevDependenciesCommand}`
);
}
private createTableCells(items: IBasePluginData[]): string[][] {
return items.map((item) => [item.name, item.version]);
}
}
injector.registerCommand("plugin|*list", ListPluginsCommand);