@domandigital/create-site 0.5.0 → 0.6.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 +42 -5
- package/dist/cli.js +94 -10
- package/package.json +4 -4
- package/templates/shared/docs/site-programme.md +101 -0
- package/templates/shared/scripts/gates/check-direction.mjs +51 -0
- package/templates/shared/scripts/gates/copy-deck.mjs +84 -0
- package/templates/shared/scripts/gates/deploy-preview.mjs +63 -0
- package/templates/shared/scripts/gates/facts.mjs +65 -0
- package/templates/shared/scripts/gates/measure.mjs +186 -0
- package/templates/shared/scripts/gates/night-contrast.mjs +68 -0
- package/templates/shared/scripts/gates/null-check.mjs +76 -0
- package/templates/shared/scripts/gates/prebuild.mjs +34 -0
- package/templates/shared/scripts/gates/programme.mjs +42 -0
- package/templates/shared/scripts/gates/tokens.mjs +79 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @domandigital/create-site
|
|
2
2
|
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 4f88631: The site programme's gates, as code (DOM-647). A new site gets `scripts/gates/`, lifted from the Doman Digital redesign: the programme issue (Stage 01), `check-direction` against the registered copy, the token generator writing both sides of the sheet, `night-contrast`, the governed-facts check, the copy deck and the null-set check, all run by `prebuild`; `measure` at 1440 and 390; and `deploy:preview`, which sets `PUBLIC_PREVIEW` itself, measures with noindex required and deploys a preview only. With `docs/site-programme.md`, `site.programme.json`, `art-direction.sheets.json`, a `--programme DOM-123` flag, and playwright and tsx as dev dependencies. A scaffolded site no longer builds until its programme exists and Stages 05 and 06 are done.
|
|
8
|
+
|
|
9
|
+
## 0.5.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 09b49ac: New sites install `@domandigital/craft` `^0.19.0`, the release whose estate comparison measures ground temperature and section structure.
|
|
14
|
+
|
|
3
15
|
## 0.5.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -40,19 +40,53 @@ it is copied, which is the failure this exists to avoid.
|
|
|
40
40
|
| `tests/seo/*`, `tests/house.test.ts` | Route coverage, the redirect gate, JSON-LD integrity, the redirect wiring, and the rule that contact details live only in the facts file |
|
|
41
41
|
| `docs/HOUSE.md` | The house rules, imported by `CLAUDE.md` (created if missing, otherwise one import line is added) |
|
|
42
42
|
| `docs/DIRECTION.md`, `docs/seo-launch-checklist.md`, `docs/seo-baseline.md` | The site's decision and blocked registers, the listings to claim for its sector, and the launch, 90-day, 6-month and 12-month baseline |
|
|
43
|
-
| `docs/client-facts.entry.json` | The technology the builder says the site uses, as an entry for Doman Digital's client register.
|
|
43
|
+
| `docs/client-facts.entry.json` | The technology the builder says the site uses, as an entry for Doman Digital's client register. It records what the builder declared, so every tracking tool has `consent: null` until someone fills it in from what the site does. Skipped answers are simply absent |
|
|
44
44
|
| `.github/workflows/seo-check.yml` | Only if the project has no workflows yet. Written to pass `dd doctor`: actions pinned to a commit SHA, the runner chosen by `--visibility`, a timeout and a concurrency group |
|
|
45
45
|
| `pnpm-workspace.yaml` | pnpm projects: `minimumReleaseAge: 1440` (house packages exempt), added to the file create-next-app writes, or a new one. A project's own value is kept |
|
|
46
|
-
| `
|
|
46
|
+
| `scripts/gates/*`, `docs/site-programme.md` | The site programme's gates and the process they belong to: see below |
|
|
47
|
+
| `site.programme.json`, `art-direction.sheets.json` | The site's answers to the gates (the programme issue, paths, pages to measure, the null harvest, the preview host), and both sides of the sheet beyond the direction's own ground and accent. Unknown is `null` |
|
|
48
|
+
| `package.json` | `seo:check`, `launch:check`, `prebuild`, `tokens`, `deck`, `measure` and `deploy:preview` scripts, and the house packages |
|
|
47
49
|
|
|
48
50
|
It then runs `craft direction init` through the installed craft bin to start
|
|
49
51
|
`art-direction.json`, unless one exists.
|
|
50
52
|
|
|
53
|
+
## The site programme
|
|
54
|
+
|
|
55
|
+
Every site is made in ten stages (`docs/site-programme.md`, decided on
|
|
56
|
+
10 October 2026 in DOM-647 after the Doman Digital redesign, DOM-392). The
|
|
57
|
+
programme lives in Linear, opened from the "Site programme" template; the
|
|
58
|
+
scaffold carries its gates as code, lifted from `apps/site/scripts` in
|
|
59
|
+
Doman-Digital. `prebuild` runs them in stage order and the first failure stops
|
|
60
|
+
the build:
|
|
61
|
+
|
|
62
|
+
| Gate | Stage | Stops the build when |
|
|
63
|
+
| --- | --- | --- |
|
|
64
|
+
| programme issue | 01 | `site.programme.json` names no Linear issue (`--programme DOM-123`) |
|
|
65
|
+
| `check-direction.mjs` | 05 | `art-direction.json` is missing, invalid, undecided, or differs from its registered copy in the craft estate |
|
|
66
|
+
| `tokens.mjs` | 05 | a day or night value is null. Writes the token stylesheet, both sides of the sheet |
|
|
67
|
+
| `night-contrast.mjs` | 05 | a text pair is under 4.5:1 by day or by night |
|
|
68
|
+
| `facts.mjs` | 06 | a price, term or response target is typed instead of imported from the facts |
|
|
69
|
+
| `copy-deck.mjs --check` | 06 | the copy deck is missing, empty or not rendered |
|
|
70
|
+
| `null-check.mjs` | 06 | the deck carries a phrase the null builds kept writing, without a reason |
|
|
71
|
+
|
|
72
|
+
`pnpm measure` serves the last build and measures it at 1440 and 390: it fails
|
|
73
|
+
on sideways scroll, on text under 12px, and on a label outside its container.
|
|
74
|
+
`pnpm deploy:preview` is the only deploy: it sets `PUBLIC_PREVIEW` itself,
|
|
75
|
+
builds, measures with noindex required, and deploys a preview to Cloudflare
|
|
76
|
+
or Vercel; it refuses a route, a custom domain or `--prod`. So a site made
|
|
77
|
+
with create-site cannot build until its programme exists and Stages 05 and 06
|
|
78
|
+
are done, and cannot reach a URL unmeasured.
|
|
79
|
+
|
|
80
|
+
The gate scripts are house files, identical on every site and reported by
|
|
81
|
+
`--check` when they drift. Everything that differs between sites is in
|
|
82
|
+
`site.programme.json`.
|
|
83
|
+
|
|
51
84
|
## What it never does
|
|
52
85
|
|
|
53
86
|
- Write outside the project, or anything at all when it refuses.
|
|
54
87
|
- Replace a data file (`site.facts.ts`, `site.routes.ts`, `links.json`,
|
|
55
|
-
`redirects.json`, `docs/DIRECTION.md`, the checklist, the baseline
|
|
88
|
+
`redirects.json`, `docs/DIRECTION.md`, the checklist, the baseline,
|
|
89
|
+
`site.programme.json`, `art-direction.sheets.json`), even with
|
|
56
90
|
`--force`. Delete one to regenerate it.
|
|
57
91
|
- Replace a house template file that differs, unless `--force`. Without it,
|
|
58
92
|
the difference is reported: a re-run is also a drift report.
|
|
@@ -66,7 +100,8 @@ It then runs `craft direction init` through the installed craft bin to start
|
|
|
66
100
|
```
|
|
67
101
|
create-site [dir] [--client <legal name>] [--trading-name <name>]
|
|
68
102
|
[--site-url <https://...>] [--sector trades|beauty|clinics|professional]
|
|
69
|
-
[--description "<one or two sentences>"] [--
|
|
103
|
+
[--description "<one or two sentences>"] [--programme DOM-123]
|
|
104
|
+
[--answers <file.json>]
|
|
70
105
|
[--visibility private|public] [--dry-run] [--check] [--force]
|
|
71
106
|
[--skip-install] [--yes] [--help] [--version]
|
|
72
107
|
```
|
|
@@ -83,7 +118,9 @@ same answers the site was made with (`--answers`).
|
|
|
83
118
|
`--answers` takes a JSON file with any of `legalName`, `tradingName`,
|
|
84
119
|
`siteUrl`, `sector`, `description`, `phone`, `email`, `locality`,
|
|
85
120
|
`postalCode`, `serviceAreas`, `registers` (ids from `src/sectors.ts`) and
|
|
86
|
-
`previousHosts`,
|
|
121
|
+
`previousHosts`, `programme` (the Linear issue, like `--programme`), and the
|
|
122
|
+
declared technology: `host` (`cloudflare` or `vercel` also becomes the preview
|
|
123
|
+
host in `site.programme.json`), `dns`, `cms`,
|
|
87
124
|
`analytics` (a list, e.g. `["ga4", "gtm", "posthog"]`), `errorMonitoring` and
|
|
88
125
|
`emailSending` (a list). Each can be skipped, and a skipped one is left out of
|
|
89
126
|
`docs/client-facts.entry.json`, never filled with a guess. Common names are
|
package/dist/cli.js
CHANGED
|
@@ -214,6 +214,8 @@ async function collectAnswers(sources) {
|
|
|
214
214
|
const previousHosts = list(await optional("previousHosts", "Previous website hostname, if moving from one"));
|
|
215
215
|
const stack = await collectStack(optional);
|
|
216
216
|
if (typeof stack === "string") return stack;
|
|
217
|
+
const programme = pick("programme") ?? text(await optional("programme", "Programme issue in Linear, e.g. DOM-123"));
|
|
218
|
+
if (programme !== null && !/^[A-Z]+-\d+$/.test(programme)) return `--programme takes a Linear issue id such as DOM-123, not "${programme}"`;
|
|
217
219
|
return {
|
|
218
220
|
legalName: values.legalName,
|
|
219
221
|
tradingName,
|
|
@@ -227,7 +229,8 @@ async function collectAnswers(sources) {
|
|
|
227
229
|
serviceAreas,
|
|
228
230
|
registers,
|
|
229
231
|
previousHosts,
|
|
230
|
-
stack
|
|
232
|
+
stack,
|
|
233
|
+
programme
|
|
231
234
|
};
|
|
232
235
|
}
|
|
233
236
|
|
|
@@ -275,10 +278,12 @@ Run it inside a fresh Next.js (App Router) or Astro TypeScript project:
|
|
|
275
278
|
Usage
|
|
276
279
|
create-site [dir] [--client <legal name>] [--trading-name <name>]
|
|
277
280
|
[--site-url <https://...>] [--sector trades|beauty|clinics|professional]
|
|
278
|
-
[--description "<one or two sentences>"] [--
|
|
279
|
-
[--
|
|
280
|
-
[--skip-install] [--yes] [--help] [--version]
|
|
281
|
+
[--description "<one or two sentences>"] [--programme DOM-123]
|
|
282
|
+
[--answers <file.json>] [--visibility private|public]
|
|
283
|
+
[--dry-run] [--check] [--force] [--skip-install] [--yes] [--help] [--version]
|
|
281
284
|
|
|
285
|
+
--programme The site's programme issue in Linear, opened from the Site programme
|
|
286
|
+
template. The build refuses to run until site.programme.json names it.
|
|
282
287
|
--dry-run Print the plan and stop. Writes nothing, runs nothing.
|
|
283
288
|
--check Like --dry-run, never prompts, and exits 3 when there is work to do,
|
|
284
289
|
a house file that differs from its template included. For CI.
|
|
@@ -303,6 +308,7 @@ function parseOptions(argv) {
|
|
|
303
308
|
"site-url": { type: "string" },
|
|
304
309
|
sector: { type: "string" },
|
|
305
310
|
description: { type: "string" },
|
|
311
|
+
programme: { type: "string" },
|
|
306
312
|
answers: { type: "string" },
|
|
307
313
|
"dry-run": { type: "boolean", default: false },
|
|
308
314
|
check: { type: "boolean", default: false },
|
|
@@ -323,6 +329,7 @@ function parseOptions(argv) {
|
|
|
323
329
|
siteUrl: values["site-url"],
|
|
324
330
|
sector: values.sector,
|
|
325
331
|
description: values.description,
|
|
332
|
+
programme: values.programme,
|
|
326
333
|
answers: values.answers,
|
|
327
334
|
dryRun: values["dry-run"] ?? false,
|
|
328
335
|
check: values.check ?? false,
|
|
@@ -419,6 +426,18 @@ import { existsSync as existsSync5, readdirSync as readdirSync3, readFileSync as
|
|
|
419
426
|
import { join as join5 } from "path";
|
|
420
427
|
|
|
421
428
|
// src/adapters.ts
|
|
429
|
+
var GATES = [
|
|
430
|
+
"programme.mjs",
|
|
431
|
+
"prebuild.mjs",
|
|
432
|
+
"check-direction.mjs",
|
|
433
|
+
"tokens.mjs",
|
|
434
|
+
"night-contrast.mjs",
|
|
435
|
+
"facts.mjs",
|
|
436
|
+
"copy-deck.mjs",
|
|
437
|
+
"null-check.mjs",
|
|
438
|
+
"measure.mjs",
|
|
439
|
+
"deploy-preview.mjs"
|
|
440
|
+
];
|
|
422
441
|
function layoutFor(project) {
|
|
423
442
|
const base = project.srcBase;
|
|
424
443
|
const shared = [
|
|
@@ -429,7 +448,9 @@ function layoutFor(project) {
|
|
|
429
448
|
{ template: "shared/tests/seo/graph.test.ts", dest: "tests/seo/graph.test.ts" },
|
|
430
449
|
{ template: "shared/tests/house.test.ts", dest: "tests/house.test.ts" },
|
|
431
450
|
{ template: "shared/lib/consent.ts", dest: `${base}lib/consent.ts` },
|
|
432
|
-
{ template: "shared/lib/legal.ts", dest: `${base}lib/legal.ts` }
|
|
451
|
+
{ template: "shared/lib/legal.ts", dest: `${base}lib/legal.ts` },
|
|
452
|
+
{ template: "shared/docs/site-programme.md", dest: "docs/site-programme.md" },
|
|
453
|
+
...GATES.map((g) => ({ template: `shared/scripts/gates/${g}`, dest: `scripts/gates/${g}` }))
|
|
433
454
|
];
|
|
434
455
|
const siteKeys = {
|
|
435
456
|
facts: "site.facts.ts",
|
|
@@ -724,6 +745,40 @@ function renderRedirects() {
|
|
|
724
745
|
return `${JSON.stringify({ $schema: "./node_modules/@domandigital/seo/redirects.schema.json", redirects: [] }, null, 2)}
|
|
725
746
|
`;
|
|
726
747
|
}
|
|
748
|
+
function renderProgramme(a, project) {
|
|
749
|
+
const base = project.srcBase;
|
|
750
|
+
const source = base ? [base.replace(/\/$/, "")] : ["app", "components", "lib", "content"];
|
|
751
|
+
const host = a.stack.host === "cloudflare" || a.stack.host === "vercel" ? a.stack.host : null;
|
|
752
|
+
const programme = {
|
|
753
|
+
$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.",
|
|
754
|
+
issue: a.programme,
|
|
755
|
+
registeredDirection: null,
|
|
756
|
+
paths: {
|
|
757
|
+
tokens: `${base}styles/tokens.css`,
|
|
758
|
+
deck: `${base}content/deck.ts`,
|
|
759
|
+
deckMarkdown: "docs/copy-deck.md",
|
|
760
|
+
nullCheck: "docs/null-check.md",
|
|
761
|
+
source
|
|
762
|
+
},
|
|
763
|
+
measure: { pages: ["/"], minFontPx: 12, labels: null, port: 4410 },
|
|
764
|
+
nullCheck: { harvest: null, justified: {} },
|
|
765
|
+
facts: { importer: null },
|
|
766
|
+
preview: { host }
|
|
767
|
+
};
|
|
768
|
+
return `${JSON.stringify(programme, null, 2)}
|
|
769
|
+
`;
|
|
770
|
+
}
|
|
771
|
+
function renderSheets() {
|
|
772
|
+
const inks = { ink: null, "ink-2": null, "ink-3": null, rule: null, "accent-soft": null };
|
|
773
|
+
const sheets = {
|
|
774
|
+
$comment: "The day side's ground and accent are art-direction.json's choices. Every other colour, and the whole night side, is decided here in Stage 05 with a reason in because, and measured by scripts/gates/night-contrast.mjs before every build.",
|
|
775
|
+
light: inks,
|
|
776
|
+
night: { ground: null, accent: null, ...inks },
|
|
777
|
+
because: null
|
|
778
|
+
};
|
|
779
|
+
return `${JSON.stringify(sheets, null, 2)}
|
|
780
|
+
`;
|
|
781
|
+
}
|
|
727
782
|
|
|
728
783
|
// src/versions.ts
|
|
729
784
|
var HOUSE_DEPENDENCIES = {
|
|
@@ -731,9 +786,13 @@ var HOUSE_DEPENDENCIES = {
|
|
|
731
786
|
"@domandigital/seo": "^0.3.0"
|
|
732
787
|
};
|
|
733
788
|
var HOUSE_DEV_DEPENDENCIES = {
|
|
734
|
-
"@domandigital/craft": "^0.
|
|
789
|
+
"@domandigital/craft": "^0.19.0",
|
|
735
790
|
"@types/node": "^22.0.0",
|
|
736
|
-
vitest: "^4.1.11"
|
|
791
|
+
vitest: "^4.1.11",
|
|
792
|
+
// scripts/gates/measure.mjs renders the pages at 1440 and 390 before every
|
|
793
|
+
// preview deploy; tsx loads the copy deck on Node older than 22.18.
|
|
794
|
+
playwright: "^1.62.0",
|
|
795
|
+
tsx: "^4.20.0"
|
|
737
796
|
};
|
|
738
797
|
var ACTIONS = {
|
|
739
798
|
checkout: "actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1",
|
|
@@ -1067,6 +1126,14 @@ function hasWorkflows(root) {
|
|
|
1067
1126
|
const dir = join5(root, ".github", "workflows");
|
|
1068
1127
|
return existsSync5(dir) && readdirSync3(dir).some((f) => /\.ya?ml$/.test(f));
|
|
1069
1128
|
}
|
|
1129
|
+
function programmeIssueIn(root) {
|
|
1130
|
+
try {
|
|
1131
|
+
const issue = JSON.parse(readFileSync5(join5(root, "site.programme.json"), "utf8")).issue;
|
|
1132
|
+
return typeof issue === "string" && issue ? issue : null;
|
|
1133
|
+
} catch {
|
|
1134
|
+
return null;
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1070
1137
|
function actionFor(root, path, contents, data, force) {
|
|
1071
1138
|
const abs = join5(root, path);
|
|
1072
1139
|
if (!existsSync5(abs)) return "create";
|
|
@@ -1101,8 +1168,13 @@ function planScaffold(project, answers, options) {
|
|
|
1101
1168
|
{ path: "docs/DIRECTION.md", contents: renderDirection(answers, options.today), data: true },
|
|
1102
1169
|
{ path: "docs/seo-launch-checklist.md", contents: renderChecklist(answers), data: true },
|
|
1103
1170
|
{ path: "docs/seo-baseline.md", contents: renderBaseline(answers, options.today), data: true },
|
|
1104
|
-
{ path: "docs/client-facts.entry.json", contents: renderStackEntry(answers, project.framework, options.today), data: true }
|
|
1171
|
+
{ path: "docs/client-facts.entry.json", contents: renderStackEntry(answers, project.framework, options.today), data: true },
|
|
1172
|
+
{ path: "site.programme.json", contents: renderProgramme(answers, project), data: true },
|
|
1173
|
+
{ path: "art-direction.sheets.json", contents: renderSheets(), data: true }
|
|
1105
1174
|
);
|
|
1175
|
+
if (!answers.programme && !programmeIssueIn(root)) {
|
|
1176
|
+
notes.push("site.programme.json names no programme issue, so the build refuses to run. Open the programme from the Site programme template in Linear and put its id in issue.");
|
|
1177
|
+
}
|
|
1106
1178
|
const workflowPath = ".github/workflows/seo-check.yml";
|
|
1107
1179
|
const workflow = renderWorkflow(project, options.visibility ?? "private");
|
|
1108
1180
|
if (existsSync5(join5(root, workflowPath)) || workflow && !hasWorkflows(root)) {
|
|
@@ -1119,7 +1191,15 @@ function planScaffold(project, answers, options) {
|
|
|
1119
1191
|
const pkg = patchPackageJson(
|
|
1120
1192
|
project.packageJson,
|
|
1121
1193
|
{
|
|
1122
|
-
scripts: {
|
|
1194
|
+
scripts: {
|
|
1195
|
+
"seo:check": "vitest run tests/seo tests/house.test.ts",
|
|
1196
|
+
"launch:check": "vitest run tests --mode launch",
|
|
1197
|
+
prebuild: "node scripts/gates/prebuild.mjs",
|
|
1198
|
+
tokens: "node scripts/gates/tokens.mjs && node scripts/gates/night-contrast.mjs",
|
|
1199
|
+
deck: "node scripts/gates/copy-deck.mjs",
|
|
1200
|
+
measure: "node scripts/gates/measure.mjs --serve",
|
|
1201
|
+
"deploy:preview": "node scripts/gates/deploy-preview.mjs"
|
|
1202
|
+
},
|
|
1123
1203
|
scriptsIfMissing: { test: "vitest run" },
|
|
1124
1204
|
dependencies: options.skipInstall ? { ...HOUSE_DEPENDENCIES } : {},
|
|
1125
1205
|
devDependencies: options.skipInstall ? { ...HOUSE_DEV_DEPENDENCIES } : {}
|
|
@@ -1239,7 +1319,8 @@ ${USAGE}`);
|
|
|
1239
1319
|
tradingName: options.tradingName,
|
|
1240
1320
|
siteUrl: options.siteUrl,
|
|
1241
1321
|
sector: options.sector,
|
|
1242
|
-
description: options.description
|
|
1322
|
+
description: options.description,
|
|
1323
|
+
programme: options.programme
|
|
1243
1324
|
},
|
|
1244
1325
|
file: options.answers,
|
|
1245
1326
|
cwd: io.cwd,
|
|
@@ -1275,6 +1356,9 @@ ${work.map((w) => ` ${w}`).join("\n")}`);
|
|
|
1275
1356
|
" Fill in legal in site.facts.ts and have the client confirm the legal pages match what the business does.",
|
|
1276
1357
|
" 3. Work through docs/seo-launch-checklist.md.",
|
|
1277
1358
|
` 4. ${pm} seo:check now, and ${pm} launch:check before go-live.`,
|
|
1359
|
+
" 5. The build runs the site programme's gates (docs/site-programme.md) and refuses until the",
|
|
1360
|
+
" programme issue, the Stage 05 direction and both sides of the sheet, and the Stage 06 copy deck exist.",
|
|
1361
|
+
` Preview deploys go through ${pm} deploy:preview only; it measures at 1440 and 390 first.`,
|
|
1278
1362
|
...pending.map((p) => ` Still to run: ${p}`)
|
|
1279
1363
|
].join("\n")
|
|
1280
1364
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domandigital/create-site",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.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",
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
"@types/node": "^20.17.0",
|
|
41
41
|
"tsup": "^8.3.5",
|
|
42
42
|
"typescript": "^5.6.3",
|
|
43
|
-
"vitest": "^
|
|
44
|
-
"@domandigital/craft": "^0.18.0",
|
|
43
|
+
"vitest": "^4.0.0",
|
|
45
44
|
"@domandigital/graph": "^0.7.0",
|
|
46
|
-
"@domandigital/seo": "^0.3.1"
|
|
45
|
+
"@domandigital/seo": "^0.3.1",
|
|
46
|
+
"@domandigital/craft": "^0.19.0"
|
|
47
47
|
},
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public",
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# The site programme
|
|
2
|
+
|
|
3
|
+
Every Doman Digital site is made, or rearchitected, in ten stages. The process
|
|
4
|
+
ran first on the Doman Digital redesign (DOM-392, stages DOM-393 to DOM-402)
|
|
5
|
+
and was made the house way on 10 October 2026 (DOM-647). It is held in place by
|
|
6
|
+
structure and by code, never by memory:
|
|
7
|
+
|
|
8
|
+
- **In Linear**, the "Site programme" template on the DOM team opens the
|
|
9
|
+
programme issue with the ten stages as its children. A parent with an open
|
|
10
|
+
child cannot be closed (the nightly enforcer reopens it), so a site cannot
|
|
11
|
+
be finished with a stage skipped. The `new-client-build` skill opens it
|
|
12
|
+
first and will not scaffold before Stage 05 is accepted.
|
|
13
|
+
- **In this repo**, the gates under `scripts/gates/` run before every build
|
|
14
|
+
and before every preview deploy. A gate that fails stops the build and names
|
|
15
|
+
its stage.
|
|
16
|
+
|
|
17
|
+
This file is a house file: `create-site --check` reports it when it differs
|
|
18
|
+
from the template. The site's own answers live in `site.programme.json`,
|
|
19
|
+
`art-direction.json` and `art-direction.sheets.json`, which are never
|
|
20
|
+
replaced.
|
|
21
|
+
|
|
22
|
+
## Working rules
|
|
23
|
+
|
|
24
|
+
- Every stage has a deliverable, a review and a recorded exit decision.
|
|
25
|
+
- One rendered artefact per stage exit.
|
|
26
|
+
- Decisions go to a register, never a chat.
|
|
27
|
+
- Governed facts are imported, never retyped.
|
|
28
|
+
- The live site is untouched until Stage 09.
|
|
29
|
+
- A gate is a script that blocks the build, never a reminder
|
|
30
|
+
(`docs/ops/time-tracking.md` in Doman-Digital for why: the one control that
|
|
31
|
+
needed a person to start it was never used once).
|
|
32
|
+
|
|
33
|
+
A stage issue moves to Done only with its deliverable linked and its exit
|
|
34
|
+
acceptance recorded on the issue: the artefact and version, the evidence and
|
|
35
|
+
its limits, the reviewer, the decision and date. Creating the issue or drafting
|
|
36
|
+
a file is not acceptance.
|
|
37
|
+
|
|
38
|
+
## The ten stages and their gates
|
|
39
|
+
|
|
40
|
+
| Stage | Deliverable | Exit | Gate in code |
|
|
41
|
+
| --- | --- | --- | --- |
|
|
42
|
+
| 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
|
+
| 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, desktop and mobile | A versioned wireframe set covering every page family, annotated with evidence, destination and holds | Hierarchy and journey coverage accepted; missing proof is an obvious placeholder | None: wireframes are reviewed, not built |
|
|
45
|
+
| 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
|
+
| 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 and 1440 | Design and content accepted at an exact version; no invented price or claim in the deck | `facts.mjs`, `copy-deck.mjs`, `null-check.mjs`, `measure.mjs`, `deploy-preview.mjs` |
|
|
48
|
+
| 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
|
+
| 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
|
+
| 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 |
|
|
51
|
+
| 10 Launch safely, measure, record what was learned | Release record, rollback reference, live checks, the observation-window review, lessons | Live checks pass; follow-ups have owners; the learning is recorded | `docs/seo-baseline.md` at 90 days, 6 and 12 months |
|
|
52
|
+
|
|
53
|
+
## The gates
|
|
54
|
+
|
|
55
|
+
Run in this order by `scripts/gates/prebuild.mjs` before every build. The first
|
|
56
|
+
failure stops the build.
|
|
57
|
+
|
|
58
|
+
| Gate | Stage | Reads | Fails when |
|
|
59
|
+
| --- | --- | --- | --- |
|
|
60
|
+
| `check-direction.mjs` | 05 | `art-direction.json`, the registered copy named in `site.programme.json` | the file is missing, craft finds it invalid, a layer is undecided, or it differs from the registered copy in the craft estate |
|
|
61
|
+
| `tokens.mjs` | 05 | `art-direction.json`, `art-direction.sheets.json` | a day or night value is still null, or the night side has no reason. Writes the token stylesheet (`paths.tokens`), both sides of the sheet |
|
|
62
|
+
| `night-contrast.mjs` | 05 | the token stylesheet | a text pair falls under 4.5:1 by day or by night |
|
|
63
|
+
| `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
|
+
| `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
|
+
| `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 |
|
|
66
|
+
|
|
67
|
+
Run around a running build:
|
|
68
|
+
|
|
69
|
+
| Gate | Stage | Fails when |
|
|
70
|
+
| --- | --- | --- |
|
|
71
|
+
| `measure.mjs` | 06 | a page in `measure.pages` does not answer, scrolls sideways, or shows text under `measure.minFontPx` at 1440 or 390; a label in `measure.labels` leaves its container or covers a label or copy; with `--preview`, a page has no noindex |
|
|
72
|
+
| `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
|
+
|
|
74
|
+
The site reads `PUBLIC_PREVIEW` (Astro, `import.meta.env.PUBLIC_PREVIEW`) or
|
|
75
|
+
`NEXT_PUBLIC_PREVIEW` (Next) to add `<meta name="robots" content="noindex">`
|
|
76
|
+
and to hold anything that must not run on a preview, such as a live form
|
|
77
|
+
handler. The measurement fails a preview that does not.
|
|
78
|
+
|
|
79
|
+
## The governed-facts importer
|
|
80
|
+
|
|
81
|
+
`site.facts.ts` is the governed source for the business's own facts, and pages
|
|
82
|
+
import it. When a figure is governed somewhere else (a price list in another
|
|
83
|
+
repo, a contract schedule), the site gets an importer: a script that reads the
|
|
84
|
+
governed modules and writes `src/generated/facts.json` before every build,
|
|
85
|
+
named in `site.programme.json` as `facts.importer`. The pages read the
|
|
86
|
+
generated file and nothing else, so a price on the site is always the price
|
|
87
|
+
the governed file holds. `apps/site/scripts/facts.ts` in Doman-Digital is the
|
|
88
|
+
worked example: it imports `docs/brand-facts.json` and the marketing app's
|
|
89
|
+
pricing modules and writes the facts the redesign renders.
|
|
90
|
+
|
|
91
|
+
## site.programme.json
|
|
92
|
+
|
|
93
|
+
| Key | What it is |
|
|
94
|
+
| --- | --- |
|
|
95
|
+
| `issue` | The programme issue in Linear (`DOM-123`) |
|
|
96
|
+
| `registeredDirection` | The direction's registered copy in the craft estate, usually `~/dd-ops/<site>/art-direction.json`; null until registered |
|
|
97
|
+
| `paths` | Where the token stylesheet, the deck, the rendered deck and the null-check report live, and the source folders `facts.mjs` reads |
|
|
98
|
+
| `measure` | `pages`, `minFontPx` (12), `labels` (`{ "selector": ".label", "within": ".screen" }` or null), `port` |
|
|
99
|
+
| `nullCheck` | `harvest` (a path, `~/` allowed) and `justified` (phrase to reason) |
|
|
100
|
+
| `facts` | `importer`: the site's importer script, or null |
|
|
101
|
+
| `preview` | `host`: `cloudflare` or `vercel`, or null to find it from the config |
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Stage 05 gate: the visual direction is decided before anything is built on
|
|
2
|
+
// it. Refuses the build when art-direction.json is missing, when craft does
|
|
3
|
+
// not find it valid, or when a layer is still undecided (the job, every
|
|
4
|
+
// declared page's hierarchy, at least five of the seven tokens). Then, when
|
|
5
|
+
// site.programme.json names a registered copy (the one in the craft estate on
|
|
6
|
+
// the work box), the two must match byte for byte, so a change made in one
|
|
7
|
+
// place reaches the other on purpose. Off the work box the registered copy is
|
|
8
|
+
// absent and the gate says so and passes on the site's own copy.
|
|
9
|
+
//
|
|
10
|
+
// Lifted from apps/site/scripts/check-direction.mjs in Doman-Digital (DOM-647).
|
|
11
|
+
|
|
12
|
+
import { spawnSync } from "node:child_process";
|
|
13
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
14
|
+
import { join } from "node:path";
|
|
15
|
+
import { craftBin, programme, root, sitePath, stop } from "./programme.mjs";
|
|
16
|
+
|
|
17
|
+
const GATE = "check-direction";
|
|
18
|
+
const file = join(root, "art-direction.json");
|
|
19
|
+
if (!existsSync(file)) stop(GATE, "05", "no art-direction.json. Run craft direction init, then decide the job, the hierarchy and the tokens with their reasons.");
|
|
20
|
+
|
|
21
|
+
const bin = craftBin();
|
|
22
|
+
if (!bin) stop(GATE, "05", "@domandigital/craft is not installed, so the direction cannot be validated. Install the site's dependencies.");
|
|
23
|
+
|
|
24
|
+
const run = spawnSync(process.execPath, [bin, "direction", "validate", "--json"], { cwd: root, encoding: "utf8" });
|
|
25
|
+
let report;
|
|
26
|
+
try {
|
|
27
|
+
report = JSON.parse(run.stdout);
|
|
28
|
+
} catch {
|
|
29
|
+
stop(GATE, "05", `craft direction validate did not report: ${(run.stderr || run.stdout).trim()}`);
|
|
30
|
+
}
|
|
31
|
+
const errors = report.problems.filter((p) => p.severity === "error");
|
|
32
|
+
if (!report.valid) stop(GATE, "05", `art-direction.json is not valid:\n${errors.map((p) => ` ${p.at || "(file)"} ${p.message}`).join("\n")}`);
|
|
33
|
+
if (!report.layers.complete) {
|
|
34
|
+
const l = report.layers;
|
|
35
|
+
const pages = l.hierarchy.map((h) => `${h.page} ${h.decided} of ${h.total}`).join(", ") || "none";
|
|
36
|
+
stop(GATE, "05", `the direction is not decided yet: job ${l.job ? "decided" : "not decided"}; hierarchy ${pages}; tokens ${l.tokens.decided} of ${l.tokens.total} (five is the least).`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const { registeredDirection } = programme();
|
|
40
|
+
if (!registeredDirection) {
|
|
41
|
+
console.log(`${GATE}: decided; no registered copy named in site.programme.json`);
|
|
42
|
+
} else {
|
|
43
|
+
const registered = sitePath(registeredDirection);
|
|
44
|
+
if (!existsSync(registered)) {
|
|
45
|
+
console.log(`${GATE}: decided; no registered copy on this machine (${registeredDirection}), so the site's copy stands`);
|
|
46
|
+
} else if (readFileSync(file, "utf8") !== readFileSync(registered, "utf8")) {
|
|
47
|
+
stop(GATE, "05", `art-direction.json differs from ${registered}. Copy the newer one over the other and run craft direction validate on it.`);
|
|
48
|
+
} else {
|
|
49
|
+
console.log(`${GATE}: decided, and matches the registered copy`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// Stage 06 gate: every string the site carries lives in one copy deck (the
|
|
2
|
+
// TypeScript module site.programme.json names in paths.deck), and this
|
|
3
|
+
// renders it to one Markdown document in page order, so copy-check and a
|
|
4
|
+
// reviewer read the whole site in one place. `--check` fails when the deck is
|
|
5
|
+
// missing, empty, or newer than the committed document: copy that has not
|
|
6
|
+
// been through the deck has not been through the gates. Without --check it
|
|
7
|
+
// writes the document.
|
|
8
|
+
//
|
|
9
|
+
// Lifted from apps/site/scripts/copy-deck.mjs in Doman-Digital (DOM-647),
|
|
10
|
+
// with the page order taken from the deck itself instead of written out.
|
|
11
|
+
|
|
12
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
13
|
+
import { dirname } from "node:path";
|
|
14
|
+
import { pathToFileURL } from "node:url";
|
|
15
|
+
import { programme, sitePath, stop } from "./programme.mjs";
|
|
16
|
+
|
|
17
|
+
const GATE = "copy-deck";
|
|
18
|
+
const check = process.argv.includes("--check");
|
|
19
|
+
const { paths } = programme();
|
|
20
|
+
const source = sitePath(paths.deck);
|
|
21
|
+
const out = sitePath(paths.deckMarkdown);
|
|
22
|
+
if (!existsSync(source)) stop(GATE, "06", `no copy deck at ${paths.deck}. Export \`deck\` from it: one key per page, every string the page shows.`);
|
|
23
|
+
|
|
24
|
+
// Node strips the types from a .ts module from 22.18; before that, tsx if the site has it.
|
|
25
|
+
let mod;
|
|
26
|
+
try {
|
|
27
|
+
mod = await import(pathToFileURL(source).href);
|
|
28
|
+
} catch (error) {
|
|
29
|
+
try {
|
|
30
|
+
const { register } = await import("tsx/esm/api");
|
|
31
|
+
register();
|
|
32
|
+
mod = await import(pathToFileURL(source).href);
|
|
33
|
+
} catch {
|
|
34
|
+
stop(GATE, "06", `could not load ${paths.deck} (${error.message}). Use Node 22.18 or later, or add tsx.`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const deck = mod.deck ?? mod.default;
|
|
38
|
+
if (!deck || typeof deck !== "object" || Object.keys(deck).length === 0) stop(GATE, "06", `${paths.deck} exports no copy. Export \`deck\` with one key per page.`);
|
|
39
|
+
|
|
40
|
+
const lines = [
|
|
41
|
+
"# Copy deck",
|
|
42
|
+
"",
|
|
43
|
+
`Generated from \`${paths.deck}\` by \`scripts/gates/copy-deck.mjs\`. Edit the deck, not this file. Figures are not in the deck: pages read them from the facts.`,
|
|
44
|
+
"",
|
|
45
|
+
];
|
|
46
|
+
const isLink = (v) => v && typeof v === "object" && typeof v.label === "string" && typeof v.href === "string" && Object.keys(v).length <= 3;
|
|
47
|
+
const inline = (v) =>
|
|
48
|
+
isLink(v)
|
|
49
|
+
? `[${v.label}](${v.href})`
|
|
50
|
+
: Array.isArray(v)
|
|
51
|
+
? v.map(inline).join(" · ")
|
|
52
|
+
: v && typeof v === "object"
|
|
53
|
+
? Object.values(v).map(inline).filter(Boolean).join(" · ")
|
|
54
|
+
: v === null || v === undefined || typeof v === "boolean"
|
|
55
|
+
? ""
|
|
56
|
+
: String(v);
|
|
57
|
+
|
|
58
|
+
function render(value, depth) {
|
|
59
|
+
for (const [key, v] of Object.entries(value)) {
|
|
60
|
+
if (v === null || v === undefined || typeof v === "boolean") continue;
|
|
61
|
+
if (Array.isArray(v)) {
|
|
62
|
+
lines.push(`**${key}**`, "", ...v.map((item) => `- ${inline(item)}`), "");
|
|
63
|
+
} else if (isLink(v)) {
|
|
64
|
+
lines.push(`**${key}**: ${inline(v)}`, "");
|
|
65
|
+
} else if (typeof v === "object") {
|
|
66
|
+
lines.push(`${"#".repeat(Math.min(depth, 6))} ${key}`, "");
|
|
67
|
+
render(v, depth + 1);
|
|
68
|
+
} else {
|
|
69
|
+
lines.push(`**${key}**: ${String(v)}`, "");
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
render(deck, 2);
|
|
74
|
+
|
|
75
|
+
const text = `${lines.join("\n").replace(/\n{3,}/g, "\n\n").trimEnd()}\n`;
|
|
76
|
+
if (check) {
|
|
77
|
+
const current = existsSync(out) ? readFileSync(out, "utf8") : "";
|
|
78
|
+
if (current !== text) stop(GATE, "06", `${paths.deckMarkdown} is not the current deck. Run the deck script, read it, and put it through copy-check.`);
|
|
79
|
+
console.log(`${GATE}: ${paths.deckMarkdown} is current`);
|
|
80
|
+
} else {
|
|
81
|
+
mkdirSync(dirname(out), { recursive: true });
|
|
82
|
+
writeFileSync(out, text);
|
|
83
|
+
console.log(`${GATE}: ${paths.deckMarkdown} written`);
|
|
84
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Stages 06 to 08: the only deploy this site has until the Stage 09 release
|
|
2
|
+
// decision, and it can only make a preview. It sets PUBLIC_PREVIEW=1 (and
|
|
3
|
+
// NEXT_PUBLIC_PREVIEW=1) itself, so nobody has to remember to; builds, which
|
|
4
|
+
// runs every build gate; serves the build locally and measures it at 1440 and
|
|
5
|
+
// 390 with --preview (noindex required); and only then deploys, preview only:
|
|
6
|
+
//
|
|
7
|
+
// cloudflare wrangler deploy, refused while the wrangler config carries a
|
|
8
|
+
// route, a custom domain or workers_dev: false
|
|
9
|
+
// vercel vercel deploy, never --prod
|
|
10
|
+
//
|
|
11
|
+
// The host is preview.host in site.programme.json, or found from the
|
|
12
|
+
// wrangler config or .vercel/project.json. Going live is a separate,
|
|
13
|
+
// recorded decision in Stage 09; nothing here can do it. --dry-run does
|
|
14
|
+
// everything but the deploy.
|
|
15
|
+
//
|
|
16
|
+
// Lifted from the build:preview and deploy:preview scripts and wrangler.jsonc
|
|
17
|
+
// of apps/site in Doman-Digital (DOM-647).
|
|
18
|
+
|
|
19
|
+
import { spawnSync } from "node:child_process";
|
|
20
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
21
|
+
import { join } from "node:path";
|
|
22
|
+
import { programme, root, stop } from "./programme.mjs";
|
|
23
|
+
|
|
24
|
+
const GATE = "deploy-preview";
|
|
25
|
+
if (process.argv.includes("--prod")) stop(GATE, "09", "this script never deploys to production. Going live is the Stage 09 release decision.");
|
|
26
|
+
const dryRun = process.argv.includes("--dry-run");
|
|
27
|
+
const { preview = {} } = programme();
|
|
28
|
+
const env = { ...process.env, PUBLIC_PREVIEW: "1", NEXT_PUBLIC_PREVIEW: "1" };
|
|
29
|
+
const bin = (name) => join(root, "node_modules", ".bin", name);
|
|
30
|
+
|
|
31
|
+
const wranglerFile = ["wrangler.jsonc", "wrangler.json", "wrangler.toml"].find((f) => existsSync(join(root, f)));
|
|
32
|
+
const host = preview.host ?? (wranglerFile ? "cloudflare" : existsSync(join(root, ".vercel", "project.json")) ? "vercel" : null);
|
|
33
|
+
if (!host) stop(GATE, "06", "no preview host. Set preview.host in site.programme.json to cloudflare or vercel.");
|
|
34
|
+
|
|
35
|
+
if (host === "cloudflare") {
|
|
36
|
+
if (!wranglerFile) stop(GATE, "06", "preview.host is cloudflare but there is no wrangler config.");
|
|
37
|
+
// Comments out, so a commented-out route still counts as no route.
|
|
38
|
+
const text = readFileSync(join(root, wranglerFile), "utf8").replace(/^\s*(\/\/|#).*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
|
|
39
|
+
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
|
+
if (/custom_domain/.test(text)) stop(GATE, "06", `${wranglerFile} carries a custom domain. A preview has none.`);
|
|
41
|
+
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 if (host !== "vercel") {
|
|
43
|
+
stop(GATE, "06", `preview.host is ${host}; this script knows cloudflare and vercel.`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// The package manager that ran this script, so the build is the one `build` names.
|
|
47
|
+
const pm = process.env.npm_execpath;
|
|
48
|
+
const build = pm ? spawnSync(process.execPath, [pm, "run", "build"], { cwd: root, env, stdio: "inherit" }) : spawnSync("npm", ["run", "build"], { cwd: root, env, stdio: "inherit" });
|
|
49
|
+
if (build.status !== 0) stop(GATE, "06", "the preview build failed. Nothing was deployed.");
|
|
50
|
+
|
|
51
|
+
const measured = spawnSync(process.execPath, [join(root, "scripts", "gates", "measure.mjs"), "--serve", "--preview"], { cwd: root, env, stdio: "inherit" });
|
|
52
|
+
if (measured.status !== 0) stop(GATE, "06", "the measurement failed. Nothing was deployed.");
|
|
53
|
+
|
|
54
|
+
if (dryRun) {
|
|
55
|
+
console.log(`${GATE}: built and measured; --dry-run, so nothing was deployed.`);
|
|
56
|
+
process.exit(0);
|
|
57
|
+
}
|
|
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" });
|
|
62
|
+
if (deploy.status !== 0) stop(GATE, "06", `the ${host} deploy failed.`);
|
|
63
|
+
console.log(`${GATE}: measured and deployed to a ${host} preview. The live site is untouched.`);
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Stage 06 gate: governed facts are imported, never retyped. A price, a term
|
|
2
|
+
// or a response target a visitor reads comes from site.facts.ts, or from a
|
|
3
|
+
// generated file an importer writes from the governed source before every
|
|
4
|
+
// build (site.programme.json facts.importer: the site's own script, run
|
|
5
|
+
// first). This fails on a pound sign followed by digits, a response target
|
|
6
|
+
// in hours or days, a minimum term or a notice period typed anywhere in the
|
|
7
|
+
// site's source or its copy deck, so a figure typed by hand cannot ship.
|
|
8
|
+
//
|
|
9
|
+
// Lifted from apps/site/scripts/facts.ts and tests/facts.test.mjs in
|
|
10
|
+
// Doman-Digital (DOM-647).
|
|
11
|
+
|
|
12
|
+
import { spawnSync } from "node:child_process";
|
|
13
|
+
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
14
|
+
import { join, relative } from "node:path";
|
|
15
|
+
import { programme, root, sitePath, stop } from "./programme.mjs";
|
|
16
|
+
|
|
17
|
+
const GATE = "facts";
|
|
18
|
+
const { paths, facts = {} } = programme();
|
|
19
|
+
|
|
20
|
+
if (facts.importer) {
|
|
21
|
+
const importer = sitePath(facts.importer);
|
|
22
|
+
if (!existsSync(importer)) stop(GATE, "06", `the importer ${facts.importer} named in site.programme.json does not exist.`);
|
|
23
|
+
const args = importer.endsWith(".ts") ? ["--import", "tsx", importer] : [importer];
|
|
24
|
+
const run = spawnSync(process.execPath, args, { cwd: root, stdio: "inherit" });
|
|
25
|
+
if (run.status !== 0) stop(GATE, "06", `the importer ${facts.importer} failed, so the generated facts are not current.`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const patterns = [
|
|
29
|
+
{ name: "a pound figure", re: /£\s?\d/ },
|
|
30
|
+
{ name: "a response target in hours", re: /within \d+ (hours?|business hours)/i },
|
|
31
|
+
{ name: "a response target in days", re: /within \d+ (UK )?(business |working )?days?/i },
|
|
32
|
+
{ name: "a minimum term", re: /\d+[- ]months? minimum/i },
|
|
33
|
+
{ name: "a notice period", re: /\d+ days['’]? notice/i },
|
|
34
|
+
];
|
|
35
|
+
const SKIP_DIRS = new Set(["generated", "node_modules", ".next", ".astro", "dist"]);
|
|
36
|
+
const walk = (dir) =>
|
|
37
|
+
readdirSync(dir).flatMap((f) => {
|
|
38
|
+
const p = join(dir, f);
|
|
39
|
+
if (statSync(p).isDirectory()) return SKIP_DIRS.has(f) ? [] : walk(p);
|
|
40
|
+
return [p];
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const files = new Set();
|
|
44
|
+
for (const dir of paths.source) {
|
|
45
|
+
const abs = sitePath(dir);
|
|
46
|
+
if (existsSync(abs)) for (const f of walk(abs)) if (/\.(astro|tsx?|jsx?|mjs|mdx?|css)$/.test(f)) files.add(f);
|
|
47
|
+
}
|
|
48
|
+
if (existsSync(sitePath(paths.deck))) files.add(sitePath(paths.deck));
|
|
49
|
+
|
|
50
|
+
const offenders = [];
|
|
51
|
+
for (const file of files) {
|
|
52
|
+
if (relative(root, file) === "site.facts.ts") continue;
|
|
53
|
+
const lines = readFileSync(file, "utf8").split("\n");
|
|
54
|
+
lines.forEach((line, i) => {
|
|
55
|
+
if (line.includes("facts-ok")) return;
|
|
56
|
+
for (const { name, re } of patterns) {
|
|
57
|
+
const m = line.match(re);
|
|
58
|
+
if (m) offenders.push(` ${relative(root, file)}:${i + 1}: ${name} (${m[0]})`);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
if (offenders.length) {
|
|
63
|
+
stop(GATE, "06", `typed figures found. Read each from site.facts.ts (or the generated facts) instead; a genuine non-claim takes facts-ok on its line.\n${offenders.join("\n")}`);
|
|
64
|
+
}
|
|
65
|
+
console.log(`${GATE}: ${files.size} files carry no typed price, term or response target`);
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// Stage 06 gate: measures the rendered pages at 1440 x 900 and 390 x 844,
|
|
2
|
+
// the two widths the design is accepted at, rather than trusting the
|
|
3
|
+
// stylesheet. On every page named in site.programme.json measure.pages, at
|
|
4
|
+
// both widths: the page answers, nothing scrolls sideways, no visible text is
|
|
5
|
+
// smaller than measure.minFontPx, and, when measure.labels names them, every
|
|
6
|
+
// label sits inside its container, over no other label and no copy. With
|
|
7
|
+
// --preview, every page must also carry a noindex robots meta, so a preview
|
|
8
|
+
// cannot be indexed. Writes measure/measure.json, with the hash of the
|
|
9
|
+
// direction it measured, and a full-page capture per page and width under
|
|
10
|
+
// measure/out. Exits 1 on any failure.
|
|
11
|
+
//
|
|
12
|
+
// --serve serves the last build itself and measures that: static output in
|
|
13
|
+
// dist/ is served from here the way the host serves it (no trailing slash,
|
|
14
|
+
// the 404 page for anything missing); a Next build runs next start.
|
|
15
|
+
// deploy-preview.mjs runs `--serve --preview` before every preview deploy.
|
|
16
|
+
// --base <url> measures a server that is already running instead.
|
|
17
|
+
//
|
|
18
|
+
// Lifted from apps/site/scripts/measure.mjs in Doman-Digital (DOM-647), with
|
|
19
|
+
// the redesign's own label component generalised to a selector.
|
|
20
|
+
|
|
21
|
+
import { spawn } from "node:child_process";
|
|
22
|
+
import { createHash } from "node:crypto";
|
|
23
|
+
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
24
|
+
import { createServer } from "node:http";
|
|
25
|
+
import { extname, join } from "node:path";
|
|
26
|
+
import { parseArgs } from "node:util";
|
|
27
|
+
import { programme, root, sitePath, stop } from "./programme.mjs";
|
|
28
|
+
|
|
29
|
+
const GATE = "measure";
|
|
30
|
+
const { values } = parseArgs({ options: { base: { type: "string" }, serve: { type: "boolean", default: false }, preview: { type: "boolean", default: false } } });
|
|
31
|
+
const { measure = {}, paths } = programme();
|
|
32
|
+
const port = measure.port ?? 4410;
|
|
33
|
+
const base = (values.base ?? `http://127.0.0.1:${port}`).replace(/\/$/, "");
|
|
34
|
+
const pages = measure.pages?.length ? measure.pages : ["/"];
|
|
35
|
+
const minFontPx = measure.minFontPx ?? 12;
|
|
36
|
+
const labels = measure.labels ?? null;
|
|
37
|
+
const outDir = join(root, "measure", "out");
|
|
38
|
+
mkdirSync(outDir, { recursive: true });
|
|
39
|
+
|
|
40
|
+
let chromium;
|
|
41
|
+
try {
|
|
42
|
+
({ chromium } = await import("playwright"));
|
|
43
|
+
} catch {
|
|
44
|
+
stop(GATE, "06", "playwright is not installed. Add it as a dev dependency and run `npx playwright install chromium`.");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const close = values.serve ? await serveBuild() : () => {};
|
|
48
|
+
|
|
49
|
+
const hash = (p) => (existsSync(p) ? createHash("sha256").update(readFileSync(p)).digest("hex").slice(0, 16) : null);
|
|
50
|
+
const slug = (route) => (route === "/" ? "home" : route.replace(/^\//, "").replace(/\//g, "-"));
|
|
51
|
+
const VIEWPORTS = [
|
|
52
|
+
{ name: "1440x900", viewport: { width: 1440, height: 900 } },
|
|
53
|
+
{ name: "390x844", viewport: { width: 390, height: 844 }, deviceScaleFactor: 2, isMobile: true },
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
const browser = await chromium.launch();
|
|
57
|
+
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: {} };
|
|
59
|
+
|
|
60
|
+
for (const route of pages) {
|
|
61
|
+
res.pages[route] = {};
|
|
62
|
+
for (const { name, ...options } of VIEWPORTS) {
|
|
63
|
+
const context = await browser.newContext(options);
|
|
64
|
+
const page = await context.newPage();
|
|
65
|
+
const resp = await page.goto(base + route).catch((error) => ({ ok: () => false, status: () => error.message }));
|
|
66
|
+
if (!resp || !resp.ok()) {
|
|
67
|
+
res.pages[route][name] = { error: `HTTP ${resp?.status()}` };
|
|
68
|
+
failures.push(`${route} at ${name}: HTTP ${resp?.status()}`);
|
|
69
|
+
await context.close();
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
await page.evaluate(() => document.fonts.ready);
|
|
73
|
+
await settle(page);
|
|
74
|
+
const m = await page.evaluate(
|
|
75
|
+
({ labels, minFontPx }) => {
|
|
76
|
+
const R = (e) => {
|
|
77
|
+
const r = e.getBoundingClientRect();
|
|
78
|
+
return { l: r.left, t: r.top, r: r.right, b: r.bottom };
|
|
79
|
+
};
|
|
80
|
+
const ov = (a, b) => !(a.r <= b.l || b.r <= a.l || a.b <= b.t || b.b <= a.t);
|
|
81
|
+
const shown = (e) => {
|
|
82
|
+
const s = getComputedStyle(e);
|
|
83
|
+
return s.display !== "none" && s.visibility !== "hidden" && e.getClientRects().length > 0;
|
|
84
|
+
};
|
|
85
|
+
// Text an element shows itself, not text it inherits from a child.
|
|
86
|
+
const texty = [...document.querySelectorAll("body *")].filter(
|
|
87
|
+
(e) => shown(e) && [...e.childNodes].some((n) => n.nodeType === 3 && n.textContent.trim()) && !e.closest("[aria-hidden='true'], .sr-only, .visually-hidden"),
|
|
88
|
+
);
|
|
89
|
+
const small = texty
|
|
90
|
+
.map((e) => ({ tag: e.tagName.toLowerCase(), cls: String(e.className || ""), px: parseFloat(getComputedStyle(e).fontSize), text: e.textContent.trim().slice(0, 40) }))
|
|
91
|
+
.filter((t) => t.px < minFontPx);
|
|
92
|
+
const out = {
|
|
93
|
+
horizontalScroll: document.documentElement.scrollWidth > window.innerWidth,
|
|
94
|
+
fontSizesUsed: [...new Set(texty.map((e) => getComputedStyle(e).fontSize))].sort((a, b) => parseFloat(a) - parseFloat(b)),
|
|
95
|
+
smallText: small.slice(0, 10),
|
|
96
|
+
noindex: /noindex/i.test(document.querySelector('meta[name="robots"]')?.getAttribute("content") ?? ""),
|
|
97
|
+
labels: [],
|
|
98
|
+
};
|
|
99
|
+
if (labels?.selector) {
|
|
100
|
+
const all = [...document.querySelectorAll(labels.selector)].filter(shown);
|
|
101
|
+
const copy = [...document.querySelectorAll("main h1, main h2, main h3, main p, main li")].filter(shown);
|
|
102
|
+
for (const l of all) {
|
|
103
|
+
const r = R(l);
|
|
104
|
+
const box = labels.within ? l.parentElement?.closest(labels.within) : null;
|
|
105
|
+
const b = box ? R(box) : null;
|
|
106
|
+
out.labels.push({
|
|
107
|
+
text: l.textContent.trim().slice(0, 40),
|
|
108
|
+
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,
|
|
109
|
+
overLabels: all.filter((o) => o !== l && ov(r, R(o))).length,
|
|
110
|
+
overCopy: copy.filter((t) => !l.contains(t) && !t.contains(l) && ov(r, R(t))).length,
|
|
111
|
+
fontPx: parseFloat(getComputedStyle(l).fontSize),
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return out;
|
|
116
|
+
},
|
|
117
|
+
{ labels, minFontPx },
|
|
118
|
+
);
|
|
119
|
+
const at = `${route} at ${name}`;
|
|
120
|
+
if (m.horizontalScroll) failures.push(`${at}: the page scrolls sideways`);
|
|
121
|
+
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}")`);
|
|
122
|
+
for (const l of m.labels) {
|
|
123
|
+
if (l.inside === false) failures.push(`${at}: label "${l.text}" leaves its ${labels.within}`);
|
|
124
|
+
if (l.overLabels) failures.push(`${at}: label "${l.text}" sits over another label`);
|
|
125
|
+
if (l.overCopy) failures.push(`${at}: label "${l.text}" sits over copy`);
|
|
126
|
+
}
|
|
127
|
+
if (values.preview && !m.noindex) failures.push(`${at}: no noindex robots meta on a preview build (read PUBLIC_PREVIEW)`);
|
|
128
|
+
res.pages[route][name] = m;
|
|
129
|
+
await page.screenshot({ path: join(outDir, `${slug(route)}-${name}.png`), fullPage: true });
|
|
130
|
+
await context.close();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
await browser.close();
|
|
134
|
+
close();
|
|
135
|
+
|
|
136
|
+
res.failures = failures;
|
|
137
|
+
writeFileSync(join(root, "measure", "measure.json"), `${JSON.stringify(res, null, 1)}\n`);
|
|
138
|
+
console.log(`${GATE}: ${pages.length} page(s) at 1440 and 390 against ${base}; captures in measure/out, report in measure/measure.json`);
|
|
139
|
+
if (failures.length) stop(GATE, "06", `${failures.length} failure(s):\n${failures.map((f) => ` ${f}`).join("\n")}`);
|
|
140
|
+
|
|
141
|
+
/** Serves the last build on measure.port and returns how to stop it. */
|
|
142
|
+
async function serveBuild() {
|
|
143
|
+
// Something already answering on the port would be measured in this build's place.
|
|
144
|
+
if (await fetch(base).then(() => true, () => false)) stop(GATE, "06", `something is already answering on ${base}. Stop it, or set measure.port in site.programme.json.`);
|
|
145
|
+
const TYPES = { ".html": "text/html; charset=utf-8", ".css": "text/css", ".js": "text/javascript", ".mjs": "text/javascript", ".json": "application/json", ".svg": "image/svg+xml", ".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".webp": "image/webp", ".avif": "image/avif", ".woff2": "font/woff2", ".ico": "image/x-icon", ".txt": "text/plain", ".xml": "application/xml" };
|
|
146
|
+
const dist = join(root, "dist");
|
|
147
|
+
const pkg = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
|
|
148
|
+
let stopServer;
|
|
149
|
+
if (existsSync(join(dist, "index.html"))) {
|
|
150
|
+
const server = createServer((req, res) => {
|
|
151
|
+
const path = decodeURIComponent(new URL(req.url, base).pathname).replace(/\/+$/, "").slice(1);
|
|
152
|
+
const candidates = path === "" ? ["index.html"] : [path, `${path}.html`, `${path}/index.html`];
|
|
153
|
+
const file = candidates.map((c) => join(dist, c)).find((f) => f.startsWith(dist) && existsSync(f) && statSync(f).isFile());
|
|
154
|
+
const notFound = join(dist, "404.html");
|
|
155
|
+
const body = file ?? (existsSync(notFound) ? notFound : null);
|
|
156
|
+
res.writeHead(file ? 200 : 404, { "content-type": TYPES[extname(body ?? ".html")] ?? "application/octet-stream" });
|
|
157
|
+
res.end(body ? readFileSync(body) : "Not found");
|
|
158
|
+
});
|
|
159
|
+
await new Promise((resolve) => server.listen(port, "127.0.0.1", resolve));
|
|
160
|
+
stopServer = () => server.close();
|
|
161
|
+
} else if (pkg.dependencies?.next ?? pkg.devDependencies?.next) {
|
|
162
|
+
const child = spawn(join(root, "node_modules", ".bin", "next"), ["start", "-p", String(port), "-H", "127.0.0.1"], { cwd: root, stdio: "ignore" });
|
|
163
|
+
stopServer = () => child.kill();
|
|
164
|
+
} else {
|
|
165
|
+
stop(GATE, "06", "no static build in dist/ and no next to start. Build first.");
|
|
166
|
+
}
|
|
167
|
+
for (let i = 0; i < 60; i++) {
|
|
168
|
+
if (await fetch(base).then((r) => r.status < 500, () => false)) return stopServer;
|
|
169
|
+
await new Promise((r) => setTimeout(r, 1000));
|
|
170
|
+
}
|
|
171
|
+
stopServer();
|
|
172
|
+
stop(GATE, "06", `the build did not answer on ${base} within a minute.`);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Scroll through the page so lazy images load before the capture, then back to the top.
|
|
176
|
+
async function settle(p) {
|
|
177
|
+
await p.evaluate(async () => {
|
|
178
|
+
const h = document.documentElement.scrollHeight;
|
|
179
|
+
for (let y = 0; y < h; y += 600) {
|
|
180
|
+
window.scrollTo(0, y);
|
|
181
|
+
await new Promise((r) => setTimeout(r, 40));
|
|
182
|
+
}
|
|
183
|
+
window.scrollTo(0, 0);
|
|
184
|
+
});
|
|
185
|
+
await p.waitForTimeout(600);
|
|
186
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Stage 05 gate: measures both sides of the sheet the way the day side was
|
|
2
|
+
// measured, every text colour against its ground by WCAG 2.x relative
|
|
3
|
+
// luminance, from the stylesheet tokens.mjs wrote. Exits 1 when a pair that
|
|
4
|
+
// carries text falls under 4.5:1, so a palette change cannot ship an
|
|
5
|
+
// unreadable label by day or by night.
|
|
6
|
+
//
|
|
7
|
+
// Lifted from apps/site/scripts/night-contrast.mjs in Doman-Digital (DOM-647).
|
|
8
|
+
|
|
9
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
10
|
+
import { programme, sitePath, stop } from "./programme.mjs";
|
|
11
|
+
|
|
12
|
+
const GATE = "night-contrast";
|
|
13
|
+
const { paths } = programme();
|
|
14
|
+
const file = sitePath(paths.tokens);
|
|
15
|
+
if (!existsSync(file)) stop(GATE, "05", `no ${paths.tokens}: tokens.mjs writes it first.`);
|
|
16
|
+
const css = readFileSync(file, "utf8");
|
|
17
|
+
const block = (sel) => {
|
|
18
|
+
const i = css.indexOf(sel);
|
|
19
|
+
if (i < 0) stop(GATE, "05", `${paths.tokens} has no ${sel} block. Run tokens.mjs.`);
|
|
20
|
+
const body = css.slice(css.indexOf("{", i) + 1, css.indexOf("}", i));
|
|
21
|
+
return Object.fromEntries([...body.matchAll(/--([a-z0-9-]+):\s*(#[0-9a-f]{6})/gi)].map((m) => [m[1], m[2].toLowerCase()]));
|
|
22
|
+
};
|
|
23
|
+
const light = block(":root {");
|
|
24
|
+
const night = block(':root[data-theme="dark"]');
|
|
25
|
+
|
|
26
|
+
const lum = (hex) => {
|
|
27
|
+
const n = parseInt(hex.slice(1), 16);
|
|
28
|
+
const f = (v) => {
|
|
29
|
+
v /= 255;
|
|
30
|
+
return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
|
|
31
|
+
};
|
|
32
|
+
return 0.2126 * f((n >> 16) & 255) + 0.7152 * f((n >> 8) & 255) + 0.0722 * f(n & 255);
|
|
33
|
+
};
|
|
34
|
+
const ratio = (a, b) => {
|
|
35
|
+
const x = lum(a);
|
|
36
|
+
const y = lum(b);
|
|
37
|
+
return (Math.max(x, y) + 0.05) / (Math.min(x, y) + 0.05);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
let failed = false;
|
|
41
|
+
for (const [name, t] of [
|
|
42
|
+
["day", light],
|
|
43
|
+
["night", night],
|
|
44
|
+
]) {
|
|
45
|
+
const g = t.ground;
|
|
46
|
+
const pairs = [
|
|
47
|
+
["ink on ground", t.ink, 4.5],
|
|
48
|
+
["ink-2 on ground", t["ink-2"], 4.5],
|
|
49
|
+
["ink-3 on ground", t["ink-3"], 4.5],
|
|
50
|
+
["accent on ground (labels and links)", t.accent, 4.5],
|
|
51
|
+
["ground on ink (primary button text)", g, 4.5, t.ink],
|
|
52
|
+
["ground on accent (button hover text)", g, 4.5, t.accent],
|
|
53
|
+
["rule on ground (1px rules, not text)", t.rule, 1.3],
|
|
54
|
+
];
|
|
55
|
+
console.log(`${GATE}: ${name}, ground ${g}`);
|
|
56
|
+
for (const [label, fg, min, bg = g] of pairs) {
|
|
57
|
+
if (!fg || !bg) {
|
|
58
|
+
failed = true;
|
|
59
|
+
console.log(` FAIL missing ${label}`);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const r = ratio(fg, bg);
|
|
63
|
+
const ok = r >= min;
|
|
64
|
+
if (!ok) failed = true;
|
|
65
|
+
console.log(` ${ok ? "ok " : "FAIL"} ${r.toFixed(2)}:1 ${label} (${fg} on ${bg}, needs ${min})`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (failed) stop(GATE, "05", "a pair falls short. Change the value in art-direction.json or art-direction.sheets.json, not the stylesheet.");
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Stage 06 gate: reads the rendered copy deck against the null set's harvest,
|
|
2
|
+
// the phrases a model kept writing when it built the same brief with nobody
|
|
3
|
+
// deciding anything (`craft null build`, then `craft tells harvest`, saved as
|
|
4
|
+
// text or with --json). Every exact hit is listed with its line. A hit is not
|
|
5
|
+
// automatically a failure: a phrase can be the buyer's own words, kept on
|
|
6
|
+
// purpose, and then site.programme.json carries it under
|
|
7
|
+
// nullCheck.justified with the reason. An unjustified hit exits 1. The table
|
|
8
|
+
// is written to paths.nullCheck for the Stage 06 review. When the harvest is
|
|
9
|
+
// not on this machine the gate says so and passes.
|
|
10
|
+
//
|
|
11
|
+
// Lifted from apps/site/scripts/null-check.mjs in Doman-Digital (DOM-647).
|
|
12
|
+
|
|
13
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
14
|
+
import { dirname } from "node:path";
|
|
15
|
+
import { programme, sitePath, stop } from "./programme.mjs";
|
|
16
|
+
|
|
17
|
+
const GATE = "null-check";
|
|
18
|
+
const { paths, nullCheck = {} } = programme();
|
|
19
|
+
if (!nullCheck.harvest) {
|
|
20
|
+
console.log(`${GATE}: no harvest named in site.programme.json (nullCheck.harvest); skipped. Run craft null build for the brief to make one.`);
|
|
21
|
+
process.exit(0);
|
|
22
|
+
}
|
|
23
|
+
const harvest = sitePath(nullCheck.harvest);
|
|
24
|
+
if (!existsSync(harvest)) {
|
|
25
|
+
console.log(`${GATE}: harvest not on this machine (${nullCheck.harvest}); skipped`);
|
|
26
|
+
process.exit(0);
|
|
27
|
+
}
|
|
28
|
+
const deckPath = sitePath(paths.deckMarkdown);
|
|
29
|
+
if (!existsSync(deckPath)) stop(GATE, "06", `no ${paths.deckMarkdown}: copy-deck.mjs writes it.`);
|
|
30
|
+
|
|
31
|
+
const raw = readFileSync(harvest, "utf8");
|
|
32
|
+
let phrases;
|
|
33
|
+
if (raw.trimStart().startsWith("{")) {
|
|
34
|
+
phrases = (JSON.parse(raw).candidates ?? []).filter((c) => c.kind === "phrase").map((c) => ({ phrase: c.value.toLowerCase(), runs: c.runs, of: c.of }));
|
|
35
|
+
} else {
|
|
36
|
+
phrases = raw
|
|
37
|
+
.split("\n")
|
|
38
|
+
.map((l) => l.match(/^\s+phrase\s+(.+?)\s{2,}(\d+) of (\d+)/))
|
|
39
|
+
.filter(Boolean)
|
|
40
|
+
.map((m) => ({ phrase: m[1].trim().toLowerCase(), runs: +m[2], of: +m[3] }));
|
|
41
|
+
}
|
|
42
|
+
const justified = Object.fromEntries(Object.entries(nullCheck.justified ?? {}).map(([k, v]) => [k.toLowerCase(), v]));
|
|
43
|
+
|
|
44
|
+
const deck = readFileSync(deckPath, "utf8").split("\n");
|
|
45
|
+
const hits = [];
|
|
46
|
+
for (const { phrase, runs, of } of phrases) {
|
|
47
|
+
deck.forEach((line, i) => {
|
|
48
|
+
if (line.toLowerCase().includes(phrase)) hits.push({ phrase, runs, of, line: i + 1, text: line.trim().slice(0, 120), justified: justified[phrase] ?? null });
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
const unjustified = hits.filter((h) => !h.justified);
|
|
52
|
+
const md = [
|
|
53
|
+
"# Null-set check · copy deck",
|
|
54
|
+
"",
|
|
55
|
+
`Run ${new Date().toISOString().slice(0, 10)} by \`scripts/gates/null-check.mjs\` against \`${nullCheck.harvest}\` (${phrases.length} phrases).`,
|
|
56
|
+
"",
|
|
57
|
+
`Hits: ${hits.length}. Unjustified: ${unjustified.length}.`,
|
|
58
|
+
"",
|
|
59
|
+
"| Phrase | Null runs | Deck line | Text | Kept because |",
|
|
60
|
+
"| --- | --- | --- | --- | --- |",
|
|
61
|
+
...hits.map((h) => `| ${h.phrase} | ${h.runs} of ${h.of} | ${h.line} | ${h.text.replace(/\|/g, "\\|")} | ${h.justified ?? "**not justified**"} |`),
|
|
62
|
+
"",
|
|
63
|
+
`Phrases checked and absent: ${
|
|
64
|
+
phrases
|
|
65
|
+
.filter((p) => !hits.some((h) => h.phrase === p.phrase))
|
|
66
|
+
.map((p) => `"${p.phrase}"`)
|
|
67
|
+
.join(", ") || "none"
|
|
68
|
+
}.`,
|
|
69
|
+
"",
|
|
70
|
+
];
|
|
71
|
+
const out = sitePath(paths.nullCheck);
|
|
72
|
+
mkdirSync(dirname(out), { recursive: true });
|
|
73
|
+
writeFileSync(out, md.join("\n"));
|
|
74
|
+
console.log(`${GATE}: ${hits.length} hits, ${unjustified.length} unjustified. Written to ${paths.nullCheck}`);
|
|
75
|
+
for (const h of unjustified) console.log(` line ${h.line}: "${h.phrase}" in: ${h.text}`);
|
|
76
|
+
if (unjustified.length) stop(GATE, "06", "rewrite each unjustified phrase, or keep it with a reason under nullCheck.justified in site.programme.json.");
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// The build gates, in stage order, run before every build (the `prebuild`
|
|
2
|
+
// script). A gate is a script that blocks the build, never a reminder: the
|
|
3
|
+
// first one to fail stops the build and names its stage. The order matters:
|
|
4
|
+
// the direction is decided before tokens are written from it, the tokens are
|
|
5
|
+
// written before they are measured, and the deck is current before the null
|
|
6
|
+
// set reads it. The measurement at 1440 and 390 needs a running build, so
|
|
7
|
+
// deploy-preview.mjs runs it before every preview deploy instead.
|
|
8
|
+
|
|
9
|
+
import { spawnSync } from "node:child_process";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { programme, root, stop } from "./programme.mjs";
|
|
12
|
+
|
|
13
|
+
const GATES = [
|
|
14
|
+
["check-direction.mjs"],
|
|
15
|
+
["tokens.mjs"],
|
|
16
|
+
["night-contrast.mjs"],
|
|
17
|
+
["facts.mjs"],
|
|
18
|
+
["copy-deck.mjs", "--check"],
|
|
19
|
+
["null-check.mjs"],
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
// Stage 01: the site has a programme in Linear before anything is built.
|
|
23
|
+
const { issue } = programme();
|
|
24
|
+
if (typeof issue !== "string" || !/^[A-Z]+-\d+$/.test(issue)) {
|
|
25
|
+
stop("programme", "01", "site.programme.json names no programme issue. Open the programme from the Site programme template in Linear and put its id (DOM-123) in issue.");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
for (const [script, ...args] of GATES) {
|
|
29
|
+
const run = spawnSync(process.execPath, [join(root, "scripts", "gates", script), ...args], { cwd: root, stdio: "inherit" });
|
|
30
|
+
if (run.status !== 0) {
|
|
31
|
+
console.error(`\nThe build stops at ${script}. docs/site-programme.md says what its stage needs.`);
|
|
32
|
+
process.exit(run.status || 1);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// What every gate shares: the site's root, its site.programme.json (the
|
|
2
|
+
// site's own file, written once by create-site and never replaced), and one
|
|
3
|
+
// way to stop. Each gate names the programme stage it belongs to, so a
|
|
4
|
+
// failing build says which stage is not done. docs/site-programme.md has the
|
|
5
|
+
// ten stages and the gate each one owns.
|
|
6
|
+
|
|
7
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
8
|
+
import { homedir } from "node:os";
|
|
9
|
+
import { dirname, join, resolve } from "node:path";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
|
|
12
|
+
export const root = resolve(dirname(fileURLToPath(import.meta.url)), "../..");
|
|
13
|
+
|
|
14
|
+
/** site.programme.json, or a stop naming the file when it is missing or unreadable. */
|
|
15
|
+
export function programme() {
|
|
16
|
+
const path = join(root, "site.programme.json");
|
|
17
|
+
if (!existsSync(path)) stop("programme", "01", "no site.programme.json. Run create-site again: it writes the file and never replaces it.");
|
|
18
|
+
try {
|
|
19
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
20
|
+
} catch (error) {
|
|
21
|
+
stop("programme", "01", `site.programme.json is not JSON: ${error.message}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** A path from site.programme.json: `~/` is the home directory, anything else is relative to the site. */
|
|
26
|
+
export function sitePath(path) {
|
|
27
|
+
return path.startsWith("~/") ? join(homedir(), path.slice(2)) : resolve(root, path);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Exit 1 with the gate, its stage and the reason. A gate never warns its way past a failure. */
|
|
31
|
+
export function stop(gate, stage, message) {
|
|
32
|
+
console.error(`${gate} (Stage ${stage}): ${message}`);
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The installed craft bin, so a gate runs the craft the site pinned, never a global one. */
|
|
37
|
+
export function craftBin() {
|
|
38
|
+
const manifest = join(root, "node_modules", "@domandigital", "craft", "package.json");
|
|
39
|
+
if (!existsSync(manifest)) return null;
|
|
40
|
+
const bin = JSON.parse(readFileSync(manifest, "utf8")).bin?.craft;
|
|
41
|
+
return bin ? join(dirname(manifest), bin) : null;
|
|
42
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Stage 05 gate: writes the token stylesheet from the direction, both sides
|
|
2
|
+
// of the sheet. The day side takes its ground, accent, faces and shape from
|
|
3
|
+
// art-direction.json, where each is decided with its reason; the inks, the
|
|
4
|
+
// rule and the night side come from art-direction.sheets.json, because the
|
|
5
|
+
// direction's schema holds a choice's value, reason and evidence and nothing
|
|
6
|
+
// else. Nothing in the stylesheet is a value the direction does not record,
|
|
7
|
+
// and a value still null stops the build: night is designed, never derived
|
|
8
|
+
// by flipping. night-contrast.mjs then measures what this wrote.
|
|
9
|
+
//
|
|
10
|
+
// Lifted from apps/site/scripts/tokens.mjs in Doman-Digital (DOM-647).
|
|
11
|
+
|
|
12
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
13
|
+
import { dirname, join } from "node:path";
|
|
14
|
+
import { programme, root, sitePath, stop } from "./programme.mjs";
|
|
15
|
+
|
|
16
|
+
const GATE = "tokens";
|
|
17
|
+
const read = (name) => {
|
|
18
|
+
const path = join(root, name);
|
|
19
|
+
if (!existsSync(path)) stop(GATE, "05", `no ${name}.`);
|
|
20
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
21
|
+
};
|
|
22
|
+
const direction = read("art-direction.json");
|
|
23
|
+
const sheets = read("art-direction.sheets.json");
|
|
24
|
+
const c = direction.choices ?? {};
|
|
25
|
+
|
|
26
|
+
const HEX = /^#[0-9a-f]{6}$/i;
|
|
27
|
+
const missing = [];
|
|
28
|
+
const colour = (where, value) => {
|
|
29
|
+
if (typeof value !== "string" || !HEX.test(value)) missing.push(where);
|
|
30
|
+
return typeof value === "string" ? value.toLowerCase() : value;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const ground = colour("art-direction.json choices.ground.value", c.ground?.value);
|
|
34
|
+
const accent = colour("art-direction.json choices.accent.value", c.accent?.value);
|
|
35
|
+
const display = c.display?.value;
|
|
36
|
+
const body = c.body?.value;
|
|
37
|
+
if (!display) missing.push("art-direction.json choices.display.value");
|
|
38
|
+
if (!body) missing.push("art-direction.json choices.body.value");
|
|
39
|
+
|
|
40
|
+
const INKS = ["ink", "ink-2", "ink-3", "rule", "accent-soft"];
|
|
41
|
+
const light = Object.fromEntries(INKS.map((k) => [k, colour(`art-direction.sheets.json light.${k}`, sheets.light?.[k])]));
|
|
42
|
+
const night = Object.fromEntries(["ground", "accent", ...INKS].map((k) => [k, colour(`art-direction.sheets.json night.${k}`, sheets.night?.[k])]));
|
|
43
|
+
if (typeof sheets.because !== "string" || sheets.because.trim().split(/\s+/).length < 8) missing.push("art-direction.sheets.json because (a sentence: why the night side is these values)");
|
|
44
|
+
|
|
45
|
+
if (missing.length) stop(GATE, "05", `the sheet is not decided yet. Still to fill:\n${missing.map((m) => ` ${m}`).join("\n")}`);
|
|
46
|
+
|
|
47
|
+
// "2px corners, 1px rules, 2px leader lines" becomes --shape-corners: 2px, and so on.
|
|
48
|
+
const shape = [...String(c.shape?.value ?? "").matchAll(/(\d+(?:\.\d+)?px)\s+([a-z][a-z-]*)/gi)].map((m) => [m[2].toLowerCase(), m[1]]);
|
|
49
|
+
|
|
50
|
+
const vars = (t) => Object.entries(t).map(([k, v]) => ` --${k}: ${v};`).join("\n");
|
|
51
|
+
const nightVars = vars(night).replace(/^/gm, " ");
|
|
52
|
+
const css = `/* Generated from art-direction.json and art-direction.sheets.json by scripts/gates/tokens.mjs.
|
|
53
|
+
Edit the direction, not this file. */
|
|
54
|
+
:root {
|
|
55
|
+
--ground: ${ground};
|
|
56
|
+
--accent: ${accent};
|
|
57
|
+
${vars(light)}
|
|
58
|
+
--display: "${display}", sans-serif;
|
|
59
|
+
--body: "${body}", system-ui, sans-serif;
|
|
60
|
+
${shape.map(([k, v]) => ` --shape-${k}: ${v};\n`).join("")}}
|
|
61
|
+
|
|
62
|
+
/* Night: ${sheets.because.trim().replace(/\*\//g, "* /")}
|
|
63
|
+
Follows the visitor's own setting; data-theme on <html> forces either side
|
|
64
|
+
for review. Measured by scripts/gates/night-contrast.mjs before every build. */
|
|
65
|
+
@media (prefers-color-scheme: dark) {
|
|
66
|
+
:root:not([data-theme="light"]) {
|
|
67
|
+
${nightVars}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
:root[data-theme="dark"] {
|
|
71
|
+
${vars(night)}
|
|
72
|
+
}
|
|
73
|
+
`;
|
|
74
|
+
|
|
75
|
+
const { paths } = programme();
|
|
76
|
+
const out = sitePath(paths.tokens);
|
|
77
|
+
mkdirSync(dirname(out), { recursive: true });
|
|
78
|
+
writeFileSync(out, css);
|
|
79
|
+
console.log(`${GATE}: ${paths.tokens} written, day and night`);
|