X-Git-Url: https://git.josue.xyz/?a=blobdiff_plain;f=_webi%2Fnormalize.js;h=0e06bcba72f12f9e9143a32a6f0a3b98e8dd74c9;hb=b228d1253c286b85f484f1fa3c6bf533fd3e0a16;hp=dac09020a7f4473ebfd917ecf3144bb3a0ac1791;hpb=5e0debf4c54c1e55476c1bc533c26db2b54d2f77;p=webi-installers%2F.git diff --git a/_webi/normalize.js b/_webi/normalize.js index dac0902..0e06bcb 100644 --- a/_webi/normalize.js +++ b/_webi/normalize.js @@ -1,8 +1,8 @@ 'use strict'; // this may need customizations between packages -const osMap = { - macos: /(\b|_)(apple|mac|darwin|iPhone|iOS|iPad)/i, +var osMap = { + macos: /(\b|_)(apple|os(\s_-)?x\b|mac|darwin|iPhone|iOS|iPad)/i, linux: /(\b|_)(linux)/i, freebsd: /(\b|_)(freebsd)/i, windows: /(\b|_)(win|microsoft|msft)/i, @@ -10,9 +10,24 @@ const osMap = { aix: /(\b|_)(aix)/i }; +var maps = { + oses: {}, + arches: {}, + formats: {} +}; + +Object.keys(osMap).forEach(function (name) { + maps.oses[name] = true; +}); + +var formats = ['zip', 'xz', 'tar', 'pkg', 'msi', 'git', 'exe', 'dmg']; +formats.forEach(function (name) { + maps.formats[name] = true; +}); + // evaluation order matters // (i.e. otherwise x86 and x64 can cross match) -var archArr = [ +var arches = [ 'amd64', // first and most likely match 'arm64', 'x86', @@ -23,17 +38,28 @@ var archArr = [ 's390x' ]; var archMap = { - amd64: /(amd.?64|x64|[_\-]64)/i, - x86: /(86)(\b|_)/i, + //amd64: /(amd.?64|x64|[_\-]64)/i, + amd64: /(\b|_|amd|(dar)?win(dows)?|mac(os)?|linux|osx|x)64([_\-]?bit)?(\b|_)/i, + //x86: /(86)(\b|_)/i, + x86: /(\b|_|amd|(dar)?win(dows)?|mac(os)?|linux|osx|x)(86|32)([_\-]?bit)(\b|_)/i, ppc64le: /(\b|_)(ppc64le)/i, ppc64: /(\b|_)(ppc64)(\b|_)/i, - arm64: /(\b|_)(arm64|arm)/i, + arm64: /(\b|_)((aarch|arm)64|arm)/i, armv7l: /(\b|_)(armv?7l)/i, - armv6l: /(\b|_)(armv?6l)/i, + armv6l: /(\b|_)(aarch32|armv?6l)/i, s390x: /(\b|_)(s390x)/i }; +arches.forEach(function (name) { + maps.arches[name] = true; +}); function normalize(all) { + var supported = { + oses: {}, + arches: {}, + formats: {} + }; + all.releases.forEach(function (rel) { rel.version = rel.version.replace(/^v/i, ''); if (!rel.name) { @@ -42,22 +68,13 @@ function normalize(all) { if (!rel.os) { rel.os = Object.keys(osMap).find(function (regKey) { - /* console.log( - 'release os:', - regKey, - osMap[regKey], - osMap[regKey].test(rel.name || rel.download), - rel.name, - rel.download - ); - // */ return osMap[regKey].test(rel.name || rel.download); }) || 'unknown'; } + supported.oses[rel.os] = true; if (!rel.arch) { - archArr.some(function (regKey) { - //console.log('release arch:', rel.download, regKey, archMap[regKey]); + arches.some(function (regKey) { var arch = (rel.name || rel.download).match(archMap[regKey]) && regKey; if (arch) { rel.arch = arch; @@ -65,27 +82,55 @@ function normalize(all) { } })[0]; } + supported.arches[rel.arch] = true; + var tarExt; if (!rel.ext) { // pkg-v1.0.tar.gz => ['gz', 'tar', '0', 'pkg-v1'] // pkg-v1.0.tar => ['tar', '0' ,'pkg-v1'] // pkg-v1.0.zip => ['zip', '0', 'pkg-v1'] - var exts = (rel.name || rel.download).split('.').reverse().slice(0, 2); - var ext; + var exts = (rel.name || rel.download).split('.'); + if (1 === exts.length) { + // for bare releases in the format of foo-linux-amd64 + rel.ext = 'exe'; + } + exts = exts.reverse().slice(0, 2); if ('tar' === exts[1]) { rel.ext = exts.reverse().join('.'); + tarExt = 'tar'; } else if ('tgz' == exts[0]) { rel.ext = 'tar.gz'; + tarExt = 'tar'; } else { rel.ext = exts[0]; } + if (/\-|linux|mac|os[_\-]?x|arm|amd|86|64|mip/i.test(rel.ext)) { + // for bare releases in the format of foo.linux-amd64 + rel.ext = 'exe'; + } } + supported.formats[tarExt || rel.ext] = true; if (all.download) { rel.download = all.download.replace(/{{ download }}/, rel.download); } }); + + all.oses = Object.keys(supported.oses).filter(function (name) { + return maps.oses[name]; + }); + all.arches = Object.keys(supported.arches).filter(function (name) { + return maps.arches[name]; + }); + all.formats = Object.keys(supported.formats).filter(function (name) { + return maps.formats[name]; + }); + return all; } module.exports = normalize; +// NOT in order of priority (which would be tar, xz, zip, ...) +module.exports.formats = formats; +module.exports.arches = arches; +module.exports.formatsMap = maps.formats;