@caweb/cli 1.4.1 → 1.4.3

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 (56) hide show
  1. package/README.md +38 -12
  2. package/bin/css-audit/.editorconfig +12 -0
  3. package/bin/css-audit/.github/workflows/build-report.yml +46 -0
  4. package/bin/css-audit/.github/workflows/merge-trunk-to-report.yml +17 -0
  5. package/bin/css-audit/.github/workflows/node.yaml +32 -0
  6. package/bin/css-audit/.nvmrc +1 -0
  7. package/bin/css-audit/README.md +131 -0
  8. package/bin/css-audit/css-audit.config.js +13 -0
  9. package/bin/css-audit/index.js +38 -0
  10. package/bin/css-audit/package-lock.json +6689 -0
  11. package/bin/css-audit/package.json +56 -0
  12. package/bin/css-audit/public/.gitkeep +1 -0
  13. package/bin/css-audit/src/__tests__/alphas.js +128 -0
  14. package/bin/css-audit/src/__tests__/colors.js +115 -0
  15. package/bin/css-audit/src/__tests__/display-none.js +52 -0
  16. package/bin/css-audit/src/__tests__/important.js +88 -0
  17. package/bin/css-audit/src/__tests__/media-queries.js +84 -0
  18. package/bin/css-audit/src/__tests__/property-values.js +55 -0
  19. package/bin/css-audit/src/__tests__/run.js +25 -0
  20. package/bin/css-audit/src/__tests__/selectors.js +66 -0
  21. package/bin/css-audit/src/audits/alphas.js +70 -0
  22. package/bin/css-audit/src/audits/colors.js +83 -0
  23. package/bin/css-audit/src/audits/display-none.js +39 -0
  24. package/bin/css-audit/src/audits/important.js +60 -0
  25. package/bin/css-audit/src/audits/media-queries.js +96 -0
  26. package/bin/css-audit/src/audits/property-values.js +65 -0
  27. package/bin/css-audit/src/audits/selectors.js +67 -0
  28. package/bin/css-audit/src/audits/typography.js +41 -0
  29. package/bin/css-audit/src/formats/cli-table.js +81 -0
  30. package/bin/css-audit/src/formats/html/_audit-alpha.twig +23 -0
  31. package/bin/css-audit/src/formats/html/_audit-colors.twig +23 -0
  32. package/bin/css-audit/src/formats/html/_audit-default.twig +24 -0
  33. package/bin/css-audit/src/formats/html/index.twig +88 -0
  34. package/bin/css-audit/src/formats/html/style.css +341 -0
  35. package/bin/css-audit/src/formats/html.js +52 -0
  36. package/bin/css-audit/src/formats/json.js +9 -0
  37. package/bin/css-audit/src/run.js +76 -0
  38. package/bin/css-audit/src/utils/__tests__/cli.js +70 -0
  39. package/bin/css-audit/src/utils/__tests__/example-config.config.js +12 -0
  40. package/bin/css-audit/src/utils/__tests__/get-specificity.js +39 -0
  41. package/bin/css-audit/src/utils/cli.js +133 -0
  42. package/bin/css-audit/src/utils/format-report.js +37 -0
  43. package/bin/css-audit/src/utils/get-specificity.js +97 -0
  44. package/bin/css-audit/src/utils/get-values-count.js +17 -0
  45. package/commands/audit.js +135 -0
  46. package/commands/index.js +7 -4
  47. package/commands/webpack/webpack.js +133 -0
  48. package/configs/css-audit.config.cjs +9 -0
  49. package/configs/webpack.config.js +126 -78
  50. package/docs/CREDITS.MD +5 -0
  51. package/docs/ROADMAP.MD +6 -5
  52. package/lib/cli.js +13 -4
  53. package/lib/helpers.js +3 -0
  54. package/package.json +15 -8
  55. package/commands/build.js +0 -80
  56. package/commands/serve.js +0 -94
@@ -10,113 +10,161 @@
10
10
  * External dependencies
11
11
  */
12
12
  import baseConfig from '@wordpress/scripts/config/webpack.config.js';
