@caweb/cli 1.4.2 → 1.4.4
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.
- package/README.md +2 -180
- package/bin/css-audit/.editorconfig +12 -0
- package/bin/css-audit/.github/workflows/build-report.yml +46 -0
- package/bin/css-audit/.github/workflows/merge-trunk-to-report.yml +17 -0
- package/bin/css-audit/.github/workflows/node.yaml +32 -0
- package/bin/css-audit/.nvmrc +1 -0
- package/bin/css-audit/README.md +131 -0
- package/bin/css-audit/css-audit.config.js +13 -0
- package/bin/css-audit/index.js +38 -0
- package/bin/css-audit/package-lock.json +6689 -0
- package/bin/css-audit/package.json +56 -0
- package/bin/css-audit/public/.gitkeep +1 -0
- package/bin/css-audit/src/__tests__/alphas.js +128 -0
- package/bin/css-audit/src/__tests__/colors.js +115 -0
- package/bin/css-audit/src/__tests__/display-none.js +52 -0
- package/bin/css-audit/src/__tests__/important.js +88 -0
- package/bin/css-audit/src/__tests__/media-queries.js +84 -0
- package/bin/css-audit/src/__tests__/property-values.js +55 -0
- package/bin/css-audit/src/__tests__/run.js +25 -0
- package/bin/css-audit/src/__tests__/selectors.js +66 -0
- package/bin/css-audit/src/audits/alphas.js +70 -0
- package/bin/css-audit/src/audits/colors.js +83 -0
- package/bin/css-audit/src/audits/display-none.js +39 -0
- package/bin/css-audit/src/audits/important.js +60 -0
- package/bin/css-audit/src/audits/media-queries.js +96 -0
- package/bin/css-audit/src/audits/property-values.js +65 -0
- package/bin/css-audit/src/audits/selectors.js +67 -0
- package/bin/css-audit/src/audits/typography.js +41 -0
- package/bin/css-audit/src/formats/cli-table.js +81 -0
- package/bin/css-audit/src/formats/html/_audit-alpha.twig +23 -0
- package/bin/css-audit/src/formats/html/_audit-colors.twig +23 -0
- package/bin/css-audit/src/formats/html/_audit-default.twig +24 -0
- package/bin/css-audit/src/formats/html/index.twig +88 -0
- package/bin/css-audit/src/formats/html/style.css +341 -0
- package/bin/css-audit/src/formats/html.js +52 -0
- package/bin/css-audit/src/formats/json.js +9 -0
- package/bin/css-audit/src/run.js +76 -0
- package/bin/css-audit/src/utils/__tests__/cli.js +70 -0
- package/bin/css-audit/src/utils/__tests__/example-config.config.js +12 -0
- package/bin/css-audit/src/utils/__tests__/get-specificity.js +39 -0
- package/bin/css-audit/src/utils/cli.js +133 -0
- package/bin/css-audit/src/utils/format-report.js +37 -0
- package/bin/css-audit/src/utils/get-specificity.js +97 -0
- package/bin/css-audit/src/utils/get-values-count.js +17 -0
- package/commands/index.js +15 -5
- package/commands/test.js +0 -3
- package/commands/webpack/webpack.js +166 -0
- package/configs/webpack.config.js +151 -81
- package/lib/cli.js +71 -35
- package/lib/helpers.js +3 -1
- package/lib/webpack/plugins/a11y/aceconfig.js +44 -0
- package/lib/webpack/plugins/a11y/index.js +272 -0
- package/lib/webpack/plugins/a11y/package.json +12 -0
- package/lib/webpack/plugins/css-audit/css-audit.config.cjs +5 -0
- package/lib/webpack/plugins/css-audit/default.config.js +19 -0
- package/lib/webpack/plugins/css-audit/index.js +297 -0
- package/lib/webpack/plugins/css-audit/package.json +12 -0
- package/lib/webpack/plugins/jshint/.jshintrc +31 -0
- package/lib/webpack/plugins/jshint/index.js +286 -0
- package/lib/webpack/plugins/jshint/package-lock.json +22 -0
- package/lib/webpack/plugins/jshint/package.json +15 -0
- package/lib/webpack/plugins/jshint/reporter.cjs +663 -0
- package/package.json +18 -12
- package/assets/logo.ico +0 -0
- package/commands/a11y.js +0 -95
- package/commands/build.js +0 -80
- package/commands/serve.js +0 -95
- package/configs/aceconfig.js +0 -28
- package/docs/CREDITS.MD +0 -27
- package/docs/ISSUES.MD +0 -7
- package/docs/OVERRIDES.md +0 -53
- package/docs/ROADMAP.MD +0 -19
- package/docs/SYNC.MD +0 -29
- package/docs/tool/index.js +0 -45
- package/gen/parser.js +0 -166
- package/gen/site-generator.js +0 -144
package/README.md
CHANGED
|
@@ -18,183 +18,5 @@
|
|
|
18
18
|
- phpMyAdmin test site started at http://localhost:9090
|
|
19
19
|
- Uses CAWebPublishing [External Project Template Configuration](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-create-block/packages-create-block-external-template/) when creating Gutenberg Blocks, see configurations [here](https://github.com/CAWebPublishing/cli/lib/template)
|
|
20
20
|
- Allows for syncing of WordPress instance via Rest API, to maintain ID's please ensure [CAWebPublishing Development Toolbox](https://github.com/CAWebPublishing/caweb-dev/) plugin is installed.
|
|
21
|
-
-
|
|
22
|
-
|
|
23
|
-
<pre>
|
|
24
|
-
path: /var/www/html
|
|
25
|
-
apache_modules:
|
|
26
|
-
- mod_rewrite
|
|
27
|
-
</pre>
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
## Command Reference
|
|
31
|
-
### `caweb start`
|
|
32
|
-
Generates the required wp-env.json, starts the WordPress environment, downloads any CAWebPublishing sources and approved plugins.
|
|
33
|
-
<pre>
|
|
34
|
-
caweb start [options]
|
|
35
|
-
|
|
36
|
-
Starts two CAWebPublishing WordPress instances
|
|
37
|
-
development on port 8888 (http://localhost:8888) (override with WP_ENV_PORT)
|
|
38
|
-
tests on port 8889 (http://localhost:8889) (override with WP_ENV_TESTS_PORT).
|
|
39
|
-
After first install, use the '--update' flag to download updates to mapped sources and to re-apply CAWeb configuration options.
|
|
40
|
-
|
|
41
|
-
Options:
|
|
42
|
-
--bare True if excluding any downloads from CAWeb, use this if you want to use a local version of the CAWeb Theme, Configurations will still be applied. (default: false)
|
|
43
|
-
-h, --help display help for command
|
|
44
|
-
-m, --multisite True if converting to multisite. (default: false)
|
|
45
|
-
-p, --plugin True if root directory is a plugin. (default: false)
|
|
46
|
-
--scripts Execute any configured lifecycle scripts. (default: true)
|
|
47
|
-
--subdomain If passed, the network will use subdomains, instead of subdirectories. Doesn't work with 'localhost', make sure to set Port to 80. (default: false)
|
|
48
|
-
-t, --theme True if root directory is a theme. (default: false)
|
|
49
|
-
--update Download source updates and apply WordPress configuration. (default: false)
|
|
50
|
-
--xdebug <mode> Enables Xdebug. If not passed, Xdebug is turned off. If no modes are set, uses "debug". You may set multiple Xdebug modes by passing them in a comma-separated list:
|
|
51
|
-
`--xdebug=develop,coverage`. See https://xdebug.org/docs/all_settings#mode for information about Xdebug modes.
|
|
52
|
-
</pre>
|
|
53
|
-
### `caweb stop`
|
|
54
|
-
<pre>
|
|
55
|
-
caweb stop
|
|
56
|
-
|
|
57
|
-
Stops running WordPress for development and tests and frees the ports.
|
|
58
|
-
|
|
59
|
-
Options:
|
|
60
|
-
--debug Enable debug output. [boolean] [default: false]
|
|
61
|
-
</pre>
|
|
62
|
-
### `caweb clean [environment]`
|
|
63
|
-
<pre>
|
|
64
|
-
caweb clean [environment]
|
|
65
|
-
|
|
66
|
-
Cleans the WordPress databases.
|
|
67
|
-
|
|
68
|
-
Positionals:
|
|
69
|
-
environment Which environments' databases to clean.
|
|
70
|
-
[string] [choices: "all", "development", "tests"] [default: "tests"]
|
|
71
|
-
|
|
72
|
-
Options:
|
|
73
|
-
--debug Enable debug output. [boolean] [default: false]
|
|
74
|
-
--scripts Execute any configured lifecycle scripts. [boolean] [default: true]
|
|
75
|
-
</pre>
|
|
76
|
-
### `caweb run <container> [command...]`
|
|
77
|
-
<pre>
|
|
78
|
-
caweb run <container> [command...]
|
|
79
|
-
|
|
80
|
-
Runs an arbitrary command in one of the underlying Docker containers. A double
|
|
81
|
-
dash can be used to pass arguments to the container without parsing them. This
|
|
82
|
-
is necessary if you are using an option that is defined below. You can use
|
|
83
|
-
`bash` to open a shell session and both `composer` and `phpunit` are available
|
|
84
|
-
in all WordPress and CLI containers. WP-CLI is also available in the CLI
|
|
85
|
-
containers.
|
|
86
|
-
|
|
87
|
-
Positionals:
|
|
88
|
-
container The underlying Docker service to run the command on.
|
|
89
|
-
[string] [required] [choices: "mysql", "tests-mysql", "wordpress",
|
|
90
|
-
"tests-wordpress", "cli", "tests-cli"]
|
|
91
|
-
command The command to run. [array] [default: []]
|
|
92
|
-
|
|
93
|
-
Options:
|
|
94
|
-
--debug Enable debug output. [boolean] [default: false]
|
|
95
|
-
--env-cwd The command's working directory inside of the container. Paths
|
|
96
|
-
without a leading slash are relative to the WordPress root.
|
|
97
|
-
[string] [default: "."]
|
|
98
|
-
</pre>
|
|
99
|
-
### `caweb destroy`
|
|
100
|
-
<pre>
|
|
101
|
-
caweb destroy
|
|
102
|
-
|
|
103
|
-
Destroy the WordPress environment. Deletes docker containers, volumes, and
|
|
104
|
-
networks associated with the WordPress environment and removes local files.
|
|
105
|
-
|
|
106
|
-
Options:
|
|
107
|
-
--debug Enable debug output. [boolean] [default: false]
|
|
108
|
-
--scripts Execute any configured lifecycle scripts. [boolean] [default: true]
|
|
109
|
-
</pre>
|
|
110
|
-
### `caweb logs [environment]`
|
|
111
|
-
<pre>
|
|
112
|
-
caweb logs [environment]
|
|
113
|
-
|
|
114
|
-
displays PHP and Docker logs for given WordPress environment.
|
|
115
|
-
|
|
116
|
-
Positionals:
|
|
117
|
-
environment Which environment to display the logs from.
|
|
118
|
-
[string] [choices: "development", "tests", "all"] [default: "development"]
|
|
119
|
-
|
|
120
|
-
Options:
|
|
121
|
-
--debug Enable debug output. [boolean] [default: false]
|
|
122
|
-
--watch Watch for logs as they happen. [boolean] [default: true]
|
|
123
|
-
</pre>
|
|
124
|
-
### `caweb install-path`
|
|
125
|
-
<pre>
|
|
126
|
-
caweb install-path
|
|
127
|
-
|
|
128
|
-
Get the path where all of the environment files are stored. This includes the
|
|
129
|
-
Docker files, WordPress, PHPUnit files, and any sources that were downloaded.
|
|
130
|
-
|
|
131
|
-
Options:
|
|
132
|
-
--debug Enable debug output. [boolean] [default: false]
|
|
133
|
-
</pre>
|
|
134
|
-
### `caweb shell [environment]`
|
|
135
|
-
<pre>
|
|
136
|
-
caweb shell [environment]
|
|
137
|
-
|
|
138
|
-
Open shell terminal in WordPress environment.
|
|
139
|
-
|
|
140
|
-
Positionals:
|
|
141
|
-
environment Which environment to open terminal in.
|
|
142
|
-
[string] [choices: "development", "tests"] [default: "development"]
|
|
143
|
-
|
|
144
|
-
Options:
|
|
145
|
-
--debug Enable debug output. [boolean] [default: false]
|
|
146
|
-
</pre>
|
|
147
|
-
### `caweb update-plugins [environment]`
|
|
148
|
-
<pre>
|
|
149
|
-
caweb update-plugins [environment]
|
|
150
|
-
|
|
151
|
-
Updates all plugins in the WordPress environment.
|
|
152
|
-
|
|
153
|
-
Positionals:
|
|
154
|
-
environment Which environment to update.
|
|
155
|
-
[string] [choices: "development", "tests"] [default: "development"]
|
|
156
|
-
|
|
157
|
-
Options:
|
|
158
|
-
--debug Enable debug output. [boolean] [default: false]
|
|
159
|
-
</pre>
|
|
160
|
-
|
|
161
|
-
### `caweb create-block [options] <slug>`
|
|
162
|
-
<pre>
|
|
163
|
-
caweb create-block [options] <slug>
|
|
164
|
-
|
|
165
|
-
Scaffold for WordPress plugin to register CA.gov Design System Block.
|
|
166
|
-
|
|
167
|
-
Arguments:
|
|
168
|
-
slug Plugin slug to use.
|
|
169
|
-
|
|
170
|
-
Options:
|
|
171
|
-
-h, --help display help for command
|
|
172
|
-
</pre>
|
|
173
|
-
### `caweb update-block [options] <slug>`
|
|
174
|
-
<pre>
|
|
175
|
-
caweb update-block [options] <slug>
|
|
176
|
-
|
|
177
|
-
Updates a CA.gov Design System Block.
|
|
178
|
-
|
|
179
|
-
Arguments:
|
|
180
|
-
slug Plugin slug to update.
|
|
181
|
-
|
|
182
|
-
Options:
|
|
183
|
-
-h, --help display help for command
|
|
184
|
-
</pre>
|
|
185
|
-
### `caweb sync <from> <to>`
|
|
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
|
-
<pre>
|
|
188
|
-
caweb sync <from> <to>
|
|
189
|
-
|
|
190
|
-
Sync changes from one destination to another.
|
|
191
|
-
|
|
192
|
-
Arguments:
|
|
193
|
-
from Target Site URL with current changes.
|
|
194
|
-
to Destination Site URL that should be synced.
|
|
195
|
-
|
|
196
|
-
Options:
|
|
197
|
-
-h, --help display help for command
|
|
198
|
-
-i, --include [include...] IDs to of taxonomies to include. Omitting this option will sync all items for given taxonomy.
|
|
199
|
-
-t, --tax [tax...] Taxonomy that should be synced. Omitting this option will sync the full site. (choices: "pages", "posts", "media", "menus")
|
|
200
|
-
</pre>
|
|
21
|
+
- Allows for generation of WordPress CSS Audits
|
|
22
|
+
- Allows for IBM Accessibility Scan reports.
|
|
@@ -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,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 );
|