diff --git a/README.md b/README.md index d07461e..33286b4 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,14 @@ npm install -g @jakepartusch/lumberjack lumberjack --url https://google.com ``` +### Options + +``` +--url // Required — The base url to scan. If a sitemap exists, its pages will be scanned as well +--strict // Optional (default: false) — Fail the process if any accessibility issues are found +--baseUrlOnly // Optional (default: false) — Skip the sitemap scan and only run the audit on the base url +``` + ## JavaScript ``` diff --git a/bin/cli.js b/bin/cli.js index 59e8ebf..01419cb 100644 --- a/bin/cli.js +++ b/bin/cli.js @@ -3,13 +3,16 @@ const arg = require("arg"); const ora = require("ora"); +const chalk = require("chalk"); const lumberjack = require("../"); const { printResults } = require("../src/output"); const main = async () => { const args = arg({ "--help": Boolean, - "--url": String // --url or --url= + "--url": String, + "--strict": Boolean, + "--baseUrlOnly": Boolean }); const spinner = ora("Fetching sitemap").start(); const baseUrl = args["--url"]; @@ -20,9 +23,25 @@ const main = async () => { ); process.exit(1); } - const totalViolationsByPage = await lumberjack(baseUrl, spinner); + const options = { + strict: args["--strict"], + baseUrlOnly: args["--baseUrlOnly"] + }; + const totalViolationsByPage = await lumberjack(baseUrl, options, spinner); spinner.stop(); printResults(totalViolationsByPage); + const isStrict = args["--strict"]; + if (isStrict) { + const hasViolations = totalViolationsByPage.some(page => { + return page.violations.length > 0; + }); + if (hasViolations) { + console.error( + chalk`{red.bold ERROR: Strict mode enabled and website has one or more issues.}` + ); + process.exit(1); + } + } }; main().catch(err => { diff --git a/index.js b/index.js index 2f726fa..b42aefc 100644 --- a/index.js +++ b/index.js @@ -21,7 +21,7 @@ const runAccessibilityTestsOnUrl = async url => { const page = await context.newPage(); await page.goto(url); await page.addScriptTag({ - url: "https://cdnjs.cloudflare.com/ajax/libs/axe-core/3.4.1/axe.min.js" + url: "https://cdnjs.cloudflare.com/ajax/libs/axe-core/3.4.2/axe.min.js" }); const axeViolations = await page.evaluate(async () => { const axeResults = await new Promise((resolve, reject) => { @@ -65,9 +65,12 @@ const runAllChecks = async (urls, spinner) => { return totalViolationsByPage; }; -const lumberjack = async (baseUrl, spinner) => { - const sitemapUrls = await fetchSitemapUrls(baseUrl); - return runAllChecks(sitemapUrls, spinner); +const lumberjack = async (baseUrl, options, spinner) => { + let urls = [baseUrl]; + if (!options.baseUrlOnly) { + urls = await fetchSitemapUrls(baseUrl); + } + return runAllChecks(urls, spinner); }; module.exports = lumberjack; diff --git a/package.json b/package.json index 57e1bd8..12f4df4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@jakepartusch/lumberjack", - "version": "0.5.0", + "version": "0.6.0", "description": "Scans your entire website for accessibility issues", "main": "index.js", "bin": "./bin/cli.js",