4 // Print help if there's no pkgdir argument
7 'Usage: node _webi/test.js --debug <path-to-package>',
8 'Example: node _webi/test.js --debug ./node/'
14 if (/\b-?-debug?\b/.test(process.argv.join(' '))) {
19 if (3 !== process.argv.length) {
24 if (/\b-?-h(elp)?\b/.test(process.argv.join(' '))) {
32 var os = require('os');
33 var fs = require('fs');
34 var path = require('path');
35 var Releases = require('./releases.js');
36 var uaDetect = require('./ua-detect.js');
37 var pkg = process.argv[2].split('@');
39 var pkgtag = pkg[1] || '';
41 var nodes = fs.readdirSync(pkgdir);
42 nodes.forEach(function (node) {
43 nodesMap[node] = true;
48 console.info('Has the necessary files?');
49 ['README.md', 'releases.js', 'install.sh', 'install.ps1']
50 .map(function (node) {
51 maxLen = Math.max(maxLen, node.length);
54 .forEach(function (node) {
55 var label = node.padStart(maxLen, ' ');
56 var found = nodesMap[node];
58 console.info('\t' + label + ': ✅ found');
60 console.info('\t' + label + ': ❌ not found');
65 Releases.get(path.join(process.cwd(), pkgdir)).then(function (all) {
66 var pkgname = path.basename(pkgdir.replace(/\/$/, ''));
67 var osrel = os.platform() + '-' + os.release();
69 var formats = ['exe', 'xz', 'tar', 'zip'];
71 var rel = all.releases.filter(function (rel) {
73 formats.filter(function (ext) {
74 return rel.ext.match(ext);
76 'stable' === rel.channel &&
77 rel.os === uaDetect.os(osrel) &&
78 rel.arch === uaDetect.arch(arch) &&
81 new RegExp('^' + pkgtag).test(rel.version))
85 rel.arches = all.arches;
86 rel.formats = all.formats;
89 console.error('Error: ❌ no release found for current os, arch, and tag');
95 console.info('Found release matching current os, arch, and tag:');
100 Releases.renderBash(pkgdir, rel, {
101 baseurl: 'https://webinstall.dev',
108 }).catch(function () {}),
109 Releases.renderPowerShell(pkgdir, rel, {
110 baseurl: 'https://webinstall.dev',
117 }).catch(function () {})
118 ]).then(function (scripts) {
119 var bashTxt = scripts[0];
120 var ps1Txt = scripts[1];
121 var bashFile = 'install-' + pkgname + '.sh';
122 var ps1File = 'install-' + pkgname + '.ps1';
125 bashTxt = (bashTxt || 'echo ERROR').replace(/#set -x/g, 'set -x');
126 ps1Txt = (ps1Txt || 'echo ERROR').replace(
127 /REM REM todo debug/g,
131 console.info('Do the scripts actually work?');
132 if (bashFile && bashTxt) {
133 fs.writeFileSync(bashFile, bashTxt, 'utf-8');
134 console.info('\tNEEDS MANUAL TEST: bash %s', bashFile);
136 if (ps1File && ps1Txt) {
137 fs.writeFileSync(ps1File, ps1Txt, 'utf-8');
138 console.info('\tNEEDS MANUAL TEST: powershell.exe %s', ps1File);