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