UNPKG

3.21 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.listPluginCapabilities = exports.getPluginCapabilities = void 0;
4const devkit_1 = require("@nrwl/devkit");
5const devkit_2 = require("@nrwl/devkit");
6const chalk = require("chalk");
7const package_json_1 = require("nx/src/utils/package-json");
8const path_1 = require("path");
9const output_1 = require("../output");
10const shared_1 = require("./shared");
11function tryGetCollection(packageJsonPath, collectionFile, propName) {
12 if (!collectionFile) {
13 return null;
14 }
15 try {
16 const collectionFilePath = (0, path_1.join)((0, path_1.dirname)(packageJsonPath), collectionFile);
17 return (0, devkit_1.readJsonFile)(collectionFilePath)[propName];
18 }
19 catch (_a) {
20 return null;
21 }
22}
23function getPluginCapabilities(workspaceRoot, pluginName) {
24 try {
25 const { path: packageJsonPath, packageJson } = (0, package_json_1.readModulePackageJson)(pluginName);
26 return {
27 name: pluginName,
28 generators: tryGetCollection(packageJsonPath, packageJson.generators, 'generators') ||
29 tryGetCollection(packageJsonPath, packageJson.schematics, 'schematics'),
30 executors: tryGetCollection(packageJsonPath, packageJson.executors, 'executors') ||
31 tryGetCollection(packageJsonPath, packageJson.builders, 'builders'),
32 };
33 }
34 catch (_a) {
35 return null;
36 }
37}
38exports.getPluginCapabilities = getPluginCapabilities;
39function listPluginCapabilities(pluginName) {
40 const plugin = getPluginCapabilities(devkit_2.workspaceRoot, pluginName);
41 if (!plugin) {
42 const pmc = (0, devkit_1.getPackageManagerCommand)();
43 output_1.output.note({
44 title: `${pluginName} is not currently installed`,
45 bodyLines: [
46 `Use "${pmc.addDev} ${pluginName}" to install the plugin.`,
47 `After that, use "${pmc.exec} nx g ${pluginName}:init" to add the required peer deps and initialize the plugin.`,
48 ],
49 });
50 return;
51 }
52 const hasBuilders = (0, shared_1.hasElements)(plugin.executors);
53 const hasGenerators = (0, shared_1.hasElements)(plugin.generators);
54 if (!hasBuilders && !hasGenerators) {
55 output_1.output.warn({ title: `No capabilities found in ${pluginName}` });
56 return;
57 }
58 const bodyLines = [];
59 if (hasGenerators) {
60 bodyLines.push(chalk.bold(chalk.green('GENERATORS')));
61 bodyLines.push('');
62 bodyLines.push(...Object.keys(plugin.generators).map((name) => `${chalk.bold(name)} : ${plugin.generators[name].description}`));
63 if (hasBuilders) {
64 bodyLines.push('');
65 }
66 }
67 if (hasBuilders) {
68 bodyLines.push(chalk.bold(chalk.green('EXECUTORS/BUILDERS')));
69 bodyLines.push('');
70 bodyLines.push(...Object.keys(plugin.executors).map((name) => `${chalk.bold(name)} : ${plugin.executors[name].description}`));
71 }
72 output_1.output.log({
73 title: `Capabilities in ${plugin.name}:`,
74 bodyLines,
75 });
76}
77exports.listPluginCapabilities = listPluginCapabilities;
78//# sourceMappingURL=plugin-capabilities.js.map
\No newline at end of file