releaseCacheManager.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. function _path() {
  7. const data = _interopRequireDefault(require("path"));
  8. _path = function () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. function _fs() {
  14. const data = _interopRequireDefault(require("fs"));
  15. _fs = function () {
  16. return data;
  17. };
  18. return data;
  19. }
  20. function _os() {
  21. const data = _interopRequireDefault(require("os"));
  22. _os = function () {
  23. return data;
  24. };
  25. return data;
  26. }
  27. function _mkdirp() {
  28. const data = _interopRequireDefault(require("mkdirp"));
  29. _mkdirp = function () {
  30. return data;
  31. };
  32. return data;
  33. }
  34. function _cliTools() {
  35. const data = require("@react-native-community/cli-tools");
  36. _cliTools = function () {
  37. return data;
  38. };
  39. return data;
  40. }
  41. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  42. function loadCache(name) {
  43. try {
  44. const cacheRaw = _fs().default.readFileSync(_path().default.resolve(getCacheRootPath(), name), 'utf8');
  45. const cache = JSON.parse(cacheRaw);
  46. return cache;
  47. } catch (e) {
  48. if (e.code === 'ENOENT') {
  49. // Create cache file since it doesn't exist.
  50. saveCache(name, {});
  51. }
  52. _cliTools().logger.debug('No release cache found');
  53. return undefined;
  54. }
  55. }
  56. function saveCache(name, cache) {
  57. _fs().default.writeFileSync(_path().default.resolve(getCacheRootPath(), name), JSON.stringify(cache, null, 2));
  58. }
  59. /**
  60. * Returns the path string of `$HOME/.react-native-cli`.
  61. *
  62. * In case it doesn't exist, it will be created.
  63. */
  64. function getCacheRootPath() {
  65. const cachePath = _path().default.resolve(_os().default.homedir(), '.react-native-cli', 'cache');
  66. if (!_fs().default.existsSync(cachePath)) {
  67. _mkdirp().default.sync(cachePath);
  68. }
  69. return cachePath;
  70. }
  71. function get(name, key) {
  72. const cache = loadCache(name);
  73. if (cache) {
  74. return cache[key];
  75. }
  76. return undefined;
  77. }
  78. function set(name, key, value) {
  79. const cache = loadCache(name);
  80. if (cache) {
  81. cache[key] = value;
  82. saveCache(name, cache);
  83. }
  84. }
  85. var _default = {
  86. get,
  87. set
  88. };
  89. exports.default = _default;
  90. //# sourceMappingURL=releaseCacheManager.js.map