summaryrefslogtreecommitdiff
path: root/desktop/node_modules/@electron/notarize/lib/helpers.js
blob: 875894fdf667c0c60e7bb28e16ff58511af61905 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.delay = exports.parseNotarizationInfo = exports.isSecret = exports.makeSecret = exports.withTempDir = void 0;
const debug = require("debug");
const fs = require("fs-extra");
const os = require("os");
const path = require("path");
const d = debug('electron-notarize:helpers');
function withTempDir(fn) {
    return __awaiter(this, void 0, void 0, function* () {
        const dir = yield fs.mkdtemp(path.resolve(os.tmpdir(), 'electron-notarize-'));
        d('doing work inside temp dir:', dir);
        let result;
        try {
            result = yield fn(dir);
        }
        catch (err) {
            d('work failed');
            yield fs.remove(dir);
            throw err;
        }
        d('work succeeded');
        yield fs.remove(dir);
        return result;
    });
}
exports.withTempDir = withTempDir;
class Secret {
    constructor(value) {
        this.value = value;
    }
    toString() {
        return this.value;
    }
    inspect() {
        return '******';
    }
}
function makeSecret(s) {
    return new Secret(s);
}
exports.makeSecret = makeSecret;
function isSecret(s) {
    return s instanceof Secret;
}
exports.isSecret = isSecret;
function parseNotarizationInfo(info) {
    const out = {};
    const matchToProperty = (key, r, modifier) => {
        const exec = r.exec(info);
        if (exec) {
            out[key] = modifier ? modifier(exec[1]) : exec[1];
        }
    };
    matchToProperty('uuid', /\n *RequestUUID: (.+?)\n/);
    matchToProperty('date', /\n *Date: (.+?)\n/, d => new Date(d));
    matchToProperty('status', /\n *Status: (.+?)\n/);
    matchToProperty('logFileUrl', /\n *LogFileURL: (.+?)\n/);
    matchToProperty('statusCode', /\n *Status Code: (.+?)\n/, n => parseInt(n, 10));
    matchToProperty('statusMessage', /\n *Status Message: (.+?)\n/);
    if (out.logFileUrl === '(null)') {
        out.logFileUrl = null;
    }
    return out;
}
exports.parseNotarizationInfo = parseNotarizationInfo;
function delay(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}
exports.delay = delay;
//# sourceMappingURL=helpers.js.map