@domandigital/craft 0.10.0 → 0.12.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.
@@ -0,0 +1,19 @@
1
+ import {
2
+ SNAPSHOT_VERSION
3
+ } from "./chunk-AL6MRG6V.js";
4
+
5
+ // src/snapshot/migrate.ts
6
+ var READABLE_SNAPSHOT_VERSIONS = [1, 2];
7
+ function readSnapshot(data, source = "snapshot") {
8
+ const v = data?.version;
9
+ if (typeof data !== "object" || data === null || !READABLE_SNAPSHOT_VERSIONS.includes(v)) {
10
+ throw new Error(`${source} is not a snapshot this craft reads (version ${String(v)}; reads ${READABLE_SNAPSHOT_VERSIONS.join(" and ")})`);
11
+ }
12
+ const snap = data;
13
+ if (snap.version === 1) return { ...snap, version: SNAPSHOT_VERSION, migratedFrom: 1 };
14
+ return snap;
15
+ }
16
+
17
+ export {
18
+ readSnapshot
19
+ };
@@ -0,0 +1,17 @@
1
+ import {
2
+ formatMatches,
3
+ formatPairs,
4
+ loadEstate,
5
+ runEstate
6
+ } from "./chunk-CDAJUS5U.js";
7
+ import "./chunk-LHGY43LL.js";
8
+ import "./chunk-ZKVJ7K6X.js";
9
+ import "./chunk-J3QUROJ5.js";
10
+ import "./chunk-PZ4MF2VV.js";
11
+ import "./chunk-AL6MRG6V.js";
12
+ export {
13
+ formatMatches,
14
+ formatPairs,
15
+ loadEstate,
16
+ runEstate
17
+ };
@@ -6,10 +6,11 @@ import {
6
6
  nullPath,
7
7
  runHarvest,
8
8
  runNull
9
- } from "./chunk-APO4BT2F.js";
10
- import "./chunk-JKIDWHG3.js";
11
- import "./chunk-QMYERCBB.js";
12
- import "./chunk-3NGWXZZE.js";
9
+ } from "./chunk-LHGY43LL.js";
10
+ import "./chunk-ZKVJ7K6X.js";
11
+ import "./chunk-J3QUROJ5.js";
12
+ import "./chunk-PZ4MF2VV.js";
13
+ import "./chunk-AL6MRG6V.js";
13
14
  export {
14
15
  describeTypicality,
15
16
  formatHarvest,
@@ -0,0 +1,19 @@
1
+ import {
2
+ describeFingerprint,
3
+ merge,
4
+ resolvePages,
5
+ runAudit
6
+ } from "./chunk-PU5G5DUC.js";
7
+ import "./chunk-ULPI335S.js";
8
+ import "./chunk-JYNXGCYZ.js";
9
+ import "./chunk-LHGY43LL.js";
10
+ import "./chunk-ZKVJ7K6X.js";
11
+ import "./chunk-J3QUROJ5.js";
12
+ import "./chunk-PZ4MF2VV.js";
13
+ import "./chunk-AL6MRG6V.js";
14
+ export {
15
+ describeFingerprint,
16
+ merge,
17
+ resolvePages,
18
+ runAudit
19
+ };
@@ -1,37 +1,43 @@
1
1
  import {
2
2
  validateDirection
3
- } from "./chunk-JWHC67ZS.js";
3
+ } from "./chunk-S3NZAVU6.js";
4
4
  import {
5
5
  merge
6
- } from "./chunk-U2JTFQKO.js";
7
- import "./chunk-TSKRBIOC.js";
6
+ } from "./chunk-PU5G5DUC.js";
7
+ import "./chunk-ULPI335S.js";
8
+ import "./chunk-JYNXGCYZ.js";
8
9
  import {
9
10
  SIBLING_AT,
10
11
  compareToEstate,
11
12
  loadEstate
12
- } from "./chunk-2NQFIDLE.js";
13
+ } from "./chunk-CDAJUS5U.js";
13
14
  import {
14
15
  loadNull,
15
16
  typicality
16
- } from "./chunk-APO4BT2F.js";
17
+ } from "./chunk-LHGY43LL.js";
18
+ import {
19
+ readSnapshot
20
+ } from "./chunk-ZKVJ7K6X.js";
17
21
  import {
18
22
  COPY_FILE,
19
23
  NOT_COPY_DIR,
20
24
  SOURCE_FILE,
25
+ applySeverity,
26
+ loadConfig,
21
27
  loadExceptions,
22
28
  parseFlags,
23
- readPaths
24
- } from "./chunk-JKIDWHG3.js";
29
+ readPaths,
30
+ toJson
31
+ } from "./chunk-J3QUROJ5.js";
25
32
  import {
26
33
  fingerprint
27
- } from "./chunk-QMYERCBB.js";
34
+ } from "./chunk-PZ4MF2VV.js";
28
35
  import {
29
36
  CATALOGUE,
30
- SNAPSHOT_VERSION,
31
37
  auditSnapshot,
32
38
  checkCopy,
33
39
  scanSource
34
- } from "./chunk-3NGWXZZE.js";
40
+ } from "./chunk-AL6MRG6V.js";
35
41
 
