@caweb/cli 1.15.11 → 1.15.12

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.
@@ -3,6 +3,7 @@
3
3
  */
4
4
  import path from 'path';
5
5
  import fs from 'fs';
6
+ import { fileURLToPath } from 'url';
6
7
 
7
8
  /**
8
9
  * Internal dependencies
@@ -13,6 +14,8 @@ import {
13
14
 
14
15
  import { buildFlags, serveFlags } from './webpack-flags.js';
15
16
 
17
+ const currentPath = path.dirname(fileURLToPath(import.meta.url));
18
+
16
19
  /**
17
20
  * Build the current project
18
21
  *
@@ -33,13 +36,17 @@ export default async function webpack({
33
36
  const webpackAllowedFlags = 'build' === webpackCommand ? buildFlags : serveFlags ;
34
37
 
35
38
  // we use our default config from the @caweb/webpack
36
- const defaultConfigPath = path.resolve('node_modules', '@caweb', 'webpack', 'webpack.config.js' );
39
+ const defaultConfigFile = path.resolve('node_modules', '@caweb', 'webpack', 'webpack.config.js' );
40
+
41
+ // we use the cli webpack plugins config
42
+ const webpackPluginsFile = 'serve' === webpackCommand ? ['--config', path.resolve( currentPath, '..', '..', 'configs','webpack.plugins.js')] : [];
37
43
 
38
44
  // prepend our default config to the arguments.
39
45
  // users can overwrite any values by creating a webconfig of their own.
40
46
  let webPackArgs = [
41
47
  '--config',
42
- defaultConfigPath,
48
+ defaultConfigFile,
49
+ ...webpackPluginsFile,
43
50
  ...process.argv.splice(3),
44
51
  ];
45
52
 
@@ -0,0 +1,29 @@
1
+ // this file is used to add any custom webpack plugins to the serve process.
2
+ /**
3
+ * External dependencies
4
+ */
5
+ import CAWebHTMLPlugin from "@caweb/html-webpack-plugin";
6
+ import CAWebA11yPlugin from '@caweb/a11y-webpack-plugin';
7
+ import CAWebCSSAuditPlugin from '@caweb/css-audit-webpack-plugin';
8
+ import CAWebJSHintPlugin from '@caweb/jshint-webpack-plugin';
9
+
10
+ import { flagExists } from '@caweb/webpack/lib/args.js';
11
+
12
+ export default {
13
+
14
+ plugins: [
15
+ // add custom plugins here
16
+ // Used for Site Generation
17
+ new CAWebHTMLPlugin(),
18
+
19
+ // // IBM Accessibility
20
+ ! flagExists('no-a11y') && new CAWebA11yPlugin(),
21
+
22
+ // // WP CSS Auditor
23
+ ! flagExists( 'no-audit' ) && new CAWebCSSAuditPlugin(),
24
+
25
+ // // JSHint
26
+ ! flagExists( 'no-jshint' ) && new CAWebJSHintPlugin(),
27
+
28
+ ].filter( Boolean ),
29
+ }
@@ -1,9 +1,8 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import fs from 'fs';
5
- import path from 'path';
6
4
  import { format } from 'util';
5
+ import { getArgVal } from '@caweb/webpack/lib/args.js';
7
6
 
