UNPKG

5.28 kBJavaScriptView Raw
1"use strict";
2
3var cov_1n5kj1atco = function () {
4 var path = "/home/travis/build/commitizen/cz-cli/src/commitizen/cache.js";
5 var hash = "eaa1323be747e42b3e17d11202bfcb8d4966dc0d";
6 var global = new Function("return this")();
7 var gcv = "__coverage__";
8 var coverageData = {
9 path: "/home/travis/build/commitizen/cz-cli/src/commitizen/cache.js",
10 statementMap: {
11 "0": {
12 start: {
13 line: 14,
14 column: 2
15 },
16 end: {
17 line: 14,
18 column: 56
19 }
20 },
21 "1": {
22 start: {
23 line: 22,
24 column: 2
25 },
26 end: {
27 line: 26,
28 column: 3
29 }
30 },
31 "2": {
32 start: {
33 line: 23,
34 column: 4
35 },
36 end: {
37 line: 23,
38 column: 45
39 }
40 },
41 "3": {
42 start: {
43 line: 25,
44 column: 4
45 },
46 end: {
47 line: 25,
48 column: 23
49 }
50 },
51 "4": {
52 start: {
53 line: 27,
54 column: 17
55 },
56 end: {
57 line: 29,
58 column: 4
59 }
60 },
61 "5": {
62 start: {
63 line: 30,
64 column: 2
65 },
66 end: {
67 line: 30,
68 column: 68
69 }
70 },
71 "6": {
72 start: {
73 line: 31,
74 column: 2
75 },
76 end: {
77 line: 31,
78 column: 18
79 }
80 },
81 "7": {
82 start: {
83 line: 38,
84 column: 2
85 },
86 end: {
87 line: 43,
88 column: 3
89 }
90 },
91 "8": {
92 start: {
93 line: 39,
94 column: 16
95 },
96 end: {
97 line: 39,
98 column: 40
99 }
100 },
101 "9": {
102 start: {
103 line: 40,
104 column: 4
105 },
106 end: {
107 line: 40,
108 column: 27
109 }
110 }
111 },
112 fnMap: {
113 "0": {
114 name: "readCacheSync",
115 decl: {
116 start: {
117 line: 13,
118 column: 9
119 },
120 end: {
121 line: 13,
122 column: 22
123 }
124 },
125 loc: {
126 start: {
127 line: 13,
128 column: 35
129 },
130 end: {
131 line: 15,
132 column: 1
133 }
134 },
135 line: 13
136 },
137 "1": {
138 name: "setCacheValueSync",
139 decl: {
140 start: {
141 line: 20,
142 column: 9
143 },
144 end: {
145 line: 20,
146 column: 26
147 }
148 },
149 loc: {
150 start: {
151 line: 20,
152 column: 51
153 },
154 end: {
155 line: 32,
156 column: 1
157 }
158 },
159 line: 20
160 },
161 "2": {
162 name: "getCacheValueSync",
163 decl: {
164 start: {
165 line: 37,
166 column: 9
167 },
168 end: {
169 line: 37,
170 column: 26
171 }
172 },
173 loc: {
174 start: {
175 line: 37,
176 column: 49
177 },
178 end: {
179 line: 44,
180 column: 1
181 }
182 },
183 line: 37
184 }
185 },
186 branchMap: {},
187 s: {
188 "0": 0,
189 "1": 0,
190 "2": 0,
191 "3": 0,
192 "4": 0,
193 "5": 0,
194 "6": 0,
195 "7": 0,
196 "8": 0,
197 "9": 0
198 },
199 f: {
200 "0": 0,
201 "1": 0,
202 "2": 0
203 },
204 b: {},
205 _coverageSchema: "43e27e138ebf9cfc5966b082cf9a028302ed4184",
206 hash: "eaa1323be747e42b3e17d11202bfcb8d4966dc0d"
207 };
208 var coverage = global[gcv] || (global[gcv] = {});
209
210 if (coverage[path] && coverage[path].hash === hash) {
211 return coverage[path];
212 }
213
214 return coverage[path] = coverageData;
215}();
216
217Object.defineProperty(exports, "__esModule", {
218 value: true
219});
220exports.getCacheValueSync = getCacheValueSync;
221exports.readCacheSync = readCacheSync;
222exports.setCacheValueSync = setCacheValueSync;
223
224var _fs = _interopRequireDefault(require("fs"));
225
226var _lodash = _interopRequireDefault(require("lodash"));
227
228function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
229
230/**
231 * Reads the entire cache
232 */
233function readCacheSync(cachePath) {
234 cov_1n5kj1atco.f[0]++;
235 cov_1n5kj1atco.s[0]++;
236 return JSON.parse(_fs.default.readFileSync(cachePath, 'utf8'));
237}
238/**
239 * Sets a cache value and writes the file to disk
240 */
241
242
243function setCacheValueSync(cachePath, key, value) {
244 cov_1n5kj1atco.f[1]++;
245 var originalCache;
246 cov_1n5kj1atco.s[1]++;
247
248 try {
249 cov_1n5kj1atco.s[2]++;
250 originalCache = readCacheSync(cachePath);
251 } catch (e) {
252 cov_1n5kj1atco.s[3]++;
253 originalCache = {};
254 }
255
256 var newCache = (cov_1n5kj1atco.s[4]++, _lodash.default.assign(originalCache, {
257 [key]: value
258 }));
259 cov_1n5kj1atco.s[5]++;
260
261 _fs.default.writeFileSync(cachePath, JSON.stringify(newCache, null, ' '));
262
263 cov_1n5kj1atco.s[6]++;
264 return newCache;
265}
266/**
267 * Gets a single value from the cache given a key
268 */
269
270
271function getCacheValueSync(cachePath, repoPath) {
272 cov_1n5kj1atco.f[2]++;
273 cov_1n5kj1atco.s[7]++;
274
275 try {
276 let cache = (cov_1n5kj1atco.s[8]++, readCacheSync(cachePath));
277 cov_1n5kj1atco.s[9]++;
278 return cache[repoPath];
279 } catch (e) {}
280}
\No newline at end of file