UNPKG

2.39 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.computeData = undefined;
7
8var _bluebirdLst;
9
10function _load_bluebirdLst() {
11 return _bluebirdLst = require("bluebird-lst");
12}
13
14var _bluebirdLst2;
15
16function _load_bluebirdLst2() {
17 return _bluebirdLst2 = _interopRequireDefault(require("bluebird-lst"));
18}
19
20let computeData = exports.computeData = (() => {
21 var _ref = (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* (resourcesPath, options) {
22 // sort to produce constant result
23 const names = (yield (0, (_fsExtraP || _load_fsExtraP()).readdir)(resourcesPath)).filter(function (it) {
24 return it.endsWith(".asar");
25 }).sort();
26 const checksums = yield (_bluebirdLst2 || _load_bluebirdLst2()).default.map(names, function (it) {
27 return hashFile(_path.join(resourcesPath, it));
28 });
29 const result = {};
30 for (let i = 0; i < names.length; i++) {
31 result[names[i]] = checksums[i];
32 }
33 return Object.assign({ checksums: result }, options);
34 });
35
36 return function computeData(_x, _x2) {
37 return _ref.apply(this, arguments);
38 };
39})();
40
41var _crypto;
42
43function _load_crypto() {
44 return _crypto = require("crypto");
45}
46
47var _fs;
48
49function _load_fs() {
50 return _fs = require("fs");
51}
52
53var _fsExtraP;
54
55function _load_fsExtraP() {
56 return _fsExtraP = require("fs-extra-p");
57}
58
59var _path = _interopRequireWildcard(require("path"));
60
61function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
62
63function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
64
65function hashFile(file, algorithm = "sha512", encoding = "base64") {
66 return new (_bluebirdLst2 || _load_bluebirdLst2()).default((resolve, reject) => {
67 const hash = (0, (_crypto || _load_crypto()).createHash)(algorithm);
68 hash.on("error", reject).setEncoding(encoding);
69 (0, (_fs || _load_fs()).createReadStream)(file).on("error", reject).on("end", () => {
70 hash.end();
71 resolve(hash.read());
72 }).pipe(hash, { end: false });
73 });
74}
75//# sourceMappingURL=main.js.map
\No newline at end of file