36
42
  // src/report/cli.ts
37
43
  import { existsSync, readFileSync, writeFileSync } from "fs";
@@ -256,20 +262,22 @@ async function runReport(command, args, io) {
256
262
  const local = resolve(io.cwd, target2);
257
263
  let snap;
258
264
  if (/\.json$/i.test(target2) && existsSync(local)) {
259
- snap = JSON.parse(readFileSync(local, "utf8"));
260
- if (snap.version !== SNAPSHOT_VERSION) throw new Error(`${target2} is not a snapshot`);
265
+ snap = readSnapshot(JSON.parse(readFileSync(local, "utf8")), target2);
261
266
  } else {
262
- const { snapshotUrl } = await import("./audit-EGDNWSQB.js");
267
+ const { snapshotUrl } = await import("./audit-5QWFLZ6L.js");
263
268
  snap = await snapshotUrl(target2);
264
269
  }
265
270
  const fp = fingerprint(snap);
266
271
  const repo = flags.repo ? resolve(io.cwd, flags.repo) : null;
267
272
  const exceptions = loadExceptions(flags, repo ?? io.cwd);
273
+ const config = loadConfig(flags, repo ?? io.cwd);
268
274
  let findings = auditSnapshot(snap, { exceptions });
269
275
  if (repo) {
270
- findings = merge(scanSource(readPaths(["."], repo, SOURCE_FILE), { exceptions }), findings);
271
- findings = merge(findings, checkCopy(readPaths(["."], repo, COPY_FILE, (d) => NOT_COPY_DIR(d) || d === "docs"), { exceptions }));
276
+ findings = merge(scanSource(readPaths(["."], repo, SOURCE_FILE, void 0, config.ignore), { exceptions }), findings);
277
+ const copyPaths = config.copyPaths ?? ["."];
278
+ findings = merge(findings, checkCopy(readPaths(copyPaths, repo, COPY_FILE, (d) => NOT_COPY_DIR(d) || d === "docs", config.ignore), { exceptions }));
272
279
  }
280
+ findings = applySeverity(findings, config);
273
281
  const nulls = flags.null ? flags.null.split(",").map((p) => loadNull(p.trim(), io.cwd)) : [];
274
282
  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;
275
283
  let estate = null;
@@ -297,8 +305,8 @@ async function runReport(command, args, io) {
297
305
  } else io.out(plan);
298
306
  return 0;
299
307
  }
