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 ['package.yash', 'releases.js', 'install.sh', 'install.bat']
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 = ['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))
86 console.error('Error: ❌ no release found for current os, arch, and tag');
92 console.info('Found release matching current os, arch, and tag:');
96 return Releases.renderBash(pkgdir, rel, {
97 baseurl: 'https://webinstall.dev',
104 }).then(function (bashTxt) {
105 var bashFile = 'install-' + pkgname + '.sh';
106 var batFile = 'install-' + pkgname + '.bat';
109 bashTxt = bashTxt.replace(/#set -x/g, 'set -x');
111 fs.writeFileSync(bashFile, bashTxt, 'utf-8');
112 console.info('Has the necessary files?');
113 console.info('\tNEEDS MANUAL TEST: %s', bashFile);
114 console.info('\t(todo: ' + batFile + ')');