@domandigital/craft 0.15.0 → 0.16.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 +7 -0
- package/CHARACTER.md +34 -0
- package/dist/{audit-MTUC24XU.js → audit-UJCUWORL.js} +2 -2
- package/dist/{chunk-LFNSB6W7.js → chunk-B2MJLGF6.js} +1 -0
- package/dist/{chunk-QU6Q2QZZ.js → chunk-CVG5GSMN.js} +5 -5
- package/dist/{chunk-RXXRXV3V.js → chunk-LWVGIJ5A.js} +171 -16
- package/dist/{chunk-MUVFECFC.js → chunk-LXDNIJFG.js} +28 -11
- package/dist/{cli-FCKHYAVZ.js → chunk-NTIPJ5U7.js} +2 -185
- package/dist/{chunk-2IQ5OXFR.js → chunk-TQKDCA4V.js} +4 -4
- package/dist/{chunk-YDURAOYR.js → chunk-WAV6AKR4.js} +1 -1
- package/dist/{chunk-OUQ25LY2.js → chunk-YK2FFL6Z.js} +1 -1
- package/dist/cli-3GQROFCB.js +241 -0
- package/dist/{cli-5ACKICBO.js → cli-52M62QBN.js} +5 -5
- package/dist/{cli-FLG3ZCAF.js → cli-AVYNHBFJ.js} +11 -5
- package/dist/cli-CWORJYOU.js +190 -0
- package/dist/{cli-7OZCYOQY.js → cli-K4LSRYBE.js} +4 -4
- package/dist/{cli-22TSWAX6.js → cli-PEATEW57.js} +5 -5
- package/dist/cli.js +2 -2
- package/dist/index.cjs +299 -100
- package/dist/index.d.cts +149 -2
- package/dist/index.d.ts +149 -2
- package/dist/index.js +287 -100
- package/package.json +1 -1
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import {
|
|
2
|
+
characterReport
|
|
3
|
+
} from "./chunk-NTIPJ5U7.js";
|
|
4
|
+
import {
|
|
5
|
+
merge
|
|
6
|
+
} from "./chunk-TQKDCA4V.js";
|
|
7
|
+
import "./chunk-YK2FFL6Z.js";
|
|
8
|
+
import "./chunk-JYNXGCYZ.js";
|
|
9
|
+
import {
|
|
10
|
+
SIBLING_AT,
|
|
11
|
+
compareToEstate,
|
|
12
|
+
loadEstate
|
|
13
|
+
} from "./chunk-CVG5GSMN.js";
|
|
14
|
+
import {
|
|
15
|
+
PAGE_TYPES,
|
|
16
|
+
validateDirection
|
|
17
|
+
} from "./chunk-WAV6AKR4.js";
|
|
18
|
+
import {
|
|
19
|
+
loadNull
|
|
20
|
+
} from "./chunk-LWVGIJ5A.js";
|
|
21
|
+
import "./chunk-OQXTQQAU.js";
|
|
22
|
+
import {
|
|
23
|
+
COPY_FILE,
|
|
24
|
+
NOT_COPY_DIR,
|
|
25
|
+
SOURCE_FILE,
|
|
26
|
+
applySeverity,
|
|
27
|
+
loadConfig,
|
|
28
|
+
loadExceptions,
|
|
29
|
+
parseFlags,
|
|
30
|
+
readPaths,
|
|
31
|
+
toJson
|
|
32
|
+
} from "./chunk-LXDNIJFG.js";
|
|
33
|
+
import {
|
|
34
|
+
readSnapshot
|
|
35
|
+
} from "./chunk-WUACK2HX.js";
|
|
36
|
+
import {
|
|
37
|
+
CATALOGUE,
|
|
38
|
+
auditSnapshot,
|
|
39
|
+
checkCopy,
|
|
40
|
+
fingerprint,
|
|
41
|
+
scanSource,
|
|
42
|
+
typicality
|
|
43
|
+
} from "./chunk-B2MJLGF6.js";
|
|
44
|
+
import "./chunk-QYBAVU3P.js";
|
|
45
|
+
|
|
46
|
+
// src/report/cli.ts
|
|
47
|
+
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
48
|
+
import { dirname, resolve } from "path";
|
|
49
|
+
|
|
50
|
+
// src/report/retrofit.ts
|
|
51
|
+
var HEADINGS = {
|
|
52
|
+
direction: "Decide first",
|
|
53
|
+
type: "Type",
|
|
54
|
+
colour: "Colour",
|
|
55
|
+
shape: "Shape",
|
|
56
|
+
effects: "Effects",
|
|
57
|
+
motion: "Motion",
|
|
58
|
+
layout: "How sections look (not where they sit)",
|
|
59
|
+
copy: "Copy"
|
|
60
|
+
};
|
|
61
|
+
var ORDER = ["direction", "type", "colour", "shape", "effects", "motion", "layout", "copy"];
|
|
62
|
+
function target(a, direction) {
|
|
63
|
+
if (!a.choice || a.area === "direction") return "";
|
|
64
|
+
const c = direction?.choices?.[a.choice];
|
|
65
|
+
if (c && c.because && !c.because.startsWith("PROPOSED:")) return `
|
|
66
|
+
- Use: **${c.value}** for ${a.choice}. ${c.because}`;
|
|
67
|
+
return `
|
|
68
|
+
- Waits on: deciding **${a.choice}** in art-direction.json.`;
|
|
69
|
+
}
|
|
70
|
+
function retrofitPlan(report, direction) {
|
|
71
|
+
const lines = [
|
|
72
|
+
`# Retrofit: ${report.site}`,
|
|
73
|
+
"",
|
|
74
|
+
`**Now:** ${report.verdict}. ${report.summary}`,
|
|
75
|
+
"",
|
|
76
|
+
"| Signal | Raised | Reading |",
|
|
77
|
+
"|---|---|---|",
|
|
78
|
+
...report.signals.map((s) => `| ${s.id} | ${s.raised === null ? "not measured" : s.raised ? "yes" : "no"} | ${s.detail} |`),
|
|
79
|
+
"",
|
|
80
|
+
"**Done when** `craft report` says *decided*: fewer than three design tells, typicality under 0.10 against this brief's null, no sibling in the estate, and at least five of the seven choices decided with a reason.",
|
|
81
|
+
""
|
|
82
|
+
];
|
|
83
|
+
let n = 0;
|
|
84
|
+
for (const area of ORDER) {
|
|
85
|
+
const list = report.actions.filter((a) => a.area === area);
|
|
86
|
+
if (list.length === 0) continue;
|
|
87
|
+
n += 1;
|
|
88
|
+
lines.push(`## ${n}. ${HEADINGS[area]}`, "");
|
|
89
|
+
for (const a of list) lines.push(`- [ ] ${a.what} *(${a.why})*${target(a, direction)}`);
|
|
90
|
+
lines.push("");
|
|
91
|
+
}
|
|
92
|
+
if (n === 0) lines.push("Nothing to change.", "");
|
|
93
|
+
lines.push(
|
|
94
|
+
"## Leave alone",
|
|
95
|
+
"",
|
|
96
|
+
"Navigation, the order of the sections, where the call to action sits, reading order and legibility. Change the look, never the page grammar. A layout tell above is about how a section looks: the icon tiles, the chip, the strip. The section stays where it is.",
|
|
97
|
+
""
|
|
98
|
+
);
|
|
99
|
+
return lines.join("\n");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// src/report/cli.ts
|
|
103
|
+
var USAGE = "usage: craft report|retrofit <url | snapshot.json> [--repo <dir>] [--null <dir>] [--estate <estate.json>] [--direction <file>] [--json] [--out <file>]";
|
|
104
|
+
var sameUrl = (a, b) => a.replace(/\/+$/, "").toLowerCase() === b.replace(/\/+$/, "").toLowerCase();
|
|
105
|
+
function formatCharacter(r) {
|
|
106
|
+
const lines = [`craft report ${r.site}`, "", `Verdict: ${r.verdict.toUpperCase()}. ${r.summary}`, ""];
|
|
107
|
+
for (const s of r.signals) lines.push(` ${s.id.padEnd(11)} ${s.raised === null ? "\xB7" : s.raised ? "RAISED" : "ok"} ${s.detail}`);
|
|
108
|
+
lines.push("", "What to do, in order:");
|
|
109
|
+
r.actions.slice(0, 12).forEach((a, i) => lines.push(` ${String(i + 1).padStart(2)}. [${a.area}] ${a.what}`, ` ${a.why}`));
|
|
110
|
+
if (r.actions.length > 12) lines.push(` ...and ${r.actions.length - 12} more: craft retrofit writes them all.`);
|
|
111
|
+
return lines.join("\n");
|
|
112
|
+
}
|
|
113
|
+
async function runReport(command, args, io) {
|
|
114
|
+
try {
|
|
115
|
+
const flags = parseFlags(args);
|
|
116
|
+
if (typeof flags === "string") throw new Error(flags);
|
|
117
|
+
const target2 = flags.positional[0];
|
|
118
|
+
if (!target2) throw new Error(USAGE);
|
|
119
|
+
const page = flags.page ?? "home";
|
|
120
|
+
if (!PAGE_TYPES.includes(page)) throw new Error(`--page takes one of ${PAGE_TYPES.join(", ")}`);
|
|
121
|
+
const local = resolve(io.cwd, target2);
|
|
122
|
+
let snap;
|
|
123
|
+
if (/\.json$/i.test(target2) && existsSync(local)) {
|
|
124
|
+
snap = readSnapshot(JSON.parse(readFileSync(local, "utf8")), target2);
|
|
125
|
+
} else {
|
|
126
|
+
const { snapshotUrl } = await import("./audit-UJCUWORL.js");
|
|
127
|
+
snap = await snapshotUrl(target2);
|
|
128
|
+
}
|
|
129
|
+
const fp = fingerprint(snap);
|
|
130
|
+
const repo = flags.repo ? resolve(io.cwd, flags.repo) : null;
|
|
131
|
+
const exceptions = loadExceptions(flags, repo ?? io.cwd);
|
|
132
|
+
const config = loadConfig(flags, repo ?? io.cwd);
|
|
133
|
+
let findings = auditSnapshot(snap, { exceptions });
|
|
134
|
+
if (repo) {
|
|
135
|
+
findings = merge(scanSource(readPaths(["."], repo, SOURCE_FILE, void 0, config.ignore), { exceptions }), findings);
|
|
136
|
+
const copyPaths = config.copyPaths ?? ["."];
|
|
137
|
+
findings = merge(findings, checkCopy(readPaths(copyPaths, repo, COPY_FILE, (d) => NOT_COPY_DIR(d) || d === "docs", config.ignore), { exceptions }));
|
|
138
|
+
}
|
|
139
|
+
findings = applySeverity(findings, config);
|
|
140
|
+
const nulls = flags.null ? flags.null.split(",").map((p) => loadNull(p.trim(), io.cwd)) : [];
|
|
141
|
+
const typical = nulls.length ? typicality(fp, nulls.flatMap((m, i) => m.runs.map((r) => nulls.length > 1 ? { ...r, id: `${i + 1}/${r.id}` } : r))) : null;
|
|
142
|
+
let estate = null;
|
|
143
|
+
if (flags.estate) {
|
|
144
|
+
const register = loadEstate(resolve(io.cwd, flags.estate));
|
|
145
|
+
const self = register.sites.find((s) => sameUrl(s.url, snap.url));
|
|
146
|
+
estate = compareToEstate(fp, register, { exclude: self?.id, siblingAt: SIBLING_AT });
|
|
147
|
+
}
|
|
148
|
+
const directionFile = resolve(repo ?? io.cwd, flags.direction ?? "art-direction.json");
|
|
149
|
+
let direction = null;
|
|
150
|
+
let directionReport = null;
|
|
151
|
+
if (existsSync(directionFile)) {
|
|
152
|
+
direction = JSON.parse(readFileSync(directionFile, "utf8"));
|
|
153
|
+
directionReport = validateDirection(direction, {
|
|
154
|
+
fingerprint: fp,
|
|
155
|
+
snapshot: snap,
|
|
156
|
+
page,
|
|
157
|
+
strict: flags.strict,
|
|
158
|
+
pathExists: (p) => existsSync(resolve(dirname(directionFile), p)),
|
|
159
|
+
readSource: (s) => {
|
|
160
|
+
if (!s.path || /^https?:/.test(s.path) || !/\.(?:txt|md|markdown|csv|json|html?)$/i.test(s.path)) return void 0;
|
|
161
|
+
const path = resolve(dirname(directionFile), s.path);
|
|
162
|
+
return existsSync(path) ? readFileSync(path, "utf8") : void 0;
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
} else if (flags.direction) {
|
|
166
|
+
throw new Error(`no such file: ${flags.direction}`);
|
|
167
|
+
}
|
|
168
|
+
const copyTells = new Set(CATALOGUE.filter((t) => t.surface === "copy").map((t) => t.id));
|
|
169
|
+
const report = characterReport({ site: snap.url, findings, typicality: typical, estate, direction: directionReport }, copyTells);
|
|
170
|
+
if (command === "retrofit") {
|
|
171
|
+
const plan = retrofitPlan(report, direction);
|
|
172
|
+
if (flags.out) {
|
|
173
|
+
writeFileSync(resolve(io.cwd, flags.out), plan);
|
|
174
|
+
io.out(`craft retrofit: ${report.actions.length} step${report.actions.length === 1 ? "" : "s"} for ${snap.url} in ${flags.out}`);
|
|
175
|
+
} else io.out(plan);
|
|
176
|
+
return 0;
|
|
177
|
+
}
|
|
178
|
+
io.out(flags.json ? toJson(report) : formatCharacter(report));
|
|
179
|
+
if (flags.out) writeFileSync(resolve(io.cwd, flags.out), `${toJson(report)}
|
|
180
|
+
`);
|
|
181
|
+
return flags.strict && report.verdict !== "decided" ? 1 : 0;
|
|
182
|
+
} catch (error) {
|
|
183
|
+
io.err(`craft: ${error.message}`);
|
|
184
|
+
return 2;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
export {
|
|
188
|
+
formatCharacter,
|
|
189
|
+
runReport
|
|
190
|
+
};
|
|
@@ -7,11 +7,11 @@ import {
|
|
|
7
7
|
PROPOSED,
|
|
8
8
|
researchPrompt,
|
|
9
9
|
validateDirection
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-WAV6AKR4.js";
|
|
11
11
|
import {
|
|
12
12
|
parseFlags,
|
|
13
13
|
toJson
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-LXDNIJFG.js";
|
|
15
15
|
import {
|
|
16
16
|
readSnapshot
|
|
17
17
|
} from "./chunk-WUACK2HX.js";
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
isCream,
|
|
25
25
|
oklchToRgb,
|
|
26
26
|
parseColour
|
|
27
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-B2MJLGF6.js";
|
|
28
28
|
import "./chunk-QYBAVU3P.js";
|
|
29
29
|
|
|
30
30
|
// src/direction/cli.ts
|
|
@@ -205,7 +205,7 @@ var readJson = (path) => JSON.parse(readFileSync(path, "utf8"));
|
|
|
205
205
|
async function snapshotFrom(target, cwd) {
|
|
206
206
|
if (!target) return void 0;
|
|
207
207
|
if (/^https?:\/\//.test(target)) {
|
|
208
|
-
const { snapshotUrl } = await import("./audit-
|
|
208
|
+
const { snapshotUrl } = await import("./audit-UJCUWORL.js");
|
|
209
209
|
return snapshotUrl(target);
|
|
210
210
|
}
|
|
211
211
|
return readSnapshot(readJson(resolve(cwd, target)), target);
|
|
@@ -4,13 +4,13 @@ import {
|
|
|
4
4
|
formatPairs,
|
|
5
5
|
loadEstate,
|
|
6
6
|
runEstate
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-CVG5GSMN.js";
|
|
8
|
+
import "./chunk-WAV6AKR4.js";
|
|
9
|
+
import "./chunk-LWVGIJ5A.js";
|
|
10
10
|
import "./chunk-OQXTQQAU.js";
|
|
11
|
-
import "./chunk-
|
|
11
|
+
import "./chunk-LXDNIJFG.js";
|
|
12
12
|
import "./chunk-WUACK2HX.js";
|
|
13
|
-
import "./chunk-
|
|
13
|
+
import "./chunk-B2MJLGF6.js";
|
|
14
14
|
import "./chunk-QYBAVU3P.js";
|
|
15
15
|
export {
|
|
16
16
|
formatComponentPairs,
|