Ingen beskrivning
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

index.js 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.doSetup = void 0;
  4. const logger_1 = require("../../../logger");
  5. const apiEnabled = require("../../../ensureApiEnabled");
  6. const ensureCloudResourceLocation_1 = require("../../../ensureCloudResourceLocation");
  7. const requirePermissions_1 = require("../../../requirePermissions");
  8. const checkDatabaseType_1 = require("../../../firestore/checkDatabaseType");
  9. const rules = require("./rules");
  10. const indexes = require("./indexes");
  11. const error_1 = require("../../../error");
  12. const clc = require("colorette");
  13. async function checkProjectSetup(setup, config, options) {
  14. const firestoreUnusedError = new error_1.FirebaseError(`It looks like you haven't used Cloud Firestore in this project before. Go to ${clc.bold(clc.underline(`https://console.firebase.google.com/project/${setup.projectId}/firestore`))} to create your Cloud Firestore database.`, { exit: 1 });
  15. const isFirestoreEnabled = await apiEnabled.check(setup.projectId, "firestore.googleapis.com", "", true);
  16. if (!isFirestoreEnabled) {
  17. throw firestoreUnusedError;
  18. }
  19. const dbType = await (0, checkDatabaseType_1.checkDatabaseType)(setup.projectId);
  20. logger_1.logger.debug(`database_type: ${dbType}`);
  21. if (!dbType) {
  22. throw firestoreUnusedError;
  23. }
  24. else if (dbType !== "CLOUD_FIRESTORE") {
  25. throw new error_1.FirebaseError(`It looks like this project is using Cloud Datastore or Cloud Firestore in Datastore mode. The Firebase CLI can only manage projects using Cloud Firestore in Native mode. For more information, visit https://cloud.google.com/datastore/docs/firestore-or-datastore`, { exit: 1 });
  26. }
  27. (0, ensureCloudResourceLocation_1.ensureLocationSet)(setup.projectLocation, "Cloud Firestore");
  28. await (0, requirePermissions_1.requirePermissions)(Object.assign(Object.assign({}, options), { project: setup.projectId }));
  29. }
  30. async function doSetup(setup, config, options) {
  31. if (setup.projectId) {
  32. await checkProjectSetup(setup, config, options);
  33. }
  34. setup.config.firestore = {};
  35. await rules.initRules(setup, config);
  36. await indexes.initIndexes(setup, config);
  37. }
  38. exports.doSetup = doSetup;