@domandigital/create-site 0.5.1 → 0.7.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 +45 -5
- package/dist/cli.js +95 -9
- package/package.json +2 -2
- package/templates/shared/docs/site-programme.md +107 -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 +229 -0
- package/templates/shared/scripts/gates/mobile-first.mjs +91 -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 +36 -0
- package/templates/shared/scripts/gates/programme.mjs +42 -0
- package/templates/shared/scripts/gates/tokens.mjs +79 -0
|
@@ -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`);
|