8
7
  /**
9
8
  * Internal dependencies
@@ -13,34 +12,7 @@ import { configureWordPress } from '../wordpress.js';
13
12
  import { isCAWeb, configureCAWeb } from './caweb.js';
14
13
  import { isDivi, configureDivi } from './divi.js';
15
14
 
16
-
17
- function processArgs( arr ){
18
- let tmp = [];
19
-
20
- arr.filter(Boolean).map((o) => {
21
- return o.replaceAll("'", '').split('=').forEach((e => tmp.push(e)))
22
- });
23
-
24
- return tmp
25
- }
26
-
27
- function flagExists(flag){
28
- return flags.includes(flag)
29
- }
30
-
31
- function getArgVal(flag){
32
- return flagExists(flag) ? flags[flags.indexOf(flag) + 1] : false;
33
- }
34
-
35
- let flags = [].concat(
36
- processArgs(process.argv),
37
- // the following can be uncommented if ever needed to process those args.
38
- // processArgs(process.argv0.split(' ')),
39
- // processArgs(process.env)
40
- // processArgs(process.env.NODE_OPTIONS ? process.env.NODE_OPTIONS.split(' ') : []),
41
- )
42
-
43
- const workingDirectoryPath = getArgVal('--cwd') ? getArgVal('--cwd') : process.cwd();
15
+ const workingDirectoryPath = getArgVal('--cwd', process.cwd() );
44
16
 
45
17
  // Collect existing wp-config.php values.
46
18
  process.stdout.write('Collecting CAWeb configuration data...');
@@ -68,7 +40,7 @@ let diviInstalled = await isDivi({
68
40
  is: 'installed'
69
41
  });
70
42
 
71
- let multisite = flagExists('--multisite') ? getArgVal('--multisite') : false;
43
+ let multisite = getArgVal('--multisite', false );
72
44
 
73
45
  process.stdout.write(`\nConfiguring WordPress...\n`);
74
46
  await configureWordPress({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caweb/cli",
3
- "version": "1.15.11",
3
+ "version": "1.15.12",
4
4
  "description": "CAWebPublishing Command Line Interface.",
5
5
  "exports": "./lib/env.js",
6
6
  "type": "module",
@@ -64,24 +64,28 @@
64
64
  }
65
65
  },
66
66
  "dependencies": {
67
- "@caweb/webpack": "^1.5.18",
67
+ "@caweb/a11y-webpack-plugin": "^2.1.0",
68
+ "@caweb/css-audit-webpack-plugin": "^2.1.0",
69
+ "@caweb/html-webpack-plugin": "^2.1.0",
70
+ "@caweb/jshint-webpack-plugin": "^2.1.0",
71
+ "@caweb/webpack": "^1.6.3",
68
72
  "@inquirer/prompts": "^8.2.0",
69
- "@wordpress/create-block": "^4.81.0",
70
- "@wordpress/env": "^10.38.0",
71
- "axios": "^1.13.2",
73
+ "@wordpress/create-block": "^4.82.0",
74
+ "@wordpress/env": "^10.39.0",
75
+ "axios": "^1.13.4",
72
76
  "axios-retry": "^4.5.0",
73
77
  "chalk": "^5.6.2",
74
78
  "commander": "^14.0.2",
75
79
  "cross-spawn": "^7.0.6",
76
80
  "crypto": "^1.0.1",
77
81
  "deepmerge": "^4.3.1",
78
- "docker-compose": "^1.3.0",
82
+ "docker-compose": "^1.3.1",
79
83
  "fs-extra": "^11.3.3",
80
84
  "html-to-json-parser": "^2.0.1",
81
85
  "inquirer-select-pro": "^1.0.0-alpha.9",
82
86
  "jsdom": "^27.4.0",
83
87
  "node-html-parser": "^7.0.2",
84
- "ora": "^9.0.0",
88
+ "ora": "^9.1.0",
85
89
  "resolve-bin": "^1.0.1",
86
90
  "rimraf": "^6.1.2",
87
91
  "terminal-link": "^5.0.0"
@@ -1,44 +0,0 @@
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
- }
@@ -1,272 +0,0 @@
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
- let { devServer, output } = compiler.options;
49
- let hostUrl = 'localhost' === devServer.host ? `http://${devServer.host}`: devServer.host;
50
- let hostPort = devServer.port;
51
-
52
- if( hostPort && 80 !== hostPort )
53
- {
54
- hostUrl = `${hostUrl}:${hostPort}`;
55
- }
56
-
57
- // if dev server allows for multiple pages to be opened
58
- // add outputFilename.html to open property.
59
- if( Array.isArray(devServer.open) ){
60
- devServer.open.push(`${hostUrl}/${this.config.outputFilename}.html`)
61
- }else if( 'object' === typeof devServer.open && Array.isArray(devServer.open.target) ){
62
- devServer.open.target.push(`${hostUrl}/${this.config.outputFilename}.html`)
63
- }
64
-
65
- // add our static directory
66
- if( Array.isArray(devServer.static) ){
67
- devServer.static.push(staticDir)
68
- }else{
69
- devServer.static = [].concat(devServer.static, staticDir );
70
- }
71
-
72
- // Wait for configuration preset plugins to apply all configure webpack defaults
73
- compiler.hooks.initialize.tap('IBM Accessibility Plugin', () => {
74
- compiler.hooks.compilation.tap(
75
- "IBM Accessibility Plugin",
76
- (compilation, { normalModuleFactory }) => {
77
- compilation.dependencyFactories.set(
78
- EntryDependency,
79
- normalModuleFactory
80
- );
81
- }
82
- );
83
-
84
- const { entry, options, context } = {
85
- entry: path.join( this.config.outputFolder, 'a11y.update.js'),
86
- options: {
87
- name: 'a11y'
88
- },
89
- context: 'a11y'
90
- };
91
-
92
- const dep = new EntryDependency(entry);
93
- dep.loc = {
94
- name: options.name
95
- };
96
- if( ! fs.existsSync(path.resolve(this.config.outputFolder))){
97
- fs.mkdirSync( path.resolve(this.config.outputFolder), {recursive: true} );
98
- }
99
-
100
- fs.writeFileSync(
101
- path.join(this.config.outputFolder, `a11y.update.js`),
102
- `` // required for hot-update to compile on our page, blank script for now
103
- );
104
-
105
-
106
- compiler.hooks.thisCompilation.tap('IBM Accessibility Plugin',
107
- /**
108
- * Hook into the webpack compilation
109
- * @param {Compilation} compilation
110
- */
111
- (compilation) => {
112
-
113
- compiler.hooks.make.tapAsync("IBM Accessibility Plugin", (compilation, callback) => {
114
-
115
- compilation.addEntry(
116
- context,
117
- dep,
118
- options,
119
- err => {
120
- callback(err);
121
- });
122
- });
123
-
124
- compiler.hooks.done.tapAsync(
125
- 'IBM Accessibility Plugin',
126
- /**
127
- * Hook into the process assets hook
128
- * @param {any} _
129
- * @param {(err?: Error) => void} callback
130
- */
131
- ({compilation}, callback) => {
132
-
133
- console.log(`<i> ${boldGreen('[webpack-dev-middleware] Running IBM Accessibility scan...')}`);
134
-
135
- this.a11yCheck(path.join(process.cwd(), output.publicPath ?? '/' ), this.config );
136
-
137
- console.log(`<i> ${boldGreen('[webpack-dev-middleware] IBM Accessibilty Report can be viewed at')} ${ boldBlue(new URL(`${hostUrl}/${this.config.outputFilename}.html`).toString()) }`);
138
-
139
- callback();
140
- });
141
-
142
- compiler.hooks.watchClose.tap( 'IBM Accessibility Plugin', () => {
143
- getAllFilesSync(compiler.options.output.path).toArray().forEach(f => {
144
- if(
145
- f.includes('a11y') || // delete any a11y files
146
- f.includes('.hot-update.js') // delete any HMR files
147
- ){
148
- fs.rmSync(f)
149
- }
150
- })
151
- });
152
-
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
- timeout: 30000 // stop after 30 seconds
232
- }
233
- )
234
-
235
- if( stderr && stderr.toString() ){
236
- console.log( stderr.toString() );
237
- }
238
-
239
- if( stdout && stdout.toString()){
240
- let reportedFile = path.join(outputDir, originalFileName );
241
- let reportedJSon = path.join(outputDir, originalJsonFileName );
242
-
243
- // if output file name option was passed
244
- if( outputFilename ){
245
-
246
- reportedFile = path.join( outputDir, `${outputFilename}.html` );
247
- reportedJSon = path.join( outputDir, `${outputFilename}.json` );
248
-
249
- // rename the output files
250
- fs.renameSync(path.join(outputDir, originalFileName), reportedFile );
251
- fs.renameSync(path.join(outputDir, originalJsonFileName), reportedJSon );
252
-
253
- // delete any empty directories.
254
- fs.rmSync( path.join(outputDir, originalFileName.split(path.sep).shift()), {recursive: true} )
255
- }
256
-
257
- if( 'a11y' === process.argv[2] ){
258
- console.log( reportedFile )
259
- }else{
260
- return reportedFile;
261
- }
262
- }
263
- }else{
264
- console.log( `${url} is not a valid url.` )
265
- }
266
-
267
- } // end of a11yCheck
268
-
269
- } // end of class
270
-
271
-
272
- export default A11yPlugin;
@@ -1,12 +0,0 @@
1
- {
2
- "name": "@caweb/a11y-webpack-plugin",
3
- "version": "1.0.0",
4
- "description": "Webpack Plugin to run Accessibility Scans",
5
- "type": "module",
6
- "main": "index.js",
7
- "scripts": {
8
- "test": "echo \"Error: no test specified\" && exit 0"
9
- },
10
- "author": "Danny Guzman",
11
- "license": "ISC"
12
- }