redis-memory-server 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,58 +8,31 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
39
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
13
  };
41
14
  Object.defineProperty(exports, "__esModule", { value: true });
42
- var url_1 = __importDefault(require("url"));
43
- var path_1 = __importDefault(require("path"));
44
- var fs_1 = __importDefault(require("fs"));
45
- var rimraf_1 = __importDefault(require("rimraf"));
46
- var https_1 = __importDefault(require("https"));
47
- var tar_1 = __importDefault(require("tar"));
48
- var extract_zip_1 = __importDefault(require("extract-zip"));
49
- var RedisBinaryDownloadUrl_1 = __importDefault(require("./RedisBinaryDownloadUrl"));
50
- var RedisBinary_1 = require("./RedisBinary");
51
- var https_proxy_agent_1 = require("https-proxy-agent");
52
- var child_process_1 = require("child_process");
53
- var util_1 = require("util");
15
+ const url_1 = __importDefault(require("url"));
16
+ const path_1 = __importDefault(require("path"));
17
+ const fs_1 = __importDefault(require("fs"));
18
+ const rimraf_1 = require("rimraf");
19
+ const http_1 = __importDefault(require("http"));
20
+ const https_1 = __importDefault(require("https"));
21
+ const tar_1 = __importDefault(require("tar"));
22
+ const extract_zip_1 = __importDefault(require("extract-zip"));
23
+ const RedisBinaryDownloadUrl_1 = __importDefault(require("./RedisBinaryDownloadUrl"));
24
+ const RedisBinary_1 = require("./RedisBinary");
25
+ const https_proxy_agent_1 = require("https-proxy-agent");
26
+ const child_process_1 = require("child_process");
27
+ const util_1 = require("util");
54
28
  require("./resolve-config");
55
- var debug_1 = __importDefault(require("debug"));
56
- var log = debug_1.default('RedisMS:RedisBinaryDownload');
29
+ const debug_1 = __importDefault(require("debug"));
30
+ const log = (0, debug_1.default)('RedisMS:RedisBinaryDownload');
57
31
  /**
58
32
  * Download and extract the "redis-server" binary
59
33
  */
