From f3aa691821bf6ec41d1ba077aa128d6819f6a414 Mon Sep 17 00:00:00 2001 From: Gilgamesh Athoraya Date: Mon, 8 Jul 2019 10:53:31 +0200 Subject: [PATCH] linted help url tool --- tools/chk-hlp-urls.js | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/tools/chk-hlp-urls.js b/tools/chk-hlp-urls.js index a3beb95c..981f82ed 100755 --- a/tools/chk-hlp-urls.js +++ b/tools/chk-hlp-urls.js @@ -1,9 +1,31 @@ #!/usr/bin/env node -D={modules:{}};require('../src/hlp');let n=0,m=0; //n:total,m:failed -const h=D.hlp,http=require('http'),a=Object.keys(h).map(k=>h[k]).sort(),o={host:'help.dyalog.com',port:80,path:''} -,rec=i=>{if(i>=a.length){console.log(m?'failed:'+m+'/'+n:'ok');return} - n++;o.path=escape(a[i].replace(/^http:\/\/[a-z0-9\.]+\//i,'/').replace(/#.*/,'')) - http.get(o,x=>{let c=x.statusCode;console.log((c===200?' ':c)+' '+a[i]);m+=c!==200;rec(i+1)}) - .on('error',x=>{console.log(JSON.stringify(x.message)+' '+a[i]);m++;rec(i+1)})} -rec(0) +D = { modules: {} }; +require('../src/hlp'); +const http = require('http'); +D.InitHelp(process.argv[2]); +let n = 0; // n:total +let m = 0; // m:failed +const h = D.hlp; +const a = Object.keys(h).map(k => h[k]).sort(); +const o = { host: 'help.dyalog.com', port: 80, path: '' }; +const rec = (i) => { + if (i >= a.length) { + console.log(m ? `failed:${m}/${n}` : 'ok'); + return; + } + n += 1; + o.path = escape(a[i].replace(/^https:\/\/[a-z0-9.]+\//i, '/').replace(/#.*/, '')); + http.get(o, (x) => { + const c = x.statusCode; + console.log(`${c === 200 ? ' ' : c} ${a[i]}`); + m += c !== 200; + rec(i + 1); + }) + .on('error', (x) => { + console.log(`${JSON.stringify(x.message)} ${a[i]}`); + m += 1; + rec(i + 1); + }); +}; +rec(0);