300
- io.out(flags.json ? JSON.stringify(report, null, 2) : formatCharacter(report));
301
- if (flags.out) writeFileSync(resolve(io.cwd, flags.out), `${JSON.stringify(report, null, 2)}
308
+ io.out(flags.json ? toJson(report) : formatCharacter(report));
309
+ if (flags.out) writeFileSync(resolve(io.cwd, flags.out), `${toJson(report)}
302
310
  `);
303
311
  return flags.strict && report.verdict !== "decided" ? 1 : 0;
304
312
  } catch (error) {
@@ -1,13 +1,20 @@
1
1
  import {
2
2
  DIRECTION_VERSION,
3
3
  validateDirection
4
- } from "./chunk-JWHC67ZS.js";
4
+ } from "./chunk-S3NZAVU6.js";
5
5
  import {
6
- parseFlags
7
- } from "./chunk-JKIDWHG3.js";
6
+ decodePng
7
+ } from "./chunk-JYNXGCYZ.js";
8
+ import {
9
+ readSnapshot
10
+ } from "./chunk-ZKVJ7K6X.js";
11
+ import {
12
+ parseFlags,
13
+ toJson
14
+ } from "./chunk-J3QUROJ5.js";
8
15
  import {
9
16
  fingerprint
10
- } from "./chunk-QMYERCBB.js";
17
+ } from "./chunk-PZ4MF2VV.js";
11
18
  import {
12
19
  deltaEOk,
13
20
  formatHex,
@@ -16,7 +23,7 @@ import {
16
23
  isCream,
17
24
  oklchToRgb,
18
25
  parseColour
19
- } from "./chunk-3NGWXZZE.js";
26
+ } from "./chunk-AL6MRG6V.js";
20
27
 
21
28
  // src/direction/cli.ts
22
29
  import { existsSync, readdirSync, readFileSync, writeFileSync } from "fs";
@@ -49,78 +56,6 @@ function initDirection(input) {
49
56
  };
50
57
  }
51
58
 
52
- // src/direction/png.ts
53
- import { inflateSync } from "zlib";
54
- function decodePng(buf) {
55
- const sig = [137, 80, 78, 71, 13, 10, 26, 10];
56
- if (!sig.every((b, i) => buf[i] === b)) throw new Error("not a PNG");
57
- const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
58
- let pos = 8;
59
- let width = 0;
60
- let height = 0;
61
- let depth = 0;
62
- let colour = 0;
63
- let interlace = 0;
64
- const idat = [];
65
- while (pos < buf.length) {
66
- const len = view.getUint32(pos);
67
- const type = String.fromCharCode(...buf.subarray(pos + 4, pos + 8));
68
- const data = buf.subarray(pos + 8, pos + 8 + len);
69
- if (type === "IHDR") {
70
- width = view.getUint32(pos + 8);
71
- height = view.getUint32(pos + 12);
72
- depth = data[8];
73
- colour = data[9];
74
- interlace = data[12];
75
- } else if (type === "IDAT") idat.push(data);
76
- else if (type === "IEND") break;
77
- pos += 12 + len;
78
- }
79
- const channels = { 0: 1, 2: 3, 4: 2, 6: 4 }[colour];
80
- if (depth !== 8 || !channels || interlace !== 0) throw new Error(`unsupported PNG (depth ${depth}, colour type ${colour}${interlace ? ", interlaced" : ""}); export it as 8-bit RGB`);
81
- const raw = inflateSync(Buffer.concat(idat.map((d) => Buffer.from(d))));
82
- const stride = width * channels;
83
- const out = new Uint8Array(width * height * 4);
84
- const prev = new Uint8Array(stride);
85
- const line = new Uint8Array(stride);
86
- for (let y = 0; y < height; y += 1) {
87
- const filter = raw[y * (stride + 1)];
88
- const src = raw.subarray(y * (stride + 1) + 1, (y + 1) * (stride + 1));
89
- for (let x = 0; x < stride; x += 1) {
90
- const a = x >= channels ? line[x - channels] : 0;
91
- const b = prev[x];
92
- const c = x >= channels ? prev[x - channels] : 0;
93
- let v = src[x];
94
- if (filter === 1) v += a;
95
- else if (filter === 2) v += b;
96
- else if (filter === 3) v += a + b >> 1;
97
- else if (filter === 4) {
98
- const p = a + b - c;
99
- const pa = Math.abs(p - a);
100
- const pb = Math.abs(p - b);
101
- const pc = Math.abs(p - c);
102
- v += pa <= pb && pa <= pc ? a : pb <= pc ? b : c;
103
- }
104
- line[x] = v & 255;
105
- }
106
- for (let x = 0; x < width; x += 1) {
107
- const i = x * channels;
108
- const o = (y * width + x) * 4;
109
- if (channels >= 3) {
110
- out[o] = line[i];
111
- out[o + 1] = line[i + 1];
112
- out[o + 2] = line[i + 2];
113
- out[o + 3] = channels === 4 ? line[i + 3] : 255;
114
- } else {
115
- out[o] = out[o + 1] = out[o + 2] = line[i];
116
- out[o + 3] = channels === 2 ? line[i + 1] : 255;
117
- }
118
- }
119
- prev.set(line);
120
- }
121
- return { width, height, rgba: out };
122
- }
123
-
124
59
  // src/direction/propose.ts
125
60
  var PROPOSED = "PROPOSED:";
126
61
  function srgbToLinear(c) {
@@ -252,8 +187,8 @@ function estateFrom(dir, cwd) {
252
187
  }
253
188
  return readdirSync(root).filter((f) => f.endsWith(".json")).flatMap((f) => {
254
189
  try {
255
- const snap = readJson(join(root, f));
256
- return snap.version === 1 && snap.fonts ? [{ id: f.replace(/(\.snapshot)?\.json$/, ""), fingerprint: fingerprint(snap) }] : [];
190
+ const snap = readSnapshot(readJson(join(root, f)), f);
191
+ return snap.fonts ? [{ id: f.replace(/(\.snapshot)?\.json$/, ""), fingerprint: fingerprint(snap) }] : [];
257
192
  } catch {
258
193
  return [];
259
194
  }
@@ -287,7 +222,7 @@ function runDirection(args, io) {
287
222
  fingerprint: current,
288
223
  pathExists: (p) => existsSync(resolve(dirname(file), p))
289
224
  });
290
- if (flags.json) io.out(JSON.stringify(report, null, 2));
225
+ if (flags.json) io.out(toJson(report));
291
226
  else {
292
227
  for (const p of report.problems) io.out(` ${p.severity === "error" ? "error" : "warn "} ${p.at || "(file)"} ${p.message}`);
293
228
  io.out(`craft direction: ${report.valid ? "valid" : "not valid"}, ${report.decided} of 7 choices decided with a reason.`);
package/dist/cli.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  run
4
- } from "./chunk-JKIDWHG3.js";
5
- import "./chunk-3NGWXZZE.js";
4
+ } from "./chunk-J3QUROJ5.js";
5
+ import "./chunk-AL6MRG6V.js";
6
6
 
7
7
  // src/cli.ts
8
8
  process.stdout.on("error", (error) => {