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.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:');
97 Releases.renderBash(pkgdir, rel, {
98 baseurl: 'https://webinstall.dev',
105 }).catch(function () {}),
106 Releases.renderBatch(pkgdir, rel, {
107 baseurl: 'https://webinstall.dev',
114 }).catch(function () {})
115 ]).then(function (scripts) {
116 var bashTxt = scripts[0];
117 var batTxt = scripts[1];
118 var bashFile = 'install-' + pkgname + '.sh';
119 var batFile = 'install-' + pkgname + '.bat';
122 bashTxt = (bashTxt || 'echo ERROR').replace(/#set -x/g, 'set -x');
123 batTxt = (batTxt || 'echo ERROR').replace(
124 /REM REM todo debug/g,
128 console.info('Has the necessary files?');
129 fs.writeFileSync(bashFile, bashTxt, 'utf-8');
130 console.info('\tNEEDS MANUAL TEST: bash %s', bashFile);
131 fs.writeFileSync(batFile, batTxt, 'utf-8');
132 console.info('\tNEEDS MANUAL TEST: cmd.exe %s', batFile);