aiax-validate / tree / bin/aiax-validate.js ยท raw (this view has old GitHub links rewritten for the mirror; raw is byte-exact)
#!/usr/bin/env node
import { validateSite, fixtureFetch } from '../src/validate.js';
const USAGE = 'Usage: aiax-validate <url> [--json] [--fixtures <dir>]\nExit codes: 0 valid, 1 not valid, 2 usage error.';
const a = process.argv.slice(2);
let url, json = false, fixtures;
for (let i = 0; i < a.length; i++) {
  if (a[i] === '--json') json = true;
  else if (a[i] === '--fixtures') { fixtures = a[++i]; if (!fixtures) { console.error(USAGE); process.exit(2); } }
  else if (a[i] === '--help' || a[i] === '-h') { console.log(USAGE); process.exit(0); }
  else if (a[i].startsWith('-') || url) { console.error(`unexpected argument: ${a[i]}\n${USAGE}`); process.exit(2); }
  else url = a[i];
}
if (!url) { console.error(USAGE); process.exit(2); }
try { new URL(/^[a-z]+:\/\//i.test(url) ? url : `https://${url}`); } catch { console.error(`not a URL: ${url}\n${USAGE}`); process.exit(2); }
const report = await validateSite(url, fixtures ? { fetch: fixtureFetch(fixtures) } : {});
if (json) console.log(JSON.stringify(report, null, 2));
else {
  for (const e of report.errors) console.log(`error ${e.url}${e.path ? ` ${e.path}` : ''}: ${e.message}`);
  for (const w of report.warnings) console.log(`warning ${w.url}${w.path ? ` ${w.path}` : ''}: ${w.message}`);
  console.log(`${report.ok ? 'valid' : 'not valid'}: score ${report.score}, ${report.errors.length} error(s), ${report.warnings.length} warning(s), ${report.sections.length} section(s)`);
}
process.exit(report.ok ? 0 : 1);

agentgate-source: code mirror on Cloudflare Pages. All repos