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.
- package/LICENSE +21 -0
- package/README.md +9 -0
- package/bin/index.js +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 +1 -1
- package/lib/util/RedisBinaryDownload.d.ts.map +1 -1
- package/lib/util/RedisBinaryDownload.js +201 -333
- 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 +45 -49
- package/scripts/postinstall.js +1 -1
|
@@ -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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
57
|
-
|
|
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
|
-
|
|
62
|
-
|
|
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
|
-
|
|
78
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
122
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
|
|
146
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
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
|
-
|
|
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
|
-
|
|
136
|
+
extract(redisArchive) {
|
|
201
137
|
var _a;
|
|
202
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
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
|
-
|
|
235
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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
|
-
|
|
256
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
257
|
-
|
|
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
|
-
|
|
274
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
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
|
-
|
|
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
|
-
|
|
241
|
+
printDownloadProgress(chunk) {
|
|
341
242
|
this.dlProgress.current += chunk.length;
|
|
342
|
-
|
|
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
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
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
|
-
|
|
365
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
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
|
-
|
|
394
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
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
|
-
|
|
418
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
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
|
-
|
|
440
|
-
}());
|
|
307
|
+
}
|
|
308
|
+
}
|
|
441
309
|
exports.default = RedisBinaryDownload;
|
|
442
310
|
//# sourceMappingURL=RedisBinaryDownload.js.map
|