3 // this may need customizations between packages
5 macos: /(\b|_)(apple|mac|darwin|iPhone|iOS|iPad)/i,
6 linux: /(\b|_)(linux)/i,
7 freebsd: /(\b|_)(freebsd)/i,
8 windows: /(\b|_)(win|microsoft|msft)/i,
13 var formats = ['zip', 'xz', 'tar', 'pkg', 'msi', 'git', 'exe', 'dmg'];
15 formats.forEach(function (ext) {
16 formatsMap[ext] = true;
19 // evaluation order matters
20 // (i.e. otherwise x86 and x64 can cross match)
22 'amd64', // first and most likely match
32 amd64: /(amd.?64|x64|[_\-]64)/i,
34 ppc64le: /(\b|_)(ppc64le)/i,
35 ppc64: /(\b|_)(ppc64)(\b|_)/i,
36 arm64: /(\b|_)(arm64|arm)/i,
37 armv7l: /(\b|_)(armv?7l)/i,
38 armv6l: /(\b|_)(armv?6l)/i,
39 s390x: /(\b|_)(s390x)/i
42 function normalize(all) {
43 var supportedFormats = {};
45 all.releases.forEach(function (rel) {
46 supportedFormats[rel.ext] = true;
47 rel.version = rel.version.replace(/^v/i, '');
49 rel.name = rel.download.replace(/.*\//, '');
53 Object.keys(osMap).find(function (regKey) {
58 osMap[regKey].test(rel.name || rel.download),
63 return osMap[regKey].test(rel.name || rel.download);
68 archArr.some(function (regKey) {
69 //console.log('release arch:', rel.download, regKey, archMap[regKey]);
70 var arch = (rel.name || rel.download).match(archMap[regKey]) && regKey;
79 // pkg-v1.0.tar.gz => ['gz', 'tar', '0', 'pkg-v1']
80 // pkg-v1.0.tar => ['tar', '0' ,'pkg-v1']
81 // pkg-v1.0.zip => ['zip', '0', 'pkg-v1']
82 var exts = (rel.name || rel.download).split('.').reverse().slice(0, 2);
84 if ('tar' === exts[1]) {
85 rel.ext = exts.reverse().join('.');
86 } else if ('tgz' == exts[0]) {
94 rel.download = all.download.replace(/{{ download }}/, rel.download);
98 all.formats = Object.keys(supportedFormats).filter(function (ext) {
99 return formatsMap[ext];
105 module.exports = normalize;
106 // NOT in order of priority (which would be tar, xz, zip, ...)
107 module.exports.formats = formats;
108 module.exports.arches = archArr;
109 module.exports.formatsMap = formatsMap;