aboutsummaryrefslogtreecommitdiff
path: root/node_modules/nexe/lib/target.js
blob: 1edd863b47bcbf2af10a7321ccfeeae194caa5a3 (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
80
81
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const platforms = ['windows', 'mac', 'alpine', 'linux'], architectures = ['x86', 'x64', 'arm', 'arm64'];
exports.platforms = platforms;
exports.architectures = architectures;
const prettyPlatform = {
    win32: 'windows',
    windows: 'windows',
    win: 'windows',
    darwin: 'mac',
    macos: 'mac',
    mac: 'mac',
    linux: 'linux',
    static: 'alpine',
    alpine: 'alpine',
};
const prettyArch = {
    x86: 'x86',
    arm6: 'arm',
    arm64: 'arm64',
    arm6l: 'arm',
    arm: 'arm',
    arm7: 'arm',
    arm7l: 'arm',
    amd64: 'x64',
    ia32: 'x86',
    x32: 'x86',
    x64: 'x64',
};
function isVersion(x) {
    if (!x) {
        return false;
    }
    return /^[\d]+$/.test(x.replace(/v|\.|\s+/g, ''));
}
function isPlatform(x) {
    return x in prettyPlatform;
}
function isArch(x) {
    return x in prettyArch;
}
class Target {
    constructor(arch, platform, version) {
        this.arch = arch;
        this.platform = platform;
        this.version = version;
    }
    toJSON() {
        return this.toString();
    }
    toString() {
        return `${this.platform}-${this.arch}-${this.version}`;
    }
}
function targetsEqual(a, b) {
    return a.arch === b.arch && a.platform === b.platform && a.version === b.version;
}
exports.targetsEqual = targetsEqual;
function getTarget(target = '') {
    const currentArch = process.arch;
    let arch = currentArch in prettyArch ? prettyArch[process.arch] : process.arch, platform = prettyPlatform[process.platform], version = process.version.slice(1);
    if (typeof target !== 'string') {
        target = `${target.platform}-${target.arch}-${target.version}`;
    }
    target
        .toLowerCase()
        .split('-')
        .forEach((x) => {
        if (isVersion(x)) {
            version = x.replace(/v/g, '');
        }
        if (isPlatform(x)) {
            platform = prettyPlatform[x];
        }
        if (isArch(x)) {
            arch = prettyArch[x];
        }
    });
    return new Target(arch, platform, version);
}
exports.getTarget = getTarget;