60
- var RedisBinaryDownload = /** @class */ (function () {
61
- function RedisBinaryDownload(_a) {
62
- var downloadDir = _a.downloadDir, version = _a.version;
34
+ class RedisBinaryDownload {
35
+ constructor({ downloadDir, version }) {
63
36
  this.version = version !== null && version !== void 0 ? version : RedisBinary_1.LATEST_VERSION;
64
37
  this.downloadDir = path_1.default.resolve(downloadDir || 'redis-download');
65
38
  this.dlProgress = {
@@ -73,278 +46,209 @@ var RedisBinaryDownload = /** @class */ (function () {
73
46
  * Get the path of the already downloaded "redis-server" file
74
47
  * otherwise download it and then return the path
75
48
  */
76
- RedisBinaryDownload.prototype.getRedisServerPath = function () {
77
- return __awaiter(this, void 0, void 0, function () {
78
- var binaryName, redisServerPath, redisArchive, extractDir;
79
- return __generator(this, function (_a) {
80
- switch (_a.label) {
81
- case 0:
82
- binaryName = process.platform === 'win32' ? 'redis-server.exe' : 'redis-server';
83
- redisServerPath = path_1.default.resolve(this.downloadDir, this.version, binaryName);
84
- return [4 /*yield*/, this.locationExists(redisServerPath)];
85
- case 1:
86
- if (_a.sent()) {
87
- return [2 /*return*/, redisServerPath];
88
- }
89
- return [4 /*yield*/, this.startDownload()];
90
- case 2:
91
- redisArchive = _a.sent();
92
- return [4 /*yield*/, this.extract(redisArchive)];
93
- case 3:
94
- extractDir = _a.sent();
95
- if (!(process.platform === 'win32')) return [3 /*break*/, 5];
96
- return [4 /*yield*/, this.makeInstallWin32(extractDir)];
97
- case 4:
98
- _a.sent();
99
- return [3 /*break*/, 7];
100
- case 5: return [4 /*yield*/, this.makeInstall(extractDir)];
101
- case 6:
102
- _a.sent();
103
- _a.label = 7;
104
- case 7:
105
- fs_1.default.unlinkSync(redisArchive);
106
- return [4 /*yield*/, this.locationExists(redisServerPath)];
107
- case 8:
108
- if (_a.sent()) {
109
- return [2 /*return*/, redisServerPath];
110
- }
111
- throw new Error("Cannot find downloaded redis-server binary by path " + redisServerPath);
112
- }
113
- });
49
+ getRedisServerPath() {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ const binaryName = process.platform === 'win32' ? 'redis-server.exe' : 'redis-server';
52
+ const redisServerPath = path_1.default.resolve(this.downloadDir, this.version, binaryName);
53
+ if (yield this.locationExists(redisServerPath)) {
54
+ return redisServerPath;
55
+ }
56
+ const redisArchive = yield this.startDownload();
57
+ const extractDir = yield this.extract(redisArchive);
58
+ if (process.platform === 'win32') {
59
+ yield this.makeInstallWin32(extractDir);
60
+ }
61
+ else {
62
+ yield this.makeInstall(extractDir);
63
+ }
64
+ fs_1.default.unlinkSync(redisArchive);
65
+ if (yield this.locationExists(redisServerPath)) {
66
+ return redisServerPath;
67
+ }
68
+ throw new Error(`Cannot find downloaded redis-server binary by path ${redisServerPath}`);
114
69
  });
115
- };
70
+ }
116
71
  /**
117
72
  * Download the Redis Archive
118
73
  * @returns The Redis Archive location
119
74
  */
120
- RedisBinaryDownload.prototype.startDownload = function () {
121
- return __awaiter(this, void 0, void 0, function () {
122
- var mbdUrl, downloadUrl;
123
- return __generator(this, function (_a) {
124
- switch (_a.label) {
125
- case 0:
126
- mbdUrl = new RedisBinaryDownloadUrl_1.default({
127
- version: this.version,
128
- });
129
- if (!fs_1.default.existsSync(this.downloadDir)) {
130
- fs_1.default.mkdirSync(this.downloadDir);
131
- }
132
- return [4 /*yield*/, mbdUrl.getDownloadUrl()];
133
- case 1:
134
- downloadUrl = _a.sent();
135
- return [2 /*return*/, this.download(downloadUrl)];
136
- }
75
+ startDownload() {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ const mbdUrl = new RedisBinaryDownloadUrl_1.default({
78
+ version: this.version,
137
79
  });
80
+ if (!fs_1.default.existsSync(this.downloadDir)) {
81
+ fs_1.default.mkdirSync(this.downloadDir);
82
+ }
83
+ const downloadUrl = yield mbdUrl.getDownloadUrl();
84
+ return this.download(downloadUrl);
138
85
  });
139
- };
86
+ }
140
87
  /**
141
88
  * Download file from downloadUrl
142
89
  * @param downloadUrl URL to download a File
143
90
  */
144
- RedisBinaryDownload.prototype.download = function (downloadUrl) {
145
- return __awaiter(this, void 0, void 0, function () {
146
- var proxy, strictSsl, urlObject, downloadOptions, filename, downloadLocation, tempDownloadLocation, downloadedFile;
147
- return __generator(this, function (_a) {
148
- switch (_a.label) {
149
- case 0:
150
- proxy = process.env['yarn_https-proxy'] ||
151
- process.env.yarn_proxy ||
152
- process.env['npm_config_https-proxy'] ||
153
- process.env.npm_config_proxy ||
154
- process.env.https_proxy ||
155
- process.env.http_proxy ||
156
- process.env.HTTPS_PROXY ||
157
- process.env.HTTP_PROXY;
158
- strictSsl = process.env.npm_config_strict_ssl === 'true';
159
- urlObject = url_1.default.parse(downloadUrl);
160
- if (!urlObject.hostname || !urlObject.path) {
161
- throw new Error("Provided incorrect download url: " + downloadUrl);
162
- }
163
- downloadOptions = {
164
- hostname: urlObject.hostname,
165
- port: urlObject.port || '443',
166
- path: urlObject.path,
167
- method: 'GET',
168
- rejectUnauthorized: strictSsl,
169
- agent: proxy ? new https_proxy_agent_1.HttpsProxyAgent(proxy) : undefined,
170
- };
171
- filename = (urlObject.pathname || '').split('/').pop();
172
- if (!filename) {
173
- throw new Error("RedisBinaryDownload: missing filename for url " + downloadUrl);
174
- }
175
- downloadLocation = path_1.default.resolve(this.downloadDir, filename);
176
- tempDownloadLocation = path_1.default.resolve(this.downloadDir, filename + ".downloading");
177
- log("Downloading" + (proxy ? " via proxy " + proxy : '') + ": \"" + downloadUrl + "\"");
178
- return [4 /*yield*/, this.locationExists(downloadLocation)];
179
- case 1:
180
- if (_a.sent()) {
181
- log('Already downloaded archive found, skipping download');
182
- return [2 /*return*/, downloadLocation];
183
- }
184
- this._downloadingUrl = downloadUrl;
185
- return [4 /*yield*/, this.httpDownload(downloadOptions, downloadLocation, tempDownloadLocation)];
186
- case 2:
187
- downloadedFile = _a.sent();
188
- return [2 /*return*/, downloadedFile];
189
- }
190
- });
91
+ download(downloadUrl) {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ const proxy = process.env['yarn_https-proxy'] ||
94
+ process.env.yarn_proxy ||
95
+ process.env['npm_config_https-proxy'] ||
96
+ process.env.npm_config_proxy ||
97
+ process.env.https_proxy ||
98
+ process.env.http_proxy ||
99
+ process.env.HTTPS_PROXY ||
100
+ process.env.HTTP_PROXY;
101
+ const strictSsl = process.env.npm_config_strict_ssl === 'true';
102
+ const urlObject = url_1.default.parse(downloadUrl);
103
+ if (!urlObject.hostname || !urlObject.path) {
104
+ throw new Error(`Provided incorrect download url: ${downloadUrl}`);
105
+ }
106
+ const downloadOptions = {
107
+ hostname: urlObject.hostname,
108
+ port: urlObject.port || '443',
109
+ path: urlObject.path,
110
+ protocol: urlObject.protocol || 'https:',
111
+ method: 'GET',
112
+ rejectUnauthorized: strictSsl,
113
+ agent: proxy ? new https_proxy_agent_1.HttpsProxyAgent(proxy) : undefined,
114
+ };
115
+ const filename = (urlObject.pathname || '').split('/').pop();
116
+ if (!filename) {
117
+ throw new Error(`RedisBinaryDownload: missing filename for url ${downloadUrl}`);
118
+ }
119
+ const downloadLocation = path_1.default.resolve(this.downloadDir, filename);
120
+ const tempDownloadLocation = path_1.default.resolve(this.downloadDir, `${filename}.downloading`);
121
+ log(`Downloading${proxy ? ` via proxy ${proxy}` : ''}: "${downloadUrl}"`);
122
+ if (yield this.locationExists(downloadLocation)) {
123
+ log('Already downloaded archive found, skipping download');
124
+ return downloadLocation;
125
+ }
126
+ this._downloadingUrl = downloadUrl;
127
+ const downloadedFile = yield this.httpDownload(downloadOptions, downloadLocation, tempDownloadLocation);
128
+ return downloadedFile;
191
129
  });
192
- };
130
+ }
193
131
  /**
194
132
  * Extract given Archive
195
133
  * @param redisArchive Archive location
196
134
  * @returns extracted directory location
197
135
  */
198
- RedisBinaryDownload.prototype.extract = function (redisArchive) {
136
+ extract(redisArchive) {
199
137
  var _a;
200
- return __awaiter(this, void 0, void 0, function () {
201
- var extractDir;
202
- return __generator(this, function (_b) {
203
- switch (_b.label) {
204
- case 0:
205
- extractDir = path_1.default.resolve(this.downloadDir, this.version, 'extracted');
206
- log("extract(): " + extractDir);
207
- if (!fs_1.default.existsSync(extractDir)) {
208
- fs_1.default.mkdirSync(extractDir, { recursive: true });
209
- }
210
- if (!redisArchive.endsWith('.zip')) return [3 /*break*/, 2];
211
- return [4 /*yield*/, this.extractZip(redisArchive, extractDir)];
212
- case 1:
213
- _b.sent();
214
- return [3 /*break*/, 5];
215
- case 2:
216
- if (!redisArchive.endsWith('.tar.gz')) return [3 /*break*/, 4];
217
- return [4 /*yield*/, this.extractTarGz(redisArchive, extractDir)];
218
- case 3:
219
- _b.sent();
220
- return [3 /*break*/, 5];
221
- case 4: throw new Error("RedisBinaryDownload: unsupported archive " + redisArchive + " (downloaded from " + ((_a = this._downloadingUrl) !== null && _a !== void 0 ? _a : 'unkown') + "). Broken archive from Redis Provider?");
222
- case 5: return [2 /*return*/, extractDir];
223
- }
224
- });
138
+ return __awaiter(this, void 0, void 0, function* () {
139
+ const extractDir = path_1.default.resolve(this.downloadDir, this.version, 'extracted');
140
+ log(`extract(): ${extractDir}`);
141
+ if (!fs_1.default.existsSync(extractDir)) {
142
+ fs_1.default.mkdirSync(extractDir, { recursive: true });
143
+ }
144
+ if (redisArchive.endsWith('.zip')) {
145
+ yield this.extractZip(redisArchive, extractDir);
146
+ }
147
+ else if (redisArchive.endsWith('.tar.gz')) {
148
+ yield this.extractTarGz(redisArchive, extractDir);
149
+ }
150
+ else {
151
+ throw new Error(`RedisBinaryDownload: unsupported archive ${redisArchive} (downloaded from ${(_a = this._downloadingUrl) !== null && _a !== void 0 ? _a : 'unkown'}). Broken archive from Redis Provider?`);
152
+ }
153
+ return extractDir;
225
154
  });
226
- };
155
+ }
227
156
  /**
228
157
  * Extract a .tar.gz archive
229
158
  * @param redisArchive Archive location
230
159
  * @param extractDir Directory to extract to
231
160
  */
232
- RedisBinaryDownload.prototype.extractTarGz = function (redisArchive, extractDir) {
233
- return __awaiter(this, void 0, void 0, function () {
234
- return __generator(this, function (_a) {
235
- switch (_a.label) {
236
- case 0: return [4 /*yield*/, tar_1.default.extract({
237
- file: redisArchive,
238
- cwd: extractDir,
239
- strip: 1,
240
- })];
241
- case 1:
242
- _a.sent();
243
- return [2 /*return*/];
244
- }
161
+ extractTarGz(redisArchive, extractDir) {
162
+ return __awaiter(this, void 0, void 0, function* () {
163
+ yield tar_1.default.extract({
164
+ file: redisArchive,
165
+ cwd: extractDir,
166
+ strip: 1,
245
167
  });
246
168
  });
247
- };
169
+ }
248
170
  /**
249
171
  * Extract a .zip archive
250
172
  * @param redisArchive Archive location
251
173
  * @param extractDir Directory to extract to
252
174
  */
253
- RedisBinaryDownload.prototype.extractZip = function (redisArchive, extractDir) {
254
- return __awaiter(this, void 0, void 0, function () {
255
- return __generator(this, function (_a) {
256
- switch (_a.label) {
257
- case 0: return [4 /*yield*/, extract_zip_1.default(redisArchive, { dir: extractDir })];
258
- case 1:
259
- _a.sent();
260
- return [2 /*return*/];
261
- }
262
- });
175
+ extractZip(redisArchive, extractDir) {
176
+ return __awaiter(this, void 0, void 0, function* () {
177
+ yield (0, extract_zip_1.default)(redisArchive, { dir: extractDir });
263
178
  });
264
- };
179
+ }
265
180
  /**
266
181
  * Downlaod given httpOptions to tempDownloadLocation, then move it to downloadLocation
267
182
  * @param httpOptions The httpOptions directly passed to https.get
268
183
  * @param downloadLocation The location the File should be after the download
269
184
  * @param tempDownloadLocation The location the File should be while downloading
270
185
  */
271
- RedisBinaryDownload.prototype.httpDownload = function (httpOptions, downloadLocation, tempDownloadLocation) {
272
- return __awaiter(this, void 0, void 0, function () {
273
- var _this = this;
274
- return __generator(this, function (_a) {
275
- return [2 /*return*/, new Promise(function (resolve, reject) {
276
- var fileStream = fs_1.default.createWriteStream(tempDownloadLocation);
277
- log("trying to download https://" + httpOptions.hostname + httpOptions.path);
278
- https_1.default
279
- .get(httpOptions, function (response) {
280
- // "as any" because otherwise the "agent" wouldnt match
281
- if (response.statusCode != 200) {
282
- if (response.statusCode === 404) {
283
- reject(new Error('Status Code is 404\n' +
284
- "This means that the requested version doesn't exist\n" +
285
- (" Used Url: \"https://" + httpOptions.hostname + httpOptions.path + "\"\n") +
286
- "Try to use different version 'new RedisMemoryServer({ binary: { version: 'X.Y.Z' } })'\n"));
287
- return;
288
- }
289
- reject(new Error('Status Code isnt 200!'));
290
- return;
291
- }
292
- if (typeof response.headers['content-length'] != 'string') {
293
- reject(new Error('Response header "content-length" is empty!'));
294
- return;
295
- }
296
- _this.dlProgress.current = 0;
297
- _this.dlProgress.length = parseInt(response.headers['content-length'], 10);
298
- _this.dlProgress.totalMb = Math.round((_this.dlProgress.length / 1048576) * 10) / 10;
299
- response.pipe(fileStream);
300
- fileStream.on('finish', function () { return __awaiter(_this, void 0, void 0, function () {
301
- var downloadUrl;
302
- return __generator(this, function (_a) {
303
- switch (_a.label) {
304
- case 0:
305
- if (this.dlProgress.current < this.dlProgress.length) {
306
- downloadUrl = this._downloadingUrl || "https://" + httpOptions.hostname + "/" + httpOptions.path;
307
- reject(new Error("Too small (" + this.dlProgress.current + " bytes) redis-server binary downloaded from " + downloadUrl));
308
- return [2 /*return*/];
309
- }
310
- fileStream.close();
311
- return [4 /*yield*/, util_1.promisify(fs_1.default.rename)(tempDownloadLocation, downloadLocation)];
312
- case 1:
313
- _a.sent();
314
- log("moved " + tempDownloadLocation + " to " + downloadLocation);
315
- resolve(downloadLocation);
316
- return [2 /*return*/];
317
- }
318
- });
319
- }); });
320
- response.on('data', function (chunk) {
321
- _this.printDownloadProgress(chunk);
322
- });
323
- })
324
- .on('error', function (e) {
325
- // log it without having debug enabled
326
- console.error("Couldnt download " + httpOptions.path + "!", e.message);
327
- reject(e);
328
- });
329
- })];
186
+ httpDownload(httpOptions, downloadLocation, tempDownloadLocation) {
187
+ return __awaiter(this, void 0, void 0, function* () {
188
+ return new Promise((resolve, reject) => {
189
+ const fileStream = fs_1.default.createWriteStream(tempDownloadLocation);
190
+ log(`trying to download ${httpOptions.protocol}//${httpOptions.hostname}${httpOptions.path}`);
191
+ (httpOptions.protocol === 'https:' ? https_1.default : http_1.default)
192
+ .get(httpOptions, (response) => {
193
+ // "as any" because otherwise the "agent" wouldnt match
194
+ if (response.statusCode != 200) {
195
+ if (response.statusCode === 404) {
196
+ reject(new Error('Status Code is 404\n' +
197
+ "This means that the requested version doesn't exist\n" +
198
+ ` Used Url: "${httpOptions.protocol}//${httpOptions.hostname}${httpOptions.path}"\n` +
199
+ "Try to use different version 'new RedisMemoryServer({ binary: { version: 'X.Y.Z' } })'\n"));
200
+ return;
201
+ }
202
+ reject(new Error('Status Code isnt 200!'));
203
+ return;
204
+ }
205
+ if (typeof response.headers['content-length'] != 'string') {
206
+ reject(new Error('Response header "content-length" is empty!'));
207
+ return;
208
+ }
209
+ this.dlProgress.current = 0;
210
+ this.dlProgress.length = parseInt(response.headers['content-length'], 10);
211
+ this.dlProgress.totalMb = Math.round((this.dlProgress.length / 1048576) * 10) / 10;
212
+ response.pipe(fileStream);
213
+ fileStream.on('finish', () => __awaiter(this, void 0, void 0, function* () {
214
+ if (this.dlProgress.current < this.dlProgress.length) {
215
+ const downloadUrl = this._downloadingUrl ||
216
+ `${httpOptions.protocol}//${httpOptions.hostname}/${httpOptions.path}`;
217
+ reject(new Error(`Too small (${this.dlProgress.current} bytes) redis-server binary downloaded from ${downloadUrl}`));
218
+ return;
219
+ }
220
+ fileStream.close();
221
+ yield (0, util_1.promisify)(fs_1.default.rename)(tempDownloadLocation, downloadLocation);
222
+ log(`moved ${tempDownloadLocation} to ${downloadLocation}`);
223
+ resolve(downloadLocation);
224
+ }));
225
+ response.on('data', (chunk) => {
226
+ this.printDownloadProgress(chunk);
227
+ });
228
+ })
229
+ .on('error', (e) => {
230
+ // log it without having debug enabled
231
+ console.error(`Couldnt download ${httpOptions.path}!`, e.message);
232
+ reject(e);
233
+ });
330
234
  });
331
235
  });
332
- };
236
+ }
333
237
  /**
334
238
  * Print the Download Progress to STDOUT
335
239
  * @param chunk A chunk to get the length
336
240
  */
337
- RedisBinaryDownload.prototype.printDownloadProgress = function (chunk) {
241
+ printDownloadProgress(chunk) {
338
242
  this.dlProgress.current += chunk.length;
339
- var now = Date.now();
243
+ const now = Date.now();
340
244
  if (now - this.dlProgress.lastPrintedAt < 2000) {
341
245
  return;
342
246
  }
343
247
  this.dlProgress.lastPrintedAt = now;
344
- var percentComplete = Math.round(((100.0 * this.dlProgress.current) / this.dlProgress.length) * 10) / 10;
345
- var mbComplete = Math.round((this.dlProgress.current / 1048576) * 10) / 10;
346
- var crReturn = '\r';
347
- var message = "Downloading Redis " + this.version + ": " + percentComplete + " % (" + mbComplete + "mb / " + this.dlProgress.totalMb + "mb)" + crReturn;
248
+ const percentComplete = Math.round(((100.0 * this.dlProgress.current) / this.dlProgress.length) * 10) / 10;
249
+ const mbComplete = Math.round((this.dlProgress.current / 1048576) * 10) / 10;
250
+ const crReturn = '\r';
251
+ const message = `Downloading Redis ${this.version}: ${percentComplete} % (${mbComplete}mb / ${this.dlProgress.totalMb}mb)${crReturn}`;
348
252
  if (process.stdout.isTTY) {
349
253
  // if TTY overwrite last line over and over until finished
350
254
  process.stdout.write(message);
@@ -352,88 +256,55 @@ var RedisBinaryDownload = /** @class */ (function () {
352
256
  else {
353
257
  console.log(message);
354
258
  }
355
- };
259
+ }
356
260
  /**
357
261
  * Make and install given extracted directory
358
262
  * @param extractDir Extracted directory location
359
263
  * @returns void
360
264
  */
361
- RedisBinaryDownload.prototype.makeInstall = function (extractDir) {
362
- return __awaiter(this, void 0, void 0, function () {
363
- var binaryName;
364
- return __generator(this, function (_a) {
365
- switch (_a.label) {
366
- case 0:
367
- binaryName = 'redis-server';
368
- log("makeInstall(): " + extractDir);
369
- return [4 /*yield*/, util_1.promisify(child_process_1.exec)('make', {
370
- cwd: extractDir,
371
- })];
372
- case 1:
373
- _a.sent();
374
- return [4 /*yield*/, util_1.promisify(fs_1.default.copyFile)(path_1.default.resolve(extractDir, 'src', binaryName), path_1.default.resolve(extractDir, '..', binaryName))];
375
- case 2:
376
- _a.sent();
377
- return [4 /*yield*/, util_1.promisify(rimraf_1.default)(extractDir)];
378
- case 3:
379
- _a.sent();
380
- return [2 /*return*/];
381
- }
265
+ makeInstall(extractDir) {
266
+ return __awaiter(this, void 0, void 0, function* () {
267
+ const binaryName = 'redis-server';
268
+ log(`makeInstall(): ${extractDir}`);
269
+ yield (0, util_1.promisify)(child_process_1.exec)('make', {
270
+ cwd: extractDir,
382
271
  });
272
+ yield (0, util_1.promisify)(fs_1.default.copyFile)(path_1.default.resolve(extractDir, 'src', binaryName), path_1.default.resolve(extractDir, '..', binaryName));
273
+ yield (0, rimraf_1.rimraf)(extractDir);
383
274
  });
384
- };
275
+ }
385
276
  /**
386
277
  * copy binary to parent folder and delete given extracted directory
387
278
  * @param extractDir Extracted directory location
388
279
  * @returns void
389
280
  */
390
- RedisBinaryDownload.prototype.makeInstallWin32 = function (extractDir) {
391
- return __awaiter(this, void 0, void 0, function () {
392
- var binaryName;
393
- return __generator(this, function (_a) {
394
- switch (_a.label) {
395
- case 0:
396
- binaryName = 'redis-server.exe';
397
- log("makeInstallWin32(): " + extractDir);
398
- return [4 /*yield*/, util_1.promisify(fs_1.default.copyFile)(path_1.default.resolve(extractDir, '.', binaryName), path_1.default.resolve(extractDir, '..', binaryName))];
399
- case 1:
400
- _a.sent();
401
- return [4 /*yield*/, util_1.promisify(rimraf_1.default)(extractDir)];
402
- case 2:
403
- _a.sent();
404
- return [2 /*return*/];
405
- }
406
- });
281
+ makeInstallWin32(extractDir) {
282
+ return __awaiter(this, void 0, void 0, function* () {
283
+ const binaryName = 'redis-server.exe';
284
+ log(`makeInstallWin32(): ${extractDir}`);
285
+ yield (0, util_1.promisify)(fs_1.default.copyFile)(path_1.default.resolve(extractDir, '.', binaryName), path_1.default.resolve(extractDir, '..', binaryName));
286
+ yield (0, rimraf_1.rimraf)(extractDir);
407
287
  });
408
- };
288
+ }
409
289
  /**
410
290
  * Test if the location given is already used
411
291
  * Does *not* dereference links
412
292
  * @param location The Path to test
413
293
  */
414
- RedisBinaryDownload.prototype.locationExists = function (location) {
415
- return __awaiter(this, void 0, void 0, function () {
416
- var e_1;
417
- return __generator(this, function (_a) {
418
- switch (_a.label) {
419
- case 0:
420
- _a.trys.push([0, 2, , 3]);
421
- return [4 /*yield*/, util_1.promisify(fs_1.default.lstat)(location)];
422
- case 1:
423
- _a.sent();
424
- return [2 /*return*/, true];
425
- case 2:
426
- e_1 = _a.sent();
427
- if (e_1.code !== 'ENOENT') {
428
- throw e_1;
429
- }
430
- return [2 /*return*/, false];
431
- case 3: return [2 /*return*/];
294
+ locationExists(location) {
295
+ return __awaiter(this, void 0, void 0, function* () {
296
+ try {
297
+ yield (0, util_1.promisify)(fs_1.default.lstat)(location);
298
+ return true;
299
+ }
300
+ catch (e) {
301
+ if (e.code !== 'ENOENT') {
302
+ throw e;
432
303
  }
433
- });
304
+ return false;
305
+ }
434
306
  });
435
- };
436
- return RedisBinaryDownload;
437
- }());
307
+ }
308
+ }
438
309
  exports.default = RedisBinaryDownload;
439
310
  //# sourceMappingURL=RedisBinaryDownload.js.map