설명 없음
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.

options-parser-util.js 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.getAppName = exports.getProjectName = exports.ensureFileExists = exports.getEmails = exports.getTestersOrGroups = void 0;
  4. const fs = require("fs-extra");
  5. const error_1 = require("../error");
  6. const projectUtils_1 = require("../projectUtils");
  7. function getTestersOrGroups(value, file) {
  8. if (!value && file) {
  9. ensureFileExists(file);
  10. value = fs.readFileSync(file, "utf8");
  11. }
  12. if (value) {
  13. return splitter(value);
  14. }
  15. return [];
  16. }
  17. exports.getTestersOrGroups = getTestersOrGroups;
  18. function getEmails(emails, file) {
  19. if (emails.length === 0) {
  20. ensureFileExists(file);
  21. const readFile = fs.readFileSync(file, "utf8");
  22. return splitter(readFile);
  23. }
  24. return emails;
  25. }
  26. exports.getEmails = getEmails;
  27. function ensureFileExists(file, message = "") {
  28. if (!fs.existsSync(file)) {
  29. throw new error_1.FirebaseError(`File ${file} does not exist: ${message}`);
  30. }
  31. }
  32. exports.ensureFileExists = ensureFileExists;
  33. function splitter(value) {
  34. return value
  35. .split(/[,\n]/)
  36. .map((entry) => entry.trim())
  37. .filter((entry) => !!entry);
  38. }
  39. async function getProjectName(options) {
  40. const projectNumber = await (0, projectUtils_1.needProjectNumber)(options);
  41. return `projects/${projectNumber}`;
  42. }
  43. exports.getProjectName = getProjectName;
  44. function getAppName(options) {
  45. if (!options.app) {
  46. throw new error_1.FirebaseError("set the --app option to a valid Firebase app id and try again");
  47. }
  48. const appId = options.app;
  49. return `projects/${appId.split(":")[1]}/apps/${appId}`;
  50. }
  51. exports.getAppName = getAppName;