chore: make Prettier
[webi-installers/.git] / _webi / test.js
index 552a5faa8a9d3b9c4c726e2f633b1e8ff40ba85e..1ffbb16d10f78fd27f2a08340085632a76d375a4 100755 (executable)
@@ -4,10 +4,18 @@
 // Print help if there's no pkgdir argument
 //
 var usage = [
-  'Usage: node _webi/test.js <path-to-package>',
-  'Example: node _webi/test.js ./node/'
+  'Usage: node _webi/test.js --debug <path-to-package>',
+  'Example: node _webi/test.js --debug ./node/'
 ].join('\n');
 
+var count = 3;
+var debug = false;
+
+if (/\b-?-debug?\b/.test(process.argv.join(' '))) {
+  count += 1;
+  debug = true;
+}
+
 if (3 !== process.argv.length) {
   console.error(usage);
   process.exit(1);
@@ -38,7 +46,7 @@ nodes.forEach(function (node) {
 var maxLen = 0;
 console.info('');
 console.info('Has the necessary files?');
-['package.yash', 'releases.js', 'install.sh', 'install.bat']
+['README.md', 'releases.js', 'install.sh', 'install.ps1']
   .map(function (node) {
     maxLen = Math.max(maxLen, node.length);
     return node;
@@ -58,7 +66,7 @@ Releases.get(path.join(process.cwd(), pkgdir)).then(function (all) {
   var pkgname = path.basename(pkgdir.replace(/\/$/, ''));
   var osrel = os.platform() + '-' + os.release();
   var arch = os.arch();
-  var formats = ['xz', 'tar', 'zip'];
+  var formats = ['exe', 'xz', 'tar', 'zip'];
 
   var rel = all.releases.filter(function (rel) {
     return (
@@ -73,6 +81,9 @@ Releases.get(path.join(process.cwd(), pkgdir)).then(function (all) {
         new RegExp('^' + pkgtag).test(rel.version))
     );
   })[0];
+  rel.oses = all.oses;
+  rel.arches = all.arches;
+  rel.formats = all.formats;
 
   if (!rel) {
     console.error('Error: ❌ no release found for current os, arch, and tag');
@@ -85,23 +96,47 @@ Releases.get(path.join(process.cwd(), pkgdir)).then(function (all) {
   console.info(rel);
   console.info('');
 
-  return Releases.renderBash(pkgdir, rel, {
-    baseurl: 'https://webinstall.dev',
-    pkg: pkgname,
-    tag: pkgtag || '',
-    ver: '',
-    os: osrel,
-    arch,
-    formats: formats
-  }).then(function (bashTxt) {
+  return Promise.all([
+    Releases.renderBash(pkgdir, rel, {
+      baseurl: 'https://webinstall.dev',
+      pkg: pkgname,
+      tag: pkgtag || '',
+      ver: '',
+      os: osrel,
+      arch,
+      formats: formats
+    }).catch(function () {}),
+    Releases.renderPowerShell(pkgdir, rel, {
+      baseurl: 'https://webinstall.dev',
+      pkg: pkgname,
+      tag: pkgtag || '',
+      ver: '',
+      os: osrel,
+      arch,
+      formats: formats
+    }).catch(function () {})
+  ]).then(function (scripts) {
+    var bashTxt = scripts[0];
+    var ps1Txt = scripts[1];
     var bashFile = 'install-' + pkgname + '.sh';
-    var batFile = 'install-' + pkgname + '.bat';
+    var ps1File = 'install-' + pkgname + '.ps1';
 
-    bashTxt = bashTxt.replace(/#set -x/g, 'set -x');
-    fs.writeFileSync(bashFile, bashTxt, 'utf-8');
-    console.info('Has the necessary files?');
-    console.info('\tNEEDS MANUAL TEST: %s', bashFile);
-    console.info('\t(todo: ' + batFile + ')');
+    if (debug) {
+      bashTxt = (bashTxt || 'echo ERROR').replace(/#set -x/g, 'set -x');
+      ps1Txt = (ps1Txt || 'echo ERROR').replace(
+        /REM REM todo debug/g,
+        'REM todo debug'
+      );
+    }
+    console.info('Do the scripts actually work?');
+    if (bashFile && bashTxt) {
+      fs.writeFileSync(bashFile, bashTxt, 'utf-8');
+      console.info('\tNEEDS MANUAL TEST: bash %s', bashFile);
+    }
+    if (ps1File && ps1Txt) {
+      fs.writeFileSync(ps1File, ps1Txt, 'utf-8');
+      console.info('\tNEEDS MANUAL TEST: powershell.exe %s', ps1File);
+    }
     console.info('');
   });
 });