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.
- package/LICENSE +21 -0
- package/lib/RedisMemoryServer.js +126 -212
- package/lib/RedisMemoryServer.js.map +1 -1
- package/lib/index.js +3 -3
- package/lib/index.js.map +1 -1
- package/lib/types.d.ts +5 -5
- package/lib/types.d.ts.map +1 -1
- package/lib/util/RedisBinary.js +123 -205
- package/lib/util/RedisBinary.js.map +1 -1
- package/lib/util/RedisBinaryDownload.d.ts +2 -1
- package/lib/util/RedisBinaryDownload.d.ts.map +1 -1
- package/lib/util/RedisBinaryDownload.js +201 -330
- package/lib/util/RedisBinaryDownload.js.map +1 -1
- package/lib/util/RedisBinaryDownloadUrl.js +32 -71
- package/lib/util/RedisBinaryDownloadUrl.js.map +1 -1
- package/lib/util/RedisInstance.d.ts +1 -0
- package/lib/util/RedisInstance.d.ts.map +1 -1
- package/lib/util/RedisInstance.js +126 -202
- package/lib/util/RedisInstance.js.map +1 -1
- package/lib/util/resolve-config.js +20 -22
- package/lib/util/resolve-config.js.map +1 -1
- package/package.json +43 -48
- package/scripts/postinstall.js +1 -1
|
@@ -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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
56
|
-
|
|
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
|
-
|
|
61
|
-
|
|
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
|
-
|
|
77
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
121
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
122
|
-
|
|
123
|
-
|
|
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
|
-
|
|
145
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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
|
-
|
|
136
|
+
extract(redisArchive) {
|
|
199
137
|
var _a;
|
|
200
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
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
|
-
|
|
233
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
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
|
-
|
|
254
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
255
|
-
|
|
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
|
-
|
|
272
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
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
|
-
|
|
241
|
+
printDownloadProgress(chunk) {
|
|
338
242
|
this.dlProgress.current += chunk.length;
|
|
339
|
-
|
|
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
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
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
|
-
|
|
362
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
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
|
-
|
|
391
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
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
|
-
|
|
415
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
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
|
-
|
|
437
|
-
}());
|
|
307
|
+
}
|
|
308
|
+
}
|
|
438
309
|
exports.default = RedisBinaryDownload;
|
|
439
310
|
//# sourceMappingURL=RedisBinaryDownload.js.map
|