@caweb/webpack 1.2.28 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/.github/workflows/config-publish.yml +33 -0
  2. package/.github/workflows/plugins-publish.yml +45 -0
  3. package/.github/workflows/test +29 -0
  4. package/.gitmodules +3 -0
  5. package/README.md +1 -2
  6. package/changelog.txt +137 -0
  7. package/package.json +9 -16
  8. package/plugins/a11y/README.md +19 -0
  9. package/plugins/a11y/aceconfig.js +44 -0
  10. package/plugins/a11y/changelog.txt +31 -0
  11. package/plugins/a11y/index.js +271 -0
  12. package/plugins/a11y/package-lock.json +3303 -0
  13. package/plugins/a11y/package.json +42 -0
  14. package/plugins/css-audit/README.md +20 -0
  15. package/plugins/css-audit/changelog.txt +41 -0
  16. package/plugins/css-audit/css-audit.config.cjs +5 -0
  17. package/plugins/css-audit/default.config.js +19 -0
  18. package/plugins/css-audit/index.js +326 -0
  19. package/plugins/css-audit/package-lock.json +1522 -0
  20. package/plugins/css-audit/package.json +53 -0
  21. package/plugins/css-audit/sample/no-files.html +9 -0
  22. package/plugins/html/README.md +40 -0
  23. package/plugins/html/changelog.txt +134 -0
  24. package/plugins/html/entry/delta.js +20 -0
  25. package/plugins/html/entry/eureka.js +20 -0
  26. package/plugins/html/entry/mono.js +20 -0
  27. package/plugins/html/entry/oceanside.js +20 -0
  28. package/plugins/html/entry/orangecounty.js +20 -0
  29. package/plugins/html/entry/pasorobles.js +20 -0
  30. package/plugins/html/entry/sacramento.js +20 -0
  31. package/plugins/html/entry/santabarbara.js +20 -0
  32. package/plugins/html/entry/santacruz.js +20 -0
  33. package/plugins/html/entry/shasta.js +20 -0
  34. package/plugins/html/entry/sierra.js +20 -0
  35. package/plugins/html/entry/trinity.js +20 -0
  36. package/plugins/html/index.js +96 -0
  37. package/plugins/html/package-lock.json +21977 -0
  38. package/plugins/html/package.json +70 -0
  39. package/plugins/html/sample/blank.html +13 -0
  40. package/plugins/html/sample/components/alerts.html +32 -0
  41. package/plugins/html/sample/components/animations.html +7 -0
  42. package/plugins/html/sample/components/buttons.html +5 -0
  43. package/plugins/html/sample/components/cards.html +73 -0
  44. package/plugins/html/sample/components/lists.html +75 -0
  45. package/plugins/html/sample/components/locations.html +49 -0
  46. package/plugins/html/sample/components/profile-banners.html +48 -0
  47. package/plugins/html/sample/components/sections.html +16 -0
  48. package/plugins/html/sample/components/service-tiles.html +73 -0
  49. package/plugins/html/sample/components/typography.html +42 -0
  50. package/plugins/html/sample/default.html +31 -0
  51. package/plugins/html/sample/favicon.ico +0 -0
  52. package/plugins/html/sample/images/black_puppy.jpg +0 -0
  53. package/plugins/html/sample/images/dolphin_marine_mammals_water.jpg +0 -0
  54. package/plugins/html/sample/images/grayscale_mountain.jpg +0 -0
  55. package/plugins/html/sample/images/silhouette.png +0 -0
  56. package/plugins/html/sample/images/squirrel_tail_bushy_tail.jpg +0 -0
  57. package/plugins/html/sample/index.html +48 -0
  58. package/plugins/html/sample/missing/content.html +4 -0
  59. package/plugins/html/sample/structural/branding.html +15 -0
  60. package/plugins/html/sample/structural/footer.html +47 -0
  61. package/plugins/html/sample/structural/header.html +16 -0
  62. package/plugins/html/sample/structural/mobile-controls.html +5 -0
  63. package/plugins/html/sample/structural/navigation.html +26 -0
  64. package/plugins/html/sample/structural/search.html +15 -0
  65. package/plugins/html/sample/structural/utility-header.html +23 -0
  66. package/plugins/html/scripts/create-entrypoints.js +62 -0
  67. package/plugins/html/scripts/icon.js +60 -0
  68. package/plugins/html/scripts/webpack.test.js +41 -0
  69. package/plugins/html/webpack.config.js +279 -0
  70. package/plugins/jshint/.jshintrc +31 -0
  71. package/plugins/jshint/README.md +26 -0
  72. package/plugins/jshint/changelog.txt +30 -0
  73. package/plugins/jshint/index.js +296 -0
  74. package/plugins/jshint/package-lock.json +1779 -0
  75. package/plugins/jshint/package.json +45 -0
  76. package/plugins/jshint/reporter.cjs +663 -0
  77. package/plugins/jshint/sample/jshint.css +247 -0
  78. package/plugins/jshint/sample/jshint.html +7 -0
  79. package/plugins/jshint/sample/jshint.js +25 -0
  80. package/plugins/jshint/sample/no-files.html +9 -0
  81. package/sample/index.html +364 -0
  82. package/scripts/update-deps.js +38 -0
  83. package/webpack.config.js +0 -54
