1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 | function _path() {
|
8 | const data = _interopRequireDefault(require("path"));
|
9 | _path = function () {
|
10 | return data;
|
11 | };
|
12 | return data;
|
13 | }
|
14 | function _fs() {
|
15 | const data = _interopRequireDefault(require("fs"));
|
16 | _fs = function () {
|
17 | return data;
|
18 | };
|
19 | return data;
|
20 | }
|
21 | function _os() {
|
22 | const data = _interopRequireDefault(require("os"));
|
23 | _os = function () {
|
24 | return data;
|
25 | };
|
26 | return data;
|
27 | }
|
28 | function _appdirsjs() {
|
29 | const data = _interopRequireDefault(require("appdirsjs"));
|
30 | _appdirsjs = function () {
|
31 | return data;
|
32 | };
|
33 | return data;
|
34 | }
|
35 | var _logger = _interopRequireDefault(require("../logger"));
|
36 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
37 | function 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 |
|
45 | saveCache(name, {});
|
46 | }
|
47 | _logger.default.debug('No release cache found');
|
48 | return undefined;
|
49 | }
|
50 | }
|
51 | function saveCache(name, cache) {
|
52 | _fs().default.writeFileSync(_path().default.resolve(getCacheRootPath(), name), JSON.stringify(cache, null, 2));
|
53 | }
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | function 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 | }
|
73 | function get(name, key) {
|
74 | const cache = loadCache(name);
|
75 | if (cache) {
|
76 | return cache[key];
|
77 | }
|
78 | return undefined;
|
79 | }
|
80 | function set(name, key, value) {
|
81 | const cache = loadCache(name);
|
82 | if (cache) {
|
83 | cache[key] = value;
|
84 | saveCache(name, cache);
|
85 | }
|
86 | }
|
87 | var _default = {
|
88 | get,
|
89 | set
|
90 | };
|
91 | exports.default = _default;
|
92 |
|
93 | //# sourceMappingURL=releaseCacheManager.js.map |
\ | No newline at end of file |