GSI - Employe Self Service Mobile
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.

48 lines
1.5 KiB

2 months ago
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.dump = exports.load = void 0;
  4. const fs = require("fs-extra");
  5. const path = require("path");
  6. const logger_1 = require("../../logger");
  7. function cachePath(cwd, name) {
  8. return path.resolve(cwd, `.firebase/hosting.${name}.cache`);
  9. }
  10. function load(cwd, name) {
  11. try {
  12. const out = new Map();
  13. const lines = fs.readFileSync(cachePath(cwd, name), "utf8");
  14. for (const line of lines.split("\n")) {
  15. const d = line.split(",");
  16. if (d.length === 3) {
  17. out.set(d[0], { mtime: parseInt(d[1]), hash: d[2] });
  18. }
  19. }
  20. return out;
  21. }
  22. catch (e) {
  23. if (e.code === "ENOENT") {
  24. logger_1.logger.debug(`[hosting] hash cache [${name}] not populated`);
  25. }
  26. else {
  27. logger_1.logger.debug(`[hosting] hash cache [${name}] load error: ${e.message}`);
  28. }
  29. return new Map();
  30. }
  31. }
  32. exports.load = load;
  33. function dump(cwd, name, data) {
  34. let st = "";
  35. let count = 0;
  36. for (const [path, d] of data) {
  37. count++;
  38. st += `${path},${d.mtime},${d.hash}\n`;
  39. }
  40. try {
  41. fs.outputFileSync(cachePath(cwd, name), st, { encoding: "utf8" });
  42. logger_1.logger.debug(`[hosting] hash cache [${name}] stored for ${count} files`);
  43. }
  44. catch (e) {
  45. logger_1.logger.debug(`[hosting] unable to store hash cache [${name}]: ${e.stack}`);
  46. }
  47. }
  48. exports.dump = dump;