Без опису
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.command = void 0;
  4. const clc = require("colorette");
  5. const command_1 = require("../command");
  6. const logger_1 = require("../logger");
  7. const utils = require("../utils");
  8. const requirePermissions_1 = require("../requirePermissions");
  9. const requireConfig_1 = require("../requireConfig");
  10. const index_1 = require("../serve/index");
  11. const filterTargets_1 = require("../filterTargets");
  12. const projectUtils_1 = require("../projectUtils");
  13. const error_1 = require("../error");
  14. const VALID_TARGETS = ["hosting", "functions"];
  15. const REQUIRES_AUTH = ["hosting", "functions"];
  16. const ALL_TARGETS = Array.from(new Set(["database", "firestore", ...VALID_TARGETS]));
  17. function filterOnly(list, only = "") {
  18. if (!only) {
  19. return [];
  20. }
  21. const targets = only.split(",").map((o) => o.split(":")[0]);
  22. return targets.filter((t) => list.includes(t));
  23. }
  24. exports.command = new command_1.Command("serve")
  25. .description("start a local server for your static assets")
  26. .option("-p, --port <port>", "the port on which to listen (default: 5000)", 5000)
  27. .option("-o, --host <host>", "the host on which to listen (default: localhost)", "localhost")
  28. .option("--only <targets>", "only serve specified targets (valid targets are: " + VALID_TARGETS.join(", ") + ")")
  29. .option("--except <targets>", "serve all except specified targets (valid targets are: " + VALID_TARGETS.join(", ") + ")")
  30. .before((options) => {
  31. if (options.only &&
  32. options.only.length > 0 &&
  33. filterOnly(REQUIRES_AUTH, options.only).length === 0) {
  34. return Promise.resolve();
  35. }
  36. return (0, requireConfig_1.requireConfig)(options)
  37. .then(() => (0, requirePermissions_1.requirePermissions)(options))
  38. .then(() => (0, projectUtils_1.needProjectNumber)(options));
  39. })
  40. .action((options) => {
  41. options.targets = filterOnly(ALL_TARGETS, options.only);
  42. if (options.targets.includes("database") || options.targets.includes("firestore")) {
  43. throw new error_1.FirebaseError(`Please use ${clc.bold("firebase emulators:start")} to start the Realtime Database or Cloud Firestore emulators. ${clc.bold("firebase serve")} only supports Hosting and Cloud Functions.`);
  44. }
  45. options.targets = filterOnly(VALID_TARGETS, options.only);
  46. if (options.targets.length > 0) {
  47. return (0, index_1.serve)(options);
  48. }
  49. if (options.config) {
  50. logger_1.logger.info();
  51. logger_1.logger.info(clc.bold(clc.white("===") + " Serving from '" + options.config.projectDir + "'..."));
  52. logger_1.logger.info();
  53. }
  54. else {
  55. utils.logWarning("No Firebase project directory detected. Serving static content from " +
  56. clc.bold(options.cwd || process.cwd()));
  57. }
  58. options.targets = (0, filterTargets_1.filterTargets)(options, VALID_TARGETS);
  59. return (0, index_1.serve)(options);
  60. });