better error handling when vailable formats mismatch
[webi-installers/.git] / _webi / normalize.js
index dac09020a7f4473ebfd917ecf3144bb3a0ac1791..16c60b80dfda711bf00011942e3137548e2b2dc6 100644 (file)
@@ -1,7 +1,7 @@
 'use strict';
 
 // this may need customizations between packages
-const osMap = {
+var osMap = {
   macos: /(\b|_)(apple|mac|darwin|iPhone|iOS|iPad)/i,
   linux: /(\b|_)(linux)/i,
   freebsd: /(\b|_)(freebsd)/i,
@@ -10,6 +10,12 @@ const osMap = {
   aix: /(\b|_)(aix)/i
 };
 
+var formats = ['zip', 'xz', 'tar', 'pkg', 'msi', 'git', 'exe', 'dmg'];
+var formatsMap = {};
+formats.forEach(function (ext) {
+  formatsMap[ext] = true;
+});
+
 // evaluation order matters
 // (i.e. otherwise x86 and x64 can cross match)
 var archArr = [
@@ -34,7 +40,10 @@ var archMap = {
 };
 
 function normalize(all) {
+  var supportedFormats = {};
+
   all.releases.forEach(function (rel) {
+    supportedFormats[rel.ext] = true;
     rel.version = rel.version.replace(/^v/i, '');
     if (!rel.name) {
       rel.name = rel.download.replace(/.*\//, '');
@@ -85,7 +94,16 @@ function normalize(all) {
       rel.download = all.download.replace(/{{ download }}/, rel.download);
     }
   });
+
+  all.formats = Object.keys(supportedFormats).filter(function (ext) {
+    return formatsMap[ext];
+  });
+
   return all;
 }
 
 module.exports = normalize;
+// NOT in order of priority (which would be tar, xz, zip, ...)
+module.exports.formats = formats;
+module.exports.arches = archArr;
+module.exports.formatsMap = formatsMap;