3 // this may need customizations between packages
5 macos: /(\b|_)(apple|os(\s_-)?x\b|mac|darwin|iPhone|iOS|iPad)/i,
6 linux: /(\b|_)(linux)/i,
7 freebsd: /(\b|_)(freebsd)/i,
8 windows: /(\b|_)(win|microsoft|msft)/i,
19 Object.keys(osMap).forEach(function (name) {
20 maps.oses[name] = true;
23 var formats = ['zip', 'xz', 'tar', 'pkg', 'msi', 'git', 'exe', 'dmg'];
24 formats.forEach(function (name) {
25 maps.formats[name] = true;
28 // evaluation order matters
29 // (i.e. otherwise x86 and x64 can cross match)
31 'amd64', // first and most likely match
41 //amd64: /(amd.?64|x64|[_\-]64)/i,
43 /(\b|_|amd|(dar)?win(dows)?|mac(os)?|linux|osx|x)64([_\-]?bit)?(\b|_)/i,
45 x86: /(\b|_|amd|(dar)?win(dows)?|mac(os)?|linux|osx|x)(86|32)([_\-]?bit)(\b|_)/i,
46 ppc64le: /(\b|_)(ppc64le)/i,
47 ppc64: /(\b|_)(ppc64)(\b|_)/i,
48 arm64: /(\b|_)((aarch|arm)64|arm)/i,
49 armv7l: /(\b|_)(armv?7l)/i,
50 armv6l: /(\b|_)(aarch32|armv?6l)/i,
51 s390x: /(\b|_)(s390x)/i
53 arches.forEach(function (name) {
54 maps.arches[name] = true;
57 function normalize(all) {
64 all.releases.forEach(function (rel) {
65 rel.version = rel.version.replace(/^v/i, '');
67 rel.name = rel.download.replace(/.*\//, '');
71 Object.keys(osMap).find(function (regKey) {
72 return osMap[regKey].test(rel.name || rel.download);
75 supported.oses[rel.os] = true;
78 arches.some(function (regKey) {
79 var arch = (rel.name || rel.download).match(archMap[regKey]) && regKey;
87 if ('macos' === rel.os) {
91 supported.arches[rel.arch] = true;
95 // pkg-v1.0.tar.gz => ['gz', 'tar', '0', 'pkg-v1']
96 // pkg-v1.0.tar => ['tar', '0' ,'pkg-v1']
97 // pkg-v1.0.zip => ['zip', '0', 'pkg-v1']
98 var exts = (rel.name || rel.download).split('.');
99 if (1 === exts.length) {
100 // for bare releases in the format of foo-linux-amd64
103 exts = exts.reverse().slice(0, 2);
104 if ('tar' === exts[1]) {
105 rel.ext = exts.reverse().join('.');
107 } else if ('tgz' === exts[0]) {
113 if (/\-|linux|mac|os[_\-]?x|arm|amd|86|64|mip/i.test(rel.ext)) {
114 // for bare releases in the format of foo.linux-amd64
118 supported.formats[tarExt || rel.ext] = true;
121 rel.download = all.download.replace(/{{ download }}/, rel.download);
125 all.oses = Object.keys(supported.oses).filter(function (name) {
126 return maps.oses[name];
128 all.arches = Object.keys(supported.arches).filter(function (name) {
129 return maps.arches[name];
131 all.formats = Object.keys(supported.formats).filter(function (name) {
132 return maps.formats[name];
138 module.exports = normalize;
139 module.exports._debug = function (all) {
140 all = normalize(all);
141 all.releases = all.releases
142 .filter(function (r) {
143 return ['windows', 'macos', 'linux'].includes(r.os) && 'amd64' === r.arch;
148 // NOT in order of priority (which would be tar, xz, zip, ...)
149 module.exports.formats = formats;
150 module.exports.arches = arches;
151 module.exports.formatsMap = maps.formats;