13
+ import path from 'path';
14
+ import fs from 'fs';
15
+ import HtmlWebpackPlugin from 'html-webpack-plugin';
16
+ import {HtmlWebpackSkipAssetsPlugin} from 'html-webpack-skip-assets-plugin';
17
+
13
18
  import MiniCssExtractPlugin from "mini-css-extract-plugin";
14
19
 
15
20
  /**
16
21
  * Internal dependencies
17
22
  */
18
- import SiteGenerator from '../gen/site-generator.js';
23
+ import {
24
+ projectPath,
25
+ appPath
26
+ } from '../lib/index.js';
19
27
 
20
- // fallback to env variable
21
- let isProduction = "production" === process.env.NODE_ENV;
22
-
23
- // because we use WordPress default WebPack config
24
- // 'mode' is defined by process.env.NODE_ENV
25
- // some of the webpack cli flags are ignored
26
- // so let's make some corrections.
27
- let corrections = {};
28
-
29
- process.argv.splice( 2 ).forEach(element => {
30
- // if flag
31
- if( element.startsWith( '--' ) ){
32
- let splitterIndex = element.indexOf( '=' );
33
- let flag = element.substring(2, splitterIndex );
34
- let value = element.substring( splitterIndex + 1 );
35
-
36
- // if flag is a webpack flag add corrections.
37
- switch( flag ){
38
- case 'mode':
39
- // if cli arg was passed use that value
40
- isProduction = "production" === value;
41
-
42
- corrections[flag] = value
43
- break
44
- }
45
-
46
- }
47
-
48
- });
28
+ const samplePath = path.join( appPath, 'sample');
29
+ const srcPath = path.join( appPath, 'src');
30
+ const dataPath = path.join( srcPath, 'data');
49
31
 
32
+ import SiteGenerator from '../gen/site-generator.js';
50
33
 
51
- // update the WordPress default webpack rules with ours.
34
+ // Update some of the default WordPress webpack rules.
52
35
  baseConfig.module.rules.forEach((rule, i) => {
53
36
  const r = new RegExp(rule.test).toString();
54
37
 
55
- // WordPress adds a hash to asset file names we remove that hash
56
- if( r === new RegExp(/\.(bmp|png|jpe?g|gif|webp)$/i).toString() ){
57
- baseConfig.module.rules[i].generator = {
58
- filename: 'images/[name][ext]'
59
- }
60
- }
61
- if( r === new RegExp(/\.(woff|woff2|eot|ttf|otf)$/i).toString() ){
62
- baseConfig.module.rules[i].generator = {
63
- filename: 'fonts/[name][ext]'
64
- }
65
- }
66
- // SVG rules
67
- if( r === new RegExp(/\.svg$/).toString() ){
68
- // we don't want SVG to be inline move them to fonts folder
69
- if( 'asset/inline' === rule.type ){
70
- baseConfig.module.rules[i].type = 'asset/resource';
71
- baseConfig.module.rules[i].generator = {
72
- filename: 'fonts/[name][ext]'
73
- };
74
-
75
- // we don't care who the issuer is
76
- delete baseConfig.module.rules[i].issuer;
77
-
78
- }
38
+ switch(r){
39
+ // WordPress adds a hash to asset file names we remove that hash.
40
+ case new RegExp(/\.(bmp|png|jpe?g|gif|webp)$/i).toString():
41
+ rule.generator.filename = 'images/[name].[ext]';
42
+ break;
43
+ case new RegExp(/\.(woff|woff2|eot|ttf|otf)$/i).toString():
44
+ rule.generator.filename = 'fonts/[name].[ext]';
45
+ break;
46
+ case new RegExp(/\.svg$/).toString():
47
+ // we don't want SVG to be asset/inline otherwise the resource may not be available.
48
+ // the asset should be an asset/resource we move them to the fonts folder.
49
+ if( 'asset/inline' === rule.type ){
50
+ rule.type = 'asset/resource';
51
+ rule.generator = { filename: 'fonts/[name].[ext]' };
52
+
53
+ delete rule.issuer;
54
+ }
55
+ break;
79
56
  }
80
- })
57
+ });
81
58
 
