@caweb/cli 1.4.2 → 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 -95
package/README.md CHANGED
@@ -31,7 +31,7 @@
31
31
  ### `caweb start`
32
32
  Generates the required wp-env.json, starts the WordPress environment, downloads any CAWebPublishing sources and approved plugins.
33
33
  <pre>
34
- caweb start [options]
34
+ Usage: caweb start [options]
35
35
 
36
36
  Starts two CAWebPublishing WordPress instances
37
37
  development on port 8888 (​http://localhost:8888​) (override with WP_ENV_PORT)
@@ -52,7 +52,7 @@ Options:
52
52
  </pre>
53
53
  ### `caweb stop`
54
54
  <pre>
55
- caweb stop
55
+ Usage: caweb stop
56
56
 
57
57
  Stops running WordPress for development and tests and frees the ports.
58
58
 
@@ -61,7 +61,7 @@ Options:
61
61
  </pre>
62
62
  ### `caweb clean [environment]`
63
63
  <pre>
64
- caweb clean [environment]
64
+ Usage: caweb clean [environment]
65
65
 
66
66
  Cleans the WordPress databases.
67
67
 
@@ -75,7 +75,7 @@ Options:
75
75
  </pre>
76
76
  ### `caweb run <container> [command...]`
77
77
  <pre>
78
- caweb run &lt;container&gt; [command...]
78
+ Usage: caweb run &lt;container&gt; [command...]
79
79
 
80
80
  Runs an arbitrary command in one of the underlying Docker containers. A double
81
81
  dash can be used to pass arguments to the container without parsing them. This
@@ -98,7 +98,7 @@ Options:
98
98
  </pre>
99
99
  ### `caweb destroy`
100
100
  <pre>
101
- caweb destroy
101
+ Usage: caweb destroy
102
102
 
103
103
  Destroy the WordPress environment. Deletes docker containers, volumes, and
104
104
  networks associated with the WordPress environment and removes local files.
@@ -109,7 +109,7 @@ Options:
109
109
  </pre>
110
110
  ### `caweb logs [environment]`
111
111
  <pre>
112
- caweb logs [environment]
112
+ Usage: caweb logs [environment]
113
113
 
114
114
  displays PHP and Docker logs for given WordPress environment.
115
115
 
@@ -123,7 +123,7 @@ Options:
123
123
  </pre>
124
124
  ### `caweb install-path`
125
125
  <pre>
126
- caweb install-path
126
+ Usage: caweb install-path
127
127
 
128
128
  Get the path where all of the environment files are stored. This includes the
129
129
  Docker files, WordPress, PHPUnit files, and any sources that were downloaded.
@@ -133,7 +133,7 @@ Options:
133
133
  </pre>
134
134
  ### `caweb shell [environment]`
135
135
  <pre>
136
- caweb shell [environment]
136
+ Usage: caweb shell [environment]
137
137
 
138
138
  Open shell terminal in WordPress environment.
139
139
 
@@ -146,7 +146,7 @@ Options:
146
146
  </pre>
147
147
  ### `caweb update-plugins [environment]`
148
148
  <pre>
149
- caweb update-plugins [environment]
149
+ Usage: caweb update-plugins [environment]
150
150
 
151
151
  Updates all plugins in the WordPress environment.
152
152
 
@@ -160,7 +160,7 @@ Options:
160
160
 
161
161
  ### `caweb create-block [options] <slug>`
162
162
  <pre>
163
- caweb create-block [options] &lt;slug&gt;
163
+ Usage: caweb create-block [options] &lt;slug&gt;
164
164
 
165
165
  Scaffold for WordPress plugin to register CA.gov Design System Block.
166
166
 
@@ -172,7 +172,7 @@ Options:
172
172
  </pre>
173
173
  ### `caweb update-block [options] <slug>`
174
174
  <pre>
175
- caweb update-block [options] &lt;slug&gt;
175
+ Usage: caweb update-block [options] &lt;slug&gt;
176
176
 
177
177
  Updates a CA.gov Design System Block.
178
178
 
@@ -185,7 +185,7 @@ Options:
185
185
  ### `caweb sync <from> <to>`
186
186
  In order for the sync process to work correctly, you must have a caweb.json file in the project root directory. For more information read [caweb.json](./docs/SYNC.MD) configuration.
187
187
  <pre>
188
- caweb sync &lt;from&gt; &lt;to&gt;
188
+ Usage: caweb sync &lt;from&gt; &lt;to&gt;
189
189
 
190
190
  Sync changes from one destination to another.
191
191
 
@@ -197,4 +197,30 @@ Options:
197
197
  -h, --help display help for command
198
198
  -i, --include [include...] IDs to of taxonomies to include. Omitting this option will sync all items for given taxonomy.
199
199
  -t, --tax [tax...] Taxonomy that should be synced. Omitting this option will sync the full site. (choices: "pages", "posts", "media", "menus")
200
+ </pre>
201
+ ### `caweb a11y <url>`
202
+ Runs accessibility checks.
203
+ <pre>
204
+ Usage: caweb a11y url
205
+
206
+ Runs accessibility checks.
207
+
208
+ Arguments:
209
+ url URL or local file to scan for accessibility checks.
210
+
211
+ Options:
212
+ -h, --help display help for command
213
+ </pre>
214
+ ### `caweb a11y <url>`
215
+ Runs WordPress CSS Audit tool against projects.
216
+ <pre>
217
+ Usage: caweb audit [options] [files...]
218
+
219
+ Runs WordPress CSS Audit tool against projects.
220
+
221
+ Arguments:
222
+ files Files or directory path to CSS files. (default: "build")
223
+
224
+ Options:
225
+ -h, --help display help for command
200
226
  </pre>
@@ -0,0 +1,12 @@
1
+ # http://editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ indent_style = tab
6
+ end_of_line = lf
7
+ charset = utf-8
8
+ trim_trailing_whitespace = true
9
+ insert_final_newline = true
10
+
11
+ [*.md]
12
+ trim_trailing_whitespace = false
@@ -0,0 +1,46 @@
1
+ name: Build Report
2
+ on:
3
+ push:
4
+ branches:
5
+ # Run only on pushes to report
6
+ - report
7
+ schedule:
8
+ # Run every day at 9am UTC.
9
+ # * is a special character in YAML so you have to quote this string
10
+ - cron: '0 9 * * *'
11
+ workflow_dispatch:
12
+ jobs:
13
+ run:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - name: Checkout CSS Audit
17
+ uses: actions/checkout@v2
18
+ with:
19
+ ref: report
20
+ - name: Checkout WordPress Core
21
+ uses: actions/checkout@v2
22
+ with:
23
+ repository: WordPress/wordpress-develop
24
+ path: wordpress
25
+
26
+ - name: Set up Node.js
27
+ uses: actions/setup-node@v1
28
+ with:
29
+ node-version: 14.x
30
+
31
+ - name: Install dependencies
32
+ run: npm install
33
+
34
+ - name: Build the audit report
35
+ run: npm run css-audit -- wordpress/src/wp-admin/css/*.css wordpress/src/wp-includes/css/*.css
36
+
37
+ - name: Commit changes
38
+ uses: EndBug/add-and-commit@v5
39
+ with:
40
+ author_name: github-actions
41
+ author_email: 41898282+github-actions[bot]@users.noreply.github.com
42
+ message: "[Automated] Update report"
43
+ branch: "report"
44
+ add: "public"
45
+ env:
46
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -0,0 +1,17 @@
1
+ name: Merge trunk into report branch
2
+ on:
3
+ push:
4
+ branches:
5
+ # Run on pushes to trunk
6
+ - 'trunk'
7
+ jobs:
8
+ merge-branch:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v2
12
+ - name: Merge trunk -> report
13
+ uses: devmasx/merge-branch@v1.3.1
14
+ with:
15
+ type: now
16
+ target_branch: report
17
+ github_token: ${{ secrets.GITHUB_TOKEN }}
@@ -0,0 +1,32 @@
1
+ name: Node.js CI
2
+
3
+ on:
4
+ push:
5
+ paths:
6
+ - '**.js'
7
+ pull_request:
8
+ paths:
9
+ - '**.js'
10
+
11
+ jobs:
12
+ build:
13
+
14
+ runs-on: ubuntu-latest
15
+
16
+ strategy:
17
+ matrix:
18
+ node-version: [14.x]
19
+
20
+ steps:
21
+ - uses: actions/checkout@v2
22
+
23
+ - name: Use Node.js ${{ matrix.node-version }}
24
+ uses: actions/setup-node@v1
25
+ with:
26
+ node-version: ${{ matrix.node-version }}
27
+
28
+ - run: npm install
29
+
30
+ - run: npm test
31
+ env:
32
+ CI: true
@@ -0,0 +1 @@
1
+ 14
@@ -0,0 +1,131 @@
1
+ # CSS Audit
2
+
3
+ This project contains an automated audit of the core WordPress CSS, including the number of distinct colors used, most specific selectors, how many properties use `!important`, and more. [View the audit report here.](https://wordpress.github.io/css-audit/public/wp-admin) This report is regenerated every day at 09:00 UTC, and runs over the latest CSS in [WordPress/wordpress-develop](https://github.com/WordPress/wordpress-develop/).
4
+
5
+ To generate this report, there is a tool `css-audit`, which runs a set of [audits](./src/audits).
6
+
7
+ ## Local Environment
8
+
9
+ To run the audits yourself, download or clone this repo, then install the dependencies. You will need [node & npm](https://nodejs.org/en/) installed.
10
+
11
+ ```
12
+ $ git clone git@github.com:wordpress/css-audit.git
13
+ $ cd css-audit
14
+ $ npm install
15
+ $ npm run css-audit -- <files...>
16
+ ```
17
+
18
+ If you want to work on the audits yourself, [fork this repo](https://help.github.com/en/github/getting-started-with-github/fork-a-repo) to your account first. You can submit issues or PRs.
19
+
20
+ ## Running Audits
21
+
22
+ To run the audits, you need a list of CSS files, and to indicate which audits you want to run. `yarn` and `npm` both automatically expand globs (`folder/*`), so you can use that, or pass in a list of CSS files. The audits are described below, and can be run via the following CLI args, or via configuration file (described in the next section).
23
+
24
+ ```
25
+ $ npm run css-audit -- <files ...> [options]
26
+
27
+ Usage: css-audit -- <files...> [options]
28
+
29
+ --colors Run colors audit.
30
+ --important Run !important audit.
31
+ --display-none Run display: none audit.
32
+ --selectors Run selectors audit.
33
+ --media-queries Run media queries audit.
34
+ --property-values Run audit for a given set of property values, comma-separated.
35
+ --recommended Run recommended audits (colors, important, selectors). Default: true.
36
+ --all Run all audits (except property values, as it requires a value).
37
+ --format Format to use for displaying report.
38
+ --filename If using a format that outputs to a file, specify the file name.
39
+ --help Show this message.
40
+ ```
41
+
42
+
43
+ ### Configuration File
44
+
45
+ The program will prioritize configuration from CLI arguments, and will fallback to configuration stored in a file called `css-audit.config.js`.
46
+
47
+ ```
48
+ module.exports = {
49
+ format: 'json',
50
+ audits: [
51
+ 'colors',
52
+ 'important',
53
+ 'display-none',
54
+ 'selectors',
55
+ 'media-queries',
56
+ [ 'property-values', 'font-size' ],
57
+ [ 'property-values', 'padding-top,padding-bottom' ],
58
+ ],
59
+ };
60
+ ```
61
+
62
+ ## Generating HTML Reports
63
+
64
+ To generate an HTML report, use the `--format=html` option and specify a name for the file with the `--filename=name` option. This will output a `{name}.html` file in public/ that is viewable on Github Pages.
65
+
66
+ For example, generating a report for wp-admin using the below strategy for pulling down CSS files from SVN:
67
+
68
+ ```
69
+ npm run css-audit -- v5.5/**/* --format=html --all --filename=wp-admin
70
+ ```
71
+
72
+ In the configuration file, the argument `filename` can be added as a simple property: value combination, the same as `format` in the example. See the [default `css-audit.config.js`](./css-audit.config.js).
73
+
74
+ ## Getting core CSS files
75
+
76
+ You can download the source files of CSS (not minified or RTL'd) from the svn repository. The following code will create a new directory, `v5.5`, and download just the files from each `css` folder.
77
+
78
+ ```
79
+ mkdir v5.5
80
+ svn export https://develop.svn.wordpress.org/branches/5.5/src/wp-admin/css --depth files v5.5/admin
81
+ svn export https://develop.svn.wordpress.org/branches/5.5/src/wp-includes/css --depth files v5.5/includes
82
+ ```
83
+
84
+ If you want to run this on trunk (code currently in development), you can swap out `branches/5.5` for `trunk`. You could also swap the `5.5` for `5.4`, etc. Example:
85
+
86
+ ```
87
+ mkdir trunk
88
+ svn export https://develop.svn.wordpress.org/trunk/src/wp-admin/css --depth files trunk/admin
89
+ svn export https://develop.svn.wordpress.org/trunk/src/wp-includes/css --depth files trunk/includes
90
+ ```
91
+
92
+ Now you can run the audits:
93
+
94
+ ```
95
+ npm run css-audit -- v5.5/**/* --recommended
96
+ ```
97
+
98
+ ## Available Audits
99
+
100
+ - `colors`
101
+ - Number of unique colors — normalizes hex colors so that uppercase & lowercase are not counted twice
102
+ - Number of unique colors (ignoring opacity)
103
+ - List of all colors
104
+ - Top 10 most-used colors
105
+ - Top 10 least-used colors
106
+ - `important`
107
+ - Number of times `!important` is used
108
+ - Top properties that use !important
109
+ - `property-values` — needs a list of properties to inspect.
110
+ - Usage: `--property-values=[properties]`. For example: `--property-values=display`, or `--property-values=padding,margin`
111
+ - Number of unique values for [property]
112
+ - Top 10 most-used values for [property]
113
+ - Top 10 least-used values for [property]
114
+ - `selectors`
115
+ - Total number of selectors
116
+ - Number of selectors with IDs — not "number of IDs", a lot of selectors use multiple IDs, but they'd only be counted once
117
+ - Top 10 selectors with the highest specificity
118
+ - Top 10 selectors by length
119
+ - `display-none`
120
+ - Number of times `display: none` is used
121
+ - Places where `display: none` is used
122
+ - `typography`
123
+ - A collection of information about various typography-related properties
124
+
125
+ ## Technical details
126
+
127
+ This tool parses each CSS file and creates an AST, which the audits traverse to pull out data. It uses [`postcss`](https://postcss.org/) for most audits, but [`csstree`](https://github.com/csstree/csstree) for the `media-queries` audit. PostCSS gives us the plugins ecosystem so that we can use `postcss-values-parser`, while csstree generates a much more detailed AST that robustly identifies media queries.
128
+
129
+ - [PostCSS API documentation](https://postcss.org/api/)
130
+ - [csstree documentation](https://github.com/csstree/csstree/tree/master/docs)
131
+ - [AST Explorer](https://astexplorer.net/) — great tool for identifying how the CSS is parsed.
@@ -0,0 +1,13 @@
1
+ module.exports = {
2
+ format: 'html',
3
+ filename: 'wp-admin',
4
+ audits: [
5
+ 'colors',
6
+ 'alphas',
7
+ 'important',
8
+ 'display-none',
9
+ 'selectors',
10
+ 'media-queries',
11
+ 'typography',
12
+ ],
13
+ };
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Node dependencies
3
+ */
4
+ const fs = require( 'fs' );
5
+ const path = require( 'path' );
6
+
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ const { runAudits } = require( './src/run' );
11
+ const { getArg, getFileArgsFromCLI, getHelp } = require( './src/utils/cli' );
12
+
13
+ const input = getFileArgsFromCLI();
14
+
15
+ if ( getArg( '--help', true ) || ! input.length ) {
16
+ console.log( getHelp() );
17
+ process.exit( 0 );
18
+ }
19
+
20
+ const cssFiles = [];
21
+ input.forEach( ( file ) => {
22
+ const filePath = path.resolve( process.env.INIT_CWD, file );
23
+ const stats = fs.statSync( filePath );
24
+ if ( stats.isDirectory() ) {
25
+ return;
26
+ }
27
+ if ( file.match( /min\.css$/ ) ) {
28
+ return;
29
+ }
30
+ cssFiles.push( {
31
+ name: file,
32
+ content: String( fs.readFileSync( filePath ) ),
33
+ } );
34
+ } );
35
+
36
+ const result = runAudits( cssFiles );
37
+
38
+ console.log( result );