GSI - Employe Self Service Mobile
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
4.9 KiB

2 months ago
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.command = void 0;
  4. const clc = require("colorette");
  5. const checkMinRequiredVersion_1 = require("../checkMinRequiredVersion");
  6. const command_1 = require("../command");
  7. const extensionsApi = require("../extensions/extensionsApi");
  8. const extensionsHelper_1 = require("../extensions/extensionsHelper");
  9. const localHelper_1 = require("../extensions/localHelper");
  10. const logger_1 = require("../logger");
  11. const requirePermissions_1 = require("../requirePermissions");
  12. const utils = require("../utils");
  13. const { marked } = require("marked");
  14. const TerminalRenderer = require("marked-terminal");
  15. const FUNCTION_TYPE_REGEX = /\..+\.function/;
  16. exports.command = new command_1.Command("ext:info <extensionName>")
  17. .description("display information about an extension by name (extensionName@x.y.z for a specific version)")
  18. .option("--markdown", "output info in Markdown suitable for constructing a README file")
  19. .before(checkMinRequiredVersion_1.checkMinRequiredVersion, "extMinVersion")
  20. .action(async (extensionName, options) => {
  21. var _a, _b;
  22. let spec;
  23. if ((0, localHelper_1.isLocalExtension)(extensionName)) {
  24. if (!options.markdown) {
  25. utils.logLabeledBullet(extensionsHelper_1.logPrefix, `reading extension from directory: ${extensionName}`);
  26. }
  27. spec = await (0, localHelper_1.getLocalExtensionSpec)(extensionName);
  28. }
  29. else {
  30. await (0, requirePermissions_1.requirePermissions)(options, ["firebaseextensions.sources.get"]);
  31. await (0, extensionsHelper_1.ensureExtensionsApiEnabled)(options);
  32. const hasPublisherId = extensionName.split("/").length >= 2;
  33. if (hasPublisherId) {
  34. const nameAndVersion = extensionName.split("/")[1];
  35. if (nameAndVersion.split("@").length < 2) {
  36. extensionName = extensionName + "@latest";
  37. }
  38. }
  39. else {
  40. const [name, version] = extensionName.split("@");
  41. extensionName = `firebase/${name}@${version || "latest"}`;
  42. }
  43. const version = await extensionsApi.getExtensionVersion(extensionName);
  44. spec = version.spec;
  45. }
  46. if (!options.markdown) {
  47. utils.logLabeledBullet(extensionsHelper_1.logPrefix, `information about ${extensionName}:\n`);
  48. }
  49. const lines = [];
  50. if (options.markdown) {
  51. lines.push(`# ${spec.displayName}`);
  52. }
  53. else {
  54. lines.push(`**Name**: ${spec.displayName}`);
  55. }
  56. const authorName = (_a = spec.author) === null || _a === void 0 ? void 0 : _a.authorName;
  57. const url = (_b = spec.author) === null || _b === void 0 ? void 0 : _b.url;
  58. const urlMarkdown = url ? `(**[${url}](${url})**)` : "";
  59. lines.push(`**Author**: ${authorName} ${urlMarkdown}`);
  60. if (spec.description) {
  61. lines.push(`**Description**: ${spec.description}`);
  62. }
  63. if (spec.preinstallContent) {
  64. lines.push("", `**Details**: ${spec.preinstallContent}`);
  65. }
  66. if (spec.params && Array.isArray(spec.params) && spec.params.length > 0) {
  67. lines.push("", "**Configuration Parameters:**");
  68. for (const param of spec.params) {
  69. lines.push(`* ${param.label}` + (param.description ? `: ${param.description}` : ""));
  70. }
  71. }
  72. const functions = [];
  73. const otherResources = [];
  74. for (const resource of spec.resources) {
  75. if (FUNCTION_TYPE_REGEX.test(resource.type)) {
  76. functions.push(resource);
  77. }
  78. else {
  79. otherResources.push(resource);
  80. }
  81. }
  82. if (functions.length > 0) {
  83. lines.push("", "**Cloud Functions:**");
  84. for (const func of functions) {
  85. lines.push(`* **${func.name}:** ${func.description}`);
  86. }
  87. }
  88. if (otherResources.length > 0) {
  89. lines.push("", "**Other Resources**:");
  90. for (const resource of otherResources) {
  91. lines.push(`* ${resource.name} (${resource.type})`);
  92. }
  93. }
  94. if (spec.apis) {
  95. lines.push("", "**APIs Used**:");
  96. for (const api of spec.apis) {
  97. lines.push(`* ${api.apiName}` + (api.reason ? ` (Reason: ${api.reason})` : ""));
  98. }
  99. }
  100. if (spec.roles) {
  101. lines.push("", "**Access Required**:");
  102. lines.push("", "This extension will operate with the following project IAM roles:");
  103. for (const role of spec.roles) {
  104. lines.push(`* ${role.role}` + (role.reason ? ` (Reason: ${role.reason})` : ""));
  105. }
  106. }
  107. if (options.markdown) {
  108. logger_1.logger.info(lines.join("\n\n"));
  109. }
  110. else {
  111. marked.setOptions({
  112. renderer: new TerminalRenderer(),
  113. });
  114. logger_1.logger.info(marked(lines.join("\n")));
  115. utils.logLabeledBullet(extensionsHelper_1.logPrefix, `to install this extension, type ` +
  116. clc.bold(`firebase ext:install ${extensionName} --project=YOUR_PROJECT`));
  117. }
  118. });