@@ -20,23 +20,23 @@ Comparators are scripts that:
2020
2121## Comparator Structure
2222
23- Comparators are standalone ESM scripts located in ` scripts/compare-builds / ` :
23+ Comparators are standalone ESM scripts located in ` scripts/comparators / ` :
2424
2525```
26- scripts/compare-builds /
27- ├── utils .mjs # Shared utilities (BASE, HEAD paths)
28- ├── legacy-json .mjs # Compare legacy JSON output
29- ├── web .mjs # Compare web bundle sizes
30- └── your-comparator.mjs # Your new comparator
26+ scripts/comparators /
27+ ├── constants .mjs # Shared constants (BASE, HEAD, TITLE paths)
28+ ├── file-size .mjs # Compare file sizes between builds
29+ ├── object-assertion .mjs # Deep equality assertion for JSON objects
30+ └── your-comparator.mjs # Your new comparator
3131```
3232
3333### Naming Convention
3434
35- ** Each comparator must have the same name as the generator it compares. ** For example:
35+ Comparators can be reused across multiple generators. You specify which comparator to use in the workflow file using the ` compare ` field. For example:
3636
37- - ` web .mjs` compares output from the ` web ` generator
38- - ` legacy-json .mjs` compares output from the ` legacy-json ` generator
39- - ` my-format .mjs ` would compare output from a ` my-format ` generator
37+ - ` file-size .mjs` can compare output from ` web ` , ` legacy-html ` , or any generator
38+ - ` object-assertion .mjs` can compare JSON output from ` legacy-json ` , ` json-simple ` , etc.
39+ - ` my-comparator .mjs ` would be a custom comparator for specific needs
4040
4141## Creating a Comparator
4242
@@ -48,7 +48,7 @@ Create a new file in `scripts/compare-builds/` with the same name as your genera
4848// scripts/compare-builds/my-format.mjs
4949import { readdir , readFile } from ' node:fs/promises' ;
5050import { join } from ' node:path' ;
51- import { BASE , HEAD } from ' ./utils.mjs' ;
51+ import { BASE , HEAD , TITLE } from ' ./utils.mjs' ;
5252
5353// Fetch files from both directories
5454const [baseFiles , headFiles ] = await Promise .all ([BASE , HEAD ].map (() => await readdir (dir)));
@@ -105,7 +105,7 @@ const differences = results.filter(Boolean);
105105
106106// Output markdown results
107107if (differences .length > 0 ) {
108- console .log (' ## `my-format` Generator ' );
108+ console .log (TITLE );
109109 console .log (' ' );
110110 console .log (` Found ${ differences .length } difference(s):` );
111111 console .log (' ' );
@@ -161,5 +161,4 @@ node scripts/compare-builds/my-format.mjs
161161
162162The comparator will automatically run in GitHub Actions when:
163163
164- 1 . Your generator is configured with ` compare: true ` in the workflow
165- 2 . The comparator filename matches the generator name
164+ 1 . Your generator is configured with ` compare: <my-comparator> ` in the workflow, which tells the system which comparator script to run
0 commit comments