@@ -0,0 +1,33 @@
1
+ # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
+ # For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
3
+
4
+ name: Publish Main Webpack Config
5
+
6
+ on:
7
+ workflow_dispatch:
8
+ push:
9
+ branches:
10
+ - main
11
+ jobs:
12
+ build:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+ - uses: actions/setup-node@v4
17
+ with:
18
+ node-version: 20
19
+ - run: npm ci
20
+ - run: npm test
21
+ publish-npm:
22
+ needs: build
23
+ runs-on: ubuntu-latest
24
+ steps:
25
+ - uses: actions/checkout@v4
26
+ - uses: actions/setup-node@v4
27
+ with:
28
+ node-version: 20
29
+ registry-url: https://registry.npmjs.org/
30
+ - run: npm ci
31
+ - run: npm publish
32
+ env:
33
+ NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
@@ -0,0 +1,45 @@
1
+ # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
+ # For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
3
+
4
+ name: Publish Plugins to NPM
5
+
6
+ on:
7
+ workflow_dispatch:
8
+ push:
9
+ branches:
10
+ - a11y
11
+ - css-audit
12
+ - html
13
+ - jshint
14
+
15
+ jobs:
16
+ build:
17
+ runs-on: ubuntu-latest
18
+ defaults:
19
+ run:
20
+ working-directory: plugins/${{ github.ref_name }}
21
+ steps:
22
+ - uses: actions/checkout@v4
23
+ - uses: actions/setup-node@v4
24
+ with:
25
+ node-version: 20
26
+ - run: git submodule update --init
27
+ - run: npm ci
28
+ - run: npm test
29
+ publish-npm:
30
+ needs: build
31
+ runs-on: ubuntu-latest
32
+ defaults:
33
+ run:
34
+ working-directory: plugins/${{ github.ref_name }}
35
+ steps:
36
+ - uses: actions/checkout@v4
37
+ - uses: actions/setup-node@v4
38
+ with:
39
+ node-version: 20
40
+ registry-url: https://registry.npmjs.org/
41
+ - run: git submodule update --init
42
+ - run: npm ci
43
+ - run: npm publish
44
+ env:
45
+ NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
@@ -0,0 +1,29 @@
1
+ # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
+ # For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
3
+
4
+ name: Publish Plugins to NPM
5
+
6
+ on:
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+ - uses: actions/setup-node@v4
15
+ with:
16
+ node-version: 20
17
+ - run: ls
18
+ publish-npm:
19
+ needs: build
20
+ runs-on: ubuntu-latest
21
+ steps:
22
+ - uses: actions/checkout@v4
23
+ - uses: actions/setup-node@v4
24
+ with:
25
+ node-version: 20
26
+ registry-url: https://registry.npmjs.org/
27
+ - run: console.log( 'published' )
28
+ env:
29
+ NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
package/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "css-audit"]
2
+ path = plugins/css-audit/bin/auditor
3
+ url = https://github.com/WordPress/css-audit
package/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  This repository houses various plugins built and distributed by the CAWebPublishing Team and also the Webpack configuration for various CAWebPublishing products.
2
2
 
