@domandigital/create-site 0.6.0 → 0.7.1
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 +5 -2
- package/dist/cli.js +3 -1
- package/package.json +3 -3
- package/templates/shared/docs/site-programme.md +9 -3
- package/templates/shared/scripts/gates/measure.mjs +66 -18
- package/templates/shared/scripts/gates/mobile-first.mjs +91 -0
- package/templates/shared/scripts/gates/prebuild.mjs +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @domandigital/create-site
|
|
2
2
|
|
|
3
|
+
## 0.7.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- c88e737: The site measure gate now sees sideways scroll at phone widths (DOM-774). It compared `scrollWidth` with `window.innerWidth`, which grows with the page under mobile emulation, so a 500px-wide page at 375 passed. It now measures against the layout viewport (`clientWidth`), reports a page with no `width=device-width` viewport meta, and treats a target parked past the right edge as off the page, as `@domandigital/craft/phone` does.
|
|
8
|
+
|
|
9
|
+
## 0.7.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 5056c6a: Mobile first, gated (DOM-774, part of DOM-772). A new Stage 06 gate, `scripts/gates/mobile-first.mjs`, runs from `prebuild` and fails the build on a `max-width` media query (including the `width <` and `width <=` range syntax) or a Tailwind `max-*:` variant in the site's source, unless the exception is recorded with a reason: `mobile-first-ok: <reason>` on the line or the line above, or the file in `site.programme.json` `mobileFirst.exceptions` as `{ "file", "reason" }`. An exception with no reason fails. `measure.mjs` now measures phone first, at 375 x 812, then 390 x 844, then 1440 x 900, and at the two phone widths also fails a link, button, field or summary under 44 x 44 CSS px (a link inside a sentence is exempt, and a field's label counts as its target) and a text field set under 16px, which Safari on iOS zooms on. `docs/site-programme.md` says phone first at Stages 03 and 06 and lists the new gate; new sites get `mobileFirst: { "exceptions": [] }` in `site.programme.json`, and an existing one without the key is read as having no exceptions.
|
|
14
|
+
|
|
3
15
|
## 0.6.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -68,9 +68,12 @@ the build:
|
|
|
68
68
|
| `facts.mjs` | 06 | a price, term or response target is typed instead of imported from the facts |
|
|
69
69
|
| `copy-deck.mjs --check` | 06 | the copy deck is missing, empty or not rendered |
|
|
70
70
|
| `null-check.mjs` | 06 | the deck carries a phrase the null builds kept writing, without a reason |
|
|
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 |
|
|
71
72
|
|
|
72
|
-
`pnpm measure` serves the last build and measures it at
|
|
73
|
-
on sideways scroll, on text under 12px, and on a label
|
|
73
|
+
`pnpm measure` serves the last build and measures it phone first, at 375, 390
|
|
74
|
+
and 1440: it fails on sideways scroll, on text under 12px, and on a label
|
|
75
|
+
outside its container, and at the two phone widths on a target under 44px and
|
|
76
|
+
a form field set under 16px.
|
|
74
77
|
`pnpm deploy:preview` is the only deploy: it sets `PUBLIC_PREVIEW` itself,
|
|
75
78
|
builds, measures with noindex required, and deploys a preview to Cloudflare
|
|
76
79
|
or Vercel; it refuses a route, a custom domain or `--prod`. So a site made
|
package/dist/cli.js
CHANGED
|
@@ -435,6 +435,7 @@ var GATES = [
|
|
|
435
435
|
"facts.mjs",
|
|
436
436
|
"copy-deck.mjs",
|
|
437
437
|
"null-check.mjs",
|
|
438
|
+
"mobile-first.mjs",
|
|
438
439
|
"measure.mjs",
|
|
439
440
|
"deploy-preview.mjs"
|
|
440
441
|
];
|
|
@@ -763,6 +764,7 @@ function renderProgramme(a, project) {
|
|
|
763
764
|
measure: { pages: ["/"], minFontPx: 12, labels: null, port: 4410 },
|
|
764
765
|
nullCheck: { harvest: null, justified: {} },
|
|
765
766
|
facts: { importer: null },
|
|
767
|
+
mobileFirst: { exceptions: [] },
|
|
766
768
|
preview: { host }
|
|
767
769
|
};
|
|
768
770
|
return `${JSON.stringify(programme, null, 2)}
|
|
@@ -789,7 +791,7 @@ var HOUSE_DEV_DEPENDENCIES = {
|
|
|
789
791
|
"@domandigital/craft": "^0.19.0",
|
|
790
792
|
"@types/node": "^22.0.0",
|
|
791
793
|
vitest: "^4.1.11",
|
|
792
|
-
// scripts/gates/measure.mjs renders the pages at
|
|
794
|
+
// scripts/gates/measure.mjs renders the pages at 375, 390 and 1440 before every
|
|
793
795
|
// preview deploy; tsx loads the copy deck on Node older than 22.18.
|
|
794
796
|
playwright: "^1.62.0",
|
|
795
797
|
tsx: "^4.20.0"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domandigital/create-site",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
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,9 +41,9 @@
|
|
|
41
41
|
"tsup": "^8.3.5",
|
|
42
42
|
"typescript": "^5.6.3",
|
|
43
43
|
"vitest": "^4.0.0",
|
|
44
|
+
"@domandigital/craft": "^0.19.3",
|
|
44
45
|
"@domandigital/graph": "^0.7.0",
|
|
45
|
-
"@domandigital/seo": "^0.3.1"
|
|
46
|
-
"@domandigital/craft": "^0.19.0"
|
|
46
|
+
"@domandigital/seo": "^0.3.1"
|
|
47
47
|
},
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public",
|
|
@@ -26,6 +26,10 @@ replaced.
|
|
|
26
26
|
- Decisions go to a register, never a chat.
|
|
27
27
|
- Governed facts are imported, never retyped.
|
|
28
28
|
- The live site is untouched until Stage 09.
|
|
29
|
+
- Phone first, at every stage from 03: designed at 375px, built with the phone
|
|
30
|
+
as the base styles and `min-width` for wider layouts, measured at 375
|
|
31
|
+
before any wider width, and reviewed from the phone capture first
|
|
32
|
+
(`STANDARD.md` section 10 in `@domandigital/craft`, DOM-772).
|
|
29
33
|
- A gate is a script that blocks the build, never a reminder
|
|
30
34
|
(`docs/ops/time-tracking.md` in Doman-Digital for why: the one control that
|
|
31
35
|
needed a person to start it was never used once).
|
|
@@ -41,10 +45,10 @@ a file is not acceptance.
|
|
|
41
45
|
| --- | --- | --- | --- |
|
|
42
46
|
| 01 Brief, scope and evidence constraints | The agreed brief, scope and exclusions, the evidence and claim inventory, success measures, owners and reviewers | A named person agrees the brief and scope; missing claims have owners and safe placeholders | `site.programme.json` names the programme issue |
|
|
43
47
|
| 02 Page roles, buyer journeys and the content model | Sitemap and page-role map, route register, journey maps, the call-to-action contract, the code and CMS ownership map | Each journey reaches a fitting next step; no orphan page or unrecorded removal | `site.routes.ts` and `tests/seo/coverage.test.ts` (every page on disk has a policy) |
|
|
44
|
-
| 03 Low-fidelity wireframes,
|
|
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 |
|
|
45
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 |
|
|
46
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` |
|
|
47
|
-
| 06 Detailed pages, content and the component system | The real app on a preview, every page family, the copy deck through the gates, measured at 390
|
|
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 375, then 390, then 1440 | 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` |
|
|
48
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` |
|
|
49
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 |
|
|
50
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 |
|
|
@@ -63,12 +67,13 @@ failure stops the build.
|
|
|
63
67
|
| `facts.mjs` | 06 | the site's source (`paths.source`) and the deck | a price, response target, minimum term or notice period is typed rather than read from `site.facts.ts` or a generated facts file. Runs `facts.importer` first when one is named |
|
|
64
68
|
| `copy-deck.mjs --check` | 06 | the deck (`paths.deck`) | the deck is missing or empty, or the rendered deck (`paths.deckMarkdown`) is not current |
|
|
65
69
|
| `null-check.mjs` | 06 | the rendered deck, the null harvest (`nullCheck.harvest`) | a phrase the null builds kept writing is in the deck without a reason under `nullCheck.justified`. Skips when the harvest is not on the machine |
|
|
70
|
+
| `mobile-first.mjs` | 06 | the site's source (`paths.source`, and `src`, `app`, `components` and `styles` when present) | a `max-width` media query (or `width <` range syntax) or a Tailwind `max-*:` variant is written without a recorded exception: `mobile-first-ok: <reason>` on its line or the line above, or the file in `mobileFirst.exceptions` with a reason. An exception with no reason fails |
|
|
66
71
|
|
|
67
72
|
Run around a running build:
|
|
68
73
|
|
|
69
74
|
| Gate | Stage | Fails when |
|
|
70
75
|
| --- | --- | --- |
|
|
71
|
-
| `measure.mjs` | 06 | a page in `measure.pages` does not answer, scrolls sideways, or shows text under `measure.minFontPx
|
|
76
|
+
| `measure.mjs` | 06 | measured phone first, at 375, then 390, then 1440: a page in `measure.pages` does not answer, scrolls sideways, or shows text under `measure.minFontPx`; at 375 and 390, 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; a label in `measure.labels` leaves its container or covers a label or copy; with `--preview`, a page has no noindex |
|
|
72
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 |
|
|
73
78
|
|
|
74
79
|
The site reads `PUBLIC_PREVIEW` (Astro, `import.meta.env.PUBLIC_PREVIEW`) or
|
|
@@ -98,4 +103,5 @@ pricing modules and writes the facts the redesign renders.
|
|
|
98
103
|
| `measure` | `pages`, `minFontPx` (12), `labels` (`{ "selector": ".label", "within": ".screen" }` or null), `port` |
|
|
99
104
|
| `nullCheck` | `harvest` (a path, `~/` allowed) and `justified` (phrase to reason) |
|
|
100
105
|
| `facts` | `importer`: the site's importer script, or null |
|
|
106
|
+
| `mobileFirst` | `exceptions`: the files allowed a `max-width` query or `max-*:` variant, each `{ "file": "src/styles/print.css", "reason": "..." }` |
|
|
101
107
|
| `preview` | `host`: `cloudflare` or `vercel`, or null to find it from the config |
|
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
// Stage 06 gate: measures the rendered pages
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
1
|
+
// Stage 06 gate: measures the rendered pages rather than trusting the
|
|
2
|
+
// stylesheet, phone first (STANDARD.md section 10 in @domandigital/craft):
|
|
3
|
+
// 375 x 812, the floor every surface is designed at, then 390 x 844, the
|
|
4
|
+
// width the design is accepted at, then 1440 x 900. On every page named in
|
|
5
|
+
// site.programme.json measure.pages, at every width: the page answers,
|
|
6
|
+
// nothing scrolls sideways, no visible text is smaller than
|
|
7
|
+
// measure.minFontPx, and, when measure.labels names them, every label sits
|
|
8
|
+
// inside its container, over no other label and no copy. At the two phone
|
|
9
|
+
// widths, also: every link, button, field and summary a thumb has to hit is
|
|
10
|
+
// at least 44 x 44 CSS px (a link inside a sentence is exempt, as in WCAG
|
|
11
|
+
// 2.5.5; a field's label counts as its target), and every text field is set
|
|
12
|
+
// at 16px or more, so Safari on iOS does not zoom on focus. With --preview,
|
|
13
|
+
// every page must also carry a noindex robots meta, so a preview cannot be
|
|
14
|
+
// indexed. Writes measure/measure.json, with the hash of the direction it
|
|
15
|
+
// measured, and a full-page capture per page and width under measure/out,
|
|
16
|
+
// phone captures first. Exits 1 on any failure.
|
|
11
17
|
//
|
|
12
18
|
// --serve serves the last build itself and measures that: static output in
|
|
13
19
|
// dist/ is served from here the way the host serves it (no trailing slash,
|
|
@@ -33,6 +39,9 @@ const port = measure.port ?? 4410;
|
|
|
33
39
|
const base = (values.base ?? `http://127.0.0.1:${port}`).replace(/\/$/, "");
|
|
34
40
|
const pages = measure.pages?.length ? measure.pages : ["/"];
|
|
35
41
|
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;
|
|
36
45
|
const labels = measure.labels ?? null;
|
|
37
46
|
const outDir = join(root, "measure", "out");
|
|
38
47
|
mkdirSync(outDir, { recursive: true });
|
|
@@ -49,17 +58,18 @@ const close = values.serve ? await serveBuild() : () => {};
|
|
|
49
58
|
const hash = (p) => (existsSync(p) ? createHash("sha256").update(readFileSync(p)).digest("hex").slice(0, 16) : null);
|
|
50
59
|
const slug = (route) => (route === "/" ? "home" : route.replace(/^\//, "").replace(/\//g, "-"));
|
|
51
60
|
const VIEWPORTS = [
|
|
52
|
-
{ name: "
|
|
53
|
-
{ name: "390x844", viewport: { width: 390, height: 844 }, deviceScaleFactor: 2, isMobile: true },
|
|
61
|
+
{ name: "375x812", phone: true, viewport: { width: 375, height: 812 }, deviceScaleFactor: 2, isMobile: true, hasTouch: true },
|
|
62
|
+
{ name: "390x844", phone: true, viewport: { width: 390, height: 844 }, deviceScaleFactor: 2, isMobile: true, hasTouch: true },
|
|
63
|
+
{ name: "1440x900", phone: false, viewport: { width: 1440, height: 900 } },
|
|
54
64
|
];
|
|
55
65
|
|
|
56
66
|
const browser = await chromium.launch();
|
|
57
67
|
const failures = [];
|
|
58
|
-
const res = { base, measuredAt: new Date().toISOString(), preview: values.preview, direction: hash(join(root, "art-direction.json")), tokens: hash(sitePath(paths.tokens)), minFontPx, pages: {} };
|
|
68
|
+
const res = { base, measuredAt: new Date().toISOString(), preview: values.preview, direction: hash(join(root, "art-direction.json")), tokens: hash(sitePath(paths.tokens)), minFontPx, minTargetPx: MIN_TARGET_PX, minFieldFontPx: MIN_FIELD_FONT_PX, pages: {} };
|
|
59
69
|
|
|
60
70
|
for (const route of pages) {
|
|
61
71
|
res.pages[route] = {};
|
|
62
|
-
for (const { name, ...options } of VIEWPORTS) {
|
|
72
|
+
for (const { name, phone, ...options } of VIEWPORTS) {
|
|
63
73
|
const context = await browser.newContext(options);
|
|
64
74
|
const page = await context.newPage();
|
|
65
75
|
const resp = await page.goto(base + route).catch((error) => ({ ok: () => false, status: () => error.message }));
|
|
@@ -72,7 +82,7 @@ for (const route of pages) {
|
|
|
72
82
|
await page.evaluate(() => document.fonts.ready);
|
|
73
83
|
await settle(page);
|
|
74
84
|
const m = await page.evaluate(
|
|
75
|
-
({ labels, minFontPx }) => {
|
|
85
|
+
({ labels, minFontPx, phone, minTargetPx, minFieldFontPx }) => {
|
|
76
86
|
const R = (e) => {
|
|
77
87
|
const r = e.getBoundingClientRect();
|
|
78
88
|
return { l: r.left, t: r.top, r: r.right, b: r.bottom };
|
|
@@ -89,13 +99,46 @@ for (const route of pages) {
|
|
|
89
99
|
const small = texty
|
|
90
100
|
.map((e) => ({ tag: e.tagName.toLowerCase(), cls: String(e.className || ""), px: parseFloat(getComputedStyle(e).fontSize), text: e.textContent.trim().slice(0, 40) }))
|
|
91
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;
|
|
92
104
|
const out = {
|
|
93
|
-
|
|
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,
|
|
94
108
|
fontSizesUsed: [...new Set(texty.map((e) => getComputedStyle(e).fontSize))].sort((a, b) => parseFloat(a) - parseFloat(b)),
|
|
95
109
|
smallText: small.slice(0, 10),
|
|
96
110
|
noindex: /noindex/i.test(document.querySelector('meta[name="robots"]')?.getAttribute("content") ?? ""),
|
|
97
111
|
labels: [],
|
|
112
|
+
smallTargets: [],
|
|
113
|
+
smallFields: [],
|
|
98
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
|
+
}
|
|
99
142
|
if (labels?.selector) {
|
|
100
143
|
const all = [...document.querySelectorAll(labels.selector)].filter(shown);
|
|
101
144
|
const copy = [...document.querySelectorAll("main h1, main h2, main h3, main p, main li")].filter(shown);
|
|
@@ -114,11 +157,16 @@ for (const route of pages) {
|
|
|
114
157
|
}
|
|
115
158
|
return out;
|
|
116
159
|
},
|
|
117
|
-
{ labels, minFontPx },
|
|
160
|
+
{ labels, minFontPx, phone, minTargetPx: MIN_TARGET_PX, minFieldFontPx: MIN_FIELD_FONT_PX },
|
|
118
161
|
);
|
|
119
162
|
const at = `${route} at ${name}`;
|
|
163
|
+
if (m.noViewportMeta) failures.push(`${at}: the page lays out wider than the screen: no width=device-width viewport meta`);
|
|
120
164
|
if (m.horizontalScroll) failures.push(`${at}: the page scrolls sideways`);
|
|
121
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)})`);
|
|
122
170
|
for (const l of m.labels) {
|
|
123
171
|
if (l.inside === false) failures.push(`${at}: label "${l.text}" leaves its ${labels.within}`);
|
|
124
172
|
if (l.overLabels) failures.push(`${at}: label "${l.text}" sits over another label`);
|
|
@@ -135,7 +183,7 @@ close();
|
|
|
135
183
|
|
|
136
184
|
res.failures = failures;
|
|
137
185
|
writeFileSync(join(root, "measure", "measure.json"), `${JSON.stringify(res, null, 1)}\n`);
|
|
138
|
-
console.log(`${GATE}: ${pages.length} page(s) at
|
|
186
|
+
console.log(`${GATE}: ${pages.length} page(s) at 375, 390 and 1440, phone first, against ${base}; captures in measure/out, report in measure/measure.json`);
|
|
139
187
|
if (failures.length) stop(GATE, "06", `${failures.length} failure(s):\n${failures.map((f) => ` ${f}`).join("\n")}`);
|
|
140
188
|
|
|
141
189
|
/** Serves the last build on measure.port and returns how to stop it. */
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Stage 06 gate: the phone is the base layout (STANDARD.md section 10 in
|
|
2
|
+
// @domandigital/craft). Base styles are the phone; wider layouts are added
|
|
3
|
+
// with min-width queries. This fails on a max-width media query (`max-width:`,
|
|
4
|
+
// or the range syntax `width <`, `width <=`, `600px > width`) and on a
|
|
5
|
+
// Tailwind max-* variant (`max-sm:`, `max-md:`, `max-[40rem]:`) anywhere in
|
|
6
|
+
// the site's source, because a layout written desktop first and taken away
|
|
7
|
+
// for the phone is how a site ends up designed for the desktop.
|
|
8
|
+
//
|
|
9
|
+
// An exception is recorded, never assumed: `mobile-first-ok: <reason>` in a
|
|
10
|
+
// comment on the line or the line above, or the whole file in
|
|
11
|
+
// site.programme.json mobileFirst.exceptions as { "file", "reason" }. An
|
|
12
|
+
// exception with no reason fails, and so does one naming a file that is not
|
|
13
|
+
// there.
|
|
14
|
+
|
|
15
|
+
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
16
|
+
import { join, normalize, relative } from "node:path";
|
|
17
|
+
import { programme, root, sitePath, stop } from "./programme.mjs";
|
|
18
|
+
|
|
19
|
+
const GATE = "mobile-first";
|
|
20
|
+
const { paths = {}, mobileFirst = {} } = programme();
|
|
21
|
+
|
|
22
|
+
// The source paths.source names, and the usual homes of styles even when it does not.
|
|
23
|
+
const DIRS = [...new Set([...(paths.source ?? []), "src", "app", "components", "styles"])];
|
|
24
|
+
const EXTENSIONS = /\.(css|scss|sass|less|astro|tsx|jsx|ts|js|mjs|vue|svelte|mdx|html)$/;
|
|
25
|
+
const SKIP_DIRS = new Set(["generated", "node_modules", ".next", ".astro", "dist"]);
|
|
26
|
+
const walk = (dir) =>
|
|
27
|
+
readdirSync(dir).flatMap((f) => {
|
|
28
|
+
const p = join(dir, f);
|
|
29
|
+
if (statSync(p).isDirectory()) return SKIP_DIRS.has(f) ? [] : walk(p);
|
|
30
|
+
return [p];
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const files = new Set();
|
|
34
|
+
for (const dir of DIRS) {
|
|
35
|
+
const abs = sitePath(dir);
|
|
36
|
+
if (existsSync(abs) && statSync(abs).isDirectory()) for (const f of walk(abs)) if (EXTENSIONS.test(f)) files.add(f);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const problems = [];
|
|
40
|
+
const excepted = new Map();
|
|
41
|
+
for (const [i, e] of (mobileFirst.exceptions ?? []).entries()) {
|
|
42
|
+
const at = `site.programme.json mobileFirst.exceptions[${i}]`;
|
|
43
|
+
if (typeof e?.file !== "string" || !e.file.trim()) problems.push(` ${at}: names no file`);
|
|
44
|
+
else if (typeof e.reason !== "string" || !e.reason.trim()) problems.push(` ${at} (${e.file}): no reason. Say why this file needs a max-width query, or remove the exception.`);
|
|
45
|
+
else if (!existsSync(sitePath(e.file))) problems.push(` ${at}: ${e.file} is not there. Remove the exception.`);
|
|
46
|
+
else excepted.set(normalize(e.file), e.reason.trim());
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// A media query whose condition caps the width. The prelude runs to the rule's `{` (or the `;` of @custom-media).
|
|
50
|
+
const MEDIA = /@(?:custom-)?media\b([^{;]*)/g;
|
|
51
|
+
const CAPS_WIDTH = /\bmax-(?:device-)?width\s*:|\bwidth\s*<|>=?\s*(?:device-)?width\b/i;
|
|
52
|
+
// A Tailwind max-* variant. Single-word CSS properties and media features spelt max-* are not variants.
|
|
53
|
+
const VARIANT = /(?<![\w@-])max-(\[[^\]\s]+\]|[a-z0-9]+):/g;
|
|
54
|
+
const NOT_VARIANTS = new Set(["width", "height", "lines", "resolution", "zoom"]);
|
|
55
|
+
const OK = /mobile-first-ok\b:?(.*)/;
|
|
56
|
+
const reasonOf = (line) => {
|
|
57
|
+
const m = line?.match(OK);
|
|
58
|
+
return m ? m[1].replace(/\*\/|-->|[{}]/g, "").trim() : null;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
let exceptions = excepted.size;
|
|
62
|
+
for (const file of files) {
|
|
63
|
+
const rel = relative(root, file);
|
|
64
|
+
if (excepted.has(normalize(rel))) continue;
|
|
65
|
+
const text = readFileSync(file, "utf8");
|
|
66
|
+
const lines = text.split("\n");
|
|
67
|
+
const lineOf = (index) => text.slice(0, index).split("\n").length;
|
|
68
|
+
const found = [];
|
|
69
|
+
for (const m of text.matchAll(MEDIA)) {
|
|
70
|
+
if (CAPS_WIDTH.test(m[1])) found.push({ line: lineOf(m.index), what: `a max-width media query (@media${m[1].replace(/\s+/g, " ").trimEnd()})` });
|
|
71
|
+
}
|
|
72
|
+
for (const m of text.matchAll(VARIANT)) {
|
|
73
|
+
if (!NOT_VARIANTS.has(m[1])) found.push({ line: lineOf(m.index), what: `a Tailwind max-* variant (${m[0]})` });
|
|
74
|
+
}
|
|
75
|
+
for (const { line, what } of found) {
|
|
76
|
+
const here = reasonOf(lines[line - 1]);
|
|
77
|
+
const above = reasonOf(lines[line - 2]);
|
|
78
|
+
const reason = here ?? above;
|
|
79
|
+
if (reason) {
|
|
80
|
+
exceptions++;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (here === "" || above === "") problems.push(` ${rel}:${line}: mobile-first-ok with no reason, on ${what}`);
|
|
84
|
+
else problems.push(` ${rel}:${line}: ${what}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (problems.length) {
|
|
89
|
+
stop(GATE, "06", `the phone is not the base layout. Write the phone as the base styles and add wider layouts with min-width (Tailwind: sm: md: lg:). A genuine exception takes mobile-first-ok: <reason> on its line, or the file in site.programme.json mobileFirst.exceptions with a reason.\n${problems.join("\n")}`);
|
|
90
|
+
}
|
|
91
|
+
console.log(`${GATE}: ${files.size} files build the phone first, with min-width only${exceptions ? ` (${exceptions} recorded exception${exceptions === 1 ? "" : "s"})` : ""}`);
|
|
@@ -3,8 +3,9 @@
|
|
|
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
|
|
7
|
-
// deploy-preview.mjs runs it before every preview deploy
|
|
6
|
+
// set reads it. The measurement at 375, 390 and 1440 (phone first) needs a
|
|
7
|
+
// running build, so deploy-preview.mjs runs it before every preview deploy
|
|
8
|
+
// instead.
|
|
8
9
|
|
|
9
10
|
import { spawnSync } from "node:child_process";
|
|
10
11
|
import { join } from "node:path";
|
|
@@ -17,6 +18,7 @@ const GATES = [
|
|
|
17
18
|
["facts.mjs"],
|
|
18
19
|
["copy-deck.mjs", "--check"],
|
|
19
20
|
["null-check.mjs"],
|
|
21
|
+
["mobile-first.mjs"],
|
|
20
22
|
];
|
|
21
23
|
|
|
22
24
|
// Stage 01: the site has a programme in Linear before anything is built.
|