No Description
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.

prepare.js 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const _ = require("lodash");
  4. const clc = require("colorette");
  5. const loadCJSON_1 = require("../../loadCJSON");
  6. const rulesDeploy_1 = require("../../rulesDeploy");
  7. const utils = require("../../utils");
  8. async function prepareRules(context, options) {
  9. var _a;
  10. const rulesFile = (_a = options.config.src.firestore) === null || _a === void 0 ? void 0 : _a.rules;
  11. if (context.firestoreRules && rulesFile) {
  12. const rulesDeploy = new rulesDeploy_1.RulesDeploy(options, rulesDeploy_1.RulesetServiceType.CLOUD_FIRESTORE);
  13. _.set(context, "firestore.rulesDeploy", rulesDeploy);
  14. rulesDeploy.addFile(rulesFile);
  15. await rulesDeploy.compile();
  16. }
  17. }
  18. function prepareIndexes(context, options) {
  19. var _a;
  20. if (!context.firestoreIndexes || !((_a = options.config.src.firestore) === null || _a === void 0 ? void 0 : _a.indexes)) {
  21. return;
  22. }
  23. const indexesFileName = options.config.src.firestore.indexes;
  24. const indexesPath = options.config.path(indexesFileName);
  25. const parsedSrc = (0, loadCJSON_1.loadCJSON)(indexesPath);
  26. utils.logBullet(`${clc.bold(clc.cyan("firestore:"))} reading indexes from ${clc.bold(indexesFileName)}...`);
  27. context.firestore = context.firestore || {};
  28. context.firestore.indexes = {
  29. name: indexesFileName,
  30. content: parsedSrc,
  31. };
  32. }
  33. async function default_1(context, options) {
  34. if (options.only) {
  35. const targets = options.only.split(",");
  36. const onlyIndexes = targets.indexOf("firestore:indexes") >= 0;
  37. const onlyRules = targets.indexOf("firestore:rules") >= 0;
  38. const onlyFirestore = targets.indexOf("firestore") >= 0;
  39. context.firestoreIndexes = onlyIndexes || onlyFirestore;
  40. context.firestoreRules = onlyRules || onlyFirestore;
  41. }
  42. else {
  43. context.firestoreIndexes = true;
  44. context.firestoreRules = true;
  45. }
  46. prepareIndexes(context, options);
  47. await prepareRules(context, options);
  48. }
  49. exports.default = default_1;