Skip to content

Commit

Permalink
Feat: Adding --strict and --basUrlOnly arguments (#4)
Browse files Browse the repository at this point in the history
* chore: bump version

* feat: adding strict and baseUrlOnly args
  • Loading branch information
JakePartusch authored Feb 10, 2020
1 parent ce9eaf7 commit cd1f21f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```
Expand Down
23 changes: 21 additions & 2 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <string> or --url=<string>
"--url": String,
"--strict": Boolean,
"--baseUrlOnly": Boolean
});
const spinner = ora("Fetching sitemap").start();
const baseUrl = args["--url"];
Expand All @@ -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 => {
Expand Down
11 changes: 7 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit cd1f21f

Please sign in to comment.