説明なし
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

fetchMOTD.js 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.fetchMOTD = void 0;
  4. const clc = require("colorette");
  5. const semver = require("semver");
  6. const apiv2_1 = require("./apiv2");
  7. const configstore_1 = require("./configstore");
  8. const logger_1 = require("./logger");
  9. const api_1 = require("./api");
  10. const utils = require("./utils");
  11. const pkg = require("../package.json");
  12. const ONE_DAY_MS = 1000 * 60 * 60 * 24;
  13. function fetchMOTD() {
  14. let motd = configstore_1.configstore.get("motd");
  15. const motdFetched = configstore_1.configstore.get("motd.fetched") || 0;
  16. if (motd && motdFetched > Date.now() - ONE_DAY_MS) {
  17. if (motd.minVersion && semver.gt(motd.minVersion, pkg.version)) {
  18. console.error(clc.red("Error:"), "CLI is out of date (on", clc.bold(pkg.version), ", need at least", clc.bold(motd.minVersion) + ")\n\nRun", clc.bold("npm install -g firebase-tools"), "to upgrade.");
  19. process.exit(1);
  20. }
  21. if (motd.message && process.stdout.isTTY) {
  22. const lastMessage = configstore_1.configstore.get("motd.lastMessage");
  23. if (lastMessage !== motd.message) {
  24. console.log();
  25. console.log(motd.message);
  26. console.log();
  27. configstore_1.configstore.set("motd.lastMessage", motd.message);
  28. }
  29. }
  30. }
  31. else {
  32. const origin = utils.addSubdomain(api_1.realtimeOrigin, "firebase-public");
  33. const c = new apiv2_1.Client({ urlPrefix: origin, auth: false });
  34. c.get("/cli.json")
  35. .then((res) => {
  36. motd = Object.assign({}, res.body);
  37. configstore_1.configstore.set("motd", motd);
  38. configstore_1.configstore.set("motd.fetched", Date.now());
  39. })
  40. .catch((err) => {
  41. utils.logWarning("Unable to fetch the CLI MOTD and remote config.");
  42. logger_1.logger.debug(`Failed to fetch MOTD ${err}`);
  43. });
  44. }
  45. }
  46. exports.fetchMOTD = fetchMOTD;