UNPKG

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