Bez popisu
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.

remoteconfig-get.js 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.command = void 0;
  4. const rcGet = require("../remoteconfig/get");
  5. const command_1 = require("../command");
  6. const requireAuth_1 = require("../requireAuth");
  7. const logger_1 = require("../logger");
  8. const projectUtils_1 = require("../projectUtils");
  9. const requirePermissions_1 = require("../requirePermissions");
  10. const get_1 = require("../remoteconfig/get");
  11. const utils = require("../utils");
  12. const Table = require("cli-table");
  13. const fs = require("fs");
  14. const util = require("util");
  15. const error_1 = require("../error");
  16. const tableHead = ["Entry Name", "Value"];
  17. const MAX_DISPLAY_ITEMS = 20;
  18. function checkValidOptionalNumber(versionNumber) {
  19. if (!versionNumber || typeof Number(versionNumber) === "number") {
  20. return versionNumber;
  21. }
  22. throw new error_1.FirebaseError(`Could not interpret "${versionNumber}" as a valid number.`);
  23. }
  24. exports.command = new command_1.Command("remoteconfig:get")
  25. .description("get a Firebase project's Remote Config template")
  26. .option("-v, --version-number <versionNumber>", "grabs the specified version of the template")
  27. .option("-o, --output [filename]", "write config output to a filename (if omitted, will use the default file path)")
  28. .before(requireAuth_1.requireAuth)
  29. .before(requirePermissions_1.requirePermissions, ["cloudconfig.configs.get"])
  30. .action(async (options) => {
  31. utils.assertIsStringOrUndefined(options.versionNumber);
  32. const template = await rcGet.getTemplate((0, projectUtils_1.needProjectId)(options), checkValidOptionalNumber(options.versionNumber));
  33. const table = new Table({ head: tableHead, style: { head: ["green"] } });
  34. if (template.conditions) {
  35. let updatedConditions = template.conditions
  36. .map((condition) => condition.name)
  37. .slice(0, MAX_DISPLAY_ITEMS)
  38. .join("\n");
  39. if (template.conditions.length > MAX_DISPLAY_ITEMS) {
  40. updatedConditions += "+more... \n";
  41. }
  42. table.push(["conditions", updatedConditions]);
  43. }
  44. const updatedParameters = (0, get_1.parseTemplateForTable)(template.parameters);
  45. table.push(["parameters", updatedParameters]);
  46. const updatedParameterGroups = (0, get_1.parseTemplateForTable)(template.parameterGroups);
  47. table.push(["parameterGroups", updatedParameterGroups]);
  48. table.push(["version", util.inspect(template.version, { showHidden: false, depth: null })]);
  49. const fileOut = !!options.output;
  50. if (fileOut) {
  51. const shouldUseDefaultFilename = options.output === true || options.output === "";
  52. let filename = undefined;
  53. if (shouldUseDefaultFilename) {
  54. filename = options.config.src.remoteconfig.template;
  55. }
  56. else {
  57. utils.assertIsString(options.output);
  58. filename = options.output;
  59. }
  60. const outTemplate = Object.assign({}, template);
  61. delete outTemplate.version;
  62. fs.writeFileSync(filename, JSON.stringify(outTemplate, null, 2));
  63. }
  64. else {
  65. logger_1.logger.info(table.toString());
  66. }
  67. return template;
  68. });