82
59
  // Our Webpack Configuration.
83
60
  let webpackConfig = {
84
61
  ...baseConfig,
85
62
  target: 'web',
86
- devtool: false,
63
+ cache: false,
87
64
  output: {
88
65
  ...baseConfig.output,
89
66
  publicPath: `/`,
90
67
  clean: true
91
68
  },
92
- plugins: [
93
- ...baseConfig.plugins,
94
- new MiniCssExtractPlugin(
95
- {
96
- linkType: "text/css",
97
- filename: '[name].css'
98
- }
99
- )
100
- ],
101
- module: {
102
- rules: [
103
- ...baseConfig.module.rules,
104
- /*{
105
- test: /\.html$/,
106
- loader:'handlebars-loader'
107
- }*/
108
- ]
109
- },
110
69
  performance: {
111
70
  maxAssetSize: 500000,
112
71
  maxEntrypointSize: 500000
113
72
  }
114
73
  };
115
74
 
116
- if( process.env.CAWEB_SERVE ){
117
- delete webpackConfig.devServer;
75
+ // Delete the default WP Dev Server
76
+ delete webpackConfig.devServer;
77
+
78
+ // Only add the Dev Server if the serve command is ran.
79
+ if( 'serve' === process.argv[2] ){
80
+
81
+ // Add html rule
82
+ webpackConfig.module.rules = [
83
+ ...baseConfig.module.rules,
84
+ {
85
+ test: /\.html$/,
86
+ loader:'handlebars-loader'
87
+ }
88
+ ]
89
+
90
+ // we only want to display errors and warnings
91
+ webpackConfig.stats = 'errors-warnings';
92
+
93
+ let pageTemplate = {
94
+ title: path.basename(appPath),
95
+ minify: false,
96
+ meta: {
97
+ "Author": "CAWebPublishing",
98
+ "Description": "State of California",
99
+ "Keywords": "California,government",
100
+ "viewport": "width=device-width, initial-scale=1.0, minimum-scale=1.0"
101
+ },
102
+ templateParameters: {
103
+ "title" : path.basename(appPath)
104
+ },
105
+ skipAssets: ['**/index-rtl.css']
106
+ }
107
+
108
+ // if an favicon exists.
109
+ if( fs.existsSync(path.join(srcPath, 'favicon.ico')) ){
110
+ pageTemplate.favicon = path.join(srcPath, 'favicon.ico');
111
+ }
112
+
113
+ // Sample Page.
114
+ let sample = {
115
+ ...pageTemplate,
116
+ filename: path.join( appPath, 'public', 'index.html'),
117
+ template: path.join(samplePath, 'index.html')
118
+ }
119
+
120
+ webpackConfig.plugins.push(
121
+ new HtmlWebpackPlugin(sample),
122
+ new HtmlWebpackSkipAssetsPlugin()
123
+ );
124
+
125
+ webpackConfig.devServer = {
126
+ devMiddleware: {
127
+ writeToDisk: true
128
+ },
129
+ headers: {
130
+ },
131
+ hot: true,
132
+ allowedHosts: 'auto',
133
+ host: 'localhost',
134
+ port: 9000,
135
+ compress: true,
136
+ static: [
137
+ {
138
+ directory: path.join( appPath, 'build'),
139
+ },
140
+ {
141
+ directory: path.join(appPath, 'public'),
142
+ },
143
+ {
144
+ directory: path.join(appPath, 'node_modules'),
145
+ },
146
+ {
147
+ directory: path.join(appPath, 'src'),
148
+ },
149
+ {
150
+ directory: path.join(projectPath, 'bin', 'css-audit', 'public'),
151
+ }
152
+ ],
153
+ proxy: [
154
+ {
155
+ context: ['/node_modules'],
156
+ target: 'http://localhost:9000',
157
+ pathRewrite: { '^/node_modules': '' },
158
+ },
159
+ {
160
+ context: ['/src'],
161
+ target: 'http://localhost:9000',
162
+ pathRewrite: { '^/src': '' },
163
+ }
164
+ ],
165
+ }
166
+
118
167
 
119
- SiteGenerator( webpackConfig );
120
168
  }
121
169
 
122
170
  export default webpackConfig;
package/docs/CREDITS.MD CHANGED
@@ -25,3 +25,8 @@
25
25
 
26
26
  ### <ins>phpMyAdmin</ins>
27
27
  [Docker](https://hub.docker.com/_/phpmyadmin)
28
+
29
+ ### <ins>css-audit</ins>
30
+ [Documentation](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/css/)
31
+ [Documentation](https://make.wordpress.org/core/2021/05/17/introducing-the-wordpress-css-audit-tool/)
32
+ [Github](https://github.com/wordpress/css-audit)
package/docs/ROADMAP.MD CHANGED
@@ -1,4 +1,10 @@
1
1
  # Roadmap Features:
2
+ ## Validation with:
3
+
4
+ - SNYK
5
+ https://www.npmjs.com/package/snyk
6
+ - CSS-Audit
7
+ https://github.com/wordpress/css-audit
2
8
 
3
9
  ## Testaro
4
10
  https://www.npmjs.com/package/testaro
@@ -9,11 +15,6 @@ https://www.npmjs.com/package/sonarqube-scanner
9
15
  ## BrowserStack
10
16
  https://www.npmjs.com/package/browserstack
11
17
 
12
- ## Accessibility Checker
13
- https://www.npmjs.com/package/accessibility-checker
14
-
15
18
  ## Control Panel
16
19
  https://aapanel.com/new/download.html
17
20
 
18
- ## SNYK
19
- https://www.npmjs.com/package/snyk
package/lib/cli.js CHANGED
@@ -212,18 +212,19 @@ export default function cli() {
212
212
  program.command('build')
213
213
  .description('Builds the current project.')
214
214
  .allowUnknownOption(true)
215
- .action(withSpinner(env.build))
215
+ .action(withSpinner(env.webpack))
216
216
 
217
217
 
218
218
  // Serve Command.
219
219
  program.command('serve')
220
220
  .description('Serve the current project')
221
221
  .option(
222
- '--no-template',
223
- 'Disables inclusion of the template page header & footer, starting off with a plain html page.'
222
+ '--audit',
223
+ 'Add CSS-Audit Page to pages served.',
224
+ false
224
225
  )
225
226
  .allowUnknownOption(true)
226
- .action(withSpinner(env.serve))
227
+ .action(withSpinner(env.webpack))
227
228
 
228
229
  // a11y Command.
229
230
  program.command('a11y')
@@ -232,6 +233,14 @@ export default function cli() {
232
233
  .allowUnknownOption(true)
233
234
  .action(withSpinner(env.a11y))
234
235
 
236
+
237
+ // audit Command.
238
+ program.command('audit')
239
+ .addArgument(new Argument('[files...]', 'Files or directory path to CSS files.').default('build'))
240
+ .description('Runs WordPress CSS Audit tool against projects.')
241
+ .allowUnknownOption(true)
242
+ .action(withSpinner(env.audit))
243
+
235
244
  // Update Plugins Command.
236
245
  program.command('update-plugins')
237
246
  .description('Updates all plugins in the WordPress environment.')
package/lib/helpers.js CHANGED
@@ -40,6 +40,9 @@ async function runCmd(cmd, args,opts = { stdio: ['inherit', 'pipe'] }){
40
40
  */
41
41
  cmd += /^win/.test(process.platform) ? '.cmd' : '';
42
42
  break;
43
+ case 'auditor':
44
+ cmd = 'node ' + resolveBin('@caweb/cli', {executable: 'auditor'} )
45
+ break;
43
46
  case 'achecker':
44
47
  cmd = resolveBin('accessibility-checker', {executable: 'achecker'})
45
48
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caweb/cli",
3
- "version": "1.4.1",
3
+ "version": "1.4.3",
4
4
  "description": "CAWebPublishing Command Line Interface.",
5
5
  "exports": "./lib/env.js",
6
6
  "type": "module",
@@ -9,7 +9,8 @@
9
9
  "author": "CAWebPublishing",
10
10
  "license": "ISC",
11
11
  "bin": {
12
- "caweb": "bin/caweb.js"
12
+ "caweb": "bin/caweb.js",
13
+ "auditor": "bin/css-audit/index.js"
13
14
  },
14
15
  "files": [
15
16
  "assets",
@@ -23,7 +24,8 @@
23
24
  ],
24
25
  "scripts": {
25
26
  "doc": "node ./docs/tool/index.js",
26
- "test": "echo \"Error: run tests from root\" && exit 0"
27
+ "test": "echo \"Error: run tests from root\" && exit 0",
28
+ "postinstall": "cd bin/css-audit && npm ci"
27
29
  },
28
30
  "homepage": "https://github.com/CAWebPublishing/cli#readme",
29
31
  "repository": {
@@ -41,7 +43,7 @@
41
43
  "access": "public"
42
44
  },
43
45
  "config": {
44
- "WP_VER": "6.5.4",
46
+ "WP_VER": "6.5.5",
45
47
  "PHP_VER": "8.1",
46
48
  "DEFAULTS": {
47
49
  "FS_METHOD": "direct",
@@ -59,29 +61,34 @@
59
61
  }
60
62
  },
61
63
  "dependencies": {
62
- "@wordpress/create-block": "^4.44.0",
63
- "@wordpress/env": "^10.1.0",
64
- "@wordpress/scripts": "^28.1.0",
64
+ "@wordpress/create-block": "^4.45.0",
65
+ "@wordpress/env": "^10.2.0",
66
+ "@wordpress/scripts": "^28.2.0",
65
67
  "accessibility-checker": "^3.1.73",
66
68
  "autoprefixer": "^10.4.19",
67
69
  "axios": "^1.7.2",
68
- "axios-retry": "^4.4.0",
70
+ "axios-retry": "^4.4.1",
69
71
  "chalk": "^5.3.0",
70
72
  "check-valid-url": "^0.1.0",
71
73
  "commander": "^12.1.0",
72
74
  "cross-spawn": "^7.0.3",
75
+ "css-audit": "file:css-audit",
73
76
  "css-loader": "^7.1.2",
77
+ "deepmerge": "^4.3.1",
74
78
  "docker-compose": "^0.24.8",
75
79
  "fs-extra": "^11.2.0",
80
+ "get-all-files": "^5.0.0",
76
81
  "got": "^14.4.1",
77
82
  "handlebars-loader": "^1.7.3",
78
83
  "html-to-json-parser": "^2.0.1",
79
84
  "html-webpack-plugin": "^5.6.0",
85
+ "html-webpack-skip-assets-plugin": "^1.0.4",
80
86
  "mini-css-extract-plugin": "^2.9.0",
81
87
  "ora": "^8.0.1",
82
88
  "postcss-loader": "^8.1.1",
83
89
  "resolve-bin": "^1.0.1",
84
90
  "sass-loader": "^14.2.1",
91
+ "snyk": "^1.1292.1",
85
92
  "terminal-link": "^3.0.0",
86
93
  "url": "^0.11.3",
87
94
  "webpack": "^5.92.1"
package/commands/build.js DELETED
@@ -1,80 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * External dependencies
5
- */
6
- import path from 'path';
7
- import fs from 'fs';
8
-
9
- /**
10
- * Internal dependencies
11
- */
12
- import {
13
- runCmd,
14
- projectPath,
15
- appPath
16
- } from '../lib/index.js';
17
-
18
-
19
- /**
20
- * Build the current project
21
- *
22
- * @param {Object} options
23
- * @param {Object} options.spinner A CLI spinner which indicates progress.
24
- * @param {boolean} options.debug True if debug mode is enabled.
25
- */
26
- export default async function build({
27
- spinner,
28
- debug,
29
- } ) {
30
-
31
- // Spinner not needed at the moment
32
- spinner.stop()
33
-
34
- // Since we use @wordpress/scripts webpack config we can leverage
35
- // the environment variables as well.
36
- process.env.WP_COPY_PHP_FILES_TO_DIST = true;
37
-
38
- // Our default Webpack Configuration
39
- const defaultConfig = path.join( projectPath, 'configs', 'webpack.config.js' );
40
-
41
- // pass any arguments from the cli
42
- // add our default config as an extension.
43
- // users can overwrite any values by creating a webconfig of their own.
44
- let webPackArgs = [
45
- '--mode=none',
46
- '--progress',
47
- '--config',
48
- defaultConfig
49
- ];
50
-
51
- // CommonJS
52
- if( fs.existsSync( path.join(appPath, 'webpack.config.cjs' ))){
53
- webPackArgs.push(
54
- '--config',
55
- path.join(appPath, 'webpack.config.cjs' ),
56
- '--merge'
57
- )
58
- // ESM
59
- }else if( fs.existsSync(path.join(appPath, 'webpack.config.js' )) ){
60
- webPackArgs.push(
61
- '--config',
62
- path.join(appPath, 'webpack.config.js' ),
63
- '--merge'
64
- )
65
- }
66
-
67
- // run webpack with our arguments.
68
- await runCmd(
69
- 'webpack',
70
- webPackArgs,
71
- ).then(({stdout, stderr}) => {
72
- // if an error was thrown, and no output
73
- if( stderr && ! stdout.toString() ){
74
- console.log( stderr.toString() )
75
- }else{
76
- spinner.text = 'Done'
77
- }
78
- });
79
-
80
- };
package/commands/serve.js DELETED
@@ -1,94 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * External dependencies
5
- */
6
- import path from 'path';
7
- import fs from 'fs';
8
-
9
- /**
10
- * Internal dependencies
11
- */
12
- import {
13
- projectPath,
14
- appPath,
15
- runCmd
16
- } from '../lib/index.js';
17
-
18
- import a11y from './a11y.js';
19
-
20
- /**
21
- * Serves the current project
22
- *
23
- * @param {Object} options
24
- * @param {Object} options.spinner A CLI spinner which indicates progress.
25
- * @param {boolean} options.debug True if debug mode is enabled.
26
- * @param {boolean} options.template Disables inclusion of the template page header & footer, starting off with a plain html page.
27
- */
28
- export default async function serve({
29
- spinner,
30
- debug,
31
- template,
32
- } ) {
33
- spinner.stop();
34
-
35
- // Since we use @wordpress/scripts webpack config we can leverage
36
- // the environment variables as well.
37
- process.env.WP_COPY_PHP_FILES_TO_DIST = true;
38
-
39
-
40
- // This lets the parser know to include the template
41
- // Otherwise we load a blank html page
42
- process.env.CDT_TEMPLATE = template;
43
-
44
- // Let our webpack config know it's serving not building
45
- process.env.CAWEB_SERVE = true;
46
-
47
- // Our default Webpack Configuration
48
- const defaultConfig = path.join( projectPath, 'configs', 'webpack.config.js' );
49
-
50
- let webPackArgs = [
51
- 'serve',
52
- '--open',
53
- '--mode=none',
54
- '--config',
55
- defaultConfig
56
- ];
57
-
58
- // merge user configurations
59
- // CommonJS
60
- if( fs.existsSync(path.join( appPath, 'webpack.config.cjs' ))){
61
- webPackArgs.push(
62
- '--config',
63
- path.join( appPath, 'webpack.config.cjs' ),
64
- '--merge'
65
- )
66
- // ESM
67
- }else if( fs.existsSync(path.join( appPath, 'webpack.config.js' )) ){
68
- webPackArgs.push(
69
- '--config',
70
- path.join( appPath, 'webpack.config.js' ),
71
- '--merge'
72
- )
73
- }
74
-
75
- // run webpack with our configuration.
76
- await runCmd(
77
- 'webpack',
78
- webPackArgs
79
- ).then(({stdout, stderr}) => {
80
- // if an error was thrown, and no output
81
- if( stderr && ! stdout.toString() ){
82
- console.log( stderr.toString() )
83
- }else{
84
-
85
- // run a11y checker as well
86
- //await a11y({spinner, debug, url: './public/index.html' })
87
-
88
- //return;
89
- spinner.text = 'Done'
90
- }
91
- });
92
-
93
-
94
- };