4 // Print help if there's no pkgdir argument
7 'Usage: node _webi/test.js <path-to-package>',
8 'Example: node _webi/test.js ./node/'
11 if (3 !== process.argv.length) {
16 if (/\b-?-h(elp)?\b/.test(process.argv.join(' '))) {
24 var os = require('os');
25 var fs = require('fs');
26 var path = require('path');
27 var Releases = require('./releases.js');
28 var uaDetect = require('./ua-detect.js');
29 var pkg = process.argv[2].split('@');
31 var pkgtag = pkg[1] || '';
33 var nodes = fs.readdirSync(pkgdir);
34 nodes.forEach(function (node) {
35 nodesMap[node] = true;
40 console.info('Has the necessary files?');
41 ['package.yash', 'releases.js', 'install.sh', 'install.bat']
42 .map(function (node) {
43 maxLen = Math.max(maxLen, node.length);
46 .forEach(function (node) {
47 var label = node.padStart(maxLen, ' ');
48 var found = nodesMap[node];
50 console.info('\t' + label + ': ✅ found');
52 console.info('\t' + label + ': ❌ not found');
57 Releases.get(path.join(process.cwd(), pkgdir)).then(function (all) {
58 var pkgname = path.basename(pkgdir.replace(/\/$/, ''));
59 var osrel = os.platform() + '-' + os.release();
61 var formats = ['xz', 'tar', 'zip'];
63 var rel = all.releases.filter(function (rel) {
65 formats.filter(function (ext) {
66 return rel.ext.match(ext);
68 'stable' === rel.channel &&
69 rel.os === uaDetect.os(osrel) &&
70 rel.arch === uaDetect.arch(arch) &&
73 new RegExp('^' + pkgtag).test(rel.version))
78 console.error('Error: ❌ no release found for current os, arch, and tag');
84 console.info('Found release matching current os, arch, and tag:');
88 return Releases.renderBash(pkgdir, rel, {
89 baseurl: 'https://webinstall.dev',
96 }).then(function (bashTxt) {
97 var bashFile = 'install-' + pkgname + '.sh';
98 var batFile = 'install-' + pkgname + '.bat';
100 bashTxt = bashTxt.replace(/#set -x/g, 'set -x');
101 fs.writeFileSync(bashFile, bashTxt, 'utf-8');
102 console.info('Has the necessary files?');
103 console.info('\tNEEDS MANUAL TEST: %s', bashFile);
104 console.info('\t(todo: ' + batFile + ')');