3
- <i>This package is inspired by [wp-scripts](https://www.npmjs.com/package/@wordpress/scripts)</i>
4
3
 
5
- ## Plugins Used
4
+ ## Plugins
6
5
  - [@caweb/a11y-webpack-plugin](https://www.npmjs.com/package/@caweb/a11y-webpack-plugin)
7
6
  - [@caweb/css-audit-webpack-plugin](https://www.npmjs.com/package/@caweb/css-audit-webpack-plugin)
8
7
  - [@caweb/html-webpack-plugin](https://www.npmjs.com/package/@caweb/html-webpack-plugin)
package/changelog.txt ADDED
@@ -0,0 +1,137 @@
1
+ v1.3.0
2
+ - Webpack configuration has been moved to @caweb/html-webpack-plugin
3
+
4
+ v1.2.28
5
+ - Updated npm packages
6
+
7
+ v1.2.27
8
+ - Updated npm packages
9
+
10
+ v1.2.26
11
+ - Updated npm packages
12
+
13
+ v1.2.25
14
+ - Updated npm packages
15
+
16
+ v1.2.24
17
+ - Updated npm packages
18
+
19
+ v1.2.23
20
+ - Updated npm packages
21
+
22
+ v1.2.22
23
+ - Updated npm packages
24
+
25
+ v1.2.21
26
+ - Updated npm packages
27
+
28
+ v1.2.20
29
+ - Updated npm packages
30
+
31
+ v1.2.19
32
+ - Updated npm packages
33
+
34
+ v1.2.18
35
+ - Added flags to webpack config, no longer using NODE_OPTIONS
36
+ - Updated npm package
37
+
38
+ v1.2.17
39
+ - Updated npm packages
40
+
41
+ v1.2.16
42
+ - Updated npm packages
43
+
44
+ v1.2.15
45
+ - Updated npm packages
46
+
47
+ v1.2.14
48
+ - Updated npm packages
49
+
50
+ v1.2.13
51
+ - Updated npm packages
52
+
53
+ v1.2.12
54
+ - Updated npm packages
55
+ - Added html-webpack-link-type-plugin package
56
+
57
+ v1.2.11
58
+ - Updated npm packages
59
+
60
+ v1.2.10
61
+ - Updated npm packages
62
+
63
+ v1.2.9
64
+ - Updated npm packages
65
+
66
+ v1.2.8
67
+ - Updated npm packages
68
+
69
+ v1.2.7
70
+ - Updated npm packages
71
+
72
+ v1.2.6
73
+ - We only add plugin if serving
74
+
75
+ v1.2.5
76
+ - Updated npm packages
77
+
78
+ v1.2.4
79
+ - Updated npm packages
80
+
81
+ v1.2.3
82
+ - Updated npm packages
83
+
84
+ v1.2.2
85
+ - Added jshint, css-audit, and a11y files to skipAssets
86
+
87
+ v1.2.1
88
+ - Added missing dependency
89
+
90
+ v1.2.0
91
+ - Webpack main configuration details moved to html plugin
92
+
93
+ v1.1.5
94
+ - Update npm packages
95
+
96
+ v1.1.4
97
+ - Resolved issue with --template flag not switching properly
98
+
99
+ v1.1.3
100
+ - Removed console messaging
101
+
102
+ v1.1.2
103
+ - Added flag to config to allow for switching from different templates
104
+
105
+ v1.1.1
106
+ - Added missing handlebars-loader dependency
107
+
108
+ v1.1.0
109
+ - Added sample site content
110
+ - Added header/footer template parameters
111
+
112
+ v1.0.5
113
+ - Update npm packages
114
+ - Added partialResolver to handlebars-loader
115
+
116
+ v1.0.4
117
+ - Update npm packages
118
+
119
+ v1.0.3
120
+ - Update npm packages
121
+
122
+ v1.0.2
123
+ - Update npm packages
124
+
125
+ v1.0.1
126
+ - Update jshint plugin
127
+
128
+ v1.0.0
129
+ - Initial CAWeb HTML Webpack Plugin added
130
+ - Updated Webpack Configurations
131
+ - Added Page Template to HTML Plugin
132
+ - WordPress CSS Audit Webpack Plugin added
133
+ - Added output folder option to WordPress CSS Audit Webpack Plugin
134
+ - JSHint Webpack Plugin added
135
+ - Accessibility Checker Webpack Plugin added
136
+ - Added jshint to workflow
137
+ - Cleaned up extra files
package/package.json CHANGED
@@ -1,20 +1,13 @@
1
1
  {
2
2
  "name": "@caweb/webpack",
3
- "version": "1.2.28",
3
+ "version": "1.3.0",
4
4
  "description": "CAWebPublishing Webpack Configuration",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
- "files": [
8
- "webpack.config.js"
9
- ],
10
7
  "scripts": {
11
8
  "webpack": "webpack",
12
- "preserve": "cd plugins/html && npm i",
13
- "serve": "set NODE_OPTIONS='--no-selectors' && webpack serve --config ./webpack.config.js",
14
- "build": "npm run build:html",
15
- "build:html": "cd ./plugins/html/ && npm i && npm run build",
9
+ "serve": "webpack serve --config ./plugins/html/webpack.config.js",
16
10
  "u:deps": "node ./scripts/update-deps.js ./plugins",
17
- "config:test": "webpack configtest ./webpack.config.js",
18
11
  "test": "echo \\\"Error: run tests from root\\\" && exit 0",
19
12
  "i:deps": "npm i @caweb/a11y-webpack-plugin @caweb/css-audit-webpack-plugin @caweb/html-webpack-plugin @caweb/jshint-webpack-plugin",
20
13
  "i:local": "npm i plugins/a11y/ plugins/css-audit/ plugins/html/ plugins/jshint/ ",
@@ -38,13 +31,13 @@
38
31
  "access": "public"
39
32
  },
40
33
  "homepage": "https://github.com/CAWebPublishing/webpack#readme",
34
+ "devDependencies": {
35
+ "webpack": "^5.96.1"
36
+ },
41
37
  "dependencies": {
42
- "@caweb/a11y-webpack-plugin": "^1.0.8",
43
- "@caweb/css-audit-webpack-plugin": "^1.0.11",
44
- "@caweb/html-webpack-plugin": "^1.5.0",
45
- "@caweb/jshint-webpack-plugin": "^1.0.8",
46
- "@wordpress/scripts": "^30.3.0",
47
- "html-webpack-link-type-plugin": "^1.1.1",
48
- "html-webpack-skip-assets-plugin": "^1.0.4"
38
+ "@caweb/a11y-webpack-plugin": "^1.0.9",
39
+ "@caweb/css-audit-webpack-plugin": "^1.0.12",
40
+ "@caweb/html-webpack-plugin": "^1.5.1",
41
+ "@caweb/jshint-webpack-plugin": "^1.0.9"
49
42
  }
50
43
  }
@@ -0,0 +1,19 @@
1
+ This is a Webpack Plugin that utilizes the [IBM Accessibility Checker](https://www.npmjs.com/package/accessibility-checker0) module to perform integrated accessibility testing.
2
+
3
+ ## Installation
4
+ <pre>npm install --save-dev @caweb/a11y-webpack-plugin</pre>
5
+
6
+ ## Get Started
7
+ In your Webpack configuration simply add the plugin to your existing plugin array.
8
+
9
+ <pre>
10
+ import A11yPlugin from '@caweb/a11y-webpack-plugin';
11
+
12
+ export default {
13
+ plugins: [
14
+ new A11yPlugin()
15
+ ]
16
+ }
17
+ </pre>
18
+
19
+ ## Options
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Configuration for Accessibility Checker
3
+ * @link https://www.npmjs.com/package/accessibility-checker
4
+ */
5
+
6
+ let levels = [
7
+ 'violation',
8
+ 'potentialviolation',
9
+ 'recommendation',
10
+ 'potentialrecommendation',
11
+ 'manual',
12
+ 'pass'
13
+ ];
14
+ let reportLevels = levels;
15
+ let failLevels = levels;
16
+
17
+ // process args
18
+ process.argv.forEach((arg) => {
19
+ // remove any report levels
20
+ if( arg.includes('--no-report-levels-') ){
21
+ let r = arg.replace('--no-report-levels-', '')
22
+ delete reportLevels[reportLevels.indexOf(r)]
23
+ }
24
+ // remove any fails levels
25
+ if( arg.includes('--no-fail-levels-') ){
26
+ let f = arg.replace('--no-fail-levels-', '')
27
+ delete failLevels[failLevels.indexOf(f)]
28
+ }
29
+ })
30
+
31
+ export default {
32
+ ruleArchive: "latest",
33
+ policies: [
34
+ 'WCAG_2_1'
35
+ ],
36
+ failLevels: failLevels.filter(e=>e),
37
+ reportLevels: reportLevels.filter(e=>e),
38
+ outputFilename: 'a11y',
39
+ outputFolder: "public",
40
+ outputFormat: [
41
+ 'html'
42
+ ],
43
+ outputFilenameTimestamp: false
44
+ }
@@ -0,0 +1,31 @@
1
+ v1.0.9
2
+ - Update npm packages
3
+ - Added npm devDependencies packages
4
+
5
+ v1.0.8
6
+ - Update npm packages
7
+
8
+ v1.0.7
9
+ - Updated Readme
10
+
11
+ v1.0.6
12
+ - Fixed issue with hot module replacement not loading
13
+
14
+ v1.0.5
15
+ - Fixed issue when publicPath is set to auto
16
+
17
+ v1.0.4
18
+ - Removed console message
19
+
20
+ v1.0.3
21
+ - If output.publicPath is set to auto the scanner will scan the public directory
22
+
23
+ v1.0.2
24
+ - Report is ran once compilation is done
25
+
26
+ v1.0.1
27
+ - Removed timeout from a11y check
28
+ - Fixed issue with hot module replacement
29
+
30
+ v1.0.0
31
+ - Accessibility Checker Webpack Plugin
@@ -0,0 +1,271 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * External dependencies
5
+ */
6
+ import { sync as resolveBin } from 'resolve-bin';
7
+ import spawn from 'cross-spawn';
8
+ import { getAllFilesSync } from 'get-all-files'
9
+ import EntryDependency from "webpack/lib/dependencies/EntryDependency.js";
10
+ import path from 'path';
11
+ import { isUrl, isValidUrl } from 'check-valid-url';
12
+ import fs from 'fs';
13
+ import deepmerge from 'deepmerge';
14
+ import chalk from 'chalk';
15
+ import { fileURLToPath, URL } from 'url';
16
+
17
+ // default configuration
18
+ import {default as DefaultConfig} from './aceconfig.js';
19
+
20
+ const boldWhite = chalk.bold.white;
21
+ const boldGreen = chalk.bold.green;
22
+ const boldBlue = chalk.bold.hex('#03a7fc');
23
+ const currentPath = path.dirname(fileURLToPath(import.meta.url));
24
+
25
+ // IBM Accessibility Checker Plugin
26
+ class A11yPlugin {
27
+ config = {}
28
+
29
+ constructor(opts = {}) {
30
+ // outputFolder must be resolved
31
+ if( opts.outputFolder ){
32
+ opts.outputFolder = path.join(process.cwd(), opts.outputFolder);
33
+ }
34
+ this.config = deepmerge(
35
+ DefaultConfig,
36
+ {
37
+ outputFolder: path.join(currentPath, DefaultConfig.outputFolder)
38
+ },
39
+ opts
40
+ );
41
+ }
42
+
43
+ apply(compiler) {
44
+ const staticDir = {
45
+ directory: this.config.outputFolder,
46
+ watch: true
47
+ }
48
+
49
+ let { devServer, output } = compiler.options;
50
+ let hostUrl = 'localhost' === devServer.host ? `http://${devServer.host}`: devServer.host;
51
+ let hostPort = devServer.port;
52
+
53
+ if( hostPort && 80 !== hostPort )
54
+ {
55
+ hostUrl = `${hostUrl}:${hostPort}`;
56
+ }
57
+
58
+ // if dev server allows for multiple pages to be opened
59
+ // add outputFilename.html to open property.
60
+ if( Array.isArray(devServer.open) ){
61
+ devServer.open.push(`${hostUrl}/${this.config.outputFilename}.html`)
62
+ }else if( 'object' === typeof devServer.open && Array.isArray(devServer.open.target) ){
63
+ devServer.open.target.push(`${hostUrl}/${this.config.outputFilename}.html`)
64
+ }
65
+
66
+ // add our static directory
67
+ if( Array.isArray(devServer.static) ){
68
+ devServer.static.push(staticDir)
69
+ }else{
70
+ devServer.static = [].concat(devServer.static, staticDir );
71
+ }
72
+
73
+ // Wait for configuration preset plugins to apply all configure webpack defaults
74
+ compiler.hooks.initialize.tap('IBM Accessibility Plugin', () => {
75
+ compiler.hooks.compilation.tap(
76
+ "IBM Accessibility Plugin",
77
+ (compilation, { normalModuleFactory }) => {
78
+ compilation.dependencyFactories.set(
79
+ EntryDependency,
80
+ normalModuleFactory
81
+ );
82
+ }
83
+ );
84
+
85
+ const { entry, options, context } = {
86
+ entry: path.join( this.config.outputFolder, 'a11y.update.js'),
87
+ options: {
88
+ name: 'a11y.update'
89
+ },
90
+ context: 'a11y'
91
+ };
92
+
93
+ const dep = new EntryDependency(entry);
94
+ dep.loc = {
95
+ name: options.name
96
+ };
97
+ if( ! fs.existsSync(path.resolve(this.config.outputFolder))){
98
+ fs.mkdirSync( path.resolve(this.config.outputFolder), {recursive: true} );
99
+ }
100
+
101
+ fs.writeFileSync(
102
+ path.join(this.config.outputFolder, `a11y.update.js`),
103
+ `` // required for hot-update to compile on our page, blank script for now
104
+ );
105
+
106
+
107
+ compiler.hooks.thisCompilation.tap('IBM Accessibility Plugin',
108
+ /**
109
+ * Hook into the webpack compilation
110
+ * @param {Compilation} compilation
111
+ */
112
+ (compilation) => {
113
+
114
+ compiler.hooks.make.tapAsync("IBM Accessibility Plugin", (compilation, callback) => {
115
+
116
+ compilation.addEntry(
117
+ context,
118
+ dep,
119
+ options,
120
+ err => {
121
+ callback(err);
122
+ });
123
+ });
124
+
125
+ });
126
+
127
+ compiler.hooks.done.tapAsync(
128
+ 'IBM Accessibility Plugin',
129
+ /**
130
+ * Hook into the process assets hook
131
+ * @param {any} _
132
+ * @param {(err?: Error) => void} callback
133
+ */
134
+ (stats, callback) => {
135
+
136
+ console.log(`<i> ${boldGreen('[webpack-dev-middleware] Running IBM Accessibility scan...')}`);
137
+
138
+ let result = this.a11yCheck('auto' === output.publicPath ? output.path : output.publicPath, this.config );
139
+
140
+ if( result ){
141
+ // we have to inject the a11y.update.js file into the head in order for the webpack-dev-server scripts to load.
142
+ let pageContent = fs.readFileSync(path.join(staticDir.directory, `${this.config.outputFilename}.html`))
143
+
144
+ fs.writeFileSync(
145
+ path.join(staticDir.directory, `${this.config.outputFilename}.html`),
146
+ pageContent.toString().replace('</head>', `<script src="./a11y.update.js"></script>\n</head>`)
147
+ )
148
+ }
149
+
150
+ console.log(`<i> ${boldGreen('[webpack-dev-middleware] IBM Accessibilty Report can be viewed at')} ${ boldBlue(new URL(`${hostUrl}/${this.config.outputFilename}.html`).toString()) }`);
151
+
152
+ callback();
153
+ });
154
+
155
+ });
156
+
157
+ }
158
+
159
+ /**
160
+ * Run accessibility checks
161
+ *
162
+ * @param {Object} options
163
+ * @param {boolean} options.debug True if debug mode is enabled.
164
+ * @param {boolean} options.ruleArchive Specify the rule archive.
165
+ * @param {boolean} options.policies Specify one or many policies to scan.
166
+ * @param {boolean} options.failLevels Specify one or many violation levels on which to fail the test.
167
+ * @param {boolean} options.reportLevels Specify one or many violation levels that should be reported.
168
+ * @param {boolean} options.labels Specify labels that you would like associated to your scan.
169
+ * @param {boolean} options.outputFormat In which formats should the results be output.
170
+ * @param {boolean} options.outputFilename Filename for the scan results.
171
+ * @param {boolean} options.outputFolder Where the scan results should be saved.
172
+ * @param {boolean} options.outputFilenameTimestamp Should the timestamp be included in the filename of the reports?
173
+ */
174
+ a11yCheck(url, {
175
+ debug,
176
+ ruleArchive,
177
+ policies,
178
+ failLevels,
179
+ reportLevels,
180
+ labels,
181
+ outputFormat,
182
+ outputFilename,
183
+ outputFolder,
184
+ outputFilenameTimestamp
185
+ }){
186
+
187
+ let acheckerArgs = [
188
+ '--ruleArchive',
189
+ ruleArchive,
190
+ '--policies',
191
+ Array.isArray(policies) ? policies.filter(e => e).join(',') : policies,
192
+ '--failLevels',
193
+ Array.isArray(failLevels) ? failLevels.filter(e => e).join(',') : failLevels,
194
+ '--reportLevels',
195
+ Array.isArray(reportLevels) ? reportLevels.filter(e => e).join(',') : reportLevels,
196
+ '--outputFolder',
197
+ outputFolder,
198
+ '--outputFormat',
199
+ outputFormat,
200
+ '---outputFilenameTimestamp',
201
+ outputFilenameTimestamp,
202
+ url
203
+ ];
204
+
205
+ let isValid = false;
206
+
207
+ if( fs.existsSync( url ) ){
208
+ if( fs.statSync(url).isDirectory() && path.join( url, 'index.html') ){
209
+ url = path.join( url, 'index.html')
210
+ }
211
+ isValid = true;
212
+ }else{
213
+ isValid = 'localhost' === new URL(url).hostname || isUrl( url )
214
+ }
215
+
216
+ if( isValid ){
217
+ let originalFileName = `${fs.existsSync( url ) ?
218
+ path.resolve(url).replace(':', '_') :
219
+ url.replace(/http[s]+:\/\//, '')}.html`;
220
+ let originalJsonFileName = `${fs.existsSync( url ) ?
221
+ path.resolve(url).replace(':', '_') :
222
+ url.replace(/http[s]+:\/\//, '')}.json`;
223
+
224
+ let outputDir = path.resolve('.', outputFolder );
225
+
226
+ let {stderr, stdout} = spawn.sync(
227
+ resolveBin('accessibility-checker', {executable: 'achecker'}),
228
+ acheckerArgs,
229
+ {
230
+ stdio: 'pipe'
231
+ }
232
+ )
233
+
234
+ if( stderr && stderr.toString() ){
235
+ console.log( stderr.toString() );
236
+ }
237
+
238
+ if( stdout && stdout.toString()){
239
+ let reportedFile = path.join(outputDir, originalFileName );
240
+ let reportedJSon = path.join(outputDir, originalJsonFileName );
241
+
242
+ // if output file name option was passed
243
+ if( outputFilename ){
244
+
245
+ reportedFile = path.join( outputDir, `${outputFilename}.html` );
246
+ reportedJSon = path.join( outputDir, `${outputFilename}.json` );
247
+
248
+ // rename the output files
249
+ fs.renameSync(path.join(outputDir, originalFileName), reportedFile );
250
+ fs.renameSync(path.join(outputDir, originalJsonFileName), reportedJSon );
251
+
252
+ // delete any empty directories.
253
+ fs.rmSync( path.join(outputDir, originalFileName.split(path.sep).shift()), {recursive: true} )
254
+ }
255
+
256
+ if( 'a11y' === process.argv[2] ){
257
+ console.log( reportedFile )
258
+ }else{
259
+ return reportedFile;
260
+ }
261
+ }
262
+ }else{
263
+ console.log( `${url} is not a valid url.` )
264
+ }
265
+
266
+ } // end of a11yCheck
267
+
268
+ } // end of class
269
+
270
+
271
+ export default A11yPlugin;