@domandigital/create-site 0.7.1 → 0.9.0
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/CHANGELOG.md +12 -0
- package/README.md +16 -7
- package/dist/cli.js +5 -5
- package/package.json +2 -2
- package/templates/shared/docs/site-programme.md +4 -4
- package/templates/shared/scripts/gates/deploy-preview.mjs +8 -12
- package/templates/shared/scripts/gates/measure.mjs +140 -149
- package/templates/shared/scripts/gates/prebuild.mjs +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @domandigital/create-site
|
|
2
2
|
|
|
3
|
+
## 0.9.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 0dba997: Sites made with create-site deploy their preview to Cloudflare only. `scripts/gates/deploy-preview.mjs` no longer has a Vercel branch or looks for `.vercel/project.json`, `preview.host` in `site.programme.json` is `cloudflare` or null, the `host` answer prompt suggests `cloudflare`, and `docs/site-programme.md` and the README say so. A site that still sets `preview.host` to `vercel` now stops at Stage 06 with a message naming the host; remove the key or set it to `cloudflare`. The synthetic README and a craft comment no longer name Vercel; no behaviour changes in those two.
|
|
8
|
+
|
|
9
|
+
## 0.8.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 63dfae5: `measure.mjs` uses craft's every-viewport measure (DOM-787, part of DOM-772): one measure that the portal gates use too. It measures every page at 320, 375, 390, 430, landscape 844 x 390, 768, 1024, 1280, 1440 and 1920, phone first, with a width sweep from 320 to 1920, and keeps its earlier failures (a page that does not answer, sideways scroll, no viewport meta, text under `measure.minFontPx`, targets under 44 x 44, fields under 16px, labels, noindex on a preview). New failures: text over text and a cut-off title at any width; on a short phone, the main action (`measure.mainAction`) off the first screen, fixed layers over a quarter of the screen, oversized or stretched images, wrong keyboards and missing autocomplete, phone numbers that are not `tel:` links; in landscape, fixed layers over half the height; at 1440 and 1920, body lines over 80 characters. `site.programme.json` `measure` gains `mainAction`, `thresholds`, `sweep` and `baseline` (known failures in craft's baseline format, written by `--update-baseline`); a failure names the widths it happens at. New sites install `@domandigital/craft` ^0.20.0, which carries the measure.
|
|
14
|
+
|
|
3
15
|
## 0.7.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -70,13 +70,22 @@ the build:
|
|
|
70
70
|
| `null-check.mjs` | 06 | the deck carries a phrase the null builds kept writing, without a reason |
|
|
71
71
|
| `mobile-first.mjs` | 06 | the source has a `max-width` media query or a Tailwind `max-*:` variant with no recorded exception: the phone is the base layout |
|
|
72
72
|
|
|
73
|
-
`pnpm measure` serves the last build and measures it
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
a
|
|
73
|
+
`pnpm measure` serves the last build and measures it at every viewport, phone
|
|
74
|
+
first, with craft's measure (`@domandigital/craft/phone`, the one the portal
|
|
75
|
+
gates use): the ladder 320, 375, 390, 430, landscape 844 x 390, 768, 1024,
|
|
76
|
+
1280, 1440 and 1920, and a sweep from 320 to 1920 in 16 to 32px steps. At any
|
|
77
|
+
width it fails on sideways scroll, on text over other text, on a cut-off page
|
|
78
|
+
title, on text under 12px and on a label outside its container; on a phone, on
|
|
79
|
+
a target under 44px and a form field set under 16px; on a short phone (375 x
|
|
80
|
+
667), on a main action below the first screen (`measure.mainAction`), fixed
|
|
81
|
+
layers over a quarter of the screen, images far larger than they are shown or
|
|
82
|
+
stretched, a phone, email or number field with the wrong keyboard or no
|
|
83
|
+
autocomplete, and a phone number that is not a `tel:` link; in landscape, on
|
|
84
|
+
fixed layers over half the height; at 1440 and 1920, on body lines over 80
|
|
85
|
+
characters. `measure.baseline` lists known failures so they stay visible.
|
|
77
86
|
`pnpm deploy:preview` is the only deploy: it sets `PUBLIC_PREVIEW` itself,
|
|
78
|
-
builds, measures with noindex required, and deploys a preview to Cloudflare
|
|
79
|
-
|
|
87
|
+
builds, measures with noindex required, and deploys a preview to Cloudflare;
|
|
88
|
+
it refuses a route, a custom domain or `--prod`. So a site made
|
|
80
89
|
with create-site cannot build until its programme exists and Stages 05 and 06
|
|
81
90
|
are done, and cannot reach a URL unmeasured.
|
|
82
91
|
|
|
@@ -122,7 +131,7 @@ same answers the site was made with (`--answers`).
|
|
|
122
131
|
`siteUrl`, `sector`, `description`, `phone`, `email`, `locality`,
|
|
123
132
|
`postalCode`, `serviceAreas`, `registers` (ids from `src/sectors.ts`) and
|
|
124
133
|
`previousHosts`, `programme` (the Linear issue, like `--programme`), and the
|
|
125
|
-
declared technology: `host` (`cloudflare`
|
|
134
|
+
declared technology: `host` (`cloudflare` also becomes the preview
|
|
126
135
|
host in `site.programme.json`), `dns`, `cms`,
|
|
127
136
|
`analytics` (a list, e.g. `["ga4", "gtm", "posthog"]`), `errorMonitoring` and
|
|
128
137
|
`emailSending` (a list). Each can be skipped, and a skipped one is left out of
|
package/dist/cli.js
CHANGED
|
@@ -162,7 +162,7 @@ async function collectStack(optional) {
|
|
|
162
162
|
...new Set(list(await optional(key, question)).map((v) => name(key, v)))
|
|
163
163
|
];
|
|
164
164
|
const stack = {
|
|
165
|
-
host: await single("host", "Hosting, e.g.
|
|
165
|
+
host: await single("host", "Hosting, e.g. cloudflare"),
|
|
166
166
|
dns: await single("dns", "DNS host, e.g. cloudflare"),
|
|
167
167
|
cms: await single("cms", "CMS, e.g. sanity"),
|
|
168
168
|
analytics: await many("analytics", "Analytics and tags, comma separated, e.g. ga4, gtm, posthog"),
|
|
@@ -749,7 +749,7 @@ function renderRedirects() {
|
|
|
749
749
|
function renderProgramme(a, project) {
|
|
750
750
|
const base = project.srcBase;
|
|
751
751
|
const source = base ? [base.replace(/\/$/, "")] : ["app", "components", "lib", "content"];
|
|
752
|
-
const host = a.stack.host === "cloudflare"
|
|
752
|
+
const host = a.stack.host === "cloudflare" ? a.stack.host : null;
|
|
753
753
|
const programme = {
|
|
754
754
|
$comment: "Read by scripts/gates/ before every build and preview deploy. docs/site-programme.md says what each key is for. Written by @domandigital/create-site; yours to edit, never overwritten.",
|
|
755
755
|
issue: a.programme,
|
|
@@ -788,11 +788,11 @@ var HOUSE_DEPENDENCIES = {
|
|
|
788
788
|
"@domandigital/seo": "^0.3.0"
|
|
789
789
|
};
|
|
790
790
|
var HOUSE_DEV_DEPENDENCIES = {
|
|
791
|
-
"@domandigital/craft": "^0.
|
|
791
|
+
"@domandigital/craft": "^0.20.0",
|
|
792
792
|
"@types/node": "^22.0.0",
|
|
793
793
|
vitest: "^4.1.11",
|
|
794
|
-
// scripts/gates/measure.mjs renders the pages at
|
|
795
|
-
// preview deploy; tsx loads the copy deck on Node older than 22.18.
|
|
794
|
+
// scripts/gates/measure.mjs renders the pages at every viewport, phone first,
|
|
795
|
+
// before every preview deploy, with craft's measure; tsx loads the copy deck on Node older than 22.18.
|
|
796
796
|
playwright: "^1.62.0",
|
|
797
797
|
tsx: "^4.20.0"
|
|
798
798
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domandigital/create-site",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The first thing that runs on a new Doman Digital client site: installs the house packages and writes the per-site files they read (the facts file, route policy, backlink register, redirects, JSON-LD, the designer credit, house docs and the SEO checks), so every build starts on the same foundation and stays upgradeable by bumping packages.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"tsup": "^8.3.5",
|
|
42
42
|
"typescript": "^5.6.3",
|
|
43
43
|
"vitest": "^4.0.0",
|
|
44
|
-
"@domandigital/craft": "^0.
|
|
44
|
+
"@domandigital/craft": "^0.20.3",
|
|
45
45
|
"@domandigital/graph": "^0.7.0",
|
|
46
46
|
"@domandigital/seo": "^0.3.1"
|
|
47
47
|
},
|
|
@@ -48,7 +48,7 @@ a file is not acceptance.
|
|
|
48
48
|
| 03 Low-fidelity wireframes, phone first | A versioned wireframe set covering every page family at 375px first, then the desktop derived from it, annotated with evidence, destination and holds | Hierarchy and journey coverage accepted on the phone set first; missing proof is an obvious placeholder | None: wireframes are reviewed, not built |
|
|
49
49
|
| 04 Validate the prototype and iterate the journeys | Test tasks, the synthetic buyer panel's run, then human sessions; findings and a revised wireframe version | Critical task failures fixed and rechecked; the approved wireframe version is named | The buyer panel (`packages/buyer-panel` in dd-packages) run on the prototype; its report linked on the issue |
|
|
50
50
|
| 05 Visual direction, argued from evidence and measured | `art-direction.json`: the job, a hierarchy per page type and the seven choices with their reasons; the night side in `art-direction.sheets.json`; the accent test | The human choice and its reason recorded on the issue; no value adopted because an earlier pack showed it | `check-direction.mjs`, `tokens.mjs`, `night-contrast.mjs` |
|
|
51
|
-
| 06 Detailed pages, content and the component system | The real app on a preview, every page family, the copy deck through the gates, built phone first and measured at
|
|
51
|
+
| 06 Detailed pages, content and the component system | The real app on a preview, every page family, the copy deck through the gates, built phone first and measured at every viewport, from 375 up, with the width sweep | Design and content accepted at an exact version, from the phone captures first; no invented price or claim in the deck | `facts.mjs`, `copy-deck.mjs`, `null-check.mjs`, `mobile-first.mjs`, `measure.mjs`, `deploy-preview.mjs` |
|
|
52
52
|
| 07 Implementation and content migration plan | Slices, the file and CMS ownership manifest, the route, SEO and redirect plan, tests per slice, release and rollback outline | A named reviewer accepts the plan and the first slice | `redirects.json` and `tests/seo/redirects.test.ts` |
|
|
53
53
|
| 08 Build the approved slices and verify rendered drafts | Reviewed PRs, protected CMS drafts, rendered previews, slice-level checks | Every slice matches the accepted design or has a recorded deviation | Every gate above, on every build and every preview |
|
|
54
54
|
| 09 QA across every journey, and the release decision | The acceptance report across every page family and journey; a named go or no-go | No release-critical defect open; residual risks accepted by the right person | `launch:check`, `craft direction validate --snapshot <preview> --strict`; the live domain is attached here and nowhere earlier |
|
|
@@ -73,7 +73,7 @@ Run around a running build:
|
|
|
73
73
|
|
|
74
74
|
| Gate | Stage | Fails when |
|
|
75
75
|
| --- | --- | --- |
|
|
76
|
-
| `measure.mjs` | 06 | measured phone first,
|
|
76
|
+
| `measure.mjs` | 06 | measured with craft's measure (`@domandigital/craft/phone`) at every viewport, phone first: the ladder 320, 375, 390, 430, landscape 844 x 390, 768, 1024, 1280, 1440, 1920, and a width sweep from 320 to 1920 in 16 to 32px steps. A page in `measure.pages` does not answer; at any width it scrolls sideways, has visible text over other text, has a cut-off page title or text under `measure.minFontPx`; on a phone, a link, button, field or summary is under 44 x 44 CSS px (a link inside a sentence is exempt) or a text field is set under 16px; on a short phone (375 x 667), the main action in `measure.mainAction` is below the first screen and not pinned, fixed and sticky layers cover more than a quarter of the screen, an image is more than about 2.5 times wider than it is shown or is stretched past its file, a phone, email or number field has the wrong keyboard, a name, email or address field has no autocomplete, or a UK phone number in the text is not a `tel:` link; on a landscape phone, header and fixed layers cover more than half the height; at 1440 and 1920, body lines run past 80 characters or an image is stretched; a label in `measure.labels` leaves its container or covers a label or copy; with `--preview`, a page has no noindex. A failure names the widths it happens at |
|
|
77
77
|
| `deploy-preview.mjs` | 06 to 08 | the build, the measurement or the host's config refuses it (a route, a custom domain or `--prod`). Sets `PUBLIC_PREVIEW=1` and `NEXT_PUBLIC_PREVIEW=1` itself |
|
|
78
78
|
|
|
79
79
|
The site reads `PUBLIC_PREVIEW` (Astro, `import.meta.env.PUBLIC_PREVIEW`) or
|
|
@@ -100,8 +100,8 @@ pricing modules and writes the facts the redesign renders.
|
|
|
100
100
|
| `issue` | The programme issue in Linear (`DOM-123`) |
|
|
101
101
|
| `registeredDirection` | The direction's registered copy in the craft estate, usually `~/dd-ops/<site>/art-direction.json`; null until registered |
|
|
102
102
|
| `paths` | Where the token stylesheet, the deck, the rendered deck and the null-check report live, and the source folders `facts.mjs` reads |
|
|
103
|
-
| `measure` | `pages`, `minFontPx` (12), `labels` (`{ "selector": ".label", "within": ".screen" }` or null), `port` |
|
|
103
|
+
| `measure` | `pages`, `minFontPx` (12), `labels` (`{ "selector": ".label", "within": ".screen" }` or null), `port`, `mainAction` (a CSS selector for the page's main action, or `{ "/": ".hero a", "*": "a.book" }` per page; not checked when absent), `thresholds` (override a house default: `maxLayerShare` 0.25, `landscapeMaxLayerShare` 0.5, `oversizeRatio` 2.5, `upscaleRatio` 1, `maxLineCh` 80, `overlapShare` 0.4, `minImagePx` 32), `sweep` (`{ "step": 16, "wideStep": 32 }`, or `false` to measure the ladder only), `baseline` (a file of known failures, craft's phone-first baseline format; `node scripts/gates/measure.mjs --serve --update-baseline` writes it, and it only shrinks) |
|
|
104
104
|
| `nullCheck` | `harvest` (a path, `~/` allowed) and `justified` (phrase to reason) |
|
|
105
105
|
| `facts` | `importer`: the site's importer script, or null |
|
|
106
106
|
| `mobileFirst` | `exceptions`: the files allowed a `max-width` query or `max-*:` variant, each `{ "file": "src/styles/print.css", "reason": "..." }` |
|
|
107
|
-
| `preview` | `host`: `cloudflare
|
|
107
|
+
| `preview` | `host`: `cloudflare`, or null to find it from the config |
|
|
@@ -4,12 +4,11 @@
|
|
|
4
4
|
// runs every build gate; serves the build locally and measures it at 1440 and
|
|
5
5
|
// 390 with --preview (noindex required); and only then deploys, preview only:
|
|
6
6
|
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
// vercel vercel deploy, never --prod
|
|
7
|
+
// Cloudflare: wrangler deploy, refused while the wrangler config carries a
|
|
8
|
+
// route, a custom domain or workers_dev: false.
|
|
10
9
|
//
|
|
11
10
|
// The host is preview.host in site.programme.json, or found from the
|
|
12
|
-
// wrangler config
|
|
11
|
+
// wrangler config. Going live is a separate,
|
|
13
12
|
// recorded decision in Stage 09; nothing here can do it. --dry-run does
|
|
14
13
|
// everything but the deploy.
|
|
15
14
|
//
|
|
@@ -29,8 +28,8 @@ const env = { ...process.env, PUBLIC_PREVIEW: "1", NEXT_PUBLIC_PREVIEW: "1" };
|
|
|
29
28
|
const bin = (name) => join(root, "node_modules", ".bin", name);
|
|
30
29
|
|
|
31
30
|
const wranglerFile = ["wrangler.jsonc", "wrangler.json", "wrangler.toml"].find((f) => existsSync(join(root, f)));
|
|
32
|
-
const host = preview.host ?? (wranglerFile ? "cloudflare" :
|
|
33
|
-
if (!host) stop(GATE, "06", "no preview host. Set preview.host in site.programme.json to cloudflare
|
|
31
|
+
const host = preview.host ?? (wranglerFile ? "cloudflare" : null);
|
|
32
|
+
if (!host) stop(GATE, "06", "no preview host. Set preview.host in site.programme.json to cloudflare.");
|
|
34
33
|
|
|
35
34
|
if (host === "cloudflare") {
|
|
36
35
|
if (!wranglerFile) stop(GATE, "06", "preview.host is cloudflare but there is no wrangler config.");
|
|
@@ -39,8 +38,8 @@ if (host === "cloudflare") {
|
|
|
39
38
|
if (/["']?\broutes?\b["']?\s*[:=]/.test(text)) stop(GATE, "06", `${wranglerFile} carries a route. A preview has none: the live domain is attached only by the Stage 09 release.`);
|
|
40
39
|
if (/custom_domain/.test(text)) stop(GATE, "06", `${wranglerFile} carries a custom domain. A preview has none.`);
|
|
41
40
|
if (/workers_dev["']?\s*[:=]\s*false/.test(text)) stop(GATE, "06", `${wranglerFile} sets workers_dev to false, so a preview would have no address.`);
|
|
42
|
-
} else
|
|
43
|
-
stop(GATE, "06", `preview.host is ${host}; this script knows cloudflare
|
|
41
|
+
} else {
|
|
42
|
+
stop(GATE, "06", `preview.host is ${host}; this script knows cloudflare.`);
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
// The package manager that ran this script, so the build is the one `build` names.
|
|
@@ -55,9 +54,6 @@ if (dryRun) {
|
|
|
55
54
|
console.log(`${GATE}: built and measured; --dry-run, so nothing was deployed.`);
|
|
56
55
|
process.exit(0);
|
|
57
56
|
}
|
|
58
|
-
const deploy =
|
|
59
|
-
host === "cloudflare"
|
|
60
|
-
? spawnSync(existsSync(bin("wrangler")) ? bin("wrangler") : "npx", existsSync(bin("wrangler")) ? ["deploy"] : ["wrangler", "deploy"], { cwd: root, env, stdio: "inherit" })
|
|
61
|
-
: spawnSync("npx", ["vercel", "deploy", "--build-env", "PUBLIC_PREVIEW=1", "--build-env", "NEXT_PUBLIC_PREVIEW=1", "--env", "PUBLIC_PREVIEW=1", "--env", "NEXT_PUBLIC_PREVIEW=1"], { cwd: root, env, stdio: "inherit" });
|
|
57
|
+
const deploy = spawnSync(existsSync(bin("wrangler")) ? bin("wrangler") : "npx", existsSync(bin("wrangler")) ? ["deploy"] : ["wrangler", "deploy"], { cwd: root, env, stdio: "inherit" });
|
|
62
58
|
if (deploy.status !== 0) stop(GATE, "06", `the ${host} deploy failed.`);
|
|
63
59
|
console.log(`${GATE}: measured and deployed to a ${host} preview. The live site is untouched.`);
|
|
@@ -1,19 +1,40 @@
|
|
|
1
1
|
// Stage 06 gate: measures the rendered pages rather than trusting the
|
|
2
|
-
// stylesheet, phone first (STANDARD.md section 10 in
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
// at
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
// phone
|
|
2
|
+
// stylesheet, at every viewport, phone first (STANDARD.md section 10 in
|
|
3
|
+
// @domandigital/craft, DOM-787). The measure itself is craft's
|
|
4
|
+
// (@domandigital/craft/phone), the same one the portal gates use: this file
|
|
5
|
+
// serves the build, names the pages, adds what only a site has (labels,
|
|
6
|
+
// noindex on a preview) and fails the build on what it finds.
|
|
7
|
+
//
|
|
8
|
+
// On every page named in site.programme.json measure.pages, in order:
|
|
9
|
+
// - the viewport ladder, phone first: 320, 375, 390, 430, landscape 844 x 390,
|
|
10
|
+
// 768, 1024, 1280, 1440, 1920, and a width sweep from 320 to 1920 in
|
|
11
|
+
// 16 to 32px steps, so what breaks between the breakpoints shows;
|
|
12
|
+
// - at any width: the page answers, nothing scrolls sideways, no visible
|
|
13
|
+
// text sits on other text, no page title is cut off, no visible text is
|
|
14
|
+
// smaller than measure.minFontPx, and, when measure.labels names them,
|
|
15
|
+
// every label sits inside its container, over no other label and no copy;
|
|
16
|
+
// - on a phone (320 to 430, and landscape): every link, button, field and
|
|
17
|
+
// summary a thumb has to hit is at least 44 x 44 CSS px (a link inside a
|
|
18
|
+
// sentence is exempt, as in WCAG 2.5.5; a field's label counts as its
|
|
19
|
+
// target), and every text field is set at 16px or more, so Safari on iOS
|
|
20
|
+
// does not zoom on focus;
|
|
21
|
+
// - on a short phone, 375 x 667: the main action (measure.mainAction, a
|
|
22
|
+
// selector, or one per page) is on the first screen or pinned; fixed and
|
|
23
|
+
// sticky layers cover at most a quarter of the screen; images are neither
|
|
24
|
+
// far larger than they are shown nor stretched; phone, email and number
|
|
25
|
+
// fields use the keyboard that fits and carry autocomplete; phone numbers
|
|
26
|
+
// in the text are tel: links;
|
|
27
|
+
// - on a landscape phone, header and fixed layers leave half the height;
|
|
28
|
+
// - at 1440 and 1920: body text lines stay under 80 characters and no image
|
|
29
|
+
// is stretched past its file.
|
|
30
|
+
// With --preview, every page must also carry a noindex robots meta, so a
|
|
31
|
+
// preview cannot be indexed. Thresholds are craft's house defaults;
|
|
32
|
+
// measure.thresholds overrides one. measure.baseline names a file of known
|
|
33
|
+
// failures (craft's phone-first baseline format, written by --update-baseline):
|
|
34
|
+
// those stay listed and visible, and anything new fails. Writes
|
|
35
|
+
// measure/measure.json, with the hash of the direction it measured, and a
|
|
36
|
+
// full-page capture per page and ladder viewport under measure/out, phone
|
|
37
|
+
// captures first. Exits 1 on any failure.
|
|
17
38
|
//
|
|
18
39
|
// --serve serves the last build itself and measures that: static output in
|
|
19
40
|
// dist/ is served from here the way the host serves it (no trailing slash,
|
|
@@ -22,7 +43,9 @@
|
|
|
22
43
|
// --base <url> measures a server that is already running instead.
|
|
23
44
|
//
|
|
24
45
|
// Lifted from apps/site/scripts/measure.mjs in Doman-Digital (DOM-647), with
|
|
25
|
-
// the redesign's own label component generalised to a selector
|
|
46
|
+
// the redesign's own label component generalised to a selector; the
|
|
47
|
+
// measuring moved into craft so a site and a portal are measured the same way
|
|
48
|
+
// (DOM-787).
|
|
26
49
|
|
|
27
50
|
import { spawn } from "node:child_process";
|
|
28
51
|
import { createHash } from "node:crypto";
|
|
@@ -33,15 +56,12 @@ import { parseArgs } from "node:util";
|
|
|
33
56
|
import { programme, root, sitePath, stop } from "./programme.mjs";
|
|
34
57
|
|
|
35
58
|
const GATE = "measure";
|
|
36
|
-
const { values } = parseArgs({ options: { base: { type: "string" }, serve: { type: "boolean", default: false }, preview: { type: "boolean", default: false } } });
|
|
59
|
+
const { values } = parseArgs({ options: { base: { type: "string" }, serve: { type: "boolean", default: false }, preview: { type: "boolean", default: false }, "update-baseline": { type: "boolean", default: false } } });
|
|
37
60
|
const { measure = {}, paths } = programme();
|
|
38
61
|
const port = measure.port ?? 4410;
|
|
39
62
|
const base = (values.base ?? `http://127.0.0.1:${port}`).replace(/\/$/, "");
|
|
40
63
|
const pages = measure.pages?.length ? measure.pages : ["/"];
|
|
41
64
|
const minFontPx = measure.minFontPx ?? 12;
|
|
42
|
-
// The house floors at phone width: STANDARD.md section 10. Not per-site settings.
|
|
43
|
-
const MIN_TARGET_PX = 44;
|
|
44
|
-
const MIN_FIELD_FONT_PX = 16;
|
|
45
65
|
const labels = measure.labels ?? null;
|
|
46
66
|
const outDir = join(root, "measure", "out");
|
|
47
67
|
mkdirSync(outDir, { recursive: true });
|
|
@@ -52,139 +72,123 @@ try {
|
|
|
52
72
|
} catch {
|
|
53
73
|
stop(GATE, "06", "playwright is not installed. Add it as a dev dependency and run `npx playwright install chromium`.");
|
|
54
74
|
}
|
|
75
|
+
let craft;
|
|
76
|
+
try {
|
|
77
|
+
craft = await import("@domandigital/craft/phone");
|
|
78
|
+
} catch {
|
|
79
|
+
stop(GATE, "06", "@domandigital/craft is not installed, or is older than the every-viewport measure (0.20). Install the site's dependencies.");
|
|
80
|
+
}
|
|
81
|
+
const { measureSite, judgeMeasured, writeBaseline, EMPTY_BASELINE, LADDER, PHONE_FLOORS, DEFAULT_THRESHOLDS } = craft;
|
|
55
82
|
|
|
56
83
|
const close = values.serve ? await serveBuild() : () => {};
|
|
57
84
|
|
|
58
85
|
const hash = (p) => (existsSync(p) ? createHash("sha256").update(readFileSync(p)).digest("hex").slice(0, 16) : null);
|
|
59
86
|
const slug = (route) => (route === "/" ? "home" : route.replace(/^\//, "").replace(/\//g, "-"));
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
87
|
+
|
|
88
|
+
// What only a site has, read at each ladder viewport as craft hands over the page.
|
|
89
|
+
const extras = Object.fromEntries(pages.map((route) => [route, { noindex: false, labels: {} }]));
|
|
90
|
+
async function atViewport(page, viewport, route) {
|
|
91
|
+
const found = await page.evaluate(
|
|
92
|
+
({ labels }) => {
|
|
93
|
+
const R = (e) => {
|
|
94
|
+
const r = e.getBoundingClientRect();
|
|
95
|
+
return { l: r.left, t: r.top, r: r.right, b: r.bottom };
|
|
96
|
+
};
|
|
97
|
+
const ov = (a, b) => !(a.r <= b.l || b.r <= a.l || a.b <= b.t || b.b <= a.t);
|
|
98
|
+
const shown = (e) => {
|
|
99
|
+
const s = getComputedStyle(e);
|
|
100
|
+
return s.display !== "none" && s.visibility !== "hidden" && e.getClientRects().length > 0;
|
|
101
|
+
};
|
|
102
|
+
const out = { noindex: /noindex/i.test(document.querySelector('meta[name="robots"]')?.getAttribute("content") ?? ""), labels: [] };
|
|
103
|
+
if (labels?.selector) {
|
|
104
|
+
const all = [...document.querySelectorAll(labels.selector)].filter(shown);
|
|
105
|
+
const copy = [...document.querySelectorAll("main h1, main h2, main h3, main p, main li")].filter(shown);
|
|
106
|
+
for (const l of all) {
|
|
107
|
+
const r = R(l);
|
|
108
|
+
const box = labels.within ? l.parentElement?.closest(labels.within) : null;
|
|
109
|
+
const b = box ? R(box) : null;
|
|
110
|
+
out.labels.push({
|
|
111
|
+
text: l.textContent.trim().slice(0, 40),
|
|
112
|
+
inside: b ? r.l >= b.l - 0.5 && r.t >= b.t - 0.5 && r.r <= b.r + 0.5 && r.b <= b.b + 0.5 : null,
|
|
113
|
+
overLabels: all.filter((o) => o !== l && ov(r, R(o))).length,
|
|
114
|
+
overCopy: copy.filter((t) => !l.contains(t) && !t.contains(l) && ov(r, R(t))).length,
|
|
115
|
+
fontPx: parseFloat(getComputedStyle(l).fontSize),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return out;
|
|
120
|
+
},
|
|
121
|
+
{ labels },
|
|
122
|
+
);
|
|
123
|
+
extras[route].noindex = found.noindex;
|
|
124
|
+
extras[route].labels[viewport.name] = found.labels;
|
|
125
|
+
await page.screenshot({ path: join(outDir, `${slug(route)}-${viewport.name}.png`), fullPage: true });
|
|
126
|
+
}
|
|
65
127
|
|
|
66
128
|
const browser = await chromium.launch();
|
|
67
|
-
|
|
68
|
-
|
|
129
|
+
let site;
|
|
130
|
+
try {
|
|
131
|
+
site = await measureSite(browser, {
|
|
132
|
+
base,
|
|
133
|
+
routes: pages,
|
|
134
|
+
out: false,
|
|
135
|
+
floors: { textPx: minFontPx },
|
|
136
|
+
...(measure.mainAction ? { mainAction: measure.mainAction } : {}),
|
|
137
|
+
...(measure.thresholds ? { thresholds: measure.thresholds } : {}),
|
|
138
|
+
...(measure.sweep !== undefined ? { sweep: measure.sweep } : {}),
|
|
139
|
+
onViewport: atViewport,
|
|
140
|
+
});
|
|
141
|
+
} finally {
|
|
142
|
+
await browser.close();
|
|
143
|
+
close();
|
|
144
|
+
}
|
|
69
145
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
({ labels, minFontPx, phone, minTargetPx, minFieldFontPx }) => {
|
|
86
|
-
const R = (e) => {
|
|
87
|
-
const r = e.getBoundingClientRect();
|
|
88
|
-
return { l: r.left, t: r.top, r: r.right, b: r.bottom };
|
|
89
|
-
};
|
|
90
|
-
const ov = (a, b) => !(a.r <= b.l || b.r <= a.l || a.b <= b.t || b.b <= a.t);
|
|
91
|
-
const shown = (e) => {
|
|
92
|
-
const s = getComputedStyle(e);
|
|
93
|
-
return s.display !== "none" && s.visibility !== "hidden" && e.getClientRects().length > 0;
|
|
94
|
-
};
|
|
95
|
-
// Text an element shows itself, not text it inherits from a child.
|
|
96
|
-
const texty = [...document.querySelectorAll("body *")].filter(
|
|
97
|
-
(e) => shown(e) && [...e.childNodes].some((n) => n.nodeType === 3 && n.textContent.trim()) && !e.closest("[aria-hidden='true'], .sr-only, .visually-hidden"),
|
|
98
|
-
);
|
|
99
|
-
const small = texty
|
|
100
|
-
.map((e) => ({ tag: e.tagName.toLowerCase(), cls: String(e.className || ""), px: parseFloat(getComputedStyle(e).fontSize), text: e.textContent.trim().slice(0, 40) }))
|
|
101
|
-
.filter((t) => t.px < minFontPx);
|
|
102
|
-
// The layout viewport. Under mobile emulation innerWidth grows with the page (the phone zooms out to fit it), so it can never show sideways scroll.
|
|
103
|
-
const vw = document.documentElement.clientWidth;
|
|
104
|
-
const out = {
|
|
105
|
-
// No width=device-width viewport meta: the phone lays the page out at 980px and shrinks it. Otherwise, the page is wider than the phone.
|
|
106
|
-
noViewportMeta: vw > window.screen.width + 1,
|
|
107
|
-
horizontalScroll: vw <= window.screen.width + 1 && document.documentElement.scrollWidth > vw + 1,
|
|
108
|
-
fontSizesUsed: [...new Set(texty.map((e) => getComputedStyle(e).fontSize))].sort((a, b) => parseFloat(a) - parseFloat(b)),
|
|
109
|
-
smallText: small.slice(0, 10),
|
|
110
|
-
noindex: /noindex/i.test(document.querySelector('meta[name="robots"]')?.getAttribute("content") ?? ""),
|
|
111
|
-
labels: [],
|
|
112
|
-
smallTargets: [],
|
|
113
|
-
smallFields: [],
|
|
114
|
-
};
|
|
115
|
-
if (phone) {
|
|
116
|
-
const name = (e) => ({ tag: e.tagName.toLowerCase(), cls: String(e.className || ""), text: (e.textContent.trim() || e.getAttribute("aria-label") || e.getAttribute("name") || "").slice(0, 40) });
|
|
117
|
-
// Visually hidden (an sr-only skip link) or parked off the page: not a target until it is shown.
|
|
118
|
-
const hidden = (e, r) => e.closest("[aria-hidden='true'], .sr-only, .visually-hidden") || r.width <= 1 || r.height <= 1 || r.right <= 0 || r.bottom <= -window.scrollY || r.left >= vw;
|
|
119
|
-
// WCAG 2.5.5's inline exception: a link in a sentence is sized by the line it sits in.
|
|
120
|
-
const inline = (e) => {
|
|
121
|
-
if (e.tagName !== "A" || getComputedStyle(e).display !== "inline") return false;
|
|
122
|
-
const block = e.parentElement?.closest("p, li, dd, td, th, blockquote, figcaption, address");
|
|
123
|
-
return !!block && block.textContent.trim().length > e.textContent.trim().length;
|
|
124
|
-
};
|
|
125
|
-
const targets = [...document.querySelectorAll("a[href], button, input:not([type='hidden']), select, textarea, [role='button'], summary")].filter(shown);
|
|
126
|
-
for (const e of targets) {
|
|
127
|
-
const r = e.getBoundingClientRect();
|
|
128
|
-
if (hidden(e, r) || inline(e)) continue;
|
|
129
|
-
// A field's label is a hit target too: a 20px checkbox in a 44px label passes.
|
|
130
|
-
const boxes = [r, ...[...(e.labels ?? [])].filter(shown).map((l) => l.getBoundingClientRect())];
|
|
131
|
-
const w = Math.max(...boxes.map((b) => b.width));
|
|
132
|
-
const h = Math.max(...boxes.map((b) => b.height));
|
|
133
|
-
if (Math.round(w) < minTargetPx || Math.round(h) < minTargetPx) out.smallTargets.push({ ...name(e), w: Math.round(w), h: Math.round(h) });
|
|
134
|
-
}
|
|
135
|
-
const NOT_TEXT = new Set(["checkbox", "radio", "range", "color", "file", "submit", "reset", "button", "image"]);
|
|
136
|
-
for (const e of document.querySelectorAll("input:not([type='hidden']), select, textarea")) {
|
|
137
|
-
if (!shown(e) || (e.tagName === "INPUT" && NOT_TEXT.has(e.type))) continue;
|
|
138
|
-
const px = parseFloat(getComputedStyle(e).fontSize);
|
|
139
|
-
if (px < minFieldFontPx) out.smallFields.push({ ...name(e), px: Math.round(px * 10) / 10 });
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
if (labels?.selector) {
|
|
143
|
-
const all = [...document.querySelectorAll(labels.selector)].filter(shown);
|
|
144
|
-
const copy = [...document.querySelectorAll("main h1, main h2, main h3, main p, main li")].filter(shown);
|
|
145
|
-
for (const l of all) {
|
|
146
|
-
const r = R(l);
|
|
147
|
-
const box = labels.within ? l.parentElement?.closest(labels.within) : null;
|
|
148
|
-
const b = box ? R(box) : null;
|
|
149
|
-
out.labels.push({
|
|
150
|
-
text: l.textContent.trim().slice(0, 40),
|
|
151
|
-
inside: b ? r.l >= b.l - 0.5 && r.t >= b.t - 0.5 && r.r <= b.r + 0.5 && r.b <= b.b + 0.5 : null,
|
|
152
|
-
overLabels: all.filter((o) => o !== l && ov(r, R(o))).length,
|
|
153
|
-
overCopy: copy.filter((t) => !l.contains(t) && !t.contains(l) && ov(r, R(t))).length,
|
|
154
|
-
fontPx: parseFloat(getComputedStyle(l).fontSize),
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return out;
|
|
159
|
-
},
|
|
160
|
-
{ labels, minFontPx, phone, minTargetPx: MIN_TARGET_PX, minFieldFontPx: MIN_FIELD_FONT_PX },
|
|
161
|
-
);
|
|
146
|
+
const baselineFile = measure.baseline ? sitePath(measure.baseline) : null;
|
|
147
|
+
const updating = values["update-baseline"];
|
|
148
|
+
if (updating) {
|
|
149
|
+
if (!baselineFile) stop(GATE, "06", "--update-baseline needs measure.baseline in site.programme.json: the file the known failures go in.");
|
|
150
|
+
const note = existsSync(baselineFile) ? JSON.parse(readFileSync(baselineFile, "utf8")).note : undefined;
|
|
151
|
+
writeFileSync(baselineFile, `${JSON.stringify(writeBaseline([], site.routes, note), null, 2)}\n`);
|
|
152
|
+
console.log(`${GATE}: wrote ${measure.baseline}. Each line in it is a failure to fix; the count only goes down.`);
|
|
153
|
+
}
|
|
154
|
+
const baseline = baselineFile && existsSync(baselineFile) ? { static: [], measured: [], ...JSON.parse(readFileSync(baselineFile, "utf8")) } : EMPTY_BASELINE;
|
|
155
|
+
const judged = judgeMeasured(site.routes, baseline);
|
|
156
|
+
|
|
157
|
+
const failures = [...site.errors.map((e) => `${e.route}: ${e.error}`), ...judged.fresh, ...judged.stale];
|
|
158
|
+
for (const [route, { noindex, labels: byViewport }] of Object.entries(extras)) {
|
|
159
|
+
if (site.errors.some((e) => e.route === route)) continue;
|
|
160
|
+
for (const [name, list] of Object.entries(byViewport)) {
|
|
162
161
|
const at = `${route} at ${name}`;
|
|
163
|
-
|
|
164
|
-
if (m.horizontalScroll) failures.push(`${at}: the page scrolls sideways`);
|
|
165
|
-
for (const t of m.smallText) failures.push(`${at}: ${t.px}px text under ${minFontPx}px (<${t.tag}${t.cls ? ` class="${t.cls}"` : ""}> "${t.text}")`);
|
|
166
|
-
const tag = (t) => `<${t.tag}${t.cls ? ` class="${t.cls}"` : ""}>${t.text ? ` "${t.text}"` : ""}`;
|
|
167
|
-
for (const t of m.smallTargets.slice(0, 10)) failures.push(`${at}: a ${t.w}x${t.h}px target under ${MIN_TARGET_PX}x${MIN_TARGET_PX} (${tag(t)})`);
|
|
168
|
-
if (m.smallTargets.length > 10) failures.push(`${at}: ${m.smallTargets.length - 10} more targets under ${MIN_TARGET_PX}x${MIN_TARGET_PX}; measure/measure.json lists them`);
|
|
169
|
-
for (const t of m.smallFields) failures.push(`${at}: a field set at ${t.px}px, under ${MIN_FIELD_FONT_PX}px, so Safari on iOS zooms on focus (${tag(t)})`);
|
|
170
|
-
for (const l of m.labels) {
|
|
162
|
+
for (const l of list) {
|
|
171
163
|
if (l.inside === false) failures.push(`${at}: label "${l.text}" leaves its ${labels.within}`);
|
|
172
164
|
if (l.overLabels) failures.push(`${at}: label "${l.text}" sits over another label`);
|
|
173
165
|
if (l.overCopy) failures.push(`${at}: label "${l.text}" sits over copy`);
|
|
174
166
|
}
|
|
175
|
-
if (values.preview && !m.noindex) failures.push(`${at}: no noindex robots meta on a preview build (read PUBLIC_PREVIEW)`);
|
|
176
|
-
res.pages[route][name] = m;
|
|
177
|
-
await page.screenshot({ path: join(outDir, `${slug(route)}-${name}.png`), fullPage: true });
|
|
178
|
-
await context.close();
|
|
179
167
|
}
|
|
168
|
+
if (values.preview && !noindex) failures.push(`${route}: no noindex robots meta on a preview build (read PUBLIC_PREVIEW)`);
|
|
180
169
|
}
|
|
181
|
-
await browser.close();
|
|
182
|
-
close();
|
|
183
170
|
|
|
184
|
-
res
|
|
171
|
+
const res = {
|
|
172
|
+
base,
|
|
173
|
+
measuredAt: new Date().toISOString(),
|
|
174
|
+
preview: values.preview,
|
|
175
|
+
direction: hash(join(root, "art-direction.json")),
|
|
176
|
+
tokens: hash(sitePath(paths.tokens)),
|
|
177
|
+
minFontPx,
|
|
178
|
+
minTargetPx: PHONE_FLOORS.targetPx,
|
|
179
|
+
minFieldFontPx: PHONE_FLOORS.fieldFontPx,
|
|
180
|
+
thresholds: { ...DEFAULT_THRESHOLDS, ...(measure.thresholds ?? {}) },
|
|
181
|
+
mainAction: measure.mainAction ?? null,
|
|
182
|
+
baseline: measure.baseline ?? null,
|
|
183
|
+
knownBreaches: judged.known,
|
|
184
|
+
pages: Object.fromEntries(site.routes.map((r) => [r.route, { viewports: r.viewports, findings: r.findings, noindex: extras[r.route].noindex, labels: extras[r.route].labels }])),
|
|
185
|
+
errors: site.errors,
|
|
186
|
+
failures,
|
|
187
|
+
};
|
|
185
188
|
writeFileSync(join(root, "measure", "measure.json"), `${JSON.stringify(res, null, 1)}\n`);
|
|
186
|
-
|
|
187
|
-
|
|
189
|
+
const ladder = LADDER.map((v) => v.name).join(", ");
|
|
190
|
+
console.log(`${GATE}: ${pages.length} page(s) at ${ladder} and the width sweep, phone first, against ${base}${judged.known ? `; ${judged.known} known breach${judged.known === 1 ? "" : "es"} in ${measure.baseline}` : ""}; captures in measure/out, report in measure/measure.json`);
|
|
191
|
+
if (!updating && failures.length) stop(GATE, "06", `${failures.length} failure(s):\n${failures.map((f) => ` ${f}`).join("\n")}`);
|
|
188
192
|
|
|
189
193
|
/** Serves the last build on measure.port and returns how to stop it. */
|
|
190
194
|
async function serveBuild() {
|
|
@@ -219,16 +223,3 @@ async function serveBuild() {
|
|
|
219
223
|
stopServer();
|
|
220
224
|
stop(GATE, "06", `the build did not answer on ${base} within a minute.`);
|
|
221
225
|
}
|
|
222
|
-
|
|
223
|
-
// Scroll through the page so lazy images load before the capture, then back to the top.
|
|
224
|
-
async function settle(p) {
|
|
225
|
-
await p.evaluate(async () => {
|
|
226
|
-
const h = document.documentElement.scrollHeight;
|
|
227
|
-
for (let y = 0; y < h; y += 600) {
|
|
228
|
-
window.scrollTo(0, y);
|
|
229
|
-
await new Promise((r) => setTimeout(r, 40));
|
|
230
|
-
}
|
|
231
|
-
window.scrollTo(0, 0);
|
|
232
|
-
});
|
|
233
|
-
await p.waitForTimeout(600);
|
|
234
|
-
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// first one to fail stops the build and names its stage. The order matters:
|
|
4
4
|
// the direction is decided before tokens are written from it, the tokens are
|
|
5
5
|
// written before they are measured, and the deck is current before the null
|
|
6
|
-
// set reads it. The measurement at
|
|
6
|
+
// set reads it. The measurement at every viewport (phone first) needs a
|
|
7
7
|
// running build, so deploy-preview.mjs runs it before every preview deploy
|
|
8
8
|
// instead.
|
|
9
9
|
|