-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
installed-plugins.ts
64 lines (58 loc) · 1.91 KB
/
installed-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
import * as chalk from 'chalk';
import { output } from '../output';
import type { CommunityPlugin, CorePlugin, PluginCapabilities } from './models';
import { getPluginCapabilities } from './plugin-capabilities';
import { hasElements } from './shared';
import { readJsonFile } from '../fileutils';
import { readModulePackageJson } from '../package-json';
export function getInstalledPluginsFromPackageJson(
workspaceRoot: string,
corePlugins: CorePlugin[],
communityPlugins: CommunityPlugin[] = []
): Map<string, PluginCapabilities> {
const packageJson = readJsonFile(`${workspaceRoot}/package.json`);
const plugins = new Set([
...corePlugins.map((p) => p.name),
...communityPlugins.map((p) => p.name),
...Object.keys(packageJson.dependencies || {}),
...Object.keys(packageJson.devDependencies || {}),
]);
return new Map(
Array.from(plugins)
.filter((name) => {
try {
// Check for `package.json` existence instead of requiring the module itself
// because malformed entries like `main`, may throw false exceptions.
readModulePackageJson(name, [workspaceRoot]);
return true;
} catch {
return false;
}
})
.sort()
.map<[string, PluginCapabilities]>((name) => [
name,
getPluginCapabilities(workspaceRoot, name),
])
.filter(([, x]) => x && !!(x.generators || x.executors))
);
}
export function listInstalledPlugins(
installedPlugins: Map<string, PluginCapabilities>
) {
const bodyLines: string[] = [];
for (const [, p] of installedPlugins) {
const capabilities = [];
if (hasElements(p.executors)) {
capabilities.push('executors');
}
if (hasElements(p.generators)) {
capabilities.push('generators');
}
bodyLines.push(`${chalk.bold(p.name)} (${capabilities.join()})`);
}
output.log({
title: `Installed plugins:`,
bodyLines: bodyLines,
});
}