From a881d9eb452d496f0ecbc84dafe5210abf3886e9 Mon Sep 17 00:00:00 2001 From: Sven Wagner Date: Thu, 31 Jan 2019 13:30:37 +0100 Subject: [PATCH] feat(config): add recommended config --- README.md | 15 +++++++++++++++ dist/bundle.js | 22 +++++++++++++++++++++- example-config.json | 1 + lib/config.js | 15 ++++++++++++++- lib/configs/recommended.js | 8 ++++++++ 5 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 lib/configs/recommended.js diff --git a/README.md b/README.md index d93888d..e67b406 100644 --- a/README.md +++ b/README.md @@ -26,16 +26,31 @@ These are the possible options for the configuration file: | Option | Description | Default | | ------------- | ------------- | ------------- | +| extends | name of a predefined set of configurations | optional | | urls | array of URLs to scan | `[]` | | extendedInfo | display extended info of the audit | `false` by default. If the audit is not satisfied extendInfo turns true | | allAudits| indicates if all audits should be evaluated | `false` | | onlyAudits| array of audit keys to evaluate (see below) | `[]` | | scores| object of minimum scores per category (see below) to obtain | `{}` | +#### Recommended Options + +There is a predefined set of options called 'recommended. This looks like this: + +```json +skipAudits: [ + "uses-webp-images", + "hreflang", + "webapp-install-banner", + "without-javascript", +] +``` + #### Example ```json { + "extends": "recommended", "urls": [ "https://www.example.com/" ], diff --git a/dist/bundle.js b/dist/bundle.js index 1fb3ee7..f9b9637 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -1,5 +1,14 @@ 'use strict'; +var recommendedOptions = { + skipAudits: [ + 'uses-webp-images', + 'hreflang', + 'webapp-install-banner', + 'without-javascript', + ], +}; + const fs = require('fs'); const { argv } = require('yargs'); @@ -8,7 +17,18 @@ const getConfig = () => { let options = {}; if (configFile) { const data = fs.readFileSync(configFile, 'utf8'); - options = JSON.parse(data); + const parsedOptions = JSON.parse(data); + + options = { + ...parsedOptions, + }; + + if (parsedOptions.extends === 'recommended') { + options = { + ...recommendedOptions, + ...options, + }; + } } else { const { url } = argv; options.urls = [url]; diff --git a/example-config.json b/example-config.json index 332e4ba..e590092 100644 --- a/example-config.json +++ b/example-config.json @@ -1,4 +1,5 @@ { + "extends": "recommended", "urls": [ "https://www.example.com/" ], diff --git a/lib/config.js b/lib/config.js index 639c42e..ad2cf3d 100644 --- a/lib/config.js +++ b/lib/config.js @@ -1,3 +1,5 @@ +import recommendedOptions from './configs/recommended' + const fs = require('fs') const { argv } = require('yargs') @@ -6,7 +8,18 @@ const getConfig = () => { let options = {} if (configFile) { const data = fs.readFileSync(configFile, 'utf8') - options = JSON.parse(data) + const parsedOptions = JSON.parse(data) + + options = { + ...parsedOptions, + } + + if (parsedOptions.extends === 'recommended') { + options = { + ...recommendedOptions, + ...options, + } + } } else { const { url } = argv options.urls = [url] diff --git a/lib/configs/recommended.js b/lib/configs/recommended.js new file mode 100644 index 0000000..81ab290 --- /dev/null +++ b/lib/configs/recommended.js @@ -0,0 +1,8 @@ +export default { + skipAudits: [ + 'uses-webp-images', + 'hreflang', + 'webapp-install-banner', + 'without-javascript', + ], +}