@iksnerd/blazon 0.3.3 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +375 -0
- package/dist/chunks/{site-builder-DlaZeZHi.js → site-builder-C8g2sfUv.js} +3471 -3650
- package/dist/cli/commands/approvals.d.ts +1 -1
- package/dist/cli/commands/approvals.d.ts.map +1 -1
- package/dist/cli/commands/mcp-check.d.ts +7 -4
- package/dist/cli/commands/mcp-check.d.ts.map +1 -1
- package/dist/cli/errors.d.ts +3 -1
- package/dist/cli/errors.d.ts.map +1 -1
- package/dist/cli/folder-first.d.ts +7 -0
- package/dist/cli/folder-first.d.ts.map +1 -0
- package/dist/cli/handlers/can.d.ts +1 -1
- package/dist/cli/handlers/can.d.ts.map +1 -1
- package/dist/cli/handlers/list.d.ts.map +1 -1
- package/dist/cli/index.js +1384 -1033
- package/dist/cli/json.d.ts +3 -2
- package/dist/cli/json.d.ts.map +1 -1
- package/dist/cli/operations.d.ts +1 -1
- package/dist/cli/operations.d.ts.map +1 -1
- package/dist/cli/read.d.ts +4 -1
- package/dist/cli/read.d.ts.map +1 -1
- package/dist/cli/where.d.ts +2 -0
- package/dist/cli/where.d.ts.map +1 -1
- package/dist/core/assets/representations.d.ts +44 -0
- package/dist/core/assets/representations.d.ts.map +1 -0
- package/dist/core/assets/scanner.d.ts.map +1 -1
- package/dist/core/assets/sidecar.d.ts.map +1 -1
- package/dist/core/blazon-pin.d.ts +19 -1
- package/dist/core/blazon-pin.d.ts.map +1 -1
- package/dist/core/brand/export.d.ts +13 -5
- package/dist/core/brand/export.d.ts.map +1 -1
- package/dist/core/brand/schema.d.ts +68 -0
- package/dist/core/brand/schema.d.ts.map +1 -1
- package/dist/core/checker/approvals.d.ts +5 -0
- package/dist/core/checker/approvals.d.ts.map +1 -1
- package/dist/core/checker/catalogue.d.ts +37 -7
- package/dist/core/checker/catalogue.d.ts.map +1 -1
- package/dist/core/checker/font-meta.d.ts.map +1 -1
- package/dist/core/checker/index.d.ts +5 -0
- package/dist/core/checker/index.d.ts.map +1 -1
- package/dist/core/checker/review.d.ts +19 -1
- package/dist/core/checker/review.d.ts.map +1 -1
- package/dist/core/docs/directives.d.ts +10 -0
- package/dist/core/docs/directives.d.ts.map +1 -1
- package/dist/core/docs/parser.d.ts.map +1 -1
- package/dist/core/font-roles.d.ts +11 -0
- package/dist/core/font-roles.d.ts.map +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/init/from-site/fonts.d.ts.map +1 -1
- package/dist/core/logo/colorways.d.ts +29 -0
- package/dist/core/logo/colorways.d.ts.map +1 -0
- package/dist/core/logo/misuse.d.ts +18 -0
- package/dist/core/logo/misuse.d.ts.map +1 -0
- package/dist/core/mcp-config.d.ts +7 -0
- package/dist/core/mcp-config.d.ts.map +1 -1
- package/dist/core/operations/check.d.ts +1 -1
- package/dist/core/operations/check.d.ts.map +1 -1
- package/dist/core/operations/index.d.ts +1 -1
- package/dist/core/operations/index.d.ts.map +1 -1
- package/dist/core/operations/limits.d.ts +2 -0
- package/dist/core/operations/limits.d.ts.map +1 -1
- package/dist/core/operations/list.d.ts.map +1 -1
- package/dist/core/operations/types.d.ts +13 -0
- package/dist/core/operations/types.d.ts.map +1 -1
- package/dist/core/preflight.d.ts.map +1 -1
- package/dist/core/read/can.d.ts +14 -3
- package/dist/core/read/can.d.ts.map +1 -1
- package/dist/core/read/fonts.d.ts +2 -6
- package/dist/core/read/fonts.d.ts.map +1 -1
- package/dist/core/read/index.d.ts +3 -2
- package/dist/core/read/index.d.ts.map +1 -1
- package/dist/core/read/list.d.ts +15 -1
- package/dist/core/read/list.d.ts.map +1 -1
- package/dist/core/read/logo.d.ts +3 -3
- package/dist/core/read/logo.d.ts.map +1 -1
- package/dist/core/read/lookup.d.ts +2 -2
- package/dist/core/read/lookup.d.ts.map +1 -1
- package/dist/core/read/theme.d.ts +8 -0
- package/dist/core/read/theme.d.ts.map +1 -0
- package/dist/core/read/token.d.ts +6 -2
- package/dist/core/read/token.d.ts.map +1 -1
- package/dist/core/tokens/alias.d.ts +5 -3
- package/dist/core/tokens/alias.d.ts.map +1 -1
- package/dist/core/tokens/contexts.d.ts +11 -3
- package/dist/core/tokens/contexts.d.ts.map +1 -1
- package/dist/core/tokens/formatters/json.d.ts +4 -1
- package/dist/core/tokens/formatters/json.d.ts.map +1 -1
- package/dist/core/tokens/key-lines.d.ts.map +1 -1
- package/dist/core/tokens/merge.d.ts.map +1 -1
- package/dist/core/tokens/resolver/compile.d.ts.map +1 -1
- package/dist/core/tokens/resolver/parse.d.ts.map +1 -1
- package/dist/core/tokens/resolver/sources.d.ts.map +1 -1
- package/dist/core/tokens/walk.d.ts.map +1 -1
- package/dist/index.js +34 -34
- package/dist/plugins/host/call.d.ts.map +1 -1
- package/dist/plugins/roles/roles.d.ts.map +1 -1
- package/dist/server/plugin.d.ts.map +1 -1
- package/dist/types/assets.d.ts +19 -1
- package/dist/types/assets.d.ts.map +1 -1
- package/dist/types/parsed.d.ts +8 -0
- package/dist/types/parsed.d.ts.map +1 -1
- package/dist/types/tokens.d.ts +12 -0
- package/dist/types/tokens.d.ts.map +1 -1
- package/dist/ui/assets/index-b4HhGGrn.js +82 -0
- package/dist/ui/assets/index-pE1ku5gt.css +2 -0
- package/dist/ui/index.html +2 -2
- package/mcp/dist/index.js +358 -45
- package/package.json +3 -2
- package/plugins/blazon.brand-deck/README.md +1 -1
- package/plugins/blazon.brand-deck/bin/blazon-blazon.brand-deck./360/237/224/214 +106 -13
- package/plugins/blazon.favicons/bin/blazon-blazon.favicons./360/237/224/214 +120 -12
- package/plugins/blazon.logo-geometry/bin/blazon-blazon.logo-geometry./360/237/224/214 +45 -1
- package/plugins/blazon.logo-kit/bin/blazon-blazon.logo-kit./360/237/224/214 +45 -1
- package/plugins/blazon.office-template/bin/blazon-blazon.office-template./360/237/224/214 +66 -3
- package/plugins/blazon.platform-tokens/README.md +1 -1
- package/plugins/blazon.press-kit/README.md +17 -9
- package/plugins/blazon.press-kit/bin/blazon-blazon.press-kit./360/237/224/214 +621 -101
- package/plugins/blazon.print-book/README.md +16 -1
- package/plugins/blazon.social-cards/bin/blazon-blazon.social-cards./360/237/224/214 +59 -3
- package/plugins/shipped.lock +9 -9
- package/dist/ui/assets/index-Biy1hkeq.css +0 -2
- package/dist/ui/assets/index-dkJG6W9p.js +0 -82
package/dist/cli/index.js
CHANGED
|
@@ -1,241 +1,242 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as e, At as t, B as n, Bt as r, C as i, D as a, Dt as o, E as s, Et as c, G as l, Gt as u, Ht as d, It as f, J as p, Jt as m, K as h, Lt as g, M as _, N as v, Nt as y, O as ee, Ot as b, Pt as x, Rn as te, Rt as S, S as C, Sn as w, St as ne, T as re, Tt as ie, Ut as ae, Vt as oe, Wt as se, Xt as ce, Yt as le, _ as ue, _n as de, _t as fe, a as pe, an as me, b as he, bn as ge, bt as _e, c as ve, cn as ye, d as be, dt as xe, f as Se, fn as Ce, g as we, gn as Te, gt as Ee, h as De, hn as Oe, ht as T, i as ke, in as Ae, j as je, k as E, l as Me, m as Ne, mn as Pe, on as Fe, p as Ie, pn as Le, q as Re, qt as ze, rn as Be, s as Ve, sn as He, t as Ue, tn as We, u as Ge, v as Ke, vn as D, vt as qe, w as Je, wn as Ye, x as Xe, xn as Ze, xt as Qe, y as $e, yn as et, yt as tt, z as nt, zn as rt, zt as it } from "../chunks/site-builder-C8g2sfUv.js";
|
|
2
2
|
import O from "node:path";
|
|
3
3
|
import k from "node:fs";
|
|
4
|
-
import { spawn as
|
|
5
|
-
import
|
|
6
|
-
import { preview as
|
|
7
|
-
import { cac as
|
|
4
|
+
import { spawn as at } from "node:child_process";
|
|
5
|
+
import ot from "node:os";
|
|
6
|
+
import { preview as st } from "vite";
|
|
7
|
+
import { cac as ct } from "cac";
|
|
8
8
|
import * as A from "@clack/prompts";
|
|
9
9
|
// src/cli/errors.ts
|
|
10
10
|
var j = class extends Error {
|
|
11
11
|
fix;
|
|
12
12
|
code;
|
|
13
|
+
hint;
|
|
13
14
|
constructor(e, t, n = "error") {
|
|
14
15
|
super(e), this.fix = t, this.code = n;
|
|
15
16
|
}
|
|
16
|
-
}, M = class extends j {},
|
|
17
|
-
function
|
|
18
|
-
return `blazon${e ? ` ${e}` : ""}: ${t}${n ? `\n ${n}` : ""}`;
|
|
17
|
+
}, M = class extends j {}, lt = (e) => new M(`port ${e} is in use`, "Pick another with --port, or leave out --strict-port to take the next free one.", "port-in-use"), ut = (e) => e.replace(/^./, (e) => e.toLowerCase()).replace(/\.$/, "");
|
|
18
|
+
function dt(e, t, n, r) {
|
|
19
|
+
return `blazon${e ? ` ${e}` : ""}: ${t}${n ? `\n ${n}` : ""}${r ? `\n ${r}` : ""}`;
|
|
19
20
|
}
|
|
20
|
-
var
|
|
21
|
-
function
|
|
22
|
-
|
|
21
|
+
var ft = (e, t) => t ? `${e}; ${ut(t)}` : e, pt;
|
|
22
|
+
function mt(e) {
|
|
23
|
+
pt = e;
|
|
23
24
|
}
|
|
24
|
-
function
|
|
25
|
-
console.error(e.replace(/^blazon(?: [a-z]+)*:/, (e) =>
|
|
25
|
+
function ht(e) {
|
|
26
|
+
console.error(e.replace(/^blazon(?: [a-z]+)*:/, (e) => a.red(e)));
|
|
26
27
|
}
|
|
27
|
-
var
|
|
28
|
+
var gt = (e, t, n) => ({
|
|
28
29
|
code: e,
|
|
29
30
|
message: t,
|
|
30
31
|
...n !== void 0 && { fix: n }
|
|
31
32
|
});
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
command:
|
|
33
|
+
function _t(e, t, n) {
|
|
34
|
+
pt !== void 0 && process.stdout.write(`${JSON.stringify({
|
|
35
|
+
command: pt,
|
|
35
36
|
passed: !1,
|
|
36
|
-
error:
|
|
37
|
+
error: gt(e, t, n)
|
|
37
38
|
})}\n`);
|
|
38
39
|
}
|
|
39
40
|
function N(e, t, n = {}) {
|
|
40
|
-
return
|
|
41
|
+
return ht(e), n.stack && console.error(n.stack), _t(t, n.json ?? e.replace(/^blazon(?: [a-z]+)?: /, ""), n.fix), process.exit(2);
|
|
41
42
|
}
|
|
42
|
-
var
|
|
43
|
+
var vt = (e) => e.replace(/`([^`]*)`/g, "\"$1\"").replace(/^./, (e) => e.toLowerCase()), yt = (e) => e instanceof Error && e.name === "CACError";
|
|
43
44
|
function P(e, t, n) {
|
|
44
45
|
let r = t instanceof j ? t.fix : void 0;
|
|
45
|
-
if (t instanceof M) return N(
|
|
46
|
+
if (t instanceof M) return N(dt(e, t.message, r, t.hint), t.code, {
|
|
46
47
|
stack: n ? t.stack : void 0,
|
|
47
|
-
json:
|
|
48
|
+
json: ft(t.message, r),
|
|
48
49
|
fix: r
|
|
49
50
|
});
|
|
50
51
|
let i = t instanceof Error ? t.message : String(t);
|
|
51
|
-
return console.error(),
|
|
52
|
+
return console.error(), ht(dt(e, i, r ?? (n || t instanceof j ? void 0 : a.dim("Run again with --debug for the stack.")))), n && t instanceof Error && t.stack && console.error(t.stack), _t(t instanceof j ? t.code : "error", ft(i, r), r), process.exit(1);
|
|
52
53
|
}
|
|
53
54
|
// src/cli/where.ts
|
|
54
55
|
function F(e, t = process.cwd()) {
|
|
55
56
|
let n = O.relative(t, O.resolve(t, e));
|
|
56
57
|
return n === "" ? "" : n.startsWith("..") || O.isAbsolute(n) ? O.resolve(t, e) : n.split(O.sep).join("/");
|
|
57
58
|
}
|
|
58
|
-
var I = (e, t) => e ? `${e}/${t}` : t,
|
|
59
|
-
function
|
|
60
|
-
if (!
|
|
59
|
+
var I = (e, t) => e ? `${e}/${t}` : t, bt = (e) => /^[\w./@%+=:,-]+$/.test(e) ? e : `'${e.replace(/'/g, "'\\''")}'`, L = (e, t) => `blazon ${e}${t ? ` ${bt(t)}` : ""}`, xt = (e) => k.statSync(e, { throwIfNoEntry: !1 })?.isDirectory() ?? !1, St = (e) => `Run ${L("init", F(e))} to start a brand book there`;
|
|
60
|
+
function Ct(e) {
|
|
61
|
+
if (!xt(e)) throw new M(`no folder "${e}"`, `${St(e)}.`, "no-folder");
|
|
61
62
|
}
|
|
62
|
-
function
|
|
63
|
-
if (!
|
|
63
|
+
function wt(e, t) {
|
|
64
|
+
if (!xt(O.resolve(e, t))) throw new M(`no tokens folder (${t.replace(/^\.\//, "").replace(/\/$/, "")}) in "${e}"`, `${St(e)}, or set tokensDir in blazon.json.`, "no-tokens-folder");
|
|
64
65
|
}
|
|
65
66
|
async function R(e, t) {
|
|
66
|
-
|
|
67
|
-
let n = await
|
|
68
|
-
return
|
|
67
|
+
Ct(e);
|
|
68
|
+
let n = await Ae(e, t);
|
|
69
|
+
return wt(e, n.tokensDir), n;
|
|
69
70
|
}
|
|
70
71
|
// src/cli/commands/dev.ts
|
|
71
|
-
var
|
|
72
|
-
async function
|
|
72
|
+
var Tt = /* @__PURE__ */ rt({ runDev: () => Et });
|
|
73
|
+
async function Et(e = process.cwd(), t, n = {}) {
|
|
73
74
|
let r = await R(e, t ? { port: t } : void 0);
|
|
74
75
|
try {
|
|
75
|
-
await
|
|
76
|
+
await ke(r, e, n);
|
|
76
77
|
} catch (e) {
|
|
77
|
-
throw n.strictPort && e instanceof Error && /already in use/.test(e.message) ?
|
|
78
|
+
throw n.strictPort && e instanceof Error && /already in use/.test(e.message) ? lt(r.port) : e;
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
81
|
// src/cli/commands/check.ts
|
|
81
|
-
var
|
|
82
|
+
var Dt = class extends j {
|
|
82
83
|
findings;
|
|
83
84
|
constructor(e, t, n, r = "check-failed") {
|
|
84
85
|
super(e, n, r), this.findings = t;
|
|
85
86
|
}
|
|
86
|
-
},
|
|
87
|
-
function
|
|
87
|
+
}, Ot = (e) => e?.plugins === !1, kt = (e) => e?.plugin === void 0 ? [] : [e.plugin].flat();
|
|
88
|
+
function At(e) {
|
|
88
89
|
return e.context ? `${e.path} (${e.context})` : e.path;
|
|
89
90
|
}
|
|
90
|
-
var
|
|
91
|
-
function
|
|
92
|
-
let t = e.slice(0,
|
|
93
|
-
return e.length >
|
|
94
|
-
}
|
|
95
|
-
var
|
|
96
|
-
function
|
|
97
|
-
let n = [], r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Map(),
|
|
98
|
-
for (let t of e) t.code === "starter-file-unchanged" && i.set(
|
|
99
|
-
for (let
|
|
100
|
-
if (r.has(
|
|
101
|
-
let e =
|
|
102
|
-
if (
|
|
91
|
+
var jt = 5;
|
|
92
|
+
function Mt(e) {
|
|
93
|
+
let t = e.slice(0, jt).join(", ");
|
|
94
|
+
return e.length > jt ? `${t} and ${e.length - jt} more` : t;
|
|
95
|
+
}
|
|
96
|
+
var Nt = (e) => e.path.split("/")[0];
|
|
97
|
+
function Pt(e, t) {
|
|
98
|
+
let n = [], r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), s = e.filter((e) => e.code === "page-review-pending");
|
|
99
|
+
for (let t of e) t.code === "starter-file-unchanged" && i.set(Nt(t), [...i.get(Nt(t)) ?? [], t]), t.code === "review-pending" && o.set(t.message, [...o.get(t.message) ?? [], t]);
|
|
100
|
+
for (let c of e) {
|
|
101
|
+
if (r.has(c)) continue;
|
|
102
|
+
let e = c.code === "starter-file-unchanged" ? i.get(Nt(c)) : void 0, l = c.code === "review-pending" ? o.get(c.message) : void 0;
|
|
103
|
+
if (c.code === "page-review-pending" && s.length > 1) s.forEach((e) => r.add(e)), n.push(`${a.bold(`page-review-pending (${s.length} pages)`)}: ${Mt(s.map(At))}: show assets still marked needs-review ${a.dim("[page-review-pending]")}`);
|
|
103
104
|
else if (e && e.length > 1) {
|
|
104
105
|
e.forEach((e) => r.add(e));
|
|
105
|
-
let t =
|
|
106
|
-
n.push(`${
|
|
107
|
-
} else if (
|
|
106
|
+
let t = Nt(c), i = e.map((e) => e.path.slice(t.length + 1));
|
|
107
|
+
n.push(`${a.bold(`${t}/`)}: ${e.length} files are still the starter's text (${Mt(i)}) ${a.dim("[starter-file-unchanged]")}`);
|
|
108
|
+
} else if (l && l.length > 1) l.forEach((e) => r.add(e)), n.push(`${a.bold(`review-pending (${l.length})`)}: ${Mt(l.map(At))}: ${c.message} ${a.dim("[review-pending]")}`);
|
|
108
109
|
else {
|
|
109
|
-
let e =
|
|
110
|
-
n.push(`${r}: ${
|
|
110
|
+
let e = ue(c, t), r = e === void 0 ? a.bold(At(c)) : c.path === c.file ? a.bold(e) : `${a.bold(e)} ${At(c)}`;
|
|
111
|
+
n.push(`${r}: ${c.message} ${a.dim(`[${c.code}]`)}`);
|
|
111
112
|
}
|
|
112
113
|
}
|
|
113
114
|
return n;
|
|
114
115
|
}
|
|
115
|
-
function
|
|
116
|
-
for (let n of
|
|
117
|
-
for (let n of
|
|
118
|
-
for (let n of
|
|
116
|
+
function Ft(e, t = "") {
|
|
117
|
+
for (let n of Pt(e.errors, t)) console.log(` ${a.bgRed(a.white(" ERROR "))} ${n}`);
|
|
118
|
+
for (let n of Pt(e.warnings, t)) console.log(` ${a.bgYellow(a.black(" WARN "))} ${n}`);
|
|
119
|
+
for (let n of Pt(e.infos, t)) console.log(` ${a.bgCyan(a.black(" NOTE "))} ${n}`);
|
|
119
120
|
}
|
|
120
|
-
var
|
|
121
|
-
function
|
|
122
|
-
e.infos.filter((e) => e.code === "starter-file-unchanged").length <
|
|
121
|
+
var It = 5;
|
|
122
|
+
function Lt(e, t = "") {
|
|
123
|
+
e.infos.filter((e) => e.code === "starter-file-unchanged").length < It || (console.log(a.bold("Next:")), console.log(` 1. Edit ${a.cyan(I(t, "tokens/colors.json"))} with your colors`), console.log(` 2. Run ${a.cyan(L("dev", t))} to see the book`), console.log(` 3. Replace blazon's artwork in ${a.cyan(I(t, "assets/"))} and the text in ${a.cyan(I(t, "docs/"))}`), console.log());
|
|
123
124
|
}
|
|
124
|
-
var
|
|
125
|
-
function
|
|
125
|
+
var Rt = 3;
|
|
126
|
+
function zt(e, t = "") {
|
|
126
127
|
let n = /* @__PURE__ */ new Map();
|
|
127
128
|
for (let t of e.errors) {
|
|
128
|
-
let e =
|
|
129
|
+
let e = $e(t);
|
|
129
130
|
e && !n.has(`${t.code}\n${e}`) && n.set(`${t.code}\n${e}`, {
|
|
130
131
|
code: t.code,
|
|
131
132
|
fix: e
|
|
132
133
|
});
|
|
133
134
|
}
|
|
134
|
-
let r = [...n.values()].slice(0,
|
|
135
|
-
console.log(
|
|
136
|
-
}
|
|
137
|
-
function
|
|
138
|
-
let
|
|
139
|
-
if (
|
|
140
|
-
let
|
|
141
|
-
if (console.log(),
|
|
142
|
-
}
|
|
143
|
-
async function
|
|
144
|
-
let
|
|
145
|
-
console.log(
|
|
146
|
-
let
|
|
147
|
-
|
|
148
|
-
let
|
|
149
|
-
if (
|
|
150
|
-
findings:
|
|
135
|
+
let r = [...n.values()].slice(0, Rt);
|
|
136
|
+
console.log(a.bold("Next:")), r.forEach(({ code: e, fix: t }, n) => console.log(` ${n + 1}. ${a.cyan(e)}: ${t}`)), console.log(` ${r.length + 1}. Run ${a.cyan(L("check", t))} again`), console.log();
|
|
137
|
+
}
|
|
138
|
+
function Bt(e, n = process.cwd()) {
|
|
139
|
+
let r = t(e.findings);
|
|
140
|
+
if (r.all.length === 0) return;
|
|
141
|
+
let i = F(n);
|
|
142
|
+
if (console.log(), Ft(r, i), console.log(), r.errors.length > 0) throw new Dt(`blazon check found ${r.errors.length} error(s)`, e.findings, `Fix them, or run ${L("check", i)} for details.`);
|
|
143
|
+
}
|
|
144
|
+
async function Vt(e = process.cwd(), n = !1, r) {
|
|
145
|
+
let i = await R(e);
|
|
146
|
+
console.log(a.cyan("\n[blazon] Checking design tokens..."));
|
|
147
|
+
let o = await T(i, e);
|
|
148
|
+
o.findings.push(...tt(e)), Ot(r) || await Je(o, i, e, new he(i, e, { named: kt(r) }));
|
|
149
|
+
let s = t(o.findings, { strict: n });
|
|
150
|
+
if (s.all.length === 0) return console.log(a.green(`\n ✔ ${o.tokens.items.length} tokens, no findings.\n`)), {
|
|
151
|
+
findings: s.all,
|
|
151
152
|
passed: !0
|
|
152
153
|
};
|
|
153
|
-
let
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
].filter(Boolean),
|
|
158
|
-
return console.log(`\nFound ${
|
|
159
|
-
findings:
|
|
154
|
+
let c = [
|
|
155
|
+
s.errors.length > 0 && `${s.errors.length} error(s)`,
|
|
156
|
+
s.warnings.length > 0 && `${s.warnings.length} warning(s)`,
|
|
157
|
+
s.infos.length > 0 && `${s.infos.length} note(s)`
|
|
158
|
+
].filter(Boolean), l = s.errors.length + s.warnings.length > 0 ? `${s.errors.length} error(s) and ${s.warnings.length} warning(s)${s.infos.length > 0 ? ` and ${s.infos.length} note(s)` : ""}` : c.join(" and "), u = F(e);
|
|
159
|
+
return console.log(`\nFound ${l}:\n`), Ft(s, u), console.log(), s.errors.length > 0 ? zt(s, u) : Lt(s, u), s.passed ? (console.log(s.warnings.length > 0 ? a.yellow("✔ Check passed with warnings.\n") : a.green("✔ Check passed.\n")), {
|
|
160
|
+
findings: s.all,
|
|
160
161
|
passed: !0
|
|
161
|
-
}) : (console.error(
|
|
162
|
-
findings:
|
|
162
|
+
}) : (console.error(a.red(`✖ Check failed${n ? " (--strict treats warnings as errors)" : ""}.\n`)), {
|
|
163
|
+
findings: s.all,
|
|
163
164
|
passed: !1
|
|
164
165
|
});
|
|
165
166
|
}
|
|
166
167
|
// src/cli/commands/build.ts
|
|
167
|
-
async function
|
|
168
|
-
let
|
|
169
|
-
|
|
170
|
-
let
|
|
171
|
-
|
|
172
|
-
let { siteOutDir:
|
|
173
|
-
if (u.length === 0) return { findings:
|
|
174
|
-
let d =
|
|
175
|
-
if (console.log(),
|
|
176
|
-
return console.log(
|
|
168
|
+
async function Ht(e = process.cwd(), n, r) {
|
|
169
|
+
let o = await R(e, n ? { outDir: n } : void 0), s = await T(o, e);
|
|
170
|
+
s.findings.push(...tt(e));
|
|
171
|
+
let c = new he(o, e, { named: kt(r) });
|
|
172
|
+
Ot(r) || await Je(s, o, e, c), Bt(s, e);
|
|
173
|
+
let { siteOutDir: l } = await Ue(o, e, { data: s }), u = Ot(r) ? [] : await i(s, o, e, c, l);
|
|
174
|
+
if (u.length === 0) return { findings: s.findings };
|
|
175
|
+
let d = t(u);
|
|
176
|
+
if (console.log(), Ft(d, F(e)), console.log(), d.errors.length > 0) throw new Dt(`a build plugin reported ${d.errors.length} error(s)`, [...s.findings, ...u], "The site is built; the plugin's findings above say what to fix.", "plugin-failed");
|
|
177
|
+
return console.log(a.dim(" Build plugins finished.")), { findings: [...s.findings, ...u] };
|
|
177
178
|
}
|
|
178
179
|
// src/cli/commands/tokens.ts
|
|
179
|
-
async function
|
|
180
|
-
let
|
|
181
|
-
console.log(
|
|
182
|
-
let
|
|
183
|
-
|
|
184
|
-
let
|
|
185
|
-
|
|
186
|
-
let
|
|
180
|
+
async function Ut(e = process.cwd(), n) {
|
|
181
|
+
let r = await R(e);
|
|
182
|
+
console.log(a.cyan("\n[blazon] Compiling design tokens..."));
|
|
183
|
+
let o = await T(r, e);
|
|
184
|
+
o.findings.push(...tt(e));
|
|
185
|
+
let s = new he(r, e, { named: kt(n) });
|
|
186
|
+
Ot(n) || await Je(o, r, e, s), Bt(o, e);
|
|
187
|
+
let c = await Ee(o, r, e);
|
|
187
188
|
for (let e of [
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
]) e && console.log(` ${
|
|
189
|
+
c.cssPath,
|
|
190
|
+
c.typographyPath,
|
|
191
|
+
c.tsPath,
|
|
192
|
+
c.jsonPath
|
|
193
|
+
]) e && console.log(` ${a.green("✔")} Emitted ${a.bold(e)}`);
|
|
193
194
|
console.log();
|
|
194
|
-
let
|
|
195
|
-
if (
|
|
196
|
-
let u =
|
|
197
|
-
if (
|
|
198
|
-
return { findings: [...
|
|
195
|
+
let l = Ot(n) ? [] : await i(o, r, e, s);
|
|
196
|
+
if (l.length === 0) return { findings: o.findings };
|
|
197
|
+
let u = t(l);
|
|
198
|
+
if (Ft(u, F(e)), console.log(), u.errors.length > 0) throw new Dt(`a build plugin reported ${u.errors.length} error(s)`, [...o.findings, ...l], "The token files are written; the plugin's findings above say what to fix.", "plugin-failed");
|
|
199
|
+
return { findings: [...o.findings, ...l] };
|
|
199
200
|
}
|
|
200
201
|
// src/core/drift/compare.ts
|
|
201
|
-
var
|
|
202
|
-
function
|
|
202
|
+
var Wt = /^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i, Gt = /^(-?(?:\d+\.?\d*|\.\d+))(px|rem)$/i, Kt = (e) => e.trim().toLowerCase().replace(/\s+/g, " ");
|
|
203
|
+
function qt(e) {
|
|
203
204
|
let t = e.trim();
|
|
204
|
-
if (!
|
|
205
|
+
if (!Wt.test(t)) return Kt(t);
|
|
205
206
|
let n = t.slice(1).toLowerCase();
|
|
206
207
|
return `#${n.length <= 4 ? [...n].map((e) => e + e).join("") : n}`;
|
|
207
208
|
}
|
|
208
|
-
function
|
|
209
|
-
let t = e.trim().match(
|
|
210
|
-
return t ? `${Number(t[1])}${t[2].toLowerCase()}` :
|
|
209
|
+
function Jt(e) {
|
|
210
|
+
let t = e.trim().match(Gt);
|
|
211
|
+
return t ? `${Number(t[1])}${t[2].toLowerCase()}` : Kt(e);
|
|
211
212
|
}
|
|
212
|
-
function
|
|
213
|
-
return e === "color" ?
|
|
213
|
+
function Yt(e, t) {
|
|
214
|
+
return e === "color" ? qt(t) : e === "dimension" ? Jt(t) : Kt(t);
|
|
214
215
|
}
|
|
215
|
-
var
|
|
216
|
-
function
|
|
216
|
+
var Xt = /\/\*[\s\S]*?\*\//g, Zt = /([^{}]*)\{([^{}]*)\}/g, Qt = /(--[A-Za-z0-9_-]+)\s*:\s*([^;]*?)\s*(?:;|$)/g, $t = /(^|,)\s*(:root|html)\s*(,|$)/, en = /^var\(\s*(--[A-Za-z0-9_-]+)\s*\)$/;
|
|
217
|
+
function tn(e) {
|
|
217
218
|
let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
|
|
218
|
-
for (let r of e.replace(
|
|
219
|
-
let e =
|
|
220
|
-
for (let t of r[2].matchAll(
|
|
219
|
+
for (let r of e.replace(Xt, "").matchAll(Zt)) {
|
|
220
|
+
let e = $t.test(r[1].trim()) ? t : n;
|
|
221
|
+
for (let t of r[2].matchAll(Qt)) e.set(t[1], t[2]);
|
|
221
222
|
}
|
|
222
223
|
let r = new Map([...n, ...t]);
|
|
223
224
|
for (let [e, t] of r) {
|
|
224
225
|
let n = t, i = /* @__PURE__ */ new Set([e]);
|
|
225
|
-
for (let e = n.match(
|
|
226
|
+
for (let e = n.match(en); e && r.has(e[1]) && !i.has(e[1]); e = n.match(en)) i.add(e[1]), n = r.get(e[1]);
|
|
226
227
|
r.set(e, n);
|
|
227
228
|
}
|
|
228
229
|
return r;
|
|
229
230
|
}
|
|
230
|
-
function
|
|
231
|
-
let r =
|
|
231
|
+
function nn(e, t, n) {
|
|
232
|
+
let r = Yt(e.type, String(e.value)), i = n.get(t);
|
|
232
233
|
if (i === void 0) return {
|
|
233
234
|
path: e.path,
|
|
234
235
|
cssVar: t,
|
|
235
236
|
status: "missing",
|
|
236
237
|
expected: r
|
|
237
238
|
};
|
|
238
|
-
let a =
|
|
239
|
+
let a = Yt(e.type, i);
|
|
239
240
|
return {
|
|
240
241
|
path: e.path,
|
|
241
242
|
cssVar: t,
|
|
@@ -244,21 +245,21 @@ function Yt(e, t, n) {
|
|
|
244
245
|
actual: a
|
|
245
246
|
};
|
|
246
247
|
}
|
|
247
|
-
var
|
|
248
|
-
function
|
|
248
|
+
var rn = 1e4;
|
|
249
|
+
function an(e) {
|
|
249
250
|
let t = e instanceof Error ? e.message : String(e), n = e instanceof Error ? e.cause : void 0;
|
|
250
251
|
return n instanceof Error && n.message && n.message !== t ? `${t}: ${n.message}` : t;
|
|
251
252
|
}
|
|
252
|
-
async function
|
|
253
|
+
async function on(e) {
|
|
253
254
|
let t;
|
|
254
255
|
try {
|
|
255
256
|
t = await fetch(e, {
|
|
256
|
-
signal: AbortSignal.timeout(
|
|
257
|
+
signal: AbortSignal.timeout(rn),
|
|
257
258
|
redirect: "follow"
|
|
258
259
|
});
|
|
259
260
|
} catch (t) {
|
|
260
261
|
let n = t instanceof Error && (t.name === "TimeoutError" || t.name === "AbortError");
|
|
261
|
-
throw Error(`could not fetch ${e}: ${n ? `no answer in ${
|
|
262
|
+
throw Error(`could not fetch ${e}: ${n ? `no answer in ${rn / 1e3} s` : an(t)}`, { cause: t });
|
|
262
263
|
}
|
|
263
264
|
if (!t.ok) throw Error(`could not fetch ${e}: ${t.status} ${t.statusText}`.trim());
|
|
264
265
|
let n = [], r = 0;
|
|
@@ -272,10 +273,10 @@ async function Qt(e) {
|
|
|
272
273
|
}
|
|
273
274
|
return Buffer.concat(n);
|
|
274
275
|
}
|
|
275
|
-
async function
|
|
276
|
-
return (await
|
|
276
|
+
async function sn(e) {
|
|
277
|
+
return (await on(e)).toString("utf8");
|
|
277
278
|
}
|
|
278
|
-
function
|
|
279
|
+
function cn(e, t) {
|
|
279
280
|
let n = [];
|
|
280
281
|
for (let [r] of e.replace(/<!--[\s\S]*?-->/g, "").matchAll(/<link\b[^>]*>/gi)) {
|
|
281
282
|
let e = (e) => r.match(RegExp(`\\s${e}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`, "i")), i = e("rel"), a = e("href");
|
|
@@ -286,12 +287,12 @@ function en(e, t) {
|
|
|
286
287
|
}
|
|
287
288
|
return n;
|
|
288
289
|
}
|
|
289
|
-
async function
|
|
290
|
+
async function ln(e) {
|
|
290
291
|
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(e)) {
|
|
291
292
|
if (!/^https?:\/\//i.test(e)) throw Error(`${e} is not an http(s) address or a file`);
|
|
292
|
-
let t =
|
|
293
|
+
let t = cn(await sn(e), e).slice(0, 20);
|
|
293
294
|
return {
|
|
294
|
-
css: (await Promise.all(t.map(
|
|
295
|
+
css: (await Promise.all(t.map(sn))).join("\n"),
|
|
295
296
|
sources: t
|
|
296
297
|
};
|
|
297
298
|
}
|
|
@@ -307,60 +308,60 @@ async function tn(e) {
|
|
|
307
308
|
sources: [t]
|
|
308
309
|
};
|
|
309
310
|
}
|
|
310
|
-
async function
|
|
311
|
+
async function un(e) {
|
|
311
312
|
if (!/^https?:\/\//i.test(e)) throw Error(`${e} is not an http(s) address`);
|
|
312
|
-
let t = await
|
|
313
|
+
let t = await sn(e), n = cn(t, e).slice(0, 20);
|
|
313
314
|
return {
|
|
314
315
|
html: t,
|
|
315
|
-
css: (await Promise.all(n.map(
|
|
316
|
+
css: (await Promise.all(n.map(sn))).join("\n"),
|
|
316
317
|
sources: n
|
|
317
318
|
};
|
|
318
319
|
}
|
|
319
320
|
// src/core/init/from-site/tree.ts
|
|
320
|
-
var
|
|
321
|
-
function
|
|
321
|
+
var dn = (e) => typeof e == "object" && !!e && "$value" in e;
|
|
322
|
+
function fn(e) {
|
|
322
323
|
return JSON.parse(k.readFileSync(e, "utf-8"));
|
|
323
324
|
}
|
|
324
|
-
function
|
|
325
|
+
function pn(e, t) {
|
|
325
326
|
k.writeFileSync(e, `${JSON.stringify(t, null, 2)}\n`);
|
|
326
327
|
}
|
|
327
|
-
var
|
|
328
|
-
function
|
|
328
|
+
var mn = (e) => ({ "dev.blazon": e });
|
|
329
|
+
function hn(e, t = []) {
|
|
329
330
|
let n = [];
|
|
330
|
-
for (let [r, i] of Object.entries(e)) !r.startsWith("$") && typeof i == "object" && i && (
|
|
331
|
+
for (let [r, i] of Object.entries(e)) !r.startsWith("$") && typeof i == "object" && i && (dn(i) ? n.push([...t, r].join(".")) : n.push(...hn(i, [...t, r])));
|
|
331
332
|
return n;
|
|
332
333
|
}
|
|
333
|
-
var
|
|
334
|
+
var gn = (e, t) => {
|
|
334
335
|
let n = e;
|
|
335
336
|
for (let e of t.split(".")) {
|
|
336
337
|
if (typeof n != "object" || !n) return;
|
|
337
338
|
n = n[e];
|
|
338
339
|
}
|
|
339
|
-
return
|
|
340
|
-
},
|
|
341
|
-
function
|
|
340
|
+
return dn(n) ? n : void 0;
|
|
341
|
+
}, _n = (e) => [...JSON.stringify(e).matchAll(/\{([A-Za-z0-9_.-]+)\}/g)].map((e) => e[1]);
|
|
342
|
+
function vn(e, t) {
|
|
342
343
|
return k.existsSync(e) ? k.readdirSync(e, { withFileTypes: !0 }).flatMap((n) => {
|
|
343
344
|
let r = O.join(e, n.name);
|
|
344
|
-
return n.isDirectory() ?
|
|
345
|
+
return n.isDirectory() ? vn(r, t) : t.some((e) => n.name.endsWith(e)) ? [r] : [];
|
|
345
346
|
}) : [];
|
|
346
347
|
}
|
|
347
|
-
function
|
|
348
|
+
function yn(e, t) {
|
|
348
349
|
let n = t.split("."), r = [e];
|
|
349
350
|
for (let e of n.slice(0, -1)) r.push(r.at(-1)[e]);
|
|
350
351
|
delete r.at(-1)[n.at(-1)];
|
|
351
352
|
for (let e = r.length - 1; e >= 2 && !Object.keys(r[e]).some((e) => !e.startsWith("$")); e--) delete r[e - 1][n[e - 1]];
|
|
352
353
|
}
|
|
353
354
|
// src/core/init/from-site/clean-colors.ts
|
|
354
|
-
function
|
|
355
|
+
function bn(e) {
|
|
355
356
|
let { tree: t, destDir: n, picks: r, starterColors: i, siteColors: a, note: o, review: s, source: c, result: l } = e, u = (e, n) => {
|
|
356
|
-
let r =
|
|
357
|
+
let r = gn(t, `${e}.${n}`)?.$value, o = typeof r == "string" ? r.match(/^\{(.+)\}$/)?.[1] : void 0;
|
|
357
358
|
return o && i.has(o) && !a.has(o) ? o : void 0;
|
|
358
359
|
}, d = (e, n, r, i = {}) => {
|
|
359
|
-
let [a, c] = e.split("."), u =
|
|
360
|
+
let [a, c] = e.split("."), u = gn(t, e), d = String(u.$value);
|
|
360
361
|
t[a][c] = {
|
|
361
362
|
$value: `{${n}}`,
|
|
362
363
|
...typeof u.$description == "string" && { $description: u.$description },
|
|
363
|
-
$extensions:
|
|
364
|
+
$extensions: mn({
|
|
364
365
|
...i,
|
|
365
366
|
review: r ? {
|
|
366
367
|
...s,
|
|
@@ -391,20 +392,20 @@ function pn(e) {
|
|
|
391
392
|
let [n, r] = e.split("."), i = p(t);
|
|
392
393
|
i && u(n, r) && d(e, f(i), "", { source: c(`:root { ${i.cssVar} }`, i.exact ? i.cssVar : void 0) });
|
|
393
394
|
}
|
|
394
|
-
let m = t.color, { color: h, ...g } = t, _ = new Set(
|
|
395
|
-
for (let e of
|
|
396
|
-
let v = [O.join(n, "blazon.json"), ...
|
|
395
|
+
let m = t.color, { color: h, ...g } = t, _ = new Set(_n(g));
|
|
396
|
+
for (let e of vn(O.join(n, "tokens"), [".json"])) if (O.basename(e) !== "colors.json") for (let t of _n(fn(e))) _.add(t);
|
|
397
|
+
let v = [O.join(n, "blazon.json"), ...vn(O.join(n, "docs"), [".md", ".mdx"])].filter((e) => k.existsSync(e)).map((e) => k.readFileSync(e, "utf-8")).join("\n");
|
|
397
398
|
for (let e of v.matchAll(/(?<![\w.-])color(?:\.[A-Za-z0-9_-]+)+/g)) _.add(e[0]);
|
|
398
399
|
let y = [..._];
|
|
399
400
|
for (; y.length > 0;) {
|
|
400
|
-
let e =
|
|
401
|
-
for (let t of e ?
|
|
401
|
+
let e = gn(t, y.pop());
|
|
402
|
+
for (let t of e ? _n(e.$value) : []) _.has(t) || (_.add(t), y.push(t));
|
|
402
403
|
}
|
|
403
|
-
for (let e of [...i].filter((e) => !a.has(e) && !_.has(e)))
|
|
404
|
+
for (let e of [...i].filter((e) => !a.has(e) && !_.has(e))) gn({ color: m }, e) && (yn({ color: m }, e), l.removed.push(`${e} (a starter color nothing uses)`));
|
|
404
405
|
}
|
|
405
406
|
// src/core/init/palette.ts
|
|
406
|
-
var
|
|
407
|
-
function
|
|
407
|
+
var xn = "#ffffff", Sn = "#0b1120";
|
|
408
|
+
function Cn(e) {
|
|
408
409
|
let t = e.trim().match(/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i);
|
|
409
410
|
if (!t) return;
|
|
410
411
|
let n = t[1].length === 3 ? [...t[1]].map((e) => e + e).join("") : t[1];
|
|
@@ -414,38 +415,38 @@ function gn(e) {
|
|
|
414
415
|
4
|
|
415
416
|
].map((e) => parseInt(n.slice(e, e + 2), 16) / 255);
|
|
416
417
|
}
|
|
417
|
-
var
|
|
418
|
-
function
|
|
419
|
-
let t =
|
|
418
|
+
var wn = (e) => e <= .04045 ? e / 12.92 : ((e + .055) / 1.055) ** 2.4;
|
|
419
|
+
function Tn(e) {
|
|
420
|
+
let t = Cn(e);
|
|
420
421
|
if (!t) throw Error(`not a hex color: ${e}`);
|
|
421
422
|
return t;
|
|
422
423
|
}
|
|
423
|
-
function
|
|
424
|
-
let [t, n, r] =
|
|
424
|
+
function En(e) {
|
|
425
|
+
let [t, n, r] = Tn(e).map(wn);
|
|
425
426
|
return .2126 * t + .7152 * n + .0722 * r;
|
|
426
427
|
}
|
|
427
428
|
function z(e, t) {
|
|
428
|
-
let [n, r] = [
|
|
429
|
+
let [n, r] = [En(e), En(t)];
|
|
429
430
|
return (Math.max(n, r) + .05) / (Math.min(n, r) + .05);
|
|
430
431
|
}
|
|
431
|
-
var
|
|
432
|
-
function
|
|
433
|
-
let t = z(e,
|
|
432
|
+
var Dn = (e) => e >= 7 ? "AAA" : e >= 4.5 ? "AA" : e >= 3 ? "AA-large" : "fail";
|
|
433
|
+
function On(e) {
|
|
434
|
+
let t = z(e, xn), n = z(e, Sn);
|
|
434
435
|
return {
|
|
435
436
|
onWhite: {
|
|
436
437
|
ratio: t,
|
|
437
|
-
level:
|
|
438
|
+
level: Dn(t)
|
|
438
439
|
},
|
|
439
440
|
onNearBlack: {
|
|
440
441
|
ratio: n,
|
|
441
|
-
level:
|
|
442
|
+
level: Dn(n)
|
|
442
443
|
},
|
|
443
444
|
carriesWhiteText: t >= 4.5
|
|
444
445
|
};
|
|
445
446
|
}
|
|
446
|
-
var
|
|
447
|
-
function
|
|
448
|
-
let t = z(e,
|
|
447
|
+
var kn = "#1E1F21", An = "#F2F0EB";
|
|
448
|
+
function jn(e) {
|
|
449
|
+
let t = z(e, kn), n = z(e, An);
|
|
449
450
|
return t >= n ? {
|
|
450
451
|
ink: "graphite",
|
|
451
452
|
ratio: t,
|
|
@@ -457,42 +458,42 @@ function wn(e) {
|
|
|
457
458
|
};
|
|
458
459
|
}
|
|
459
460
|
// src/core/init/vocabulary.ts
|
|
460
|
-
var
|
|
461
|
+
var Mn = "color.signal.orange", Nn = "color.signal.primary", Pn = "color.signal.hazard", Fn = (e) => typeof e == "object" && !!e && "$value" in e;
|
|
461
462
|
function B(e, t) {
|
|
462
463
|
let n = e;
|
|
463
464
|
for (let e of t.split(".")) {
|
|
464
465
|
if (typeof n != "object" || !n) return;
|
|
465
466
|
n = n[e];
|
|
466
467
|
}
|
|
467
|
-
return
|
|
468
|
+
return Fn(n) ? n : void 0;
|
|
468
469
|
}
|
|
469
|
-
function
|
|
470
|
+
function In(e, t) {
|
|
470
471
|
let n = e.$extensions ??= {}, r = n["dev.blazon"] ??= {};
|
|
471
472
|
r.review === void 0 && (r.review = {
|
|
472
473
|
status: "needs-review",
|
|
473
474
|
note: t
|
|
474
475
|
});
|
|
475
476
|
}
|
|
476
|
-
function
|
|
477
|
+
function Ln(e, t) {
|
|
477
478
|
let n = [], r = e.color, i = r?.signal, a = i?.orange;
|
|
478
|
-
if (!i || !
|
|
479
|
+
if (!i || !Fn(a)) throw Error(`${Mn} is not in the tokens`);
|
|
479
480
|
let o = {};
|
|
480
481
|
for (let [e, t] of Object.entries(i)) o[e === "orange" ? "primary" : e] = t;
|
|
481
482
|
r.signal = o;
|
|
482
|
-
let s = JSON.parse(JSON.stringify(e).split(`{${
|
|
483
|
+
let s = JSON.parse(JSON.stringify(e).split(`{${Mn}}`).join(`{${Nn}}`));
|
|
483
484
|
for (let t of Object.keys(e)) e[t] = s[t];
|
|
484
|
-
let c = B(e,
|
|
485
|
+
let c = B(e, Nn);
|
|
485
486
|
c.$value = t, c.$description = "Primary signal color";
|
|
486
|
-
let l =
|
|
487
|
+
let l = Rn(e, t, `{${Nn}}`);
|
|
487
488
|
n.push(...l.hints);
|
|
488
|
-
let u = B(e,
|
|
489
|
-
return u && (
|
|
489
|
+
let u = B(e, Pn);
|
|
490
|
+
return u && (In(u, "Still blazon's hazard yellow: it was not chosen to go with your primary. Set the brand's own, or remove it."), n.push(`${Pn} is still blazon's hazard yellow and is marked needs-review: set the brand's own or remove it`)), {
|
|
490
491
|
hints: n,
|
|
491
492
|
label: l.label
|
|
492
493
|
};
|
|
493
494
|
}
|
|
494
|
-
function
|
|
495
|
-
let i = [], a = z(t,
|
|
495
|
+
function Rn(e, t, n, r = !1) {
|
|
496
|
+
let i = [], a = z(t, kn), o = z(t, An), s = B(e, "text.onSignal"), c = a < 4.5 && o >= 4.5 && s !== void 0;
|
|
496
497
|
if (c ? (s.$value = "{color.base.bone}", s.$description = "Labels on the brand color are bone", i.push(`Labels on ${t} are bone, because graphite is ${a.toFixed(1)}:1 there; blazon's hazard yellow has no label pair now`)) : a < 4.5 && i.push(`Neither graphite (${a.toFixed(1)}:1) nor bone (${o.toFixed(1)}:1) reaches AA (4.5:1) as a label on ${t}: blazon check will report text.onSignal, so choose a lighter or darker color`), c || r) {
|
|
497
498
|
let t = e.text?.$extensions?.["dev.blazon"];
|
|
498
499
|
for (let e of t?.pairs ?? []) e.bg === "{color.signal.*}" && (e.bg = n);
|
|
@@ -502,16 +503,16 @@ function jn(e, t, n, r = !1) {
|
|
|
502
503
|
label: c ? "bone" : "graphite"
|
|
503
504
|
};
|
|
504
505
|
}
|
|
505
|
-
var
|
|
506
|
-
function
|
|
506
|
+
var zn = (e) => JSON.parse(k.readFileSync(e, "utf-8")), Bn = (e, t) => k.writeFileSync(e, `${JSON.stringify(t, null, 2)}\n`);
|
|
507
|
+
function Vn(e, t) {
|
|
507
508
|
return [...t, ...Array.isArray(e) ? e.filter((e) => typeof e == "object" && !!e) : []];
|
|
508
509
|
}
|
|
509
|
-
var
|
|
510
|
+
var Hn = ["blazon-graphite", "blazon-bone"], Un = [...Hn, "blazon-mark"];
|
|
510
511
|
// src/core/init/shared/hex.ts
|
|
511
|
-
function
|
|
512
|
+
function Wn(e) {
|
|
512
513
|
let t = e.trim();
|
|
513
514
|
if (/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(t)) return {
|
|
514
|
-
hex:
|
|
515
|
+
hex: qt(t),
|
|
515
516
|
exact: !0
|
|
516
517
|
};
|
|
517
518
|
let n = t.match(/^rgba?\(\s*([\d.]+)(%?)[\s,]+([\d.]+)%?[\s,]+([\d.]+)%?(?:\s*[,/]\s*([\d.]+)(%?))?\s*\)$/i);
|
|
@@ -527,12 +528,12 @@ function Ln(e) {
|
|
|
527
528
|
};
|
|
528
529
|
}
|
|
529
530
|
// src/core/init/from-site/colors.ts
|
|
530
|
-
var
|
|
531
|
-
function
|
|
531
|
+
var Gn = 40, Kn = /brand|primary|secondary|accent|background|foreground|surface/i;
|
|
532
|
+
function qn(e) {
|
|
532
533
|
let t = [], n = /* @__PURE__ */ new Set();
|
|
533
534
|
for (let [r, i] of e) {
|
|
534
|
-
if (!
|
|
535
|
-
let e =
|
|
535
|
+
if (!Kn.test(r)) continue;
|
|
536
|
+
let e = Wn(i);
|
|
536
537
|
if (!e || e.hex.length !== 7) continue;
|
|
537
538
|
let a = r.slice(2).toLowerCase().split(/[-_]+/).filter(Boolean);
|
|
538
539
|
a.length > 1 && (a[0] === "color" || a[0] === "colors") && (a = a.slice(1)), a.length > 1 && a.at(-1) === "foreground" || a.length > 1 && a.at(-2) === "on" && /^(dark|light)$/.test(a.at(-1)) || a.length === 0 || n.has(a.join(".")) || (n.add(a.join(".")), t.push({
|
|
@@ -541,20 +542,20 @@ function Bn(e) {
|
|
|
541
542
|
segments: a
|
|
542
543
|
}));
|
|
543
544
|
}
|
|
544
|
-
return t.slice(0,
|
|
545
|
+
return t.slice(0, Gn);
|
|
545
546
|
}
|
|
546
|
-
function
|
|
547
|
+
function Jn(e, t, n = []) {
|
|
547
548
|
let r = e.filter((e) => e.segments.includes(t)).sort((e, n) => Number(e.segments.at(-1) !== t) - Number(n.segments.at(-1) !== t) || e.segments.length - n.segments.length)[0];
|
|
548
549
|
return r || t !== "secondary" ? r : e.find((e) => !n.includes(e) && e.segments.includes("brand") && !e.segments.some((e) => /light|dark|strong|hero|raised|navy|background|foreground|surface/.test(e)));
|
|
549
550
|
}
|
|
550
551
|
// src/core/init/from-site/context.ts
|
|
551
|
-
var
|
|
552
|
+
var Yn = (...e) => e.join("/");
|
|
552
553
|
// src/core/init/from-site/sections/colors.ts
|
|
553
|
-
function
|
|
554
|
-
let { destDir: n, vars: r, result: i, note: a, review: o, source: s, mayChange: c } = e, l =
|
|
554
|
+
function Xn(e, t) {
|
|
555
|
+
let { destDir: n, vars: r, result: i, note: a, review: o, source: s, mayChange: c } = e, l = qn(r).filter((e) => !t?.has(e.cssVar));
|
|
555
556
|
if (l.length === 0) i.missing.push("no brand color: no custom property named brand, primary, secondary, accent, background, foreground or surface holds a hex or rgb() color");
|
|
556
|
-
else if (c(
|
|
557
|
-
let e = O.join(n, "tokens", "colors.json"), t =
|
|
557
|
+
else if (c(Yn("tokens", "colors.json"))) {
|
|
558
|
+
let e = O.join(n, "tokens", "colors.json"), t = fn(e), r = t.color ??= {}, c = new Set(hn(r, ["color"])), u = /* @__PURE__ */ new Set(), d = new Set(l.map((e) => e.segments.join(".")));
|
|
558
559
|
for (let e of l) {
|
|
559
560
|
let t = e.segments;
|
|
560
561
|
[...d].some((e) => e.startsWith(`${t.join(".")}.`)) && (t = [...t, "base"]);
|
|
@@ -563,37 +564,37 @@ function Un(e, t) {
|
|
|
563
564
|
let t = n[r];
|
|
564
565
|
if (t === void 0) {
|
|
565
566
|
let t = {};
|
|
566
|
-
e === 0 && (t.$extensions =
|
|
567
|
-
} else if (
|
|
567
|
+
e === 0 && (t.$extensions = mn({ review: o }), a = !0), n[r] = t, n = t;
|
|
568
|
+
} else if (dn(t) || typeof t != "object" || !t) {
|
|
568
569
|
c = !1;
|
|
569
570
|
break;
|
|
570
571
|
} else n = t;
|
|
571
572
|
}
|
|
572
573
|
let l = t.at(-1);
|
|
573
|
-
!c || typeof n[l] == "object" && n[l] !== null && !
|
|
574
|
+
!c || typeof n[l] == "object" && n[l] !== null && !dn(n[l]) ? i.missing.push(`${e.cssVar} was not written: color.${t.join(".")} clashes with a starter token`) : (n[l] = {
|
|
574
575
|
$value: e.hex,
|
|
575
|
-
$extensions:
|
|
576
|
+
$extensions: mn({
|
|
576
577
|
source: s(`:root { ${e.cssVar} }`, e.exact ? e.cssVar : void 0),
|
|
577
578
|
...a ? {} : { review: o }
|
|
578
579
|
})
|
|
579
580
|
}, e.segments = t, u.add(e));
|
|
580
581
|
}
|
|
581
|
-
let f = new Set([...u].map((e) => `color.${e.segments.join(".")}`)), p =
|
|
582
|
+
let f = new Set([...u].map((e) => `color.${e.segments.join(".")}`)), p = Jn(l, "primary"), m = t.interactive, h = gn(t, "interactive.primary");
|
|
582
583
|
if (!p) i.missing.push("no primary color: interactive.primary keeps the starter's value");
|
|
583
584
|
else if (m && h) {
|
|
584
585
|
let e = `color.${p.segments.join(".")}`;
|
|
585
586
|
m.primary = {
|
|
586
587
|
$value: `{${e}}`,
|
|
587
588
|
...typeof h.$description == "string" && { $description: h.$description },
|
|
588
|
-
$extensions:
|
|
589
|
+
$extensions: mn({
|
|
589
590
|
source: s(`:root { ${p.cssVar} }`, p.exact ? p.cssVar : void 0),
|
|
590
591
|
review: o
|
|
591
592
|
})
|
|
592
593
|
}, i.repointed.push(`interactive.primary to {${e}}`);
|
|
593
|
-
let n =
|
|
594
|
+
let n = Rn(t, p.hex, `{${e}}`, !0);
|
|
594
595
|
for (let e of n.hints) i.missing.push(e);
|
|
595
596
|
} else i.missing.push("interactive.primary was not found in tokens/colors.json, so the primary color was not set");
|
|
596
|
-
|
|
597
|
+
bn({
|
|
597
598
|
tree: t,
|
|
598
599
|
destDir: n,
|
|
599
600
|
picks: [...u],
|
|
@@ -603,11 +604,11 @@ function Un(e, t) {
|
|
|
603
604
|
review: o,
|
|
604
605
|
source: s,
|
|
605
606
|
result: i
|
|
606
|
-
}),
|
|
607
|
+
}), pn(e, t), i.written.push(Yn("tokens", "colors.json"));
|
|
607
608
|
}
|
|
608
609
|
}
|
|
609
610
|
// src/core/init/from-site/html.ts
|
|
610
|
-
function
|
|
611
|
+
function Zn(e) {
|
|
611
612
|
return e.replace(/&/g, "&").replace(/"/g, "\"").replace(/�?39;|'/g, "'").replace(/</g, "<").replace(/>/g, ">").replace(/ /g, " ").replace(/\s+/g, " ").trim().split(/ [|:–—-] /)[0].trim();
|
|
612
613
|
}
|
|
613
614
|
var V = (e, t) => {
|
|
@@ -620,36 +621,36 @@ function H(e, t) {
|
|
|
620
621
|
if (e) return e;
|
|
621
622
|
}
|
|
622
623
|
}
|
|
623
|
-
function
|
|
624
|
+
function Qn(e) {
|
|
624
625
|
let t = H(e, "og:site_name") ?? H(e, "application-name");
|
|
625
626
|
if (t) return t;
|
|
626
627
|
let n = e.match(/<title\b[^>]*>([\s\S]*?)<\/title>/i);
|
|
627
|
-
return (n ?
|
|
628
|
+
return (n ? Zn(n[1]) : "") || void 0;
|
|
628
629
|
}
|
|
629
|
-
async function
|
|
630
|
+
async function $n(e, t) {
|
|
630
631
|
let n = (e.match(/<link\b[^>]*>/gi) ?? []).find((e) => V(e, "rel")?.toLowerCase() === "manifest"), r = n && V(n, "href");
|
|
631
632
|
if (r) try {
|
|
632
633
|
let e = new URL(r, t);
|
|
633
634
|
if (e.protocol !== "http:" && e.protocol !== "https:") return;
|
|
634
|
-
let n = JSON.parse(await
|
|
635
|
+
let n = JSON.parse(await sn(e.href)), i = typeof n.short_name == "string" ? n.short_name.trim() : "", a = typeof n.name == "string" ? Zn(n.name) : "";
|
|
635
636
|
return i || a || void 0;
|
|
636
637
|
} catch {
|
|
637
638
|
return;
|
|
638
639
|
}
|
|
639
640
|
}
|
|
640
641
|
// src/core/init/from-site/sections/config.ts
|
|
641
|
-
async function
|
|
642
|
-
let { destDir: r, url: i, page: a, result: o, mayChange: s } = e, { fontUrls: c } = n, l = "blazon.json", u = H(a.html, "og:site_name") ?? H(a.html, "application-name") ?? await
|
|
642
|
+
async function er(e, t, n) {
|
|
643
|
+
let { destDir: r, url: i, page: a, result: o, mayChange: s } = e, { fontUrls: c } = n, l = "blazon.json", u = H(a.html, "og:site_name") ?? H(a.html, "application-name") ?? await $n(a.html, i) ?? Qn(a.html), d = H(a.html, "description");
|
|
643
644
|
u || o.missing.push("no <title> on the page: the config title keeps the folder name");
|
|
644
645
|
let f = !1;
|
|
645
646
|
if ((u || d || t.single || t.onLight || c.length > 0) && s(l)) {
|
|
646
|
-
let e = O.join(r, l), n =
|
|
647
|
+
let e = O.join(r, l), n = zn(e);
|
|
647
648
|
u && (n.title = u), d && (n.description = d);
|
|
648
649
|
let i = t.single ?? (t.onLight ? {
|
|
649
650
|
onLight: t.onLight,
|
|
650
651
|
...t.onDark ? { onDark: t.onDark } : {}
|
|
651
652
|
} : void 0);
|
|
652
|
-
i && (n.logo = i), c.length > 0 && (n.fonts =
|
|
653
|
+
i && (n.logo = i), c.length > 0 && (n.fonts = Vn(n.fonts, c)), Bn(e, n), o.written.push(l), f = !!i;
|
|
653
654
|
}
|
|
654
655
|
return {
|
|
655
656
|
title: u,
|
|
@@ -658,15 +659,15 @@ async function qn(e, t, n) {
|
|
|
658
659
|
};
|
|
659
660
|
}
|
|
660
661
|
// src/core/init/from-site/sections/directives.ts
|
|
661
|
-
var
|
|
662
|
-
function
|
|
662
|
+
var tr = /^[ \t]*<!--\s*blazon:tokens\b([^>]*?)-->[ \t]*\r?\n?/gm;
|
|
663
|
+
function nr(e) {
|
|
663
664
|
let { destDir: t, created: n, result: r } = e, i = O.join(t, "docs");
|
|
664
665
|
if (!k.existsSync(i)) return;
|
|
665
|
-
let a =
|
|
666
|
+
let a = ce(Be(O.join(t, "tokens"), t), "--").items, o = (e) => a.some((t) => t.path === e || t.path.startsWith(`${e}.`));
|
|
666
667
|
for (let e of k.readdirSync(i).filter((e) => e.endsWith(".md"))) {
|
|
667
668
|
let t = `docs/${e}`;
|
|
668
669
|
if (!n.has(t)) continue;
|
|
669
|
-
let a = O.join(i, e), s = k.readFileSync(a, "utf-8"), c = [], l = s.replace(
|
|
670
|
+
let a = O.join(i, e), s = k.readFileSync(a, "utf-8"), c = [], l = s.replace(tr, (e, t) => {
|
|
670
671
|
let n = t.split(/\s+/).filter(Boolean), r = n.filter(o);
|
|
671
672
|
return c.push(...n.filter((e) => !o(e))), r.length === n.length ? e : r.length === 0 ? "" : `<!-- blazon:tokens ${r.join(" ")} -->\n`;
|
|
672
673
|
}).replace(/\n{3,}/g, "\n\n");
|
|
@@ -674,7 +675,7 @@ function Yn(e) {
|
|
|
674
675
|
}
|
|
675
676
|
}
|
|
676
677
|
// src/core/init/shared/google-fonts.ts
|
|
677
|
-
var
|
|
678
|
+
var rr = [
|
|
678
679
|
"Inter",
|
|
679
680
|
"Roboto",
|
|
680
681
|
"Open Sans",
|
|
@@ -692,12 +693,12 @@ var Xn = [
|
|
|
692
693
|
"Playfair Display",
|
|
693
694
|
"JetBrains Mono"
|
|
694
695
|
];
|
|
695
|
-
function
|
|
696
|
-
let t =
|
|
696
|
+
function ir(e) {
|
|
697
|
+
let t = rr.find((t) => t.toLowerCase() === e.toLowerCase());
|
|
697
698
|
return t ? `https://fonts.googleapis.com/css2?family=${t.replace(/ /g, "+")}:wght@400;500;600;700&display=swap` : void 0;
|
|
698
699
|
}
|
|
699
700
|
// src/core/init/from-site/fonts.ts
|
|
700
|
-
var
|
|
701
|
+
var ar = /* @__PURE__ */ new Set([
|
|
701
702
|
"serif",
|
|
702
703
|
"sans-serif",
|
|
703
704
|
"monospace",
|
|
@@ -717,19 +718,55 @@ var Qn = /* @__PURE__ */ new Set([
|
|
|
717
718
|
"-apple-system",
|
|
718
719
|
"blinkmacsystemfont",
|
|
719
720
|
"segoe ui"
|
|
720
|
-
]),
|
|
721
|
+
]), or = /* @__PURE__ */ new Set([
|
|
721
722
|
"serif",
|
|
722
723
|
"sans-serif",
|
|
723
724
|
"monospace",
|
|
724
725
|
"cursive",
|
|
725
726
|
"fantasy"
|
|
726
|
-
])
|
|
727
|
-
function
|
|
728
|
-
|
|
729
|
-
|
|
727
|
+
]), sr = /[0-9a-fA-F]/, cr = /[\n\r\f]/;
|
|
728
|
+
function lr(e, t) {
|
|
729
|
+
if (!sr.test(e[t])) return {
|
|
730
|
+
text: e[t],
|
|
731
|
+
next: t + 1
|
|
732
|
+
};
|
|
733
|
+
let n = "", r = t;
|
|
734
|
+
for (; n.length < 6 && r < e.length && sr.test(e[r]);) n += e[r++];
|
|
735
|
+
e.startsWith("\r\n", r) ? r += 2 : r < e.length && /\s/.test(e[r]) && (r += 1);
|
|
736
|
+
let i = parseInt(n, 16);
|
|
737
|
+
return {
|
|
738
|
+
text: i !== 0 && i <= 1114111 && (i < 55296 || i > 57343) ? String.fromCodePoint(i) : "�",
|
|
739
|
+
next: r
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
function ur(e) {
|
|
743
|
+
let t = [], n = "", r = "bare", i = "", a = 0, o = 0;
|
|
744
|
+
for (; o < e.length;) {
|
|
745
|
+
let s = e[o];
|
|
746
|
+
if (r === "string") {
|
|
747
|
+
if (s === i) r = "bare", o++;
|
|
748
|
+
else if (cr.test(s)) r = "bare";
|
|
749
|
+
else if (s === "\\") {
|
|
750
|
+
if (o + 1 >= e.length) o++;
|
|
751
|
+
else if (e.startsWith("\r\n", o + 1)) o += 3;
|
|
752
|
+
else if (cr.test(e[o + 1])) o += 2;
|
|
753
|
+
else {
|
|
754
|
+
let t = lr(e, o + 1);
|
|
755
|
+
n += t.text, o = t.next;
|
|
756
|
+
}
|
|
757
|
+
} else n += s, o++;
|
|
758
|
+
} else if (r === "call") n += s, o++, i ? s === "\\" && o < e.length ? n += e[o++] : s === i && (i = "") : s === "\"" || s === "'" ? i = s : s === "(" ? a++ : s === ")" && --a === 0 && (r = "bare");
|
|
759
|
+
else if (s === "\"" || s === "'") r = "string", i = s, o++;
|
|
760
|
+
else if (s === "(") r = "call", i = "", a = 1, n += s, o++;
|
|
761
|
+
else if (s === ",") t.push(n.trim()), n = "", o++;
|
|
762
|
+
else if (s === "\\" && o + 1 < e.length && !cr.test(e[o + 1])) {
|
|
763
|
+
let t = lr(e, o + 1);
|
|
764
|
+
n += t.text, o = t.next;
|
|
765
|
+
} else n += s, o++;
|
|
766
|
+
}
|
|
730
767
|
return t.push(n.trim()), t.filter(Boolean);
|
|
731
768
|
}
|
|
732
|
-
function
|
|
769
|
+
function dr(e, t, n) {
|
|
733
770
|
let r;
|
|
734
771
|
for (let i of e.replace(/\/\*[\s\S]*?\*\//g, "").matchAll(/([^{}]*)\{([^{}]*)\}/g)) {
|
|
735
772
|
let e = i[1].split(",").map((e) => e.trim().toLowerCase()).find((e) => n.test(e));
|
|
@@ -741,7 +778,7 @@ function tr(e, t, n) {
|
|
|
741
778
|
let e = t.get(c[1]);
|
|
742
779
|
o = e ?? c[2] ?? "", e !== void 0 && (s = c[1]);
|
|
743
780
|
}
|
|
744
|
-
let l =
|
|
781
|
+
let l = ur(o), u = l.find((e) => !ar.has(e.toLowerCase()) && !e.startsWith("var("));
|
|
745
782
|
u && (r = {
|
|
746
783
|
family: u,
|
|
747
784
|
stack: l,
|
|
@@ -751,21 +788,21 @@ function tr(e, t, n) {
|
|
|
751
788
|
}
|
|
752
789
|
return r;
|
|
753
790
|
}
|
|
754
|
-
function
|
|
755
|
-
let t = e.stack.find((e) =>
|
|
791
|
+
function fr(e) {
|
|
792
|
+
let t = e.stack.find((e) => or.has(e.toLowerCase()));
|
|
756
793
|
return [e.family, (t ?? "sans-serif").toLowerCase()];
|
|
757
794
|
}
|
|
758
795
|
// src/core/init/from-site/sections/fonts.ts
|
|
759
|
-
function
|
|
760
|
-
let { destDir: t, page: n, vars: r, result: i, note: a, review: o, source: s, mayChange: c } = e, l =
|
|
796
|
+
function pr(e) {
|
|
797
|
+
let { destDir: t, page: n, vars: r, result: i, note: a, review: o, source: s, mayChange: c } = e, l = dr(n.css, r, /^(body|html)$/), u = dr(n.css, r, /^h[1-6]$/), d = [];
|
|
761
798
|
if (!l && !u) i.missing.push("no font: no body or heading rule in the stylesheets names a font-family");
|
|
762
|
-
else if (c(
|
|
763
|
-
let e = O.join(t, "tokens", "typography.json"), n =
|
|
799
|
+
else if (c(Yn("tokens", "typography.json"))) {
|
|
800
|
+
let e = O.join(t, "tokens", "typography.json"), n = fn(e), r = (n.font ??= {}).family ??= {}, c = l ?? u, f = [["body", c], ["display", u ?? c]];
|
|
764
801
|
for (let [e, t] of f) {
|
|
765
|
-
let n =
|
|
802
|
+
let n = ir(t.family);
|
|
766
803
|
n ? d.includes(n) || d.push(n) : i.missing.push(`the font ${t.family} is not one blazon knows a stylesheet for: add its stylesheet to fonts in blazon.json`), r[e] = {
|
|
767
|
-
$value:
|
|
768
|
-
$extensions:
|
|
804
|
+
$value: fr(t),
|
|
805
|
+
$extensions: mn({
|
|
769
806
|
source: s(t.cssVar ? `${t.locator}, from ${t.cssVar}` : t.locator),
|
|
770
807
|
review: n ? o : {
|
|
771
808
|
status: "needs-review",
|
|
@@ -775,23 +812,23 @@ function rr(e) {
|
|
|
775
812
|
};
|
|
776
813
|
}
|
|
777
814
|
let p = r.mono;
|
|
778
|
-
p &&
|
|
815
|
+
p && In(p, `${a} Still blazon's mono font: the site's stylesheets named no monospace font. Set the brand's own.`), pn(e, n), i.written.push(Yn("tokens", "typography.json"));
|
|
779
816
|
}
|
|
780
817
|
return { fontUrls: d };
|
|
781
818
|
}
|
|
782
819
|
// src/core/init/from-site/sections/intro.ts
|
|
783
|
-
var
|
|
784
|
-
function
|
|
820
|
+
var mr = (e) => e.length === 1 && e[0] === "logo", hr = (e) => e.length < 2 ? e.join("") : `${e.slice(0, -1).join(", ")} and ${e[e.length - 1]}`;
|
|
821
|
+
function gr(e) {
|
|
785
822
|
let { url: t, date: n, result: r } = e, i = {
|
|
786
823
|
colors: r.written.includes("tokens/colors.json"),
|
|
787
824
|
fonts: r.written.includes("tokens/typography.json"),
|
|
788
825
|
logo: r.written.some((e) => e.startsWith("assets/logos/"))
|
|
789
826
|
}, a = Object.entries(i).filter(([, e]) => e).map(([e]) => e), o = Object.entries(i).filter(([, e]) => !e).map(([e]) => e);
|
|
790
827
|
if (a.length === 0) return `Nothing could be read from ${t} on ${n}: it gave no brand colors, no fonts and no logo. This brand book is still blazon's own starter, so replace its colors, fonts and logo with the brand's.`;
|
|
791
|
-
let s = `The ${
|
|
792
|
-
return o.length === 0 ? s : `${s} The ${
|
|
828
|
+
let s = `The ${hr(a)} in this brand book ${mr(a) ? "was" : "were"} read from ${t} on ${n}. They are what the site shows today, so the brand owner needs to confirm them before anyone relies on them.`;
|
|
829
|
+
return o.length === 0 ? s : `${s} The ${hr(o)} ${mr(o) ? "was" : "were"} not found, so ${mr(o) ? "it is" : "they are"} still blazon's own starter: replace ${mr(o) ? "it" : "them"}.`;
|
|
793
830
|
}
|
|
794
|
-
function
|
|
831
|
+
function _r(e, t, n) {
|
|
795
832
|
let { destDir: r, url: i, created: a, result: o } = e, s = "docs/01-principles.md";
|
|
796
833
|
if (a.has(s) && k.existsSync(O.join(r, s))) {
|
|
797
834
|
let a = t ?? new URL(i).hostname.replace(/^www\./, ""), c = [
|
|
@@ -806,19 +843,19 @@ function sr(e, t, n) {
|
|
|
806
843
|
`# ${a}`,
|
|
807
844
|
"",
|
|
808
845
|
...n ? [n, ""] : [],
|
|
809
|
-
|
|
846
|
+
gr(e),
|
|
810
847
|
""
|
|
811
848
|
];
|
|
812
849
|
k.writeFileSync(O.join(r, s), c.join("\n")), o.written.push(s);
|
|
813
850
|
}
|
|
814
851
|
}
|
|
815
852
|
// src/core/init/shared/svg.ts
|
|
816
|
-
function
|
|
853
|
+
function vr(e) {
|
|
817
854
|
let t = e.replace(/<script\b[\s\S]*?<\/script>/gi, "").replace(/\son\w+\s*=\s*(?:"[^"]*"|'[^']*')/gi, "").replace(/(href\s*=\s*["'])\s*javascript:[^"']*/gi, "$1#");
|
|
818
855
|
return /<svg\b[^>]*\sxmlns\s*=/i.test(t) || (t = t.replace(/<svg\b/i, "<svg xmlns=\"http://www.w3.org/2000/svg\"")), `${t.trim()}\n`;
|
|
819
856
|
}
|
|
820
857
|
// src/core/init/from-site/logo.ts
|
|
821
|
-
function
|
|
858
|
+
function yr(e, t) {
|
|
822
859
|
let n = e.replace(/<!--[\s\S]*?-->/g, "").match(/<header\b[^>]*>([\s\S]*?)<\/header>/i)?.[1];
|
|
823
860
|
if (!n) return;
|
|
824
861
|
let r = [];
|
|
@@ -867,7 +904,7 @@ function lr(e, t) {
|
|
|
867
904
|
locator: "header img"
|
|
868
905
|
} : void 0;
|
|
869
906
|
}
|
|
870
|
-
function
|
|
907
|
+
function br(e, t) {
|
|
871
908
|
let n = [];
|
|
872
909
|
for (let [r] of e.replace(/<!--[\s\S]*?-->/g, "").matchAll(/<link\b[^>]*>/gi)) {
|
|
873
910
|
let e = (V(r, "rel") ?? "").toLowerCase().split(/\s+/), i = e.includes("apple-touch-icon") || e.includes("apple-touch-icon-precomposed");
|
|
@@ -888,14 +925,14 @@ function ur(e, t) {
|
|
|
888
925
|
}
|
|
889
926
|
return n.find((e) => e.svg) ?? n.find((e) => e.apple) ?? n[0];
|
|
890
927
|
}
|
|
891
|
-
function
|
|
928
|
+
function xr(e) {
|
|
892
929
|
let t = new URL(e).hostname.replace(/^www\./, "");
|
|
893
930
|
return /^[\d.]+$/.test(t) || t.includes(":") || t.startsWith("[") ? "site" : t.split(".")[0].replace(/[^a-z0-9-]/gi, "-").toLowerCase() || "site";
|
|
894
931
|
}
|
|
895
932
|
// src/core/init/from-site/sections/logo.ts
|
|
896
|
-
async function
|
|
897
|
-
let { destDir: t, url: n, date: r, page: i, result: a, note: o, review: s } = e, c = {}, l =
|
|
898
|
-
|
|
933
|
+
async function Sr(e) {
|
|
934
|
+
let { destDir: t, url: n, date: r, page: i, result: a, note: o, review: s } = e, c = {}, l = xr(n), u = (e, i, c) => {
|
|
935
|
+
pn(O.join(t, e.replace(/\.[a-z]+$/, ".json")), {
|
|
899
936
|
description: o,
|
|
900
937
|
...c,
|
|
901
938
|
source: {
|
|
@@ -907,24 +944,24 @@ async function fr(e) {
|
|
|
907
944
|
}, d = (e, n) => {
|
|
908
945
|
let r = O.join(t, e), i = [e, e.replace(/\.[a-z]+$/, ".json")].filter((e) => k.existsSync(O.join(t, e)));
|
|
909
946
|
return i.length > 0 ? (a.missing.push(`${i.join(" and ")} already existed, so ${i.length > 1 ? "they were" : "it was"} kept as ${i.length > 1 ? "they were" : "it was"}, and no logo was written to ${e}`), !1) : (k.mkdirSync(O.dirname(r), { recursive: !0 }), k.writeFileSync(r, n), a.written.push(e), !0);
|
|
910
|
-
}, f =
|
|
947
|
+
}, f = yr(i.html, n), p, m = "";
|
|
911
948
|
if (f?.kind === "inline") p = f.svg, m = f.locator;
|
|
912
949
|
else if (f?.kind === "url") {
|
|
913
950
|
try {
|
|
914
|
-
p = (await
|
|
951
|
+
p = (await on(f.url)).toString("utf8"), m = `${f.locator} (${f.url})`;
|
|
915
952
|
} catch (e) {
|
|
916
953
|
a.missing.push(`the header logo could not be read: ${e instanceof Error ? e.message : String(e)}`);
|
|
917
954
|
}
|
|
918
955
|
p !== void 0 && !/<svg\b/i.test(p) && (p = void 0, a.missing.push(`${f.url} is not an SVG`));
|
|
919
956
|
}
|
|
920
957
|
let h;
|
|
921
|
-
if (p === void 0 && (h =
|
|
922
|
-
p = (await
|
|
958
|
+
if (p === void 0 && (h = br(i.html, n), h?.svg)) try {
|
|
959
|
+
p = (await on(h.url)).toString("utf8"), m = `${h.locator} (${h.url})`, /<svg\b/i.test(p) || (p = void 0);
|
|
923
960
|
} catch (e) {
|
|
924
961
|
a.missing.push(`the icon could not be read: ${e instanceof Error ? e.message : String(e)}`);
|
|
925
962
|
}
|
|
926
963
|
if (p !== void 0) {
|
|
927
|
-
let e =
|
|
964
|
+
let e = vr(p);
|
|
928
965
|
if (/<use\b/i.test(e) && !/<symbol\b/i.test(e) && a.missing.push("the logo uses <use> to point at a sprite elsewhere on the page, so it may draw nothing: check it"), /currentColor/i.test(e)) {
|
|
929
966
|
let t = `assets/logos/${l}.svg`, n = `assets/logos/${l}-white.svg`;
|
|
930
967
|
d(t, e.replace(/currentColor/gi, "#111111")) && (u(t, m, {
|
|
@@ -951,7 +988,7 @@ async function fr(e) {
|
|
|
951
988
|
].includes(h.ext)) a.missing.push(`only a ${h.ext} icon was found (${h.url}), which blazon cannot show: no logo was written`);
|
|
952
989
|
else try {
|
|
953
990
|
let e = `assets/logos/${l}${h.ext === ".jpeg" ? ".jpg" : h.ext}`;
|
|
954
|
-
d(e, await
|
|
991
|
+
d(e, await on(h.url)) && (u(e, h.locator, { title: "Site icon" }), c.single = `./${e}`, a.missing.push(`no SVG logo was found: ${e} is the site's raster icon (${h.url}), not a logo, so replace it with the real one`));
|
|
955
992
|
} catch (e) {
|
|
956
993
|
a.missing.push(`the icon could not be read: ${e instanceof Error ? e.message : String(e)}`);
|
|
957
994
|
}
|
|
@@ -959,28 +996,28 @@ async function fr(e) {
|
|
|
959
996
|
return c;
|
|
960
997
|
}
|
|
961
998
|
// src/core/init/from-site/sections/placeholder.ts
|
|
962
|
-
function
|
|
999
|
+
function Cr(e, t, n) {
|
|
963
1000
|
let { destDir: r, created: i, result: a } = e, o = t.single ?? t.onLight;
|
|
964
1001
|
if (n && o) {
|
|
965
|
-
let e = O.join(r, `assets/logos/${
|
|
966
|
-
if (i.has(`assets/logos/${
|
|
967
|
-
let { description: n, background: i, ...a } =
|
|
1002
|
+
let e = O.join(r, `assets/logos/${Hn[0]}.json`), t = O.join(r, o.replace(/^\.\//, "").replace(/\.[a-z]+$/, ".json"));
|
|
1003
|
+
if (i.has(`assets/logos/${Hn[0]}.json`) && k.existsSync(e) && k.existsSync(t)) {
|
|
1004
|
+
let { description: n, background: i, ...a } = fn(e), s = fn(t), c = k.readFileSync(O.join(r, o.replace(/^\.\//, "")), "utf-8").match(/<svg\b[^>]*>/i)?.[0] ?? "", l = c.match(/viewBox\s*=\s*["']\s*[-\d.]+[\s,]+[-\d.]+[\s,]+[\d.]+[\s,]+([\d.]+)/i)?.[1] ?? c.match(/\sheight\s*=\s*["']?([\d.]+)/i)?.[1];
|
|
968
1005
|
l && Number(l) > 0 && (a.clearSpace = {
|
|
969
1006
|
value: Math.max(1, Math.round(Number(l) * .3 * 100) / 100),
|
|
970
1007
|
unit: "px"
|
|
971
1008
|
});
|
|
972
1009
|
for (let [e, t] of Object.entries(a)) s[e] ??= t;
|
|
973
|
-
s.description = `${String(s.description)} Clear space, minimum size, lockup, placement and partnership are blazon's, not the brand's: set them.`,
|
|
1010
|
+
s.description = `${String(s.description)} Clear space, minimum size, lockup, placement and partnership are blazon's, not the brand's: set them.`, pn(t, s);
|
|
974
1011
|
}
|
|
975
|
-
for (let e of
|
|
1012
|
+
for (let e of Un) for (let t of ["svg", "json"]) {
|
|
976
1013
|
let n = `assets/logos/${e}.${t}`;
|
|
977
1014
|
i.has(n) && (k.rmSync(O.join(r, n), { force: !0 }), a.removed.push(`${n} (blazon's own logo)`));
|
|
978
1015
|
}
|
|
979
1016
|
}
|
|
980
1017
|
}
|
|
981
1018
|
// src/core/init/from-site/apply.ts
|
|
982
|
-
async function
|
|
983
|
-
let a = r.toISOString().slice(0, 10), o = i.page ?? await
|
|
1019
|
+
async function wr(e, t, n, r = /* @__PURE__ */ new Date(), i = {}) {
|
|
1020
|
+
let a = r.toISOString().slice(0, 10), o = i.page ?? await un(t), s = {
|
|
984
1021
|
written: [],
|
|
985
1022
|
missing: [],
|
|
986
1023
|
removed: [],
|
|
@@ -991,7 +1028,7 @@ async function mr(e, t, n, r = /* @__PURE__ */ new Date(), i = {}) {
|
|
|
991
1028
|
date: a,
|
|
992
1029
|
created: n,
|
|
993
1030
|
page: o,
|
|
994
|
-
vars:
|
|
1031
|
+
vars: tn(o.css),
|
|
995
1032
|
result: s,
|
|
996
1033
|
note: c,
|
|
997
1034
|
review: {
|
|
@@ -1005,23 +1042,23 @@ async function mr(e, t, n, r = /* @__PURE__ */ new Date(), i = {}) {
|
|
|
1005
1042
|
}),
|
|
1006
1043
|
mayChange: (e) => n.has(e) ? !0 : (s.missing.push(`${e} already existed, so it was kept as it was`), !1)
|
|
1007
1044
|
};
|
|
1008
|
-
|
|
1009
|
-
let u =
|
|
1010
|
-
return
|
|
1045
|
+
Xn(l, i.skipVars);
|
|
1046
|
+
let u = pr(l), d = await Sr(l), { title: f, description: p, configLogo: m } = await er(l, d, u);
|
|
1047
|
+
return Cr(l, d, m), _r(l, f, p), nr(l), s;
|
|
1011
1048
|
}
|
|
1012
1049
|
// src/core/init/from-site/inspect.ts
|
|
1013
|
-
async function
|
|
1014
|
-
let t = await
|
|
1050
|
+
async function Tr(e) {
|
|
1051
|
+
let t = await un(e), n = tn(t.css), r = qn(n), i = dr(t.css, n, /^(body|html)$/), a = dr(t.css, n, /^h[1-6]$/), o = [];
|
|
1015
1052
|
i && o.push({
|
|
1016
1053
|
family: i.family,
|
|
1017
1054
|
role: "body",
|
|
1018
|
-
stylesheet: !!
|
|
1055
|
+
stylesheet: !!ir(i.family)
|
|
1019
1056
|
}), a && a.family.toLowerCase() !== i?.family.toLowerCase() && o.push({
|
|
1020
1057
|
family: a.family,
|
|
1021
1058
|
role: "headings",
|
|
1022
|
-
stylesheet: !!
|
|
1059
|
+
stylesheet: !!ir(a.family)
|
|
1023
1060
|
});
|
|
1024
|
-
let s =
|
|
1061
|
+
let s = yr(t.html, e), c = br(t.html, e), l = s ? `${s.kind === "inline" ? "an inline SVG" : `an SVG image (${s.url})`} in the page header` : c ? `the site icon (${c.url})${c.svg ? "" : `, a ${c.ext} image, not an SVG logo`}` : void 0, u = H(t.html, "og:site_name") ?? H(t.html, "application-name") ?? await $n(t.html, e) ?? Qn(t.html), d = [];
|
|
1025
1062
|
return r.length === 0 && d.push("no brand colors: no custom property named brand, primary, secondary, accent, background, foreground or surface holds a hex or rgb() color"), o.length === 0 && d.push("no font: no body or heading rule names a font-family"), l || d.push("no logo: no SVG in the header and no icon link on the page"), u || d.push("no site name: the brand name stays as you typed it"), {
|
|
1026
1063
|
page: t,
|
|
1027
1064
|
name: u,
|
|
@@ -1036,23 +1073,23 @@ async function hr(e) {
|
|
|
1036
1073
|
};
|
|
1037
1074
|
}
|
|
1038
1075
|
// src/core/init/answers.ts
|
|
1039
|
-
var
|
|
1076
|
+
var Er = [
|
|
1040
1077
|
".svg",
|
|
1041
1078
|
".png",
|
|
1042
1079
|
".jpg",
|
|
1043
1080
|
".jpeg",
|
|
1044
1081
|
".webp"
|
|
1045
|
-
],
|
|
1046
|
-
function
|
|
1047
|
-
let t = e.trim(), n = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.test(t) ?
|
|
1082
|
+
], Dr = (e) => e.trim() ? { value: e.trim() } : { hint: "A name cannot be empty." }, Or = (e) => e.trim().length <= 240 ? { value: e.trim() } : { hint: "Keep the description to one sentence, 240 characters at most." };
|
|
1083
|
+
function kr(e) {
|
|
1084
|
+
let t = e.trim(), n = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.test(t) ? Wn(t.startsWith("#") ? t : `#${t}`) : void 0;
|
|
1048
1085
|
return n ? { value: n.hex } : { hint: "Give the color as hex, for example #2563eb or #26e." };
|
|
1049
1086
|
}
|
|
1050
|
-
var
|
|
1051
|
-
function
|
|
1087
|
+
var Ar = (e) => /^[A-Za-z0-9][A-Za-z0-9 -]{0,60}$/.test(e.trim()) ? { value: e.trim() } : { hint: "Give a font family name, for example Inter or DM Sans." };
|
|
1088
|
+
function jr(e, t = process.cwd()) {
|
|
1052
1089
|
let n = O.resolve(t, e.trim());
|
|
1053
|
-
return
|
|
1090
|
+
return Er.includes(O.extname(n).toLowerCase()) ? !k.existsSync(n) || !k.statSync(n).isFile() ? { hint: `There is no file at ${n}. Check the path, or press Enter to skip the logo.` } : { value: n } : { hint: "The logo must be an SVG or PNG file (JPG and WebP also work)." };
|
|
1054
1091
|
}
|
|
1055
|
-
function
|
|
1092
|
+
function Mr(e) {
|
|
1056
1093
|
let t = k.readFileSync(e), n = O.extname(e).toLowerCase() === ".svg";
|
|
1057
1094
|
return {
|
|
1058
1095
|
bytes: t.length,
|
|
@@ -1060,20 +1097,20 @@ function Sr(e) {
|
|
|
1060
1097
|
usesCurrentColor: n && /currentColor/i.test(t.toString("utf8"))
|
|
1061
1098
|
};
|
|
1062
1099
|
}
|
|
1063
|
-
var
|
|
1064
|
-
function
|
|
1100
|
+
var Nr = (e) => /^https?:\/\/[^\s/]/i.test(e);
|
|
1101
|
+
function Pr(e, t, n) {
|
|
1065
1102
|
let r = {
|
|
1066
1103
|
set: [],
|
|
1067
1104
|
hints: [],
|
|
1068
1105
|
files: []
|
|
1069
|
-
}, i = (e) => r.hints.push(`${e} already existed, so it was kept as it was`), a = O.join(e, "blazon.json"), o = n.has("blazon.json") ?
|
|
1106
|
+
}, i = (e) => r.hints.push(`${e} already existed, so it was kept as it was`), a = O.join(e, "blazon.json"), o = n.has("blazon.json") ? zn(a) : void 0, s = o === void 0 ? void 0 : JSON.stringify(o), c = (e) => (o === void 0 && i(`blazon.json (${e} not set)`), o !== void 0);
|
|
1070
1107
|
if (t.name !== void 0 && c("name") && (o.title = t.name, r.set.push(`name "${t.name}"`)), t.description && c("description") && (o.description = t.description, r.set.push("description")), t.color !== void 0) {
|
|
1071
1108
|
let a = O.join(e, "tokens", "colors.json");
|
|
1072
1109
|
if (!n.has("tokens/colors.json")) i("tokens/colors.json");
|
|
1073
1110
|
else {
|
|
1074
1111
|
let e = JSON.parse(k.readFileSync(a, "utf-8"));
|
|
1075
1112
|
if (B(e, "color.signal.orange")) {
|
|
1076
|
-
let n =
|
|
1113
|
+
let n = Ln(e, t.color);
|
|
1077
1114
|
k.writeFileSync(a, `${JSON.stringify(e, null, 2)}\n`), r.files.push("tokens/colors.json"), r.set.push(`primary color ${t.color} (color.signal.primary, which interactive.primary uses)`), r.hints.push(...n.hints);
|
|
1078
1115
|
} else r.hints.push("color.signal.orange was not found in tokens/colors.json, so the color was not set");
|
|
1079
1116
|
}
|
|
@@ -1086,9 +1123,9 @@ function wr(e, t, n) {
|
|
|
1086
1123
|
if (n && i) {
|
|
1087
1124
|
n.$value = [t.font, "sans-serif"], i.$value = [t.font, "sans-serif"];
|
|
1088
1125
|
let s = B(e, "font.family.mono");
|
|
1089
|
-
s &&
|
|
1090
|
-
let l =
|
|
1091
|
-
l && c("font stylesheet") ? (o.fonts =
|
|
1126
|
+
s && In(s, "Still blazon's mono font: it was not chosen to go with your font. Set the brand's own."), k.writeFileSync(a, `${JSON.stringify(e, null, 2)}\n`), r.files.push("tokens/typography.json");
|
|
1127
|
+
let l = ir(t.font);
|
|
1128
|
+
l && c("font stylesheet") ? (o.fonts = Vn(o.fonts, [l]), r.set.push(`font ${t.font} (font.family.display and font.family.body)`)) : l || (r.set.push(`font ${t.font} (font.family.display and font.family.body)`), r.hints.push(`${t.font} is not a font blazon knows a stylesheet for: add its stylesheet to fonts in blazon.json`)), r.hints.push("font.family.mono and the type scale are still blazon's: set the brand's own");
|
|
1092
1129
|
} else r.hints.push("font.family.display and font.family.body were not found in tokens/typography.json, so the font was not set");
|
|
1093
1130
|
}
|
|
1094
1131
|
}
|
|
@@ -1098,25 +1135,25 @@ function wr(e, t, n) {
|
|
|
1098
1135
|
for (let e of l) i(`assets/logos/${e}`);
|
|
1099
1136
|
r.hints.push(`the logo ${t.logo} was not copied: pick another file name, or remove the existing file`);
|
|
1100
1137
|
} else {
|
|
1101
|
-
let e = O.join(c, `${
|
|
1102
|
-
if (n.has(`assets/logos/${
|
|
1138
|
+
let e = O.join(c, `${Hn[0]}.json`), i = {};
|
|
1139
|
+
if (n.has(`assets/logos/${Hn[0]}.json`) && k.existsSync(e)) {
|
|
1103
1140
|
let { description: t, background: n, ...r } = JSON.parse(k.readFileSync(e, "utf-8"));
|
|
1104
1141
|
i = r;
|
|
1105
1142
|
}
|
|
1106
|
-
for (let e of
|
|
1143
|
+
for (let e of Un) for (let t of ["svg", "json"]) n.has(`assets/logos/${e}.${t}`) && k.rmSync(O.join(c, `${e}.${t}`), { force: !0 });
|
|
1107
1144
|
k.mkdirSync(c, { recursive: !0 });
|
|
1108
1145
|
let l = k.readFileSync(t.logo);
|
|
1109
|
-
k.writeFileSync(O.join(c, a), a.toLowerCase().endsWith(".svg") ?
|
|
1146
|
+
k.writeFileSync(O.join(c, a), a.toLowerCase().endsWith(".svg") ? vr(l.toString("utf8")) : l), k.writeFileSync(O.join(c, `${s}.json`), `${JSON.stringify({
|
|
1110
1147
|
title: "Logo",
|
|
1111
1148
|
description: "The brand's logo. Clear space, minimum size, lockup, placement and partnership are blazon's, not the brand's: set them.",
|
|
1112
1149
|
...i
|
|
1113
1150
|
}, null, 2)}\n`), o.logo = `./assets/logos/${a}`, r.files.push(`assets/logos/${a}`, `assets/logos/${s}.json`), r.set.push(`logo ${a}`);
|
|
1114
1151
|
}
|
|
1115
1152
|
}
|
|
1116
|
-
return o !== void 0 && JSON.stringify(o) !== s && (
|
|
1153
|
+
return o !== void 0 && JSON.stringify(o) !== s && (Bn(a, o), r.files.push("blazon.json")), r;
|
|
1117
1154
|
}
|
|
1118
1155
|
// src/core/init/prompts.ts
|
|
1119
|
-
var
|
|
1156
|
+
var Fr = class extends Error {
|
|
1120
1157
|
constructor() {
|
|
1121
1158
|
super("cancelled"), this.name = "PromptCancelled";
|
|
1122
1159
|
}
|
|
@@ -1130,33 +1167,33 @@ function U(e, t) {
|
|
|
1130
1167
|
}).join("\n");
|
|
1131
1168
|
}
|
|
1132
1169
|
var W = () => Math.max(30, (process.stdout.columns ?? 80) - 6);
|
|
1133
|
-
function
|
|
1134
|
-
if (A.isCancel(e)) throw new
|
|
1170
|
+
function Ir(e) {
|
|
1171
|
+
if (A.isCancel(e)) throw new Fr();
|
|
1135
1172
|
return e;
|
|
1136
1173
|
}
|
|
1137
|
-
function
|
|
1174
|
+
function Lr() {
|
|
1138
1175
|
return {
|
|
1139
1176
|
intro: (e) => A.intro(e),
|
|
1140
1177
|
outro: (e) => A.outro(e),
|
|
1141
1178
|
cancel: (e) => A.cancel(e),
|
|
1142
|
-
text: async (e) =>
|
|
1179
|
+
text: async (e) => Ir(await A.text({
|
|
1143
1180
|
message: e.message,
|
|
1144
1181
|
placeholder: e.placeholder,
|
|
1145
1182
|
defaultValue: e.defaultValue,
|
|
1146
1183
|
validate: e.validate && ((t) => e.validate(t ?? ""))
|
|
1147
1184
|
})) ?? "",
|
|
1148
|
-
select: async (e) =>
|
|
1185
|
+
select: async (e) => Ir(await A.select({
|
|
1149
1186
|
message: e.message,
|
|
1150
1187
|
options: e.options,
|
|
1151
1188
|
initialValue: e.initialValue
|
|
1152
1189
|
})),
|
|
1153
|
-
multiselect: async (e) =>
|
|
1190
|
+
multiselect: async (e) => Ir(await A.multiselect({
|
|
1154
1191
|
message: e.message,
|
|
1155
1192
|
options: e.options,
|
|
1156
1193
|
initialValues: e.initialValues,
|
|
1157
1194
|
required: !1
|
|
1158
1195
|
})),
|
|
1159
|
-
confirm: async (e) =>
|
|
1196
|
+
confirm: async (e) => Ir(await A.confirm({
|
|
1160
1197
|
message: e.message,
|
|
1161
1198
|
initialValue: e.initialValue
|
|
1162
1199
|
})),
|
|
@@ -1180,15 +1217,15 @@ function Dr() {
|
|
|
1180
1217
|
};
|
|
1181
1218
|
}
|
|
1182
1219
|
// src/cli/init-ui.ts
|
|
1183
|
-
function
|
|
1184
|
-
let n =
|
|
1220
|
+
function Rr(e = process.env, t = !!process.stdout.isTTY) {
|
|
1221
|
+
let n = s(e, t, []);
|
|
1185
1222
|
return {
|
|
1186
1223
|
color: n,
|
|
1187
1224
|
truecolor: n && /^(truecolor|24bit)$/i.test(e.COLORTERM ?? "")
|
|
1188
1225
|
};
|
|
1189
1226
|
}
|
|
1190
|
-
function
|
|
1191
|
-
let [n, r, i] = (
|
|
1227
|
+
function zr(e, t) {
|
|
1228
|
+
let [n, r, i] = (Cn(e) ?? [
|
|
1192
1229
|
0,
|
|
1193
1230
|
0,
|
|
1194
1231
|
0
|
|
@@ -1197,62 +1234,62 @@ function kr(e, t) {
|
|
|
1197
1234
|
let a = (e) => Math.round(e / 255 * 5);
|
|
1198
1235
|
return `\x1b[48;5;${16 + 36 * a(n) + 6 * a(r) + a(i)}m`;
|
|
1199
1236
|
}
|
|
1200
|
-
function
|
|
1201
|
-
return t.color ? `${
|
|
1237
|
+
function Br(e, t, n = 2) {
|
|
1238
|
+
return t.color ? `${zr(e, t)}${" ".repeat(n)}\x1b[0m` : `[${e}]`;
|
|
1202
1239
|
}
|
|
1203
|
-
var
|
|
1240
|
+
var Vr = {
|
|
1204
1241
|
AAA: "AAA",
|
|
1205
1242
|
AA: "AA",
|
|
1206
1243
|
"AA-large": "AA for large text only",
|
|
1207
1244
|
fail: "below AA"
|
|
1208
|
-
},
|
|
1209
|
-
function
|
|
1245
|
+
}, Hr = (e) => `${e.toFixed(1)}:1`;
|
|
1246
|
+
function Ur(e, t, n = On(e)) {
|
|
1210
1247
|
let r = (e) => e === "AAA" || e === "AA" ? "yes" : "no";
|
|
1211
1248
|
return [
|
|
1212
|
-
`${
|
|
1213
|
-
`AA for text on white: ${r(n.onWhite.level)} (${
|
|
1214
|
-
`AA for text on near-black: ${r(n.onNearBlack.level)} (${
|
|
1249
|
+
`${Br(e, t, 4)} ${e}`,
|
|
1250
|
+
`AA for text on white: ${r(n.onWhite.level)} (${Hr(n.onWhite.ratio)}, ${Vr[n.onWhite.level]})`,
|
|
1251
|
+
`AA for text on near-black: ${r(n.onNearBlack.level)} (${Hr(n.onNearBlack.ratio)}, ${Vr[n.onNearBlack.level]})`
|
|
1215
1252
|
];
|
|
1216
1253
|
}
|
|
1217
|
-
function
|
|
1218
|
-
let { ink: t, ratio: n, aa: r } =
|
|
1254
|
+
function Wr(e) {
|
|
1255
|
+
let { ink: t, ratio: n, aa: r } = jn(e);
|
|
1219
1256
|
return r ? `Labels on ${e} will be ${t} (${n.toFixed(1)}:1).` : `Neither graphite nor bone reaches AA (4.5:1) as a label on ${e} (best is ${t} at ${n.toFixed(1)}:1). blazon check will report it; a lighter or darker color fixes that.`;
|
|
1220
1257
|
}
|
|
1221
|
-
var
|
|
1222
|
-
function
|
|
1258
|
+
var Gr = (e, t, n) => `${e} of ${t} ${n}`;
|
|
1259
|
+
function Kr(e) {
|
|
1223
1260
|
return e < 1024 ? `${e} bytes` : `${(e / 1024).toFixed(1)} KB`;
|
|
1224
1261
|
}
|
|
1225
1262
|
// src/cli/init-flow.ts
|
|
1226
|
-
var
|
|
1263
|
+
var qr = 4;
|
|
1227
1264
|
function G(e, t, n, r) {
|
|
1228
|
-
return e.log.message(r.color ?
|
|
1265
|
+
return e.log.message(r.color ? a.dim(n) : n), t;
|
|
1229
1266
|
}
|
|
1230
|
-
function
|
|
1267
|
+
function Jr(e) {
|
|
1231
1268
|
return (t) => {
|
|
1232
1269
|
if (t.trim() === "") return;
|
|
1233
1270
|
let n = e(t);
|
|
1234
1271
|
return "hint" in n ? n.hint : void 0;
|
|
1235
1272
|
};
|
|
1236
1273
|
}
|
|
1237
|
-
var
|
|
1274
|
+
var Yr = (e, t) => {
|
|
1238
1275
|
let n = t.trim() === "" ? void 0 : e(t);
|
|
1239
1276
|
return n && "value" in n ? n.value : void 0;
|
|
1240
1277
|
};
|
|
1241
|
-
async function
|
|
1278
|
+
async function Xr(e) {
|
|
1242
1279
|
let { prompter: t, look: n } = e, r = {};
|
|
1243
|
-
t.intro(n.color ?
|
|
1280
|
+
t.intro(n.color ? a.bold(`blazon init ${a.dim(e.dir)}`) : `blazon init ${e.dir}`), e.kept && t.log.warn(`${e.kept} starter ${e.kept === 1 ? "file is" : "files are"} already in this folder and ${e.kept === 1 ? "is" : "are"} kept as ${e.kept === 1 ? "it is" : "they are"}. Only missing files are added.`), t.log.step(Gr(1, qr, "Brand"));
|
|
1244
1281
|
let i = (await t.text({
|
|
1245
1282
|
message: G(t, "Brand name", "The title of the brand book. Enter keeps the name taken from the folder.", n),
|
|
1246
1283
|
placeholder: "from the folder name",
|
|
1247
1284
|
validate: () => void 0
|
|
1248
1285
|
})).trim();
|
|
1249
1286
|
i && (r.name = i);
|
|
1250
|
-
let
|
|
1287
|
+
let o = (await t.text({
|
|
1251
1288
|
message: G(t, "One-line description", "What the brand is, in a sentence. It goes in the config and opens the intro page. Enter skips it.", n),
|
|
1252
1289
|
placeholder: "what the brand is, in one sentence",
|
|
1253
|
-
validate: (e) => "hint" in
|
|
1290
|
+
validate: (e) => "hint" in Or(e) ? "Keep it to one sentence, 240 characters at most." : void 0
|
|
1254
1291
|
})).trim();
|
|
1255
|
-
if (
|
|
1292
|
+
if (o && (r.description = o), await t.select({
|
|
1256
1293
|
message: G(t, "Where should the colors, fonts and logo come from?", "Reading a live site fills them in for you to review before anything is written.", n),
|
|
1257
1294
|
options: [{
|
|
1258
1295
|
value: "manual",
|
|
@@ -1264,36 +1301,36 @@ async function Br(e) {
|
|
|
1264
1301
|
hint: "you review what was found first"
|
|
1265
1302
|
}]
|
|
1266
1303
|
}) === "site") {
|
|
1267
|
-
let n = await
|
|
1304
|
+
let n = await Zr(e);
|
|
1268
1305
|
if (n) return {
|
|
1269
1306
|
answers: r,
|
|
1270
1307
|
site: n
|
|
1271
1308
|
};
|
|
1272
1309
|
t.log.info("Nothing from a site will be written. Giving the values here instead.");
|
|
1273
1310
|
}
|
|
1274
|
-
t.log.step(
|
|
1275
|
-
let
|
|
1311
|
+
t.log.step(Gr(2, qr, "Colors"));
|
|
1312
|
+
let s = Yr(kr, (await t.text({
|
|
1276
1313
|
message: G(t, "Primary color", "Hex, for example #2563eb. Buttons and links use it. Enter keeps the orange it starts with.", n),
|
|
1277
1314
|
placeholder: "#2563eb",
|
|
1278
|
-
validate:
|
|
1315
|
+
validate: Jr(kr)
|
|
1279
1316
|
})).trim());
|
|
1280
|
-
|
|
1281
|
-
let
|
|
1317
|
+
s && (r.color = s, t.log.info(Ur(s, n).join("\n")), t.log.info(Wr(s))), t.log.step(Gr(3, qr, "Type"));
|
|
1318
|
+
let c = Yr(Ar, (await t.text({
|
|
1282
1319
|
message: G(t, "Font family", "A Google Fonts name, for example Inter. Enter keeps the fonts it starts with.", n),
|
|
1283
1320
|
placeholder: "Inter",
|
|
1284
|
-
validate:
|
|
1321
|
+
validate: Jr(Ar)
|
|
1285
1322
|
})).trim());
|
|
1286
|
-
|
|
1287
|
-
let
|
|
1323
|
+
c && (r.font = c, ir(c) ? t.log.success(`${c} is on Google Fonts. Its stylesheet will be added to fonts in blazon.json.`) : t.log.warn(`${c} is not in blazon's short list of Google Fonts, so only the font name is written. Add its stylesheet to fonts in blazon.json.`)), t.log.step(Gr(4, qr, "Logo"));
|
|
1324
|
+
let l = Yr((e) => jr(e), (await t.text({
|
|
1288
1325
|
message: G(t, "Logo file", "The path to an SVG or PNG. Enter skips it and keeps the logo it starts with.", n),
|
|
1289
1326
|
placeholder: "./logo.svg",
|
|
1290
|
-
validate:
|
|
1327
|
+
validate: Jr((e) => jr(e))
|
|
1291
1328
|
})).trim());
|
|
1292
|
-
if (
|
|
1293
|
-
r.logo =
|
|
1294
|
-
let e =
|
|
1329
|
+
if (l) {
|
|
1330
|
+
r.logo = l;
|
|
1331
|
+
let e = Mr(l), n = O.basename(l);
|
|
1295
1332
|
t.log.info([
|
|
1296
|
-
`${n}: ${e.svg ? "SVG" : "raster image"}, ${
|
|
1333
|
+
`${n}: ${e.svg ? "SVG" : "raster image"}, ${Kr(e.bytes)}.`,
|
|
1297
1334
|
"It will be copied to assets/logos/ and replace the starter's placeholder.",
|
|
1298
1335
|
...e.usesCurrentColor ? ["It draws in currentColor, so it takes the text color of the page it is on."] : [],
|
|
1299
1336
|
...e.svg ? [] : ["A raster logo cannot be recolored; an SVG is better if you have one."]
|
|
@@ -1301,13 +1338,13 @@ async function Br(e) {
|
|
|
1301
1338
|
}
|
|
1302
1339
|
return { answers: r };
|
|
1303
1340
|
}
|
|
1304
|
-
async function
|
|
1305
|
-
let { prompter: t, look: n } = e, r = e.inspect ??
|
|
1341
|
+
async function Zr(e) {
|
|
1342
|
+
let { prompter: t, look: n } = e, r = e.inspect ?? Tr;
|
|
1306
1343
|
for (;;) {
|
|
1307
1344
|
let i = (await t.text({
|
|
1308
1345
|
message: G(t, "Website address", "Blazon reads its stylesheets and page. It sends no cookies and runs none of the site's scripts.", n),
|
|
1309
1346
|
placeholder: "https://example.com (leave empty to enter the values by hand)",
|
|
1310
|
-
validate: (e) => e.trim() === "" ||
|
|
1347
|
+
validate: (e) => e.trim() === "" || Nr(e.trim()) ? void 0 : "Give the full address, starting with http:// or https://, or leave it empty to enter the values by hand."
|
|
1311
1348
|
})).trim();
|
|
1312
1349
|
if (i === "") {
|
|
1313
1350
|
t.log.info("No address given: you can enter the values by hand.");
|
|
@@ -1322,7 +1359,7 @@ async function Vr(e) {
|
|
|
1322
1359
|
a.error(`Could not read ${i}`), t.log.error(`${e instanceof Error ? e.message : String(e)}\nCheck the address and your connection. The starter is in place, so nothing is lost.`);
|
|
1323
1360
|
}
|
|
1324
1361
|
if (o) {
|
|
1325
|
-
let t = await
|
|
1362
|
+
let t = await Qr(e, i, o);
|
|
1326
1363
|
return t ? {
|
|
1327
1364
|
url: i,
|
|
1328
1365
|
findings: o,
|
|
@@ -1335,7 +1372,7 @@ async function Vr(e) {
|
|
|
1335
1372
|
})) return;
|
|
1336
1373
|
}
|
|
1337
1374
|
}
|
|
1338
|
-
async function
|
|
1375
|
+
async function Qr(e, t, n) {
|
|
1339
1376
|
let { prompter: r, look: i } = e, a = [];
|
|
1340
1377
|
n.name && a.push(`Name: ${n.name}`), n.description && a.push(`Description: ${n.description}`);
|
|
1341
1378
|
for (let e of n.fonts) a.push(`Font (${e.role}): ${e.family}${e.stylesheet ? ", its Google Fonts stylesheet will be added" : ", not in blazon's short list, so add its stylesheet yourself"}`);
|
|
@@ -1347,7 +1384,7 @@ async function Hr(e, t, n) {
|
|
|
1347
1384
|
message: G(r, "Brand colors found", "Untick any you do not want. Everything written is marked needs-review.", i),
|
|
1348
1385
|
options: n.colors.map((e) => ({
|
|
1349
1386
|
value: e.cssVar,
|
|
1350
|
-
label: `${
|
|
1387
|
+
label: `${Br(e.hex, i)} ${e.hex} ${e.cssVar}`
|
|
1351
1388
|
})),
|
|
1352
1389
|
initialValues: n.colors.map((e) => e.cssVar)
|
|
1353
1390
|
});
|
|
@@ -1359,69 +1396,69 @@ async function Hr(e, t, n) {
|
|
|
1359
1396
|
}) ? o : void 0;
|
|
1360
1397
|
}
|
|
1361
1398
|
// src/cli/commands/init.ts
|
|
1362
|
-
var
|
|
1363
|
-
function
|
|
1399
|
+
var $r = (e, t, n) => `${e} ${e === 1 ? t : n}`;
|
|
1400
|
+
function ei(e, t) {
|
|
1364
1401
|
let n = t.map((e) => e.split("/").slice(1));
|
|
1365
1402
|
if (n.length === 0) return;
|
|
1366
|
-
if (e === "docs") return `${
|
|
1367
|
-
if (e === "tokens") return `${
|
|
1403
|
+
if (e === "docs") return `${$r(n.length, "page", "pages")}, ${n[0][0]} to ${n[n.length - 1][0]}`;
|
|
1404
|
+
if (e === "tokens") return `${$r(n.length, "file", "files")}: ${n.map((e) => e.join("/")).join(", ")}`;
|
|
1368
1405
|
let r = [...new Set(n.filter((e) => e.length > 1).map((e) => e[0]))];
|
|
1369
|
-
return r.length > 0 ? `${
|
|
1406
|
+
return r.length > 0 ? `${$r(n.length, "file", "files")} in ${$r(r.length, "folder", "folders")}: ${r.join(", ")}` : `${$r(n.length, "file", "files")}: ${n.map((e) => e[0]).join(", ")}`;
|
|
1370
1407
|
}
|
|
1371
|
-
var
|
|
1372
|
-
function
|
|
1408
|
+
var ti = /^(brand|book|guidelines|guide)$/i;
|
|
1409
|
+
function ni(e) {
|
|
1373
1410
|
let t = O.basename(e).split(/[-_\s]+/).filter(Boolean), n = t.length > 0;
|
|
1374
|
-
for (; t.length > 0 &&
|
|
1411
|
+
for (; t.length > 0 && ti.test(t[t.length - 1]);) t = t.slice(0, -1);
|
|
1375
1412
|
let r = t.map((e) => e.charAt(0).toUpperCase() + e.slice(1)).join(" ");
|
|
1376
1413
|
return r ? `${r} Brand Book` : n ? "Brand Book" : "Blazon Brand Book";
|
|
1377
1414
|
}
|
|
1378
|
-
var
|
|
1415
|
+
var ri = [
|
|
1379
1416
|
[
|
|
1380
1417
|
"--name",
|
|
1381
1418
|
"name",
|
|
1382
|
-
|
|
1419
|
+
Dr
|
|
1383
1420
|
],
|
|
1384
1421
|
[
|
|
1385
1422
|
"--description",
|
|
1386
1423
|
"description",
|
|
1387
|
-
|
|
1424
|
+
Or
|
|
1388
1425
|
],
|
|
1389
1426
|
[
|
|
1390
1427
|
"--color",
|
|
1391
1428
|
"color",
|
|
1392
|
-
|
|
1429
|
+
kr
|
|
1393
1430
|
],
|
|
1394
1431
|
[
|
|
1395
1432
|
"--font",
|
|
1396
1433
|
"font",
|
|
1397
|
-
|
|
1434
|
+
Ar
|
|
1398
1435
|
],
|
|
1399
1436
|
[
|
|
1400
1437
|
"--logo",
|
|
1401
1438
|
"logo",
|
|
1402
|
-
(e) =>
|
|
1439
|
+
(e) => jr(e)
|
|
1403
1440
|
]
|
|
1404
1441
|
];
|
|
1405
|
-
async function
|
|
1442
|
+
async function ii(e = ".", t = {}) {
|
|
1406
1443
|
if (t.from !== void 0 && !/^https?:\/\/[^\s/]/i.test(t.from)) {
|
|
1407
1444
|
let e = `--from needs an http(s) address, got ${JSON.stringify(t.from)}`;
|
|
1408
|
-
return console.error(
|
|
1445
|
+
return console.error(a.red(`blazon init: ${e}`)), t.failure?.({
|
|
1409
1446
|
code: "invalid-option-value",
|
|
1410
1447
|
message: e
|
|
1411
1448
|
}), 2;
|
|
1412
1449
|
}
|
|
1413
1450
|
let n = {};
|
|
1414
|
-
for (let [e, r, i] of
|
|
1415
|
-
let
|
|
1416
|
-
if (
|
|
1417
|
-
let
|
|
1418
|
-
if ("hint" in
|
|
1451
|
+
for (let [e, r, i] of ri) {
|
|
1452
|
+
let o = t[r];
|
|
1453
|
+
if (o === void 0) continue;
|
|
1454
|
+
let s = i(String(o));
|
|
1455
|
+
if ("hint" in s) return console.error(a.red(`blazon init: ${e}: ${s.hint}`)), t.failure?.({
|
|
1419
1456
|
code: "invalid-option-value",
|
|
1420
|
-
message: `${e}: ${
|
|
1457
|
+
message: `${e}: ${s.hint}`
|
|
1421
1458
|
}), 2;
|
|
1422
|
-
n[r] =
|
|
1459
|
+
n[r] = s.value;
|
|
1423
1460
|
}
|
|
1424
|
-
let r = O.resolve(process.cwd(), e), i =
|
|
1461
|
+
let r = O.resolve(process.cwd(), e), i = c();
|
|
1425
1462
|
if (!k.existsSync(i)) throw Error(`Template directory not found at ${i}`);
|
|
1426
1463
|
let o = t.tty ?? !!(process.stdin.isTTY && process.stdout.isTTY), s = [
|
|
1427
1464
|
t.from,
|
|
@@ -1430,16 +1467,16 @@ async function Jr(e = ".", t = {}) {
|
|
|
1430
1467
|
t.color,
|
|
1431
1468
|
t.font,
|
|
1432
1469
|
t.logo
|
|
1433
|
-
].some((e) => e !== void 0),
|
|
1434
|
-
|
|
1435
|
-
let f = O.join(r, "blazon.json"), p = k.existsSync(f), m =
|
|
1470
|
+
].some((e) => e !== void 0), l = o && !s && !t.yes && t.input !== !1, u = l ? t.prompter ?? Lr() : void 0, d = t.look ?? Rr(process.env, o);
|
|
1471
|
+
l || console.log(a.cyan(`\n✨ Initializing Blazon Brand Book in ${a.bold(r)}...\n`));
|
|
1472
|
+
let f = O.join(r, "blazon.json"), p = k.existsSync(f), m = ie(r, i), h = m.kept, g = m.written.map((e) => O.relative(r, e).split(O.sep).join("/")).sort(), _ = new Set(g);
|
|
1436
1473
|
t.report?.({
|
|
1437
1474
|
dir: r,
|
|
1438
1475
|
created: g,
|
|
1439
1476
|
kept: h.map((e) => O.relative(r, e).split(O.sep).join("/")).sort()
|
|
1440
|
-
}), !p && k.existsSync(f) &&
|
|
1441
|
-
...
|
|
1442
|
-
title:
|
|
1477
|
+
}), !p && k.existsSync(f) && Bn(f, {
|
|
1478
|
+
...zn(f),
|
|
1479
|
+
title: ni(r),
|
|
1443
1480
|
description: "Brand guidelines, built from design tokens"
|
|
1444
1481
|
});
|
|
1445
1482
|
let v = [];
|
|
@@ -1448,66 +1485,66 @@ async function Jr(e = ".", t = {}) {
|
|
|
1448
1485
|
"assets",
|
|
1449
1486
|
"docs"
|
|
1450
1487
|
]) {
|
|
1451
|
-
let t =
|
|
1488
|
+
let t = ei(e, g.filter((t) => t.startsWith(`${e}/`)));
|
|
1452
1489
|
t && v.push(`${e}/ (${t})`);
|
|
1453
1490
|
}
|
|
1454
1491
|
g.includes("blazon.json") && v.push("blazon.json"), g.includes("blazon.resolver.json") && v.push("blazon.resolver.json");
|
|
1455
1492
|
let y = { answers: n };
|
|
1456
1493
|
if (u) try {
|
|
1457
|
-
y = await
|
|
1494
|
+
y = await Xr({
|
|
1458
1495
|
prompter: u,
|
|
1459
1496
|
look: d,
|
|
1460
1497
|
dir: r,
|
|
1461
1498
|
kept: h.length
|
|
1462
1499
|
});
|
|
1463
1500
|
} catch (e) {
|
|
1464
|
-
if (e instanceof
|
|
1501
|
+
if (e instanceof Fr) return u.cancel("Stopped. The starter was copied as it is, and nothing else was changed."), 130;
|
|
1465
1502
|
throw e;
|
|
1466
1503
|
}
|
|
1467
1504
|
else {
|
|
1468
|
-
for (let e of v) console.log(` ${
|
|
1469
|
-
h.length > 0 && console.log(` ${
|
|
1505
|
+
for (let e of v) console.log(` ${a.green("✔")} Created ${e}`);
|
|
1506
|
+
h.length > 0 && console.log(` ${a.yellow("!")} ${h.length} starter files were already here and are kept as they are`), console.log();
|
|
1470
1507
|
}
|
|
1471
|
-
let
|
|
1472
|
-
if (
|
|
1473
|
-
if (
|
|
1508
|
+
let ee = y.site?.url ?? t.from, b = 0, x, te = u?.spinner();
|
|
1509
|
+
if (te?.start("Writing the brand book"), ee !== void 0) try {
|
|
1510
|
+
if (x = await wr(r, ee, _, /* @__PURE__ */ new Date(), {
|
|
1474
1511
|
page: y.site?.findings.page,
|
|
1475
1512
|
skipVars: y.site?.skipVars
|
|
1476
1513
|
}), !u) {
|
|
1477
|
-
console.log(
|
|
1478
|
-
for (let e of
|
|
1479
|
-
for (let e of
|
|
1480
|
-
for (let e of
|
|
1481
|
-
for (let e of
|
|
1482
|
-
console.log(
|
|
1514
|
+
console.log(a.bold(`Read from ${ee}:`));
|
|
1515
|
+
for (let e of x.written) console.log(` ${a.green("✔")} Wrote ${e}`);
|
|
1516
|
+
for (let e of x.removed) console.log(` ${a.green("✔")} Removed ${e}`);
|
|
1517
|
+
for (let e of x.repointed) console.log(` ${a.green("✔")} Re-pointed ${e}`);
|
|
1518
|
+
for (let e of x.missing) console.log(` ${a.yellow("!")} ${e}`);
|
|
1519
|
+
console.log(a.dim("\n All of it is marked needs-review: it is a starting point, so confirm it with the brand owner.\n"));
|
|
1483
1520
|
}
|
|
1484
1521
|
} catch (e) {
|
|
1485
1522
|
let n = e instanceof Error ? e.message : String(e);
|
|
1486
1523
|
t.failure?.({
|
|
1487
1524
|
code: "site-unreadable",
|
|
1488
1525
|
message: n
|
|
1489
|
-
}), u ? u.log.error(`Could not read ${
|
|
1526
|
+
}), u ? u.log.error(`Could not read ${ee}: ${n}\nThe starter was copied as it is. To start from the site, run blazon init again with --from in a new folder (a folder that already has the starter is kept as it is), or carry on with the starter.`) : (console.error(a.red(`blazon init: ${n}`)), console.error(a.dim(" The starter was copied as it is. To start from the site, run blazon init again with --from in a new folder (a folder that already has the starter is kept as it is), or carry on with the starter.\n"))), b = 2;
|
|
1490
1527
|
}
|
|
1491
|
-
let
|
|
1528
|
+
let S;
|
|
1492
1529
|
try {
|
|
1493
|
-
|
|
1530
|
+
S = Pr(r, y.answers, _);
|
|
1494
1531
|
} catch (e) {
|
|
1495
|
-
throw
|
|
1496
|
-
}
|
|
1497
|
-
|
|
1498
|
-
let
|
|
1499
|
-
`Run ${
|
|
1500
|
-
`Replace blazon's artwork in ${
|
|
1501
|
-
`Run ${
|
|
1502
|
-
`Point a coding agent at ${
|
|
1532
|
+
throw te?.error("Could not write the brand book"), e;
|
|
1533
|
+
}
|
|
1534
|
+
te?.stop("Wrote the brand book");
|
|
1535
|
+
let C = (e) => d.color ? a.cyan(e) : e, w = F(r), ne = [
|
|
1536
|
+
`Run ${C(L("dev", w))} to see the book`,
|
|
1537
|
+
`Replace blazon's artwork in ${C(I(w, "assets/"))} and the text in ${C(I(w, "docs/"))}`,
|
|
1538
|
+
`Run ${C(L("check", w))} to see what is left`,
|
|
1539
|
+
`Point a coding agent at ${C(I(w, "AGENTS.md"))}: it is the guide for editing this brand`
|
|
1503
1540
|
];
|
|
1504
|
-
|
|
1505
|
-
let
|
|
1541
|
+
x && !x.written.some((e) => e.startsWith("assets/logos/")) && ne.splice(1, 0, `Add your logo: the book still shows blazon's own. Put it in ${C(I(w, "assets/logos/"))} and point ${C("logo")} in ${C(I(w, "blazon.json"))} at it`);
|
|
1542
|
+
let re = C(I(w, "tokens/colors.json")), ae = S.set.some((e) => e.startsWith("primary color")) ? `Finish the palette in ${re}: the primary color is set, the rest is still blazon's` : x?.written.includes("tokens/colors.json") ? `Confirm the colors read from the site in ${re} with the brand owner` : `Edit ${re} with your colors`;
|
|
1506
1543
|
if (u) {
|
|
1507
1544
|
let e = [...v.map((e) => `Created ${e}`)];
|
|
1508
|
-
|
|
1509
|
-
for (let t of
|
|
1510
|
-
e.push(...
|
|
1545
|
+
x && e.push(`Read from ${ee}: ${x.written.length} files written, ${x.removed.length} starter files removed`, ...x.missing.map((e) => `Not found: ${e}`));
|
|
1546
|
+
for (let t of S.set) e.push(`Set ${t}`);
|
|
1547
|
+
e.push(...S.hints.map((e) => `Note: ${e}`)), u.note(e.join("\n"), "What was written"), b === 0 && u.note(ne.map((e, t) => `${t + 1}. ${e}`).join("\n"), "Next steps");
|
|
1511
1548
|
let n;
|
|
1512
1549
|
try {
|
|
1513
1550
|
n = t.dev ?? await u.confirm({
|
|
@@ -1515,48 +1552,48 @@ async function Jr(e = ".", t = {}) {
|
|
|
1515
1552
|
initialValue: !1
|
|
1516
1553
|
});
|
|
1517
1554
|
} catch (e) {
|
|
1518
|
-
if (!(e instanceof
|
|
1519
|
-
return u.cancel("Stopped. Everything above was written."),
|
|
1555
|
+
if (!(e instanceof Fr)) throw e;
|
|
1556
|
+
return u.cancel("Stopped. Everything above was written."), b === 0 ? 130 : b;
|
|
1520
1557
|
}
|
|
1521
|
-
return u.outro(n ? "Starting blazon dev. Press Ctrl-C to stop it." : `Done. Run ${
|
|
1558
|
+
return u.outro(n ? "Starting blazon dev. Press Ctrl-C to stop it." : `Done. Run ${C(L("dev", w))} when you are ready.`), n && await (t.startDev ?? ai)(r), b;
|
|
1522
1559
|
}
|
|
1523
|
-
for (let e of
|
|
1524
|
-
return
|
|
1560
|
+
for (let e of S.hints) console.log(` ${a.yellow("!")} ${e}`);
|
|
1561
|
+
return S.set.length > 0 && console.log(` ${a.green("✔")} Set ${S.set.join(", ")}\n`), b === 0 && (console.log(a.bold("Next steps:")), console.log(` 1. ${ae}`), ne.forEach((e, t) => console.log(` ${t + 2}. ${e}`))), console.log(), t.dev && await (t.startDev ?? ai)(r), b;
|
|
1525
1562
|
}
|
|
1526
|
-
async function
|
|
1527
|
-
let { runDev: t } = await Promise.resolve().then(() =>
|
|
1563
|
+
async function ai(e) {
|
|
1564
|
+
let { runDev: t } = await Promise.resolve().then(() => Tt);
|
|
1528
1565
|
await t(e);
|
|
1529
1566
|
}
|
|
1530
1567
|
// src/server/preview-guard.ts
|
|
1531
|
-
function
|
|
1532
|
-
return (n, r
|
|
1533
|
-
let
|
|
1568
|
+
function oi(e) {
|
|
1569
|
+
return (t, n, r) => {
|
|
1570
|
+
let i;
|
|
1534
1571
|
try {
|
|
1535
|
-
|
|
1572
|
+
i = decodeURIComponent((t.url ?? "").split("?")[0]);
|
|
1536
1573
|
} catch {
|
|
1537
|
-
return
|
|
1574
|
+
return r();
|
|
1538
1575
|
}
|
|
1539
|
-
if (
|
|
1540
|
-
let
|
|
1541
|
-
if (
|
|
1542
|
-
|
|
1576
|
+
if (i.includes("\0")) return r();
|
|
1577
|
+
let a = O.join(e, O.normalize(`/${i}`));
|
|
1578
|
+
if (Fe(me(e), me(a))) return r();
|
|
1579
|
+
n.statusCode = 403, n.setHeader("Content-Type", "text/plain"), n.end("blazon preview serves only files inside the built site: this path is a link that leaves it");
|
|
1543
1580
|
};
|
|
1544
1581
|
}
|
|
1545
|
-
var
|
|
1582
|
+
var si = (e) => ({
|
|
1546
1583
|
name: "blazon-site-link-guard",
|
|
1547
1584
|
configurePreviewServer(t) {
|
|
1548
|
-
t.middlewares.use(
|
|
1585
|
+
t.middlewares.use(oi(e));
|
|
1549
1586
|
}
|
|
1550
1587
|
});
|
|
1551
1588
|
// src/cli/commands/preview.ts
|
|
1552
|
-
async function
|
|
1553
|
-
|
|
1554
|
-
let r = await
|
|
1589
|
+
async function ci(e = process.cwd(), t, n = {}) {
|
|
1590
|
+
Ct(e);
|
|
1591
|
+
let r = await Ae(e, t ? { port: t } : void 0), i = O.resolve(e, r.outDir);
|
|
1555
1592
|
if (!k.existsSync(O.join(i, "index.html"))) throw new M(`no built site at "${i}"`, `Run ${L("build", F(e))} first.`, "no-built-site");
|
|
1556
|
-
let
|
|
1593
|
+
let o;
|
|
1557
1594
|
try {
|
|
1558
|
-
|
|
1559
|
-
plugins: [
|
|
1595
|
+
o = await st({
|
|
1596
|
+
plugins: [pe(), si(i)],
|
|
1560
1597
|
build: { outDir: i },
|
|
1561
1598
|
preview: {
|
|
1562
1599
|
port: r.port,
|
|
@@ -1566,61 +1603,61 @@ async function Qr(e = process.cwd(), t, n = {}) {
|
|
|
1566
1603
|
}
|
|
1567
1604
|
});
|
|
1568
1605
|
} catch (e) {
|
|
1569
|
-
throw n.strictPort && e instanceof Error && /already in use/.test(e.message) ?
|
|
1606
|
+
throw n.strictPort && e instanceof Error && /already in use/.test(e.message) ? lt(r.port) : e;
|
|
1570
1607
|
}
|
|
1571
|
-
let
|
|
1572
|
-
console.log(`\n ${
|
|
1573
|
-
for (let e of
|
|
1574
|
-
return console.log(` ${
|
|
1608
|
+
let s = o.resolvedUrls, c = s?.local[0] || `http://localhost:${r.port}/`;
|
|
1609
|
+
console.log(`\n ${a.bold(a.blue("blazon preview"))}`), console.log(` ${a.dim("➜")} ${a.bold("Local:")} ${a.cyan(c)}`);
|
|
1610
|
+
for (let e of s?.network ?? []) console.log(` ${a.dim("➜")} ${a.bold("Network:")} ${a.cyan(e)}`);
|
|
1611
|
+
return console.log(` ${a.dim("➜")} ${a.bold("Dist:")} ${a.dim(i)}\n`), o;
|
|
1575
1612
|
}
|
|
1576
1613
|
// src/plugins/roles/check-cases.ts
|
|
1577
|
-
var
|
|
1578
|
-
function
|
|
1579
|
-
let t = O.basename(e), n =
|
|
1580
|
-
return
|
|
1614
|
+
var li = "docs/manual/12-plugins.md (\"What a plugin can look at, and where it writes\")";
|
|
1615
|
+
function ui(e) {
|
|
1616
|
+
let t = O.basename(e), n = Ze(t) ?? t.replace(/^blazon-/, "");
|
|
1617
|
+
return ge(n) ? n : void 0;
|
|
1581
1618
|
}
|
|
1582
|
-
function
|
|
1619
|
+
function di(e, t) {
|
|
1583
1620
|
return k.readdirSync(e, { recursive: !0 }).filter((n) => O.join(e, n) !== t && !O.join(e, n).startsWith(t + O.sep)).sort();
|
|
1584
1621
|
}
|
|
1585
|
-
function
|
|
1586
|
-
let n =
|
|
1587
|
-
return async (
|
|
1588
|
-
let i = t
|
|
1622
|
+
function fi(t) {
|
|
1623
|
+
let n = ui(t);
|
|
1624
|
+
return async (t, r) => {
|
|
1625
|
+
let i = je(t), a = i.answers.join(" or "), o = i.stdoutLimit ?? 65536, s = [], c = {
|
|
1589
1626
|
exit: `a valid request is answered with exit ${a}`,
|
|
1590
1627
|
limit: `the answer is at most ${o} bytes`,
|
|
1591
|
-
shape: `the answer is one the ${
|
|
1628
|
+
shape: `the answer is one the ${t} role accepts: a findings list of at most 500, each with the plugin's code, a severity, a path and a message`,
|
|
1592
1629
|
folder: "the plugin writes into out_dir and nothing beside it"
|
|
1593
|
-
}, l = JSON.parse(
|
|
1630
|
+
}, l = JSON.parse(e()[t]), u = k.mkdtempSync(O.join(ot.tmpdir(), "blazon-plugin-check-")), d = O.join(u, "tokens"), f = O.join(d, n ?? "plugin");
|
|
1594
1631
|
try {
|
|
1595
|
-
|
|
1632
|
+
t === "build" && (k.mkdirSync(O.join(u, "site")), k.mkdirSync(f, { recursive: !0 }), Object.assign(l, {
|
|
1596
1633
|
site_dir: O.join(u, "site"),
|
|
1597
1634
|
tokens_dir: d,
|
|
1598
1635
|
out_dir: f
|
|
1599
1636
|
}));
|
|
1600
|
-
let
|
|
1601
|
-
p ? s.push(
|
|
1637
|
+
let e = await r(Buffer.from(JSON.stringify(l)), o), p = !e.answered && e.breakReason.startsWith("output over the limit");
|
|
1638
|
+
p ? s.push(v(6, c.exit, t, {
|
|
1602
1639
|
skipped: !0,
|
|
1603
1640
|
detail: "the output went over the limit before the plugin exited (case 7)"
|
|
1604
|
-
})) :
|
|
1605
|
-
let m = i.stdoutLimit === void 0 ? "the core's limit, which the role does not raise" : `the ${
|
|
1606
|
-
if (s.push(p ?
|
|
1641
|
+
})) : e.answered && i.answers.includes(e.code) ? s.push(v(6, c.exit, t, { passed: !0 })) : e.answered && e.code === 1 ? s.push(v(6, c.exit, t, { detail: `got exit 1, and exit 1 is a break in blazon: the ${t} role defines only ${a}, so blazon reports the plugin as failed and counts it toward its breaker. Exit 2 with the reason on the first line when the plugin cannot answer` })) : s.push(v(6, c.exit, t, { detail: e.answered ? `got exit ${e.code}` : `a break: ${e.breakReason}` }));
|
|
1642
|
+
let m = i.stdoutLimit === void 0 ? "the core's limit, which the role does not raise" : `the ${t} role's limit (stdout_limit_bytes)`;
|
|
1643
|
+
if (s.push(p ? v(7, c.limit, t, { detail: `the plugin printed more than ${o} bytes, ${m}` }) : v(7, c.limit, t, { passed: !0 })), !e.answered || e.code !== 0) s.push(v(8, c.shape, t, {
|
|
1607
1644
|
skipped: !0,
|
|
1608
1645
|
detail: "the plugin did not answer with exit 0"
|
|
1609
1646
|
}));
|
|
1610
|
-
else if (n === void 0) s.push(
|
|
1647
|
+
else if (n === void 0) s.push(v(8, c.shape, t, {
|
|
1611
1648
|
skipped: !0,
|
|
1612
1649
|
detail: "the program's file name is not blazon-<plugin name>, so the check does not know the plugin's code prefix"
|
|
1613
1650
|
}));
|
|
1614
1651
|
else {
|
|
1615
|
-
let r =
|
|
1616
|
-
s.push("problem" in r ?
|
|
1652
|
+
let r = Xe(t, n, e.stdout, []);
|
|
1653
|
+
s.push("problem" in r ? v(8, c.shape, t, { detail: r.problem }) : v(8, c.shape, t, { passed: !0 }));
|
|
1617
1654
|
}
|
|
1618
|
-
if (
|
|
1619
|
-
let
|
|
1620
|
-
s.push(
|
|
1655
|
+
if (t === "build") {
|
|
1656
|
+
let e = di(d, f);
|
|
1657
|
+
s.push(e.length === 0 ? v(9, c.folder, t, { passed: !0 }) : v(9, c.folder, t, {
|
|
1621
1658
|
passed: !0,
|
|
1622
1659
|
warning: !0,
|
|
1623
|
-
detail: `it wrote ${
|
|
1660
|
+
detail: `it wrote ${e.map((e) => `tokens_dir/${e}`).join(", ")}. Blazon empties only out_dir before a build, so a file beside it is never cleaned and can collide with another plugin's. Blazon has no folder for a plugin's own state yet, so this is a warning; see ${li}`
|
|
1624
1661
|
}));
|
|
1625
1662
|
}
|
|
1626
1663
|
} finally {
|
|
@@ -1633,30 +1670,30 @@ function ni(e) {
|
|
|
1633
1670
|
};
|
|
1634
1671
|
}
|
|
1635
1672
|
// src/cli/commands/plugin.ts
|
|
1636
|
-
var
|
|
1673
|
+
var pi = {
|
|
1637
1674
|
plugin: "usage: blazon plugin check <program> [--core] | blazon plugin pin <path> [--name <plugin name>] | blazon plugin profile",
|
|
1638
1675
|
check: "usage: blazon plugin check <program> [--core]",
|
|
1639
1676
|
pin: "usage: blazon plugin pin <path> [--name <plugin name> [--digest <digest>] [--entry <path>]]"
|
|
1640
1677
|
};
|
|
1641
|
-
function
|
|
1642
|
-
let t = e.warning ?
|
|
1678
|
+
function mi(e) {
|
|
1679
|
+
let t = e.warning ? a.yellow("warn") : e.passed ? a.green("ok ") : e.skipped ? a.dim("skip") : a.red("FAIL"), n = e.role ? `${e.role}: ` : "", r = e.detail ? ` (${e.detail})` : "";
|
|
1643
1680
|
return ` ${t} ${e.case} ${n}${e.name}${r}`;
|
|
1644
1681
|
}
|
|
1645
|
-
async function
|
|
1646
|
-
if (!
|
|
1647
|
-
let
|
|
1648
|
-
|
|
1649
|
-
let
|
|
1650
|
-
...
|
|
1651
|
-
host:
|
|
1652
|
-
profile:
|
|
1653
|
-
program:
|
|
1682
|
+
async function hi(t, n = {}) {
|
|
1683
|
+
if (!t) throw new M(pi.check, void 0, "missing-argument");
|
|
1684
|
+
let r = n.core === !0;
|
|
1685
|
+
n.json || (console.log(`${E.host} plugin check: host ${E.host}, adopts: ${E.adopts.length > 0 ? E.adopts.join(", ") : "none"}`), r && console.log("core cases only (1 to 5): no role cases, no layout line"));
|
|
1686
|
+
let i = await _({
|
|
1687
|
+
...r ? {} : { approvals: await gi(t) },
|
|
1688
|
+
host: E.host,
|
|
1689
|
+
profile: ee,
|
|
1690
|
+
program: t,
|
|
1654
1691
|
validate: !1,
|
|
1655
|
-
requests:
|
|
1656
|
-
...
|
|
1657
|
-
}),
|
|
1658
|
-
if (
|
|
1659
|
-
let e = (e) => e.warning ? "warn" : e.passed ? "ok" : e.skipped ? "skip" : "fail", t =
|
|
1692
|
+
requests: e(),
|
|
1693
|
+
...r ? {} : { roleCases: fi(t) }
|
|
1694
|
+
}), o = i.filter((e) => e.warning).length, s = i.filter((e) => !e.passed && !e.skipped), c = r ? void 0 : w(O.resolve(t));
|
|
1695
|
+
if (n.json) {
|
|
1696
|
+
let e = (e) => e.warning ? "warn" : e.passed ? "ok" : e.skipped ? "skip" : "fail", t = i.map((t) => ({
|
|
1660
1697
|
case: t.case,
|
|
1661
1698
|
name: t.name,
|
|
1662
1699
|
role: t.role,
|
|
@@ -1665,128 +1702,129 @@ async function ai(e, t = {}) {
|
|
|
1665
1702
|
}));
|
|
1666
1703
|
return process.stdout.write(`${JSON.stringify({
|
|
1667
1704
|
command: "plugin check",
|
|
1668
|
-
passed:
|
|
1669
|
-
host:
|
|
1670
|
-
adopts:
|
|
1671
|
-
...
|
|
1705
|
+
passed: s.length === 0 && !c,
|
|
1706
|
+
host: E.host,
|
|
1707
|
+
adopts: E.adopts,
|
|
1708
|
+
...r ? { core: !0 } : {},
|
|
1672
1709
|
cases: t,
|
|
1673
|
-
...
|
|
1674
|
-
})}\n`),
|
|
1710
|
+
...c ? { layout: c } : {}
|
|
1711
|
+
})}\n`), s.length === 0 && !c ? 0 : 1;
|
|
1675
1712
|
}
|
|
1676
|
-
for (let e of
|
|
1677
|
-
return
|
|
1713
|
+
for (let e of i) console.log(mi(e));
|
|
1714
|
+
return c && console.log(` ${a.red("FAIL")} layout: ${c}`), s.length > 0 ? console.log(a.red(`\n${s.length} case${s.length === 1 ? "" : "s"} failed`)) : console.log(c ? a.red("\nFailed: the file name does not follow the layout of a shipped plugin") : a.green(`\nPassed${o > 0 ? `, with ${o} warning${o === 1 ? "" : "s"}` : ""}`)), s.length === 0 && !c ? 0 : 1;
|
|
1678
1715
|
}
|
|
1679
|
-
async function
|
|
1716
|
+
async function gi(e) {
|
|
1680
1717
|
let t;
|
|
1681
1718
|
try {
|
|
1682
1719
|
t = (await R(process.cwd())).plugins ?? [];
|
|
1683
1720
|
} catch {
|
|
1684
1721
|
return;
|
|
1685
1722
|
}
|
|
1686
|
-
let n = O.basename(e), r =
|
|
1723
|
+
let n = O.basename(e), r = Ze(n) ?? n.replace(/^blazon-/, "");
|
|
1687
1724
|
return t.flatMap((e, t) => e.name === r ? [{
|
|
1688
1725
|
key: `plugins[${t}].env`,
|
|
1689
1726
|
approved: e.env ?? []
|
|
1690
1727
|
}] : []);
|
|
1691
1728
|
}
|
|
1692
|
-
function
|
|
1693
|
-
if (!e) throw new M(
|
|
1694
|
-
if (!t.name && (t.digest || t.entry)) throw new M(`--digest and --entry say what to record, so they need --name; ${
|
|
1729
|
+
function _i(e, t = {}, r = process.cwd()) {
|
|
1730
|
+
if (!e) throw new M(pi.pin, void 0, "missing-argument");
|
|
1731
|
+
if (!t.name && (t.digest || t.entry)) throw new M(`--digest and --entry say what to record, so they need --name; ${pi.pin}`, void 0, "conflicting-options");
|
|
1695
1732
|
if (!k.existsSync(e)) return console.error(`blazon plugin pin: there is nothing at ${e}.`), 2;
|
|
1696
1733
|
try {
|
|
1697
1734
|
if (t.name) {
|
|
1698
|
-
let
|
|
1735
|
+
let i = n(r, t.name, e, {
|
|
1699
1736
|
digest: t.digest,
|
|
1700
1737
|
entry: t.entry
|
|
1701
1738
|
});
|
|
1702
|
-
return console.log(`pinned ${t.name}: ${
|
|
1739
|
+
return console.log(`pinned ${t.name}: ${i.digest} (${i.source}) in ${nt}`), 0;
|
|
1703
1740
|
}
|
|
1704
|
-
let
|
|
1705
|
-
return console.log(
|
|
1741
|
+
let i = k.lstatSync(e);
|
|
1742
|
+
return console.log(i.isDirectory() && !i.isSymbolicLink() ? Re(e) : h(e)), 0;
|
|
1706
1743
|
} catch (t) {
|
|
1707
|
-
return console.error(t instanceof
|
|
1744
|
+
return console.error(t instanceof l ? t.message : `cannot read ${e}: ${t instanceof Error ? t.message : String(t)}`), 1;
|
|
1708
1745
|
}
|
|
1709
1746
|
}
|
|
1710
|
-
function
|
|
1711
|
-
return console.log(JSON.stringify(
|
|
1747
|
+
function vi() {
|
|
1748
|
+
return console.log(JSON.stringify(E, null, 2)), 0;
|
|
1712
1749
|
}
|
|
1713
|
-
async function
|
|
1714
|
-
if (e === "check") return
|
|
1750
|
+
async function yi(e, t, n = {}) {
|
|
1751
|
+
if (e === "check") return hi(t, {
|
|
1715
1752
|
json: n.json,
|
|
1716
1753
|
core: n.core
|
|
1717
1754
|
});
|
|
1718
|
-
if (e === "pin") return
|
|
1719
|
-
if (e === "profile") return
|
|
1720
|
-
throw new M(
|
|
1755
|
+
if (e === "pin") return _i(t, n);
|
|
1756
|
+
if (e === "profile") return vi();
|
|
1757
|
+
throw new M(pi.plugin, void 0, "missing-argument");
|
|
1721
1758
|
}
|
|
1722
1759
|
// src/cli/commands/pin.ts
|
|
1723
|
-
function
|
|
1724
|
-
|
|
1760
|
+
function bi(e = process.cwd(), t = {}) {
|
|
1761
|
+
Ct(e);
|
|
1725
1762
|
try {
|
|
1726
|
-
let n = t.identity === void 0 ?
|
|
1763
|
+
let n = t.identity === void 0 ? ne(e) : ne(e, t.identity);
|
|
1727
1764
|
return t.json ? process.stdout.write(`${JSON.stringify({
|
|
1728
1765
|
command: "pin",
|
|
1729
1766
|
passed: !0,
|
|
1730
1767
|
commit: n,
|
|
1731
|
-
file:
|
|
1732
|
-
})}\n`) : console.log(`pinned blazon ${
|
|
1768
|
+
file: fe
|
|
1769
|
+
})}\n`) : console.log(`pinned blazon ${a.bold(n)} in ${fe}; commit the file with the book`), 0;
|
|
1733
1770
|
} catch (e) {
|
|
1734
1771
|
if (t.json) throw e;
|
|
1735
1772
|
return console.error(e instanceof Error ? e.message : String(e)), 1;
|
|
1736
1773
|
}
|
|
1737
1774
|
}
|
|
1738
1775
|
// src/cli/commands/drift.ts
|
|
1739
|
-
async function
|
|
1740
|
-
let n = (e, n, r) => (console.error(
|
|
1776
|
+
async function xi(e, t = {}) {
|
|
1777
|
+
let n = (e, n, r) => (console.error(dt("drift", n, r).replace(/^blazon drift:/, (e) => a.red(e))), t.json && console.log(JSON.stringify({
|
|
1741
1778
|
command: "drift",
|
|
1742
1779
|
passed: !1,
|
|
1743
|
-
error: { ...
|
|
1780
|
+
error: { ...gt(e, ft(n, r), r) }
|
|
1744
1781
|
})), 2);
|
|
1745
1782
|
if (!e) return n("missing-argument", "needs the address of a page or the path of a CSS file", "Run blazon drift <url-or-css-file>.");
|
|
1746
1783
|
let r = t.cwd ?? process.cwd();
|
|
1747
1784
|
if (!/^[a-z][a-z0-9+.-]*:\/\//i.test(e) && !k.existsSync(O.resolve(e))) return n("no-file", `there is no file "${e}"`, "Give the path of a CSS file, or the http(s) address of a page.");
|
|
1748
|
-
let i,
|
|
1785
|
+
let i, o;
|
|
1749
1786
|
try {
|
|
1750
|
-
let n = await R(r, t.tokens ? { tokensDir: t.tokens } : void 0),
|
|
1787
|
+
let n = await R(r, t.tokens ? { tokensDir: t.tokens } : void 0), a = await T(n, r), s = await ln(e);
|
|
1751
1788
|
i = s.sources;
|
|
1752
|
-
let c =
|
|
1753
|
-
|
|
1789
|
+
let c = tn(s.css);
|
|
1790
|
+
o = a.tokens.items.flatMap((e) => {
|
|
1754
1791
|
let t = e.blazon.source?.cssVar;
|
|
1755
|
-
return typeof t == "string" ? [
|
|
1792
|
+
return typeof t == "string" ? [nn(e, t, c)] : [];
|
|
1756
1793
|
});
|
|
1757
1794
|
} catch (e) {
|
|
1758
1795
|
return n(e instanceof j ? e.code : "error", e instanceof Error ? e.message : String(e), e instanceof j ? e.fix : void 0);
|
|
1759
1796
|
}
|
|
1760
|
-
if (
|
|
1761
|
-
let
|
|
1762
|
-
ok:
|
|
1763
|
-
drift:
|
|
1764
|
-
missing:
|
|
1765
|
-
},
|
|
1797
|
+
if (o.length === 0) return n("error", "no token declares a source.cssVar, so there is nothing to compare", "Name the site's custom property in a token's dev.blazon source.cssVar (manual chapter 2).");
|
|
1798
|
+
let s = (e) => o.filter((t) => t.status === e).length, c = {
|
|
1799
|
+
ok: s("ok"),
|
|
1800
|
+
drift: s("drift"),
|
|
1801
|
+
missing: s("missing")
|
|
1802
|
+
}, l = +(c.drift + c.missing > 0);
|
|
1766
1803
|
if (t.json) return console.log(JSON.stringify({
|
|
1767
1804
|
target: e,
|
|
1768
1805
|
sources: i,
|
|
1769
|
-
summary:
|
|
1770
|
-
tokens:
|
|
1771
|
-
}, null, 2)),
|
|
1772
|
-
let u = Math.max(...
|
|
1773
|
-
for (let e of
|
|
1806
|
+
summary: c,
|
|
1807
|
+
tokens: o
|
|
1808
|
+
}, null, 2)), l;
|
|
1809
|
+
let u = Math.max(...o.map((e) => e.path.length));
|
|
1810
|
+
for (let e of o) {
|
|
1774
1811
|
let t = e.path.padEnd(u);
|
|
1775
|
-
e.status === "ok" ? console.log(`${
|
|
1812
|
+
e.status === "ok" ? console.log(`${a.green("ok ")} ${t} ${a.dim(e.cssVar)}`) : e.status === "drift" ? console.log(`${a.red("drift ")} ${t} ${e.cssVar}: token ${e.expected}, site ${e.actual}`) : console.log(`${a.yellow("missing")} ${t} ${e.cssVar} is not declared (token ${e.expected})`);
|
|
1776
1813
|
}
|
|
1777
|
-
return console.log(`\n${
|
|
1814
|
+
return console.log(`\n${c.ok} ok, ${c.drift} drifted, ${c.missing} missing`), l;
|
|
1778
1815
|
}
|
|
1779
1816
|
// src/cli/commands/approvals.ts
|
|
1780
|
-
async function
|
|
1781
|
-
let n = await R(e), r = await
|
|
1817
|
+
async function Si(e = process.cwd(), t = {}) {
|
|
1818
|
+
let n = await R(e), r = await T(n, e), i = o(r.tokens, r.assets.all, {
|
|
1782
1819
|
assetsDir: O.resolve(e, n.assetsDir),
|
|
1783
|
-
dirs:
|
|
1784
|
-
}),
|
|
1820
|
+
dirs: se(n.assets, e)
|
|
1821
|
+
}), s = (e) => e.review.value === void 0 ? "not recorded" : e.review.value === e.current ? "recorded" : "stale";
|
|
1785
1822
|
if (t.json) {
|
|
1786
1823
|
let e = i.map((e) => ({
|
|
1787
1824
|
path: e.path,
|
|
1788
1825
|
fingerprint: e.current ?? null,
|
|
1789
|
-
state:
|
|
1826
|
+
state: s(e),
|
|
1827
|
+
...e.files && { files: e.files }
|
|
1790
1828
|
}));
|
|
1791
1829
|
return process.stdout.write(`${JSON.stringify({
|
|
1792
1830
|
command: "approvals",
|
|
@@ -1794,43 +1832,63 @@ async function fi(e = process.cwd(), t = {}) {
|
|
|
1794
1832
|
approvals: e
|
|
1795
1833
|
})}\n`), 0;
|
|
1796
1834
|
}
|
|
1797
|
-
if (i.length === 0) return console.log(
|
|
1798
|
-
let
|
|
1835
|
+
if (i.length === 0) return console.log(a.dim("\n No token or asset is marked review.status: ok.\n")), 0;
|
|
1836
|
+
let c = Math.max(...i.map((e) => e.path.length));
|
|
1799
1837
|
console.log();
|
|
1800
1838
|
for (let e of i) {
|
|
1801
|
-
let t =
|
|
1802
|
-
console.log(` ${e.path.padEnd(
|
|
1839
|
+
let t = s(e), n = t === "recorded" ? a.green : t === "stale" ? a.yellow : a.dim, r = e.files ? ` ${a.dim(e.files.join(", "))}` : "";
|
|
1840
|
+
console.log(` ${e.path.padEnd(c)} ${(e.current ?? "(no value)").padEnd(12)} ${n(t)}${" ".repeat(12 - t.length)}${r}`.trimEnd());
|
|
1803
1841
|
}
|
|
1804
|
-
return console.log(), console.log(
|
|
1842
|
+
return console.log(), console.log(a.dim(" Set review.value to the fingerprint once a person has confirmed the value.\n")), 0;
|
|
1805
1843
|
}
|
|
1806
1844
|
// src/cli/commands/cwd.ts
|
|
1807
|
-
function
|
|
1845
|
+
function Ci(e) {
|
|
1808
1846
|
if (e === void 0) return;
|
|
1809
1847
|
if (typeof e != "string" || e === "") throw new M("--cwd needs a folder", "Give one, such as blazon --cwd ./my-brand check.");
|
|
1810
1848
|
let t = O.resolve(process.cwd(), e);
|
|
1811
|
-
|
|
1849
|
+
Ct(t), process.chdir(t);
|
|
1812
1850
|
}
|
|
1813
|
-
function
|
|
1851
|
+
function wi(e, t = process.env) {
|
|
1814
1852
|
let n = (Array.isArray(e) ? e : e === void 0 ? [] : [e]).map((e) => typeof e == "string" || typeof e == "number" ? String(e) : "");
|
|
1815
1853
|
if (n.some((e) => e.trim() === "")) throw new M("--allow-dir needs a folder", "Give one, such as blazon dev --allow-dir ../shared.");
|
|
1816
|
-
|
|
1854
|
+
ye(He(n, t, process.cwd()));
|
|
1817
1855
|
}
|
|
1818
1856
|
// src/core/read/lookup.ts
|
|
1819
|
-
var K = class extends Error {},
|
|
1820
|
-
function
|
|
1821
|
-
let
|
|
1822
|
-
if (
|
|
1823
|
-
let
|
|
1824
|
-
throw new K(e.tokens.items.some((e) => e.path.startsWith(`${
|
|
1857
|
+
var K = class extends Error {}, Ti = (e) => e.trim().replace(/^\{(.*)\}$/, "$1").trim();
|
|
1858
|
+
function Ei(e, t, n) {
|
|
1859
|
+
let r = Ti(t), i = e.tokens.byPath.get(r);
|
|
1860
|
+
if (i) return i;
|
|
1861
|
+
let a = D(r, e.tokens.items.map((e) => e.path));
|
|
1862
|
+
throw new K(e.tokens.items.some((e) => e.path.startsWith(`${r}.`)) ? `"${r}" is a group, not a token; \`blazon rules ${r}\` shows its rules.` : `no token "${r}"${n === void 0 ? "" : ` in theme "${n}"`}${a ? `; did you mean "${a}"?` : "."}`);
|
|
1863
|
+
}
|
|
1864
|
+
// src/core/read/theme.ts
|
|
1865
|
+
var Di = "theme";
|
|
1866
|
+
function Oi(e) {
|
|
1867
|
+
return e.tokens.modifiers?.find((e) => e.name === "theme")?.contexts ?? [];
|
|
1868
|
+
}
|
|
1869
|
+
function ki(e, t) {
|
|
1870
|
+
let n = e.tokens.modifiers?.find((e) => e.name === Di);
|
|
1871
|
+
if (!n) throw new K(`no theme "${t}": this brand has no resolver "${Di}" modifier, so it has no themes.`);
|
|
1872
|
+
if (!n.contexts.includes(t)) throw new K(`no theme "${t}". The themes are ${n.contexts.map((e) => `"${e}"`).join(", ")}.`);
|
|
1873
|
+
let r = (e.tokens.contexts ?? []).filter((e) => e.modifier === "theme" && e.context === t), i = le(e.tokens.items, r), a = m(e.tokens.groupMeta, r);
|
|
1874
|
+
return {
|
|
1875
|
+
...e,
|
|
1876
|
+
tokens: {
|
|
1877
|
+
...e.tokens,
|
|
1878
|
+
items: i,
|
|
1879
|
+
groupMeta: a,
|
|
1880
|
+
byPath: new Map(i.map((e) => [e.path, e]))
|
|
1881
|
+
}
|
|
1882
|
+
};
|
|
1825
1883
|
}
|
|
1826
1884
|
// src/core/read/rules.ts
|
|
1827
|
-
var
|
|
1828
|
-
function
|
|
1829
|
-
return
|
|
1885
|
+
var Ai = (e) => e.extensions?.["dev.blazon"] ?? {};
|
|
1886
|
+
function ji(e, t, n) {
|
|
1887
|
+
return Ai(t)[n] === void 0 ? e.tokens.groupMeta.filter((e) => t.path.startsWith(`${e.path}.`) && e.blazon[n] !== void 0).sort((e, t) => t.path.length - e.path.length)[0]?.path : t.path;
|
|
1830
1888
|
}
|
|
1831
1889
|
var q = (e) => Array.isArray(e) ? e.filter((e) => typeof e == "string") : void 0;
|
|
1832
|
-
function
|
|
1833
|
-
let n = t.blazon.usage, r =
|
|
1890
|
+
function Mi(e, t) {
|
|
1891
|
+
let n = t.blazon.usage, r = ji(e, t, "usage");
|
|
1834
1892
|
if (!n || typeof n != "object" || r === void 0) return;
|
|
1835
1893
|
let i = q(n.allow), a = q(n.deny);
|
|
1836
1894
|
return {
|
|
@@ -1839,15 +1897,15 @@ function yi(e, t) {
|
|
|
1839
1897
|
from: r
|
|
1840
1898
|
};
|
|
1841
1899
|
}
|
|
1842
|
-
function
|
|
1843
|
-
let n = t.blazon.logo, r =
|
|
1900
|
+
function Ni(e, t) {
|
|
1901
|
+
let n = t.blazon.logo, r = ji(e, t, "logo"), i = q(n?.deny);
|
|
1844
1902
|
if (n && i && r !== void 0) return {
|
|
1845
1903
|
deny: i,
|
|
1846
1904
|
...typeof n.reason == "string" && { reason: n.reason },
|
|
1847
1905
|
from: r
|
|
1848
1906
|
};
|
|
1849
1907
|
}
|
|
1850
|
-
function
|
|
1908
|
+
function Pi(e) {
|
|
1851
1909
|
return e.tokens.groupMeta.flatMap((e) => (e.blazon.pairs ?? []).map((t) => ({
|
|
1852
1910
|
fg: t.fg,
|
|
1853
1911
|
bg: t.bg,
|
|
@@ -1855,19 +1913,19 @@ function xi(e) {
|
|
|
1855
1913
|
from: e.path
|
|
1856
1914
|
})));
|
|
1857
1915
|
}
|
|
1858
|
-
function
|
|
1916
|
+
function Fi(e, t) {
|
|
1859
1917
|
let n = [];
|
|
1860
|
-
for (let r of
|
|
1918
|
+
for (let r of Pi(e)) S(r.fg, e.tokens.items).some((e) => e.path === t.path) && n.push({
|
|
1861
1919
|
...r,
|
|
1862
1920
|
as: "fg"
|
|
1863
|
-
}),
|
|
1921
|
+
}), S(r.bg, e.tokens.items).some((e) => e.path === t.path) && n.push({
|
|
1864
1922
|
...r,
|
|
1865
1923
|
as: "bg"
|
|
1866
1924
|
});
|
|
1867
1925
|
return n;
|
|
1868
1926
|
}
|
|
1869
|
-
function
|
|
1870
|
-
let n =
|
|
1927
|
+
function Ii(e, t) {
|
|
1928
|
+
let n = Ai(t).review, r = n ? t.path : ji(e, t, "review"), i = n ?? e.tokens.groupMeta.find((e) => e.path === r)?.blazon.review;
|
|
1871
1929
|
if (i && r !== void 0) return {
|
|
1872
1930
|
status: i.status,
|
|
1873
1931
|
...i.note && { note: i.note },
|
|
@@ -1876,8 +1934,8 @@ function Ci(e, t) {
|
|
|
1876
1934
|
from: r
|
|
1877
1935
|
};
|
|
1878
1936
|
}
|
|
1879
|
-
function
|
|
1880
|
-
let n =
|
|
1937
|
+
function Li(e, t) {
|
|
1938
|
+
let n = Mi(e, t), r = Ni(e, t), i = Ii(e, t), a = t.blazon.role === void 0 ? void 0 : ji(e, t, "role");
|
|
1881
1939
|
return {
|
|
1882
1940
|
...t.blazon.role !== void 0 && a !== void 0 && { role: {
|
|
1883
1941
|
value: t.blazon.role,
|
|
@@ -1885,11 +1943,11 @@ function wi(e, t) {
|
|
|
1885
1943
|
} },
|
|
1886
1944
|
...n && { usage: n },
|
|
1887
1945
|
...r && { logo: r },
|
|
1888
|
-
pairs:
|
|
1946
|
+
pairs: Fi(e, t),
|
|
1889
1947
|
...i && { review: i }
|
|
1890
1948
|
};
|
|
1891
1949
|
}
|
|
1892
|
-
function
|
|
1950
|
+
function Ri(e, t, n) {
|
|
1893
1951
|
let r = n.usage && typeof n.usage == "object" ? {
|
|
1894
1952
|
...q(n.usage.allow) && { allow: q(n.usage.allow) },
|
|
1895
1953
|
...q(n.usage.deny) && { deny: q(n.usage.deny) }
|
|
@@ -1910,59 +1968,66 @@ function Ti(e, t, n) {
|
|
|
1910
1968
|
};
|
|
1911
1969
|
return Object.keys(a).length > 2 ? a : void 0;
|
|
1912
1970
|
}
|
|
1913
|
-
function
|
|
1914
|
-
let n =
|
|
1971
|
+
function zi(e, t) {
|
|
1972
|
+
let n = Ti(t), r = (e) => n === "" || e === n || e.startsWith(`${n}.`);
|
|
1915
1973
|
if (!(n === "" || e.tokens.items.some((e) => r(e.path)))) {
|
|
1916
|
-
let t = [...new Set(e.tokens.items.flatMap((e) => e.path.split(".").slice(0, -1).map((e, t, n) => n.slice(0, t + 1).join("."))))], r =
|
|
1974
|
+
let t = [...new Set(e.tokens.items.flatMap((e) => e.path.split(".").slice(0, -1).map((e, t, n) => n.slice(0, t + 1).join("."))))], r = D(n, [...t, ...e.tokens.items.map((e) => e.path)]);
|
|
1917
1975
|
throw new K(`no token or group "${n}"${r ? `; did you mean "${r}"?` : "."}`);
|
|
1918
1976
|
}
|
|
1919
1977
|
return [
|
|
1920
|
-
...e.tokens.groupMeta.filter((e) => n !== "" && n.startsWith(`${e.path}.`)).map((e) =>
|
|
1978
|
+
...e.tokens.groupMeta.filter((e) => n !== "" && n.startsWith(`${e.path}.`)).map((e) => Ri(e.path, "group", {
|
|
1921
1979
|
...e.blazon,
|
|
1922
1980
|
pairs: void 0
|
|
1923
1981
|
})).map((e) => e && {
|
|
1924
1982
|
...e,
|
|
1925
1983
|
inherited: !0
|
|
1926
1984
|
}),
|
|
1927
|
-
...e.tokens.groupMeta.filter((e) => r(e.path)).map((e) =>
|
|
1928
|
-
...e.tokens.items.filter((e) => r(e.path)).map((e) =>
|
|
1985
|
+
...e.tokens.groupMeta.filter((e) => r(e.path)).map((e) => Ri(e.path, "group", e.blazon)),
|
|
1986
|
+
...e.tokens.items.filter((e) => r(e.path)).map((e) => Ri(e.path, "token", Ai(e)))
|
|
1929
1987
|
].filter((e) => e !== void 0);
|
|
1930
1988
|
}
|
|
1931
1989
|
// src/core/read/token.ts
|
|
1932
|
-
function
|
|
1933
|
-
let [
|
|
1990
|
+
function Bi(e, t) {
|
|
1991
|
+
let [n, ...r] = y(t);
|
|
1934
1992
|
return {
|
|
1935
1993
|
theme: {
|
|
1936
|
-
variable:
|
|
1937
|
-
...t.parts && { parts: Object.fromEntries(Object.keys(t.parts).map((e, t) => [e,
|
|
1994
|
+
variable: n,
|
|
1995
|
+
...t.parts && { parts: Object.fromEntries(Object.keys(t.parts).map((e, t) => [e, r[t]])) }
|
|
1938
1996
|
},
|
|
1939
|
-
...t.type === "typography" && { typographyClass:
|
|
1997
|
+
...t.type === "typography" && { typographyClass: We(t.path) }
|
|
1940
1998
|
};
|
|
1941
1999
|
}
|
|
1942
|
-
function
|
|
1943
|
-
let n =
|
|
2000
|
+
function Vi(e, t, n) {
|
|
2001
|
+
let r = Ei(n === void 0 ? e : ki(e, n), t, n), i = n === void 0 ? void 0 : Ei(e, t), a = (e.tokens.contexts ?? []).flatMap((e) => e.tokens.filter((e) => e.path === r.path).map((t) => ({
|
|
1944
2002
|
modifier: e.modifier,
|
|
1945
2003
|
context: e.context,
|
|
1946
2004
|
selector: e.selector,
|
|
1947
2005
|
value: t.value
|
|
1948
2006
|
})));
|
|
1949
2007
|
return {
|
|
1950
|
-
path:
|
|
1951
|
-
...
|
|
1952
|
-
value:
|
|
1953
|
-
...
|
|
1954
|
-
...n
|
|
1955
|
-
...
|
|
1956
|
-
...
|
|
1957
|
-
...
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
2008
|
+
path: r.path,
|
|
2009
|
+
...r.type && { type: r.type },
|
|
2010
|
+
value: r.value,
|
|
2011
|
+
...i && i.value !== r.value && { defaultValue: i.value },
|
|
2012
|
+
...n !== void 0 && { theme: n },
|
|
2013
|
+
...r.parts && { parts: r.parts },
|
|
2014
|
+
...r.description && { description: r.description },
|
|
2015
|
+
...r.deprecated && { deprecated: r.deprecated },
|
|
2016
|
+
...r.aliasOf && { aliasOf: r.aliasOf },
|
|
2017
|
+
...r.blazon.tier && { tier: r.blazon.tier },
|
|
2018
|
+
names: Bi(e, r),
|
|
2019
|
+
rules: Li(e, r),
|
|
2020
|
+
...a.length > 0 && { contexts: a },
|
|
2021
|
+
sourceFile: r.file.replace(/ \(inline\)$/, "")
|
|
1962
2022
|
};
|
|
1963
2023
|
}
|
|
1964
2024
|
// src/core/read/list.ts
|
|
1965
|
-
|
|
2025
|
+
var Hi = [
|
|
2026
|
+
"primitive",
|
|
2027
|
+
"semantic",
|
|
2028
|
+
"component"
|
|
2029
|
+
];
|
|
2030
|
+
function Ui(e) {
|
|
1966
2031
|
let t = /* @__PURE__ */ new Set();
|
|
1967
2032
|
for (let { path: n } of e.tokens.items) {
|
|
1968
2033
|
let e = n.split(".");
|
|
@@ -1970,53 +2035,63 @@ function ki(e) {
|
|
|
1970
2035
|
}
|
|
1971
2036
|
return t;
|
|
1972
2037
|
}
|
|
1973
|
-
function
|
|
1974
|
-
let n =
|
|
1975
|
-
return !e.tokens.byPath.has(n) &&
|
|
2038
|
+
function Wi(e, t) {
|
|
2039
|
+
let n = Ti(t);
|
|
2040
|
+
return !e.tokens.byPath.has(n) && Ui(e).has(n);
|
|
1976
2041
|
}
|
|
1977
|
-
function
|
|
2042
|
+
function Gi(e, t = {}) {
|
|
1978
2043
|
let n;
|
|
1979
|
-
if (t.type !== void 0 && (n =
|
|
2044
|
+
if (t.type !== void 0 && (n = te.find((e) => e === t.type), !n)) throw new K(`no token type "${t.type}"; the types are ${te.join(", ")}.`);
|
|
1980
2045
|
let r;
|
|
2046
|
+
if (t.tier !== void 0 && (r = Hi.find((e) => e === t.tier), !r)) throw new K(`no tier "${t.tier}"; the tiers are ${Hi.join(", ")}.`);
|
|
2047
|
+
let i = Oi(e), a = t.theme === void 0 ? e : ki(e, t.theme), o;
|
|
1981
2048
|
if (t.group !== void 0) {
|
|
1982
|
-
|
|
1983
|
-
let n =
|
|
1984
|
-
if (!n.has(
|
|
1985
|
-
let e =
|
|
1986
|
-
throw new K(`no group "${
|
|
2049
|
+
o = Ti(t.group);
|
|
2050
|
+
let n = Ui(e);
|
|
2051
|
+
if (!n.has(o)) {
|
|
2052
|
+
let e = D(o, [...n]);
|
|
2053
|
+
throw new K(`no group "${o}"${e ? `; did you mean "${e}"?` : "."}`);
|
|
1987
2054
|
}
|
|
1988
2055
|
}
|
|
1989
|
-
let
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
2056
|
+
let s = a.tokens.items.filter((e) => (o === void 0 || e.path.startsWith(`${o}.`)) && (n === void 0 || e.type === n) && (r === void 0 || e.blazon.tier === r)).map((n) => {
|
|
2057
|
+
let r = t.theme === void 0 ? void 0 : e.tokens.byPath.get(n.path);
|
|
2058
|
+
return {
|
|
2059
|
+
path: n.path,
|
|
2060
|
+
...n.type && { type: n.type },
|
|
2061
|
+
value: n.value,
|
|
2062
|
+
...n.aliasOf && { aliasOf: n.aliasOf },
|
|
2063
|
+
...n.blazon.tier && { tier: n.blazon.tier },
|
|
2064
|
+
...r && r.value !== n.value && { defaultValue: r.value }
|
|
2065
|
+
};
|
|
2066
|
+
});
|
|
1995
2067
|
return {
|
|
1996
|
-
...
|
|
2068
|
+
...o !== void 0 && { group: o },
|
|
1997
2069
|
...n && { type: n },
|
|
1998
|
-
|
|
2070
|
+
...r && { tier: r },
|
|
2071
|
+
...t.theme !== void 0 && { theme: t.theme },
|
|
2072
|
+
...i.length > 0 && { themes: i },
|
|
2073
|
+
tokens: s
|
|
1999
2074
|
};
|
|
2000
2075
|
}
|
|
2001
|
-
// src/core/
|
|
2002
|
-
var
|
|
2076
|
+
// src/core/operations/limits.ts
|
|
2077
|
+
var Ki = 4e4, qi = ["text", "ui"], Ji = f["AA-large"], Yi = [
|
|
2003
2078
|
"border",
|
|
2004
2079
|
"icon",
|
|
2005
2080
|
"interactive"
|
|
2006
|
-
],
|
|
2081
|
+
], Xi = [
|
|
2007
2082
|
"AAA",
|
|
2008
2083
|
"AA",
|
|
2009
2084
|
"AA-large"
|
|
2010
2085
|
];
|
|
2011
|
-
function
|
|
2086
|
+
function Zi(e, t) {
|
|
2012
2087
|
let n = [];
|
|
2013
2088
|
for (let r = t; r && !n.includes(r); r = r.aliasOf ? e.tokens.byPath.get(r.aliasOf) : void 0) n.push(r);
|
|
2014
2089
|
return n;
|
|
2015
2090
|
}
|
|
2016
|
-
function
|
|
2017
|
-
for (let r of
|
|
2018
|
-
if (
|
|
2019
|
-
let t =
|
|
2091
|
+
function Qi(e, t, n) {
|
|
2092
|
+
for (let r of Zi(e, t)) {
|
|
2093
|
+
if (x(r, n)) continue;
|
|
2094
|
+
let t = Mi(e, r), i = t.deny?.includes(n) ? `denies "${n}"` : `allows only ${(t.allow ?? []).map((e) => `"${e}"`).join(", ")}, not "${n}"`;
|
|
2020
2095
|
return {
|
|
2021
2096
|
rule: "usage",
|
|
2022
2097
|
ok: !1,
|
|
@@ -2024,15 +2099,15 @@ function Li(e, t, n) {
|
|
|
2024
2099
|
from: t.from
|
|
2025
2100
|
};
|
|
2026
2101
|
}
|
|
2027
|
-
let r =
|
|
2102
|
+
let r = Zi(e, t).find((t) => Mi(e, t));
|
|
2028
2103
|
return {
|
|
2029
2104
|
rule: "usage",
|
|
2030
2105
|
ok: !0,
|
|
2031
2106
|
message: r ? `usage rules on {${r.path}} leave "${n}" open` : `{${t.path}} has no usage rule against "${n}"`
|
|
2032
2107
|
};
|
|
2033
2108
|
}
|
|
2034
|
-
function
|
|
2035
|
-
let n =
|
|
2109
|
+
function $i(e, t) {
|
|
2110
|
+
let n = Yi.map((n) => Qi(e, t, n)), r = Yi.filter((e, t) => n[t].ok);
|
|
2036
2111
|
return r.length > 0 ? {
|
|
2037
2112
|
rule: "usage",
|
|
2038
2113
|
ok: !0,
|
|
@@ -2044,37 +2119,22 @@ function Ri(e, t) {
|
|
|
2044
2119
|
from: n[0].from
|
|
2045
2120
|
};
|
|
2046
2121
|
}
|
|
2047
|
-
var
|
|
2048
|
-
|
|
2049
|
-
let n = e.tokens.modifiers?.find((e) => e.name === zi);
|
|
2050
|
-
if (!n) throw new K(`no theme "${t}": this brand has no resolver "${zi}" modifier, so it has no themes.`);
|
|
2051
|
-
if (!n.contexts.includes(t)) throw new K(`no theme "${t}". The themes are ${n.contexts.map((e) => `"${e}"`).join(", ")}.`);
|
|
2052
|
-
let r = (e.tokens.contexts ?? []).filter((e) => e.modifier === "theme" && e.context === t), i = fe(e.tokens.items, r);
|
|
2053
|
-
return {
|
|
2054
|
-
...e,
|
|
2055
|
-
tokens: {
|
|
2056
|
-
...e.tokens,
|
|
2057
|
-
items: i,
|
|
2058
|
-
byPath: new Map(i.map((e) => [e.path, e]))
|
|
2059
|
-
}
|
|
2060
|
-
};
|
|
2061
|
-
}
|
|
2062
|
-
var Vi = (e, t) => {
|
|
2063
|
-
let n = e.type === "color" ? f(String(e.value)) : void 0;
|
|
2122
|
+
var ea = (e, t) => {
|
|
2123
|
+
let n = e.type === "color" ? r(String(e.value)) : void 0;
|
|
2064
2124
|
if (!n) throw new K(`{${e.path}} (${t}) is not a color blazon can read: it is ${e.type ?? "untyped"} with the value ${String(e.value)}.`);
|
|
2065
2125
|
return n;
|
|
2066
2126
|
};
|
|
2067
|
-
function
|
|
2127
|
+
function ta(e, t, n, r = "text", i, a) {
|
|
2068
2128
|
if (i !== void 0) return {
|
|
2069
|
-
...
|
|
2129
|
+
...ta(ki(e, i), t, n, r, void 0, i),
|
|
2070
2130
|
theme: i
|
|
2071
2131
|
};
|
|
2072
|
-
if (!
|
|
2073
|
-
let
|
|
2132
|
+
if (!qi.includes(r)) throw new K(`"${String(r)}" is not a role blazon can judge. Use ${qi.map((e) => `"${e}"`).join(" or ")}.`);
|
|
2133
|
+
let o = Ei(e, t, a), s = Ei(e, n, a), c = g(ea(o, "foreground"), ea(s, "background")), l = Xi.find((e) => c >= f[e]) ?? "fail", u = `${c.toFixed(2)}:1`, d = Math.round(c * 100) / 100;
|
|
2074
2134
|
if (r === "ui") {
|
|
2075
2135
|
let t = [
|
|
2076
|
-
|
|
2077
|
-
|
|
2136
|
+
$i(e, o),
|
|
2137
|
+
Qi(e, s, "background"),
|
|
2078
2138
|
{
|
|
2079
2139
|
rule: "pairs",
|
|
2080
2140
|
ok: !0,
|
|
@@ -2082,77 +2142,98 @@ function Hi(e, t, n, r = "text", i) {
|
|
|
2082
2142
|
},
|
|
2083
2143
|
{
|
|
2084
2144
|
rule: "contrast",
|
|
2085
|
-
ok:
|
|
2086
|
-
message: `non-text contrast needs ${
|
|
2145
|
+
ok: c >= Ji,
|
|
2146
|
+
message: `non-text contrast needs ${Ji}:1, this is ${u}`
|
|
2087
2147
|
}
|
|
2088
2148
|
], n = t.find((e) => !e.ok), i = n ? n.message : t[t.length - 1].message;
|
|
2089
2149
|
return {
|
|
2090
|
-
fg:
|
|
2091
|
-
bg:
|
|
2150
|
+
fg: o.path,
|
|
2151
|
+
bg: s.path,
|
|
2092
2152
|
role: r,
|
|
2093
2153
|
allowed: n === void 0,
|
|
2094
2154
|
reason: i,
|
|
2095
2155
|
checks: t,
|
|
2096
2156
|
contrast: {
|
|
2097
2157
|
ratio: d,
|
|
2098
|
-
level:
|
|
2099
|
-
threshold:
|
|
2158
|
+
level: l,
|
|
2159
|
+
threshold: Ji
|
|
2100
2160
|
}
|
|
2101
2161
|
};
|
|
2102
2162
|
}
|
|
2103
|
-
let
|
|
2104
|
-
if (
|
|
2105
|
-
let t =
|
|
2106
|
-
|
|
2163
|
+
let p = [Qi(e, o, "text"), Qi(e, s, "background")], m = Pi(e), h = it(e.tokens.items, m, o.path, s.path);
|
|
2164
|
+
if (h.length > 0) for (let e of h) {
|
|
2165
|
+
let t = f[e.min];
|
|
2166
|
+
p.push({
|
|
2107
2167
|
rule: "pairs",
|
|
2108
|
-
ok:
|
|
2109
|
-
message: `pairs on ${e.from} list ${e.fg} on ${e.bg}: ${e.min} needs ${t}:1, this is ${
|
|
2168
|
+
ok: c >= t,
|
|
2169
|
+
message: `pairs on ${e.from} list ${e.fg} on ${e.bg}: ${e.min} needs ${t}:1, this is ${u}`,
|
|
2110
2170
|
from: e.from
|
|
2111
2171
|
});
|
|
2112
2172
|
}
|
|
2113
|
-
else
|
|
2173
|
+
else m.length > 0 ? p.push({
|
|
2114
2174
|
rule: "pairs",
|
|
2115
2175
|
ok: !1,
|
|
2116
|
-
message: `no pair lists {${
|
|
2117
|
-
}) :
|
|
2176
|
+
message: `no pair lists {${o.path}} on {${s.path}}; the brand lists ${m.length} pair${m.length === 1 ? "" : "s"} and only those may sit together. Component tokens are not read for pairs: to allow this pair, declare it in \`pairs\` on a token group (docs/manual/02-tokens.md, "Contrast pairs")`
|
|
2177
|
+
}) : p.push({
|
|
2118
2178
|
rule: "pairs",
|
|
2119
2179
|
ok: !0,
|
|
2120
2180
|
message: "the brand lists no pairs, so contrast is the only measure left"
|
|
2121
2181
|
});
|
|
2122
|
-
|
|
2182
|
+
p.push({
|
|
2123
2183
|
rule: "contrast",
|
|
2124
2184
|
ok: !0,
|
|
2125
|
-
message: `contrast is ${
|
|
2185
|
+
message: `contrast is ${u}${l === "fail" ? ", below every WCAG level" : `, which meets ${l}`} (reported, never a rule of its own)`
|
|
2126
2186
|
});
|
|
2127
|
-
let
|
|
2187
|
+
let _ = p.find((e) => !e.ok && e.rule !== "contrast") ?? void 0, v = _ === void 0, y = _ ? _.message : (p.find((e) => e.rule === "pairs" && e.from) ?? p[p.length - 1]).message;
|
|
2128
2188
|
return {
|
|
2129
|
-
fg:
|
|
2130
|
-
bg:
|
|
2189
|
+
fg: o.path,
|
|
2190
|
+
bg: s.path,
|
|
2131
2191
|
role: r,
|
|
2132
2192
|
allowed: v,
|
|
2133
2193
|
reason: y,
|
|
2134
|
-
checks:
|
|
2194
|
+
checks: p,
|
|
2135
2195
|
contrast: {
|
|
2136
2196
|
ratio: d,
|
|
2137
|
-
level:
|
|
2197
|
+
level: l
|
|
2138
2198
|
}
|
|
2139
2199
|
};
|
|
2140
2200
|
}
|
|
2201
|
+
function na(e) {
|
|
2202
|
+
if (!e.allowed) return e;
|
|
2203
|
+
let { checks: t, ...n } = e;
|
|
2204
|
+
return n;
|
|
2205
|
+
}
|
|
2206
|
+
function ra(e, t, n = "text", r) {
|
|
2207
|
+
if (t.length === 0) throw new K("give at least one pair.");
|
|
2208
|
+
if (t.length > 50) throw new K(`give at most 50 pairs in one call; this call has ${t.length}.`);
|
|
2209
|
+
let i = r === void 0 ? e : ki(e, r);
|
|
2210
|
+
return t.map((e, t) => {
|
|
2211
|
+
try {
|
|
2212
|
+
let t = ta(i, e.fg, e.bg, n, void 0, r);
|
|
2213
|
+
return r === void 0 ? t : {
|
|
2214
|
+
...t,
|
|
2215
|
+
theme: r
|
|
2216
|
+
};
|
|
2217
|
+
} catch (e) {
|
|
2218
|
+
throw e instanceof K ? new K(`pairs[${t}]: ${e.message}`) : e;
|
|
2219
|
+
}
|
|
2220
|
+
});
|
|
2221
|
+
}
|
|
2141
2222
|
// src/core/read/fonts.ts
|
|
2142
|
-
function
|
|
2143
|
-
let r = t.fonts ?? [], i =
|
|
2223
|
+
function ia(e, t, n) {
|
|
2224
|
+
let r = t.fonts ?? [], i = de(t.fonts, n), a = /* @__PURE__ */ new Map();
|
|
2144
2225
|
for (let t of e.tokens.items) {
|
|
2145
|
-
let e = t.resolvedValue, n = t.type === "fontFamily" ? (Array.isArray(e) ? e : [e]).filter((e) => typeof e == "string") : void 0, r = t.type === "fontFamily" ?
|
|
2226
|
+
let e = t.resolvedValue, n = t.type === "fontFamily" ? (Array.isArray(e) ? e : [e]).filter((e) => typeof e == "string") : void 0, r = t.type === "fontFamily" ? Le(e) : t.type === "typography" && typeof e == "object" && e ? Le(e.fontFamily) : void 0;
|
|
2146
2227
|
if (!r) continue;
|
|
2147
2228
|
let o = r.toLowerCase(), s = a.get(o);
|
|
2148
2229
|
s ? (s.tokens.push(t.path), !s.stack && n && (s.stack = n)) : a.set(o, {
|
|
2149
2230
|
family: r,
|
|
2150
2231
|
tokens: [t.path],
|
|
2151
2232
|
...n && { stack: n },
|
|
2152
|
-
system:
|
|
2233
|
+
system: Ce.has(o),
|
|
2153
2234
|
loaded: i.families.has(o) ? !0 : i.opaque ? null : !1,
|
|
2154
2235
|
...t.blazon.webFont !== void 0 && { webFont: t.blazon.webFont },
|
|
2155
|
-
...t.blazon.font && { font: t.blazon.font }
|
|
2236
|
+
...t.blazon.font && { font: u(t.blazon.font) }
|
|
2156
2237
|
});
|
|
2157
2238
|
}
|
|
2158
2239
|
let o = (t) => e.theme[t] || e.themeTokens?.[t] ? {
|
|
@@ -2160,8 +2241,8 @@ function Ui(e, t, n) {
|
|
|
2160
2241
|
value: e.theme[t]
|
|
2161
2242
|
} : void 0;
|
|
2162
2243
|
return {
|
|
2163
|
-
stylesheets: r.filter((e) => !
|
|
2164
|
-
files: r.filter(
|
|
2244
|
+
stylesheets: r.filter((e) => !Te(e)),
|
|
2245
|
+
files: r.filter(Te).map((e) => ({
|
|
2165
2246
|
family: e.family,
|
|
2166
2247
|
file: e.file,
|
|
2167
2248
|
...e.weight !== void 0 && { weight: e.weight },
|
|
@@ -2174,45 +2255,45 @@ function Ui(e, t, n) {
|
|
|
2174
2255
|
families: [...a.values()]
|
|
2175
2256
|
};
|
|
2176
2257
|
}
|
|
2177
|
-
function
|
|
2258
|
+
function aa(e, t) {
|
|
2178
2259
|
let n = e.stylesheets.map((e) => `/* Stylesheet, not fetched by blazon: ${e.replace(/\*\//g, "*%2F")} */`);
|
|
2179
2260
|
for (let r of e.files) {
|
|
2180
|
-
let e =
|
|
2261
|
+
let e = Oe(r.file);
|
|
2181
2262
|
if (!e) {
|
|
2182
2263
|
n.push(`/* ${r.file.replace(/\*\//g, "*%2F")}: not a font file blazon embeds, so no rule */`);
|
|
2183
2264
|
continue;
|
|
2184
2265
|
}
|
|
2185
2266
|
let i = t === void 0 ? r.file : `${t.endsWith("/") ? t : `${t}/`}${r.file.split("/").pop()}`;
|
|
2186
|
-
n.push(
|
|
2267
|
+
n.push(Pe(r, `url("${encodeURI(i).replace(/"/g, "%22")}") format("${e}")`, !0));
|
|
2187
2268
|
}
|
|
2188
2269
|
return n.length === 0 ? "/* The config lists no fonts. */\n" : `${n.join("\n\n")}\n`;
|
|
2189
2270
|
}
|
|
2190
2271
|
// src/core/read/logo.ts
|
|
2191
|
-
function
|
|
2192
|
-
let
|
|
2193
|
-
let n =
|
|
2272
|
+
function oa(e, t, n) {
|
|
2273
|
+
let r = oe(t), i = O.resolve(n, t.assetsDir), a = se(t.assets, n), o = (e) => O.relative(n, ae(e, i, a)).split(O.sep).join("/"), s = ["onLight", "onDark"].flatMap((t) => {
|
|
2274
|
+
let n = r[t];
|
|
2194
2275
|
if (!n) return [];
|
|
2195
|
-
let
|
|
2276
|
+
let i = t === "onLight" ? e.logo?.onLightAsset : e.logo?.onDarkAsset, a = t === "onLight" ? e.logo?.onLightInk : e.logo?.onDarkInk;
|
|
2196
2277
|
return [{
|
|
2197
2278
|
variant: t,
|
|
2198
2279
|
file: n,
|
|
2199
2280
|
found: !!(t === "onLight" ? e.logo?.onLight : e.logo?.onDark),
|
|
2200
|
-
...
|
|
2281
|
+
...i && { asset: i },
|
|
2201
2282
|
...a && { ink: a }
|
|
2202
2283
|
}];
|
|
2203
2284
|
});
|
|
2204
2285
|
return {
|
|
2205
|
-
variants:
|
|
2206
|
-
assets: e.assets.logos.map((e) => {
|
|
2207
|
-
let t =
|
|
2286
|
+
variants: s,
|
|
2287
|
+
assets: [...new Set(e.assets.logos.map((e) => e.id))].map((t) => {
|
|
2288
|
+
let c = ze(e.assets.logos, t), l = c.map((e) => ae(e, i, a));
|
|
2208
2289
|
return {
|
|
2209
|
-
id:
|
|
2210
|
-
|
|
2211
|
-
variants:
|
|
2212
|
-
rules:
|
|
2290
|
+
id: t,
|
|
2291
|
+
files: c.map(o),
|
|
2292
|
+
variants: s.filter((e) => r[e.variant] ? l.some((t) => d(O.resolve(n, r[e.variant]), t)) : !1).map((e) => e.variant),
|
|
2293
|
+
rules: c[0].meta ?? {}
|
|
2213
2294
|
};
|
|
2214
2295
|
}),
|
|
2215
|
-
forbidden:
|
|
2296
|
+
forbidden: zi(e, "").flatMap((e) => e.logo ? [{
|
|
2216
2297
|
at: e.at,
|
|
2217
2298
|
deny: e.logo.deny,
|
|
2218
2299
|
...e.logo.reason && { reason: e.logo.reason }
|
|
@@ -2221,13 +2302,16 @@ function Gi(e, t, n) {
|
|
|
2221
2302
|
}
|
|
2222
2303
|
// src/cli/read.ts
|
|
2223
2304
|
async function J(e) {
|
|
2224
|
-
let t = await R(e), n = await
|
|
2225
|
-
|
|
2305
|
+
let t = await R(e), n = await T(t, e), r = b(n.findings);
|
|
2306
|
+
r.length > 0 && console.error(a.yellow(`blazon: this brand has ${r.length} error(s), so a value below may be wrong; run blazon check.`));
|
|
2307
|
+
let { problems: i, mismatch: o } = _e(e);
|
|
2308
|
+
for (let e of i) console.error(a.yellow(`blazon: ${e.message}`));
|
|
2309
|
+
return o && console.error(a.yellow(Qe(o))), {
|
|
2226
2310
|
config: t,
|
|
2227
2311
|
data: n
|
|
2228
2312
|
};
|
|
2229
2313
|
}
|
|
2230
|
-
function
|
|
2314
|
+
function sa(e) {
|
|
2231
2315
|
try {
|
|
2232
2316
|
return e();
|
|
2233
2317
|
} catch (e) {
|
|
@@ -2241,12 +2325,12 @@ function Y(e, t, n) {
|
|
|
2241
2325
|
...n
|
|
2242
2326
|
}, null, 2)}\n`);
|
|
2243
2327
|
}
|
|
2244
|
-
function
|
|
2328
|
+
function ca(e, t = " ") {
|
|
2245
2329
|
let n = e.filter((e) => e[1] !== void 0), r = Math.max(0, ...n.map(([e]) => e.length));
|
|
2246
|
-
for (let [e, i] of n) console.log(`${t}${
|
|
2330
|
+
for (let [e, i] of n) console.log(`${t}${a.dim(e.padEnd(r))} ${i}`);
|
|
2247
2331
|
}
|
|
2248
2332
|
// src/cli/commands/doctor.ts
|
|
2249
|
-
var
|
|
2333
|
+
var la = [
|
|
2250
2334
|
"blazon.brand-deck",
|
|
2251
2335
|
"blazon.favicons",
|
|
2252
2336
|
"blazon.logo-geometry",
|
|
@@ -2254,15 +2338,15 @@ var Ji = [
|
|
|
2254
2338
|
"blazon.press-kit",
|
|
2255
2339
|
"blazon.print-book",
|
|
2256
2340
|
"blazon.social-cards"
|
|
2257
|
-
],
|
|
2341
|
+
], ua = (e) => {
|
|
2258
2342
|
try {
|
|
2259
2343
|
return k.accessSync(e, k.constants.X_OK), k.statSync(e).isFile();
|
|
2260
2344
|
} catch {
|
|
2261
2345
|
return !1;
|
|
2262
2346
|
}
|
|
2263
2347
|
};
|
|
2264
|
-
function
|
|
2265
|
-
if (e.BLAZON_CHROME) return
|
|
2348
|
+
function da(e = process.env) {
|
|
2349
|
+
if (e.BLAZON_CHROME) return ua(e.BLAZON_CHROME);
|
|
2266
2350
|
let t = [];
|
|
2267
2351
|
if (process.platform === "darwin") t.push("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome");
|
|
2268
2352
|
else if (process.platform === "win32") for (let n of [
|
|
@@ -2271,19 +2355,19 @@ function Xi(e = process.env) {
|
|
|
2271
2355
|
e.LOCALAPPDATA
|
|
2272
2356
|
]) n && t.push(O.join(n, "Google", "Chrome", "Application", "chrome.exe"));
|
|
2273
2357
|
else t.push("/opt/google/chrome/chrome", ...(e.PATH ?? "").split(O.delimiter).filter(Boolean).flatMap((e) => ["google-chrome", "google-chrome-stable"].map((t) => O.join(e, t))));
|
|
2274
|
-
return t.some(
|
|
2358
|
+
return t.some(ua);
|
|
2275
2359
|
}
|
|
2276
|
-
var
|
|
2277
|
-
let e = JSON.parse(k.readFileSync(O.join(
|
|
2360
|
+
var fa = () => {
|
|
2361
|
+
let e = JSON.parse(k.readFileSync(O.join(et(), "package.json"), "utf-8"));
|
|
2278
2362
|
return {
|
|
2279
2363
|
nodeVersion: process.version,
|
|
2280
2364
|
engine: e.engines?.node,
|
|
2281
|
-
hostProblem: (e) =>
|
|
2282
|
-
chrome: () =>
|
|
2283
|
-
identity:
|
|
2365
|
+
hostProblem: (e) => p(e, { final: "dir" }),
|
|
2366
|
+
chrome: () => da(),
|
|
2367
|
+
identity: qe()
|
|
2284
2368
|
};
|
|
2285
2369
|
};
|
|
2286
|
-
function
|
|
2370
|
+
function pa(e, t) {
|
|
2287
2371
|
let n = /^>=\s*v?(\d+)(?:\.(\d+))?(?:\.(\d+))?$/.exec(t.trim()), r = /^v?(\d+)\.(\d+)\.(\d+)/.exec(e);
|
|
2288
2372
|
if (!n || !r) return;
|
|
2289
2373
|
let i = [
|
|
@@ -2298,14 +2382,14 @@ function Qi(e, t) {
|
|
|
2298
2382
|
for (let e = 0; e < 3; e++) if (a[e] !== i[e]) return a[e] > i[e];
|
|
2299
2383
|
return !0;
|
|
2300
2384
|
}
|
|
2301
|
-
function
|
|
2385
|
+
function ma(e) {
|
|
2302
2386
|
if (!e.engine) return {
|
|
2303
2387
|
id: "node",
|
|
2304
2388
|
status: "warn",
|
|
2305
2389
|
message: `Node ${e.nodeVersion}; blazon's package.json names no engines range to compare`,
|
|
2306
2390
|
fix: "Reinstall blazon."
|
|
2307
2391
|
};
|
|
2308
|
-
let t =
|
|
2392
|
+
let t = pa(e.nodeVersion, e.engine);
|
|
2309
2393
|
return t === void 0 ? {
|
|
2310
2394
|
id: "node",
|
|
2311
2395
|
status: "warn",
|
|
@@ -2322,7 +2406,7 @@ function $i(e) {
|
|
|
2322
2406
|
fix: `Install Node ${e.engine.replace(/^>=\s*/, "")} or newer, such as with nvm install ${e.engine.replace(/^>=\s*v?(\d+).*$/, "$1")}.`
|
|
2323
2407
|
};
|
|
2324
2408
|
}
|
|
2325
|
-
async function
|
|
2409
|
+
async function ha(e) {
|
|
2326
2410
|
try {
|
|
2327
2411
|
let t = await R(e);
|
|
2328
2412
|
return {
|
|
@@ -2342,14 +2426,14 @@ async function ea(e) {
|
|
|
2342
2426
|
} };
|
|
2343
2427
|
}
|
|
2344
2428
|
}
|
|
2345
|
-
function
|
|
2429
|
+
function ga(e, t, n) {
|
|
2346
2430
|
let r = t.hostProblem(e);
|
|
2347
2431
|
if (!r) return {
|
|
2348
2432
|
id: "plugin-host",
|
|
2349
2433
|
status: "ok",
|
|
2350
2434
|
message: `${e} is a folder blazon will run plugins from`
|
|
2351
2435
|
};
|
|
2352
|
-
let i = /written by group or others/.test(r) ?
|
|
2436
|
+
let i = /written by group or others/.test(r) ? C(e) : "Run blazon from a folder under your own home folder that only you can write.";
|
|
2353
2437
|
return {
|
|
2354
2438
|
id: "plugin-host",
|
|
2355
2439
|
status: n > 0 ? "fail" : "warn",
|
|
@@ -2357,8 +2441,8 @@ function ta(e, t, n) {
|
|
|
2357
2441
|
fix: i
|
|
2358
2442
|
};
|
|
2359
2443
|
}
|
|
2360
|
-
function
|
|
2361
|
-
let n = [...new Set((t?.plugins ?? []).map((e) => e.name).filter((e) =>
|
|
2444
|
+
function _a(e, t) {
|
|
2445
|
+
let n = [...new Set((t?.plugins ?? []).map((e) => e.name).filter((e) => la.includes(e)))];
|
|
2362
2446
|
return n.length === 0 ? {
|
|
2363
2447
|
id: "chrome",
|
|
2364
2448
|
status: "ok",
|
|
@@ -2374,61 +2458,66 @@ function na(e, t) {
|
|
|
2374
2458
|
fix: "Install Google Chrome, or set BLAZON_CHROME to a Chrome or Chromium program; or take the plugin out of blazon.json."
|
|
2375
2459
|
};
|
|
2376
2460
|
}
|
|
2377
|
-
function
|
|
2461
|
+
function va(e, t) {
|
|
2378
2462
|
if (!k.existsSync(O.join(e, "blazon.lock"))) return {
|
|
2379
2463
|
id: "lock",
|
|
2380
2464
|
status: "ok",
|
|
2381
2465
|
message: "no blazon.lock: this book is not pinned to a blazon build"
|
|
2382
2466
|
};
|
|
2383
|
-
let n =
|
|
2467
|
+
let n = tt(e, t.identity)[0];
|
|
2384
2468
|
return n ? {
|
|
2385
2469
|
id: "lock",
|
|
2386
2470
|
status: "fail",
|
|
2387
2471
|
message: n.message,
|
|
2388
|
-
fix: n.fix ??
|
|
2472
|
+
fix: n.fix ?? Ye[n.code].fix
|
|
2389
2473
|
} : {
|
|
2390
2474
|
id: "lock",
|
|
2391
2475
|
status: "ok",
|
|
2392
2476
|
message: "blazon.lock matches the blazon that is running"
|
|
2393
2477
|
};
|
|
2394
2478
|
}
|
|
2395
|
-
async function
|
|
2396
|
-
let n = await
|
|
2479
|
+
async function ya(e, t = fa()) {
|
|
2480
|
+
let n = await ha(e);
|
|
2397
2481
|
return [
|
|
2398
|
-
|
|
2482
|
+
ma(t),
|
|
2399
2483
|
n.check,
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2484
|
+
ga(e, t, n.config?.plugins?.length ?? 0),
|
|
2485
|
+
_a(t, n.config),
|
|
2486
|
+
va(e, t)
|
|
2403
2487
|
];
|
|
2404
2488
|
}
|
|
2405
|
-
var
|
|
2406
|
-
ok:
|
|
2407
|
-
warn:
|
|
2408
|
-
fail:
|
|
2489
|
+
var ba = {
|
|
2490
|
+
ok: a.green,
|
|
2491
|
+
warn: a.yellow,
|
|
2492
|
+
fail: a.red
|
|
2409
2493
|
};
|
|
2410
|
-
async function
|
|
2411
|
-
let n = await
|
|
2494
|
+
async function xa(e = process.cwd(), t = {}) {
|
|
2495
|
+
let n = await ya(e), r = !n.some((e) => e.status === "fail");
|
|
2412
2496
|
if (t.json) return Y("doctor", r, { checks: n }), +!r;
|
|
2413
2497
|
console.log();
|
|
2414
|
-
for (let e of n) console.log(` ${
|
|
2498
|
+
for (let e of n) console.log(` ${ba[e.status](e.status.padEnd(4))} ${e.id.padEnd(11)} ${e.message}`), e.status !== "ok" && e.fix && console.log(a.dim(` fix: ${e.fix}`));
|
|
2415
2499
|
return console.log(), +!r;
|
|
2416
2500
|
}
|
|
2417
|
-
// src/core/operations/
|
|
2418
|
-
var
|
|
2501
|
+
// src/core/operations/list.ts
|
|
2502
|
+
var X = {
|
|
2419
2503
|
readOnlyHint: !0,
|
|
2420
2504
|
destructiveHint: !1,
|
|
2421
2505
|
idempotentHint: !0,
|
|
2422
2506
|
openWorldHint: !1
|
|
2423
|
-
},
|
|
2507
|
+
}, Sa = {
|
|
2424
2508
|
type: "string",
|
|
2425
2509
|
description: "The brand folder. Default: the current folder"
|
|
2426
|
-
},
|
|
2510
|
+
}, Ca = (e) => ({
|
|
2511
|
+
type: "string",
|
|
2512
|
+
maxLength: 200,
|
|
2513
|
+
pattern: "^[A-Za-z0-9_][A-Za-z0-9_-]*$",
|
|
2514
|
+
description: `${e} in this context of the resolver's theme modifier, such as dark. An unknown theme is refused with the list of themes. Default: the default tokens`
|
|
2515
|
+
}), wa = "^[A-Za-z0-9_][A-Za-z0-9_-]*(\\.[A-Za-z0-9_][A-Za-z0-9_-]*)*$", Z = (e, t) => ({
|
|
2427
2516
|
type: "object",
|
|
2428
2517
|
properties: e,
|
|
2429
2518
|
...t.length > 0 && { required: t },
|
|
2430
2519
|
additionalProperties: !1
|
|
2431
|
-
}),
|
|
2520
|
+
}), Ta = {
|
|
2432
2521
|
warnings: {
|
|
2433
2522
|
type: "array",
|
|
2434
2523
|
items: { type: "string" },
|
|
@@ -2436,7 +2525,31 @@ var sa = 4e4, X = {
|
|
|
2436
2525
|
},
|
|
2437
2526
|
brandHasErrors: {
|
|
2438
2527
|
type: "boolean",
|
|
2439
|
-
description: "True when the brand has
|
|
2528
|
+
description: "True when the brand's own data has error findings, so a value read from it may be wrong. Run check_brand to see them. A blazon.lock that names another blazon build does not set it: that is `pinMismatch`"
|
|
2529
|
+
},
|
|
2530
|
+
pinMismatch: {
|
|
2531
|
+
type: "object",
|
|
2532
|
+
properties: {
|
|
2533
|
+
pinned: {
|
|
2534
|
+
type: "string",
|
|
2535
|
+
description: "The blazon build blazon.lock names, as blazon prints it (12 hex digits)"
|
|
2536
|
+
},
|
|
2537
|
+
running: {
|
|
2538
|
+
type: "string",
|
|
2539
|
+
description: "The blazon build running, as blazon prints it, or \"unknown\" when it cannot say"
|
|
2540
|
+
},
|
|
2541
|
+
message: {
|
|
2542
|
+
type: "string",
|
|
2543
|
+
description: "One line: which build the book is pinned to, which is running, and what to do"
|
|
2544
|
+
}
|
|
2545
|
+
},
|
|
2546
|
+
required: [
|
|
2547
|
+
"pinned",
|
|
2548
|
+
"running",
|
|
2549
|
+
"message"
|
|
2550
|
+
],
|
|
2551
|
+
additionalProperties: {},
|
|
2552
|
+
description: "Present only when blazon.lock names a different blazon build than the one running. The build and the book disagree; no token or value is wrong because of it, so there is no need to re-check values. Tell the user. `blazon check`, `build` and `tokens` refuse until it is fixed"
|
|
2440
2553
|
},
|
|
2441
2554
|
truncated: {
|
|
2442
2555
|
description: "True when the answer was cut to fit the size limit. `notice` says how to narrow the question",
|
|
@@ -2449,7 +2562,7 @@ var sa = 4e4, X = {
|
|
|
2449
2562
|
}, Q = (e, t) => ({
|
|
2450
2563
|
type: "object",
|
|
2451
2564
|
properties: {
|
|
2452
|
-
...
|
|
2565
|
+
...Ta,
|
|
2453
2566
|
...e
|
|
2454
2567
|
},
|
|
2455
2568
|
required: [
|
|
@@ -2458,11 +2571,11 @@ var sa = 4e4, X = {
|
|
|
2458
2571
|
...t
|
|
2459
2572
|
],
|
|
2460
2573
|
additionalProperties: {}
|
|
2461
|
-
}),
|
|
2574
|
+
}), Ea = [
|
|
2462
2575
|
{
|
|
2463
2576
|
name: "check_brand",
|
|
2464
2577
|
title: "Check the brand",
|
|
2465
|
-
description: "Runs blazon check on the brand, without plugins, and returns its findings and counts. Plugins in blazon.json do not run, so the counts can be lower than `blazon check` prints, but only for a plugin with a check role; a build-only plugin adds no finding. `pluginsSkipped` and `warnings` list every configured plugin, since a role is known only by starting the plugin. `passed` is false when the brand has errors, and values read from such a brand can be wrong
|
|
2578
|
+
description: "Runs blazon check on the brand, without plugins, and returns its findings and counts. Plugins in blazon.json do not run, so the counts can be lower than `blazon check` prints, but only for a plugin with a check role; a build-only plugin adds no finding. `pluginsSkipped` and `warnings` list every configured plugin, since a role is known only by starting the plugin. `passed` is false when the brand's own data has errors (`brandHasErrors`), and values read from such a brand can be wrong; a `pin-mismatch` finding is listed and counted but does not make `passed` false, and is also in `pinMismatch`. Returns at most `limit` findings (default 50, at most 500); `counts` stay whole. Not for reading a value: use get_token.",
|
|
2466
2579
|
annotations: X,
|
|
2467
2580
|
inputSchema: Z({
|
|
2468
2581
|
severity: {
|
|
@@ -2485,7 +2598,7 @@ var sa = 4e4, X = {
|
|
|
2485
2598
|
outputSchema: Q({
|
|
2486
2599
|
passed: {
|
|
2487
2600
|
type: "boolean",
|
|
2488
|
-
description: "True when the
|
|
2601
|
+
description: "True when no finding other than the pin family is an error. A pin-mismatch alone leaves it true"
|
|
2489
2602
|
},
|
|
2490
2603
|
counts: {
|
|
2491
2604
|
type: "object",
|
|
@@ -2564,7 +2677,7 @@ var sa = 4e4, X = {
|
|
|
2564
2677
|
{
|
|
2565
2678
|
name: "list_tokens",
|
|
2566
2679
|
title: "List the tokens",
|
|
2567
|
-
description: `Lists the design tokens of the brand, or of one group, or
|
|
2680
|
+
description: `Lists the design tokens of the brand, or of one group, type or tier, each with its path, type, tier and value, in the order the token files write them. Use it to find a path or to read many values at once. \`tier\` (primitive, semantic or component) keeps to one layer of the brand. \`theme\` gives the values as that theme resolves them, and \`defaultValue\` on a token the theme changes; \`themes\` names the themes the brand has. For a token's CSS variable names and rules use get_token; for the brand's usage rules use get_rules. An answer over ${Ki} characters is cut to whole tokens, and \`tokensTotal\` says how many matched: narrow with \`group\`, \`type\` or \`tier\`.`,
|
|
2568
2681
|
annotations: X,
|
|
2569
2682
|
inputSchema: Z({
|
|
2570
2683
|
group: {
|
|
@@ -2579,6 +2692,13 @@ var sa = 4e4, X = {
|
|
|
2579
2692
|
maxLength: 40,
|
|
2580
2693
|
pattern: "^[A-Za-z0-9_][A-Za-z0-9_-]*$"
|
|
2581
2694
|
},
|
|
2695
|
+
tier: {
|
|
2696
|
+
description: "A tier: primitive, semantic or component. Leave out for every tier. An unknown tier is refused with the list of tiers",
|
|
2697
|
+
type: "string",
|
|
2698
|
+
maxLength: 40,
|
|
2699
|
+
pattern: "^[A-Za-z0-9_][A-Za-z0-9_-]*$"
|
|
2700
|
+
},
|
|
2701
|
+
theme: Ca("List the values"),
|
|
2582
2702
|
dir: {
|
|
2583
2703
|
type: "string",
|
|
2584
2704
|
description: "The brand folder. Default: the current folder"
|
|
@@ -2593,6 +2713,19 @@ var sa = 4e4, X = {
|
|
|
2593
2713
|
description: "The type asked for. Absent when every type was listed",
|
|
2594
2714
|
type: "string"
|
|
2595
2715
|
},
|
|
2716
|
+
tier: {
|
|
2717
|
+
description: "The tier asked for. Absent when every tier was listed",
|
|
2718
|
+
type: "string"
|
|
2719
|
+
},
|
|
2720
|
+
theme: {
|
|
2721
|
+
description: "The theme the values are resolved in. Absent when the default tokens were listed",
|
|
2722
|
+
type: "string"
|
|
2723
|
+
},
|
|
2724
|
+
themes: {
|
|
2725
|
+
description: "The names of the themes the brand has, to pass as `theme`. Absent when the brand has no resolver theme modifier",
|
|
2726
|
+
type: "array",
|
|
2727
|
+
items: { type: "string" }
|
|
2728
|
+
},
|
|
2596
2729
|
tokens: {
|
|
2597
2730
|
type: "array",
|
|
2598
2731
|
items: {
|
|
@@ -2610,7 +2743,12 @@ var sa = 4e4, X = {
|
|
|
2610
2743
|
aliasOf: {
|
|
2611
2744
|
description: "The token this one is an alias of, when it is one",
|
|
2612
2745
|
type: "string"
|
|
2613
|
-
}
|
|
2746
|
+
},
|
|
2747
|
+
tier: {
|
|
2748
|
+
description: "primitive, semantic or component, when the brand writes one",
|
|
2749
|
+
type: "string"
|
|
2750
|
+
},
|
|
2751
|
+
defaultValue: { description: "With `theme`: the value in the default tokens, present only when the theme changes it" }
|
|
2614
2752
|
},
|
|
2615
2753
|
required: ["path", "value"],
|
|
2616
2754
|
additionalProperties: {}
|
|
@@ -2629,20 +2767,33 @@ var sa = 4e4, X = {
|
|
|
2629
2767
|
cliOnly: ["dir"],
|
|
2630
2768
|
folder: "group",
|
|
2631
2769
|
summary: "List the tokens: path, type and value, and the token each aliases. With a group path, only the tokens in that group",
|
|
2632
|
-
options: [
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2770
|
+
options: [
|
|
2771
|
+
{
|
|
2772
|
+
property: "json",
|
|
2773
|
+
description: "Print the list as JSON on standard output"
|
|
2774
|
+
},
|
|
2775
|
+
{
|
|
2776
|
+
property: "type",
|
|
2777
|
+
value: "type",
|
|
2778
|
+
description: "List only the tokens of one $type (color, dimension, fontFamily, ...)"
|
|
2779
|
+
},
|
|
2780
|
+
{
|
|
2781
|
+
property: "tier",
|
|
2782
|
+
value: "tier",
|
|
2783
|
+
description: "List only the tokens of one tier: primitive, semantic or component"
|
|
2784
|
+
},
|
|
2785
|
+
{
|
|
2786
|
+
property: "theme",
|
|
2787
|
+
value: "name",
|
|
2788
|
+
description: "list the values as this context of the resolver's theme modifier resolves them (such as dark), and the default value of each token it changes; exits 2 for an unknown theme"
|
|
2789
|
+
}
|
|
2790
|
+
]
|
|
2640
2791
|
}
|
|
2641
2792
|
},
|
|
2642
2793
|
{
|
|
2643
2794
|
name: "get_token",
|
|
2644
2795
|
title: "Read a token",
|
|
2645
|
-
description: "Looks up one design token of the brand: its value, type, the CSS variable names it gets, and the rules that apply to it. Use it for the value of a path you know; a group path is refused. For a path you do not know use list_tokens.",
|
|
2796
|
+
description: "Looks up one design token of the brand: its value, type, the CSS variable names it gets, and the rules that apply to it. Use it for the value of a path you know; a group path is refused. With `theme` the value is the one that theme resolves, and `defaultValue` is the default one when it differs. For a path you do not know use list_tokens.",
|
|
2646
2797
|
annotations: X,
|
|
2647
2798
|
inputSchema: Z({
|
|
2648
2799
|
path: {
|
|
@@ -2651,6 +2802,7 @@ var sa = 4e4, X = {
|
|
|
2651
2802
|
pattern: "^[A-Za-z0-9_][A-Za-z0-9_-]*(\\.[A-Za-z0-9_][A-Za-z0-9_-]*)*$",
|
|
2652
2803
|
description: "The token path, for example color.brand.primary. A path from list_tokens works"
|
|
2653
2804
|
},
|
|
2805
|
+
theme: Ca("Read the value"),
|
|
2654
2806
|
dir: {
|
|
2655
2807
|
type: "string",
|
|
2656
2808
|
description: "The brand folder. Default: the current folder"
|
|
@@ -2668,7 +2820,16 @@ var sa = 4e4, X = {
|
|
|
2668
2820
|
description: "The token type, such as color",
|
|
2669
2821
|
type: "string"
|
|
2670
2822
|
},
|
|
2671
|
-
value: { description: "The value as CSS needs it, with aliases resolved" }
|
|
2823
|
+
value: { description: "The value as CSS needs it, with aliases resolved; with `theme`, as that theme resolves it" },
|
|
2824
|
+
defaultValue: { description: "With `theme`: the value in the default tokens, present only when the theme changes it" },
|
|
2825
|
+
theme: {
|
|
2826
|
+
description: "The theme the value is resolved in. Absent for the default tokens",
|
|
2827
|
+
type: "string"
|
|
2828
|
+
},
|
|
2829
|
+
tier: {
|
|
2830
|
+
description: "primitive, semantic or component, when the brand writes one",
|
|
2831
|
+
type: "string"
|
|
2832
|
+
}
|
|
2672
2833
|
},
|
|
2673
2834
|
required: ["path", "value"],
|
|
2674
2835
|
additionalProperties: {}
|
|
@@ -2680,6 +2841,10 @@ var sa = 4e4, X = {
|
|
|
2680
2841
|
cliOnly: ["dir"],
|
|
2681
2842
|
summary: "Read one token: its value, type, CSS variable name in theme.css, its usage, pairs and logo rules, and the file it is in. To find a path, use blazon list",
|
|
2682
2843
|
options: [{
|
|
2844
|
+
property: "theme",
|
|
2845
|
+
value: "name",
|
|
2846
|
+
description: "read the value as this context of the resolver's theme modifier resolves it (such as dark), and the default value when it differs; exits 2 for an unknown theme"
|
|
2847
|
+
}, {
|
|
2683
2848
|
property: "json",
|
|
2684
2849
|
description: "Print the token as JSON on standard output"
|
|
2685
2850
|
}]
|
|
@@ -2688,7 +2853,7 @@ var sa = 4e4, X = {
|
|
|
2688
2853
|
{
|
|
2689
2854
|
name: "get_rules",
|
|
2690
2855
|
title: "Read the brand rules",
|
|
2691
|
-
description: `Lists the brand rules (allowed uses, approved color pairs, logo restrictions) of a token or a group of tokens, or of the whole brand when no path is given. The whole brand can be larger than the size limit (${
|
|
2856
|
+
description: `Lists the brand rules (allowed uses, approved color pairs, logo restrictions) of a token or a group of tokens, or of the whole brand when no path is given. The whole brand can be larger than the size limit (${Ki} characters): give a path, or read the resource blazon://rules, which is not cut.`,
|
|
2692
2857
|
annotations: X,
|
|
2693
2858
|
inputSchema: Z({
|
|
2694
2859
|
path: {
|
|
@@ -2738,20 +2903,50 @@ var sa = 4e4, X = {
|
|
|
2738
2903
|
{
|
|
2739
2904
|
name: "can_use",
|
|
2740
2905
|
title: "Can this color be used here",
|
|
2741
|
-
description: "Answers whether one color token may be text on another color token, by the brand rules. Set `role` to ui for a focus ring, border or icon stroke: it is judged against the 3:1 non-text contrast and the pairs rules do not apply. A denied answer is a normal result (`allowed` is false, `reason` names the rule), not an error. For a color you have not picked, find one with list_tokens and type color.",
|
|
2906
|
+
description: "Answers whether one color token may be text on another color token, by the brand rules. Give `fg` and `bg` for one pair, or `pairs` (at most 50) for several in one call: the answer then has one result per pair, in order, and `allowed` is true only when every pair is. Exactly one of the two forms. Set `role` to ui for a focus ring, border or icon stroke: it is judged against the 3:1 non-text contrast and the pairs rules do not apply. `verbose` false leaves out the `checks` of an allowed answer; a denial keeps them. A denied answer is a normal result (`allowed` is false, `reason` names the rule), not an error. Pairs come only from the `pairs` rules of token groups; component tokens are not read for them. For a color you have not picked, find one with list_tokens and type color.",
|
|
2742
2907
|
annotations: X,
|
|
2743
2908
|
inputSchema: Z({
|
|
2744
2909
|
fg: {
|
|
2745
2910
|
type: "string",
|
|
2746
2911
|
maxLength: 200,
|
|
2747
2912
|
pattern: "^[A-Za-z0-9_][A-Za-z0-9_-]*(\\.[A-Za-z0-9_][A-Za-z0-9_-]*)*$",
|
|
2748
|
-
description: "The text color token path, for example text.primary"
|
|
2913
|
+
description: "The text color token path, for example text.primary. Give it with bg, or give pairs instead"
|
|
2749
2914
|
},
|
|
2750
2915
|
bg: {
|
|
2751
2916
|
type: "string",
|
|
2752
2917
|
maxLength: 200,
|
|
2753
2918
|
pattern: "^[A-Za-z0-9_][A-Za-z0-9_-]*(\\.[A-Za-z0-9_][A-Za-z0-9_-]*)*$",
|
|
2754
|
-
description: "The background color token path, for example surface.background"
|
|
2919
|
+
description: "The background color token path, for example surface.background. Give it with fg, or give pairs instead"
|
|
2920
|
+
},
|
|
2921
|
+
pairs: {
|
|
2922
|
+
type: "array",
|
|
2923
|
+
minItems: 1,
|
|
2924
|
+
maxItems: 50,
|
|
2925
|
+
description: "Several pairs to judge in one call, each a text color token fg and a background color token bg, in place of fg and bg. At most 50",
|
|
2926
|
+
items: {
|
|
2927
|
+
type: "object",
|
|
2928
|
+
properties: {
|
|
2929
|
+
fg: {
|
|
2930
|
+
type: "string",
|
|
2931
|
+
maxLength: 200,
|
|
2932
|
+
pattern: wa,
|
|
2933
|
+
description: "The text color token path"
|
|
2934
|
+
},
|
|
2935
|
+
bg: {
|
|
2936
|
+
type: "string",
|
|
2937
|
+
maxLength: 200,
|
|
2938
|
+
pattern: wa,
|
|
2939
|
+
description: "The background color token path"
|
|
2940
|
+
}
|
|
2941
|
+
},
|
|
2942
|
+
required: ["fg", "bg"],
|
|
2943
|
+
additionalProperties: !1
|
|
2944
|
+
}
|
|
2945
|
+
},
|
|
2946
|
+
verbose: {
|
|
2947
|
+
type: "boolean",
|
|
2948
|
+
default: !0,
|
|
2949
|
+
description: "False leaves out the `checks` of an answer that is allowed, which shortens the answer; a denial keeps its checks, since they are the reason. Default: true"
|
|
2755
2950
|
},
|
|
2756
2951
|
role: {
|
|
2757
2952
|
type: "string",
|
|
@@ -2769,11 +2964,16 @@ var sa = 4e4, X = {
|
|
|
2769
2964
|
type: "string",
|
|
2770
2965
|
description: "The brand folder. Default: the current folder"
|
|
2771
2966
|
}
|
|
2772
|
-
}, [
|
|
2967
|
+
}, []),
|
|
2773
2968
|
outputSchema: Q({
|
|
2774
2969
|
allowed: {
|
|
2775
2970
|
type: "boolean",
|
|
2776
|
-
description: "True when the brand allows this text color on this background"
|
|
2971
|
+
description: "True when the brand allows this text color on this background; with `pairs`, true when it allows every pair"
|
|
2972
|
+
},
|
|
2973
|
+
results: {
|
|
2974
|
+
description: "With `pairs`: one answer for each pair, in order, each with the fields of a single answer: fg, bg, allowed, reason, role, contrast and, unless `verbose` is false and the pair is allowed, checks",
|
|
2975
|
+
type: "array",
|
|
2976
|
+
items: { type: "object" }
|
|
2777
2977
|
},
|
|
2778
2978
|
reason: {
|
|
2779
2979
|
type: "string",
|
|
@@ -2800,7 +3000,7 @@ var sa = 4e4, X = {
|
|
|
2800
3000
|
description: "The contrast ratio of the pair, the strictest WCAG level it meets, and for role ui the threshold it had to reach",
|
|
2801
3001
|
type: "object"
|
|
2802
3002
|
}
|
|
2803
|
-
}, ["allowed"
|
|
3003
|
+
}, ["allowed"]),
|
|
2804
3004
|
cli: {
|
|
2805
3005
|
rank: 4,
|
|
2806
3006
|
command: ["can"],
|
|
@@ -2810,8 +3010,21 @@ var sa = 4e4, X = {
|
|
|
2810
3010
|
"dir"
|
|
2811
3011
|
],
|
|
2812
3012
|
cliOnly: ["dir"],
|
|
2813
|
-
|
|
3013
|
+
folder: "fg",
|
|
3014
|
+
summary: "Ask whether the foreground token may be text (or, with --role ui, a border or focus ring) on the background token, by the brand rules; exits 0 allowed, 1 denied, 2 unknown token. Several pairs: --pair fg:bg, repeated",
|
|
2814
3015
|
options: [
|
|
3016
|
+
{
|
|
3017
|
+
property: "pairs",
|
|
3018
|
+
flag: "pair",
|
|
3019
|
+
value: "fg:bg",
|
|
3020
|
+
items: ["fg", "bg"],
|
|
3021
|
+
description: "judge this pair, in place of the fg and bg arguments; repeat the flag for up to 50 pairs, one result each, in order; exits 0 when every pair is allowed, else 1"
|
|
3022
|
+
},
|
|
3023
|
+
{
|
|
3024
|
+
property: "verbose",
|
|
3025
|
+
flag: "no-verbose",
|
|
3026
|
+
description: "leave out the checks of an allowed answer, which are all it adds to the reason; a denial keeps them"
|
|
3027
|
+
},
|
|
2815
3028
|
{
|
|
2816
3029
|
property: "role",
|
|
2817
3030
|
value: "text|ui",
|
|
@@ -2819,7 +3032,7 @@ var sa = 4e4, X = {
|
|
|
2819
3032
|
},
|
|
2820
3033
|
{
|
|
2821
3034
|
property: "theme",
|
|
2822
|
-
value: "
|
|
3035
|
+
value: "name",
|
|
2823
3036
|
description: "judge the pair in this context of the resolver's theme modifier (such as dark); exits 2 for an unknown theme"
|
|
2824
3037
|
},
|
|
2825
3038
|
{
|
|
@@ -2936,7 +3149,7 @@ var sa = 4e4, X = {
|
|
|
2936
3149
|
type: "string",
|
|
2937
3150
|
description: "Only this part of the document, by its dotted path, such as theme.roles"
|
|
2938
3151
|
},
|
|
2939
|
-
dir:
|
|
3152
|
+
dir: Sa
|
|
2940
3153
|
}, []),
|
|
2941
3154
|
cli: {
|
|
2942
3155
|
rank: 7,
|
|
@@ -2952,10 +3165,47 @@ var sa = 4e4, X = {
|
|
|
2952
3165
|
},
|
|
2953
3166
|
mcp: !1
|
|
2954
3167
|
}
|
|
2955
|
-
],
|
|
3168
|
+
], Da = (e) => e.filter((e) => e.mcp !== !1), Oa = (e) => e.filter((e) => e.cli !== !1).sort((e, t) => e.cli.rank - t.cli.rank), ka = (e) => {
|
|
3169
|
+
try {
|
|
3170
|
+
return k.statSync(e, { throwIfNoEntry: !1 })?.isDirectory() ?? !1;
|
|
3171
|
+
} catch {
|
|
3172
|
+
return !1;
|
|
3173
|
+
}
|
|
3174
|
+
};
|
|
3175
|
+
function Aa(e) {
|
|
3176
|
+
if (!ka(e)) return !1;
|
|
3177
|
+
let t = O.join(e, "blazon.json");
|
|
3178
|
+
return k.statSync(t, { throwIfNoEntry: !1 })?.isFile() ? !0 : ka(O.join(e, "tokens"));
|
|
3179
|
+
}
|
|
3180
|
+
var ja = /* @__PURE__ */ new Set([
|
|
3181
|
+
"no-folder",
|
|
3182
|
+
"no-tokens-folder",
|
|
3183
|
+
"unknown-token"
|
|
3184
|
+
]), Ma = (e) => e.map((e) => /^<.*>$/.test(e) ? e : bt(e)).join(" ");
|
|
3185
|
+
function Na(e, t, n, r, i) {
|
|
3186
|
+
if (!(i instanceof j) || !ja.has(i.code)) return;
|
|
3187
|
+
let a = n.map((e) => typeof e == "string" ? e : void 0), o = t.findIndex((e, t) => {
|
|
3188
|
+
let n = a[t];
|
|
3189
|
+
return e === "dir" || n === void 0 || !Aa(n) ? !1 : i.code !== "unknown-token" || i.message.includes(`"${n}"`);
|
|
3190
|
+
});
|
|
3191
|
+
if (o === -1) return;
|
|
3192
|
+
let s = a[o], c = t[o], l = a.filter((e, t) => e !== void 0 && t !== o), u = l.length === 0 ? [`<${c}>`] : [], d = Ma([
|
|
3193
|
+
"blazon",
|
|
3194
|
+
...e,
|
|
3195
|
+
...l.length > 0 ? l : u,
|
|
3196
|
+
s
|
|
3197
|
+
]), f = Ma([
|
|
3198
|
+
"blazon",
|
|
3199
|
+
...e,
|
|
3200
|
+
...l.length > 0 || r.has(c) ? [...l, ...u] : [],
|
|
3201
|
+
"--cwd",
|
|
3202
|
+
s
|
|
3203
|
+
]);
|
|
3204
|
+
return `"${s}" was read as ${c === "path" ? "the path" : `the ${c} (a token path)`}, not a folder; the folder goes last: ${d}, or ${f}`;
|
|
3205
|
+
}
|
|
2956
3206
|
// src/cli/handlers/rules.ts
|
|
2957
|
-
function
|
|
2958
|
-
let t = (e) =>
|
|
3207
|
+
function Pa(e) {
|
|
3208
|
+
let t = (e) => a.dim(`(on ${e})`);
|
|
2959
3209
|
return [
|
|
2960
3210
|
...e.role ? [`role ${e.role.value} ${t(e.role.from)}`] : [],
|
|
2961
3211
|
...e.usage ? [`usage ${[e.usage.deny && `deny ${e.usage.deny.join(", ")}`, e.usage.allow && `allow ${e.usage.allow.join(", ")}`].filter(Boolean).join("; ")} ${t(e.usage.from)}`] : [],
|
|
@@ -2964,7 +3214,7 @@ function pa(e) {
|
|
|
2964
3214
|
...e.review ? [`review ${e.review.status}${e.review.by ? ` by ${e.review.by}` : ""}${e.review.at ? ` on ${e.review.at}` : ""} ${t(e.review.from)}`] : []
|
|
2965
3215
|
];
|
|
2966
3216
|
}
|
|
2967
|
-
function
|
|
3217
|
+
function Fa(e) {
|
|
2968
3218
|
return [
|
|
2969
3219
|
...e.role ? [`role ${e.role}`] : [],
|
|
2970
3220
|
...e.usage ? [`usage ${[e.usage.deny && `deny ${e.usage.deny.join(", ")}`, e.usage.allow && `allow ${e.usage.allow.join(", ")}`].filter(Boolean).join("; ")}`] : [],
|
|
@@ -2972,52 +3222,54 @@ function ma(e) {
|
|
|
2972
3222
|
...e.logo ? [`logo deny ${e.logo.deny.join(", ")}${e.logo.reason ? `: ${e.logo.reason}` : ""}`] : []
|
|
2973
3223
|
];
|
|
2974
3224
|
}
|
|
2975
|
-
var
|
|
2976
|
-
let { data: n } = await J(t), r =
|
|
3225
|
+
var Ia = async ({ path: e }, { dir: t }) => {
|
|
3226
|
+
let { data: n } = await J(t), r = Ti(e ?? ""), i = r !== "" && n.tokens.byPath.has(r), o = sa(() => i ? {
|
|
2977
3227
|
path: r,
|
|
2978
3228
|
kind: "token",
|
|
2979
|
-
rules:
|
|
3229
|
+
rules: Li(n, Ei(n, r))
|
|
2980
3230
|
} : {
|
|
2981
3231
|
path: r,
|
|
2982
3232
|
kind: r === "" ? "brand" : "group",
|
|
2983
|
-
entries:
|
|
3233
|
+
entries: zi(n, r)
|
|
2984
3234
|
});
|
|
2985
3235
|
return {
|
|
2986
3236
|
command: "rules",
|
|
2987
3237
|
passed: !0,
|
|
2988
3238
|
status: 0,
|
|
2989
|
-
body:
|
|
3239
|
+
body: o,
|
|
2990
3240
|
text: () => {
|
|
2991
|
-
if (console.log(),
|
|
2992
|
-
let e =
|
|
2993
|
-
console.log(` ${
|
|
3241
|
+
if (console.log(), o.kind === "token") {
|
|
3242
|
+
let e = Pa(o.rules);
|
|
3243
|
+
console.log(` ${a.bold(o.path)}`), e.length === 0 && console.log(a.dim(" no rules apply to this token"));
|
|
2994
3244
|
for (let t of e) console.log(` ${t}`);
|
|
2995
3245
|
} else {
|
|
2996
|
-
|
|
2997
|
-
for (let e of
|
|
2998
|
-
console.log(` ${
|
|
2999
|
-
for (let t of
|
|
3246
|
+
o.entries.length === 0 && console.log(a.dim(` No rules are written ${r === "" ? "in this brand" : `at or under ${r}`}.`));
|
|
3247
|
+
for (let e of o.entries) {
|
|
3248
|
+
console.log(` ${a.bold(e.at)} ${a.dim(e.kind === "group" ? "group" : "token")}${e.inherited ? a.dim(", passes its rules down") : ""}`);
|
|
3249
|
+
for (let t of Fa(e)) console.log(` ${t}`);
|
|
3000
3250
|
}
|
|
3001
3251
|
}
|
|
3002
3252
|
console.log();
|
|
3003
3253
|
}
|
|
3004
3254
|
};
|
|
3005
|
-
},
|
|
3006
|
-
let { data:
|
|
3007
|
-
if (
|
|
3008
|
-
let
|
|
3255
|
+
}, La = async ({ path: e, theme: t }, { dir: n }) => {
|
|
3256
|
+
let { data: r } = await J(n);
|
|
3257
|
+
if (Wi(r, String(e))) throw new M(`"${String(e)}" is a group of tokens, not one token; \`blazon list ${String(e)}\` lists its tokens.`, void 0, "not-a-token");
|
|
3258
|
+
let i = sa(() => Vi(r, String(e), t));
|
|
3009
3259
|
return {
|
|
3010
3260
|
command: "get",
|
|
3011
3261
|
passed: !0,
|
|
3012
3262
|
status: 0,
|
|
3013
|
-
body: { token:
|
|
3014
|
-
text: () =>
|
|
3263
|
+
body: { token: i },
|
|
3264
|
+
text: () => Ra(i)
|
|
3015
3265
|
};
|
|
3016
3266
|
};
|
|
3017
|
-
function
|
|
3267
|
+
function Ra(e) {
|
|
3018
3268
|
let { names: t } = e;
|
|
3019
|
-
console.log(`\n ${
|
|
3269
|
+
console.log(`\n ${a.bold(e.path)}${e.deprecated ? a.yellow(" deprecated") : ""}`), ca([
|
|
3020
3270
|
["value", String(e.value)],
|
|
3271
|
+
["default", e.defaultValue === void 0 ? void 0 : String(e.defaultValue)],
|
|
3272
|
+
["theme", e.theme],
|
|
3021
3273
|
["type", e.type],
|
|
3022
3274
|
["alias of", e.aliasOf && `{${e.aliasOf}}`],
|
|
3023
3275
|
["tier", e.tier],
|
|
@@ -3026,65 +3278,99 @@ function _a(e) {
|
|
|
3026
3278
|
["typography.css", t.typographyClass && `.${t.typographyClass}`],
|
|
3027
3279
|
["written in", e.sourceFile]
|
|
3028
3280
|
]);
|
|
3029
|
-
for (let t of e.contexts ?? []) console.log(` ${
|
|
3030
|
-
let n =
|
|
3031
|
-
console.log(`\n ${
|
|
3281
|
+
for (let t of e.contexts ?? []) console.log(` ${a.dim(`${t.modifier}=${t.context}`.padEnd(12))} ${String(t.value)} ${a.dim(t.selector)}`);
|
|
3282
|
+
let n = Pa(e.rules);
|
|
3283
|
+
console.log(`\n ${a.bold("Rules")}`), n.length === 0 && console.log(a.dim(" none written for this token"));
|
|
3032
3284
|
for (let e of n) console.log(` ${e}`);
|
|
3033
3285
|
console.log();
|
|
3034
3286
|
}
|
|
3035
3287
|
// src/cli/handlers/list.ts
|
|
3036
|
-
var
|
|
3037
|
-
let { data:
|
|
3288
|
+
var za = async ({ group: e, type: t, tier: n, theme: r }, { dir: i }) => {
|
|
3289
|
+
let { data: a } = await J(i), o = sa(() => Gi(a, {
|
|
3038
3290
|
group: e,
|
|
3039
|
-
type: t
|
|
3291
|
+
type: t,
|
|
3292
|
+
tier: n,
|
|
3293
|
+
theme: r
|
|
3040
3294
|
}));
|
|
3041
3295
|
return {
|
|
3042
3296
|
command: "list",
|
|
3043
3297
|
passed: !0,
|
|
3044
3298
|
status: 0,
|
|
3045
3299
|
body: {
|
|
3046
|
-
...
|
|
3047
|
-
...
|
|
3048
|
-
|
|
3300
|
+
...o.group !== void 0 && { group: o.group },
|
|
3301
|
+
...o.type && { type: o.type },
|
|
3302
|
+
...o.tier && { tier: o.tier },
|
|
3303
|
+
...o.theme !== void 0 && { theme: o.theme },
|
|
3304
|
+
...o.themes && { themes: o.themes },
|
|
3305
|
+
tokens: o.tokens
|
|
3049
3306
|
},
|
|
3050
|
-
text: () =>
|
|
3307
|
+
text: () => Ba(o)
|
|
3051
3308
|
};
|
|
3052
3309
|
};
|
|
3053
|
-
function
|
|
3054
|
-
if (e.tokens.length === 0) return console.log(
|
|
3310
|
+
function Ba(e) {
|
|
3311
|
+
if (e.tokens.length === 0) return console.log(a.dim(`\n no tokens${e.type ? ` of type ${e.type}` : ""}${e.tier ? ` of tier ${e.tier}` : ""}${e.group ? ` in ${e.group}` : ""}\n`));
|
|
3055
3312
|
let t = Math.max(...e.tokens.map((e) => e.path.length)), n = Math.max(...e.tokens.map((e) => (e.type ?? "").length)), r;
|
|
3056
3313
|
for (let i of e.tokens) {
|
|
3057
3314
|
let e = i.path.split(".")[0];
|
|
3058
|
-
e !== r && console.log(`\n ${
|
|
3059
|
-
let
|
|
3060
|
-
console.log(` ${i.path.padEnd(t)} ${
|
|
3315
|
+
e !== r && console.log(`\n ${a.dim(e)}`), r = e;
|
|
3316
|
+
let o = i.aliasOf ? ` ${a.dim(`-> ${i.aliasOf}`)}` : "", s = i.defaultValue === void 0 ? "" : ` ${a.dim(`(default ${String(i.defaultValue)})`)}`;
|
|
3317
|
+
console.log(` ${i.path.padEnd(t)} ${a.dim((i.type ?? "").padEnd(n))} ${String(i.value)}${s}${o}`);
|
|
3061
3318
|
}
|
|
3062
|
-
|
|
3319
|
+
let i = e.themes ? `; themes: ${e.themes.join(", ")}${e.theme ? ` (showing ${e.theme})` : ""}` : "";
|
|
3320
|
+
console.log(`\n ${a.dim(`${e.tokens.length} token${e.tokens.length === 1 ? "" : "s"}; blazon get <path> shows one in full${i}`)}\n`);
|
|
3063
3321
|
}
|
|
3064
3322
|
// src/cli/handlers/can.ts
|
|
3065
|
-
|
|
3066
|
-
|
|
3323
|
+
function Va(e) {
|
|
3324
|
+
return (e === void 0 ? [] : Array.isArray(e) ? e : [e]).map((e) => {
|
|
3325
|
+
let t = String(e).split(":");
|
|
3326
|
+
if (t.length !== 2 || !t[0] || !t[1]) throw new M(`--pair takes fg:bg, such as text.primary:surface.canvas; got "${String(e)}".`, void 0, "invalid-option-value");
|
|
3327
|
+
return {
|
|
3328
|
+
fg: t[0],
|
|
3329
|
+
bg: t[1]
|
|
3330
|
+
};
|
|
3331
|
+
});
|
|
3332
|
+
}
|
|
3333
|
+
var Ha = async ({ fg: e, bg: t, role: n, theme: r, pairs: i, verbose: a }, { dir: o }) => {
|
|
3334
|
+
let s = Va(i), c = e !== void 0 || t !== void 0;
|
|
3335
|
+
if (s.length > 0 && c) throw new M("give fg and bg, or --pair, not both.", void 0, "conflicting-options");
|
|
3336
|
+
if (s.length === 0 && (e === void 0 || t === void 0)) throw new M("give fg and bg, or one or more --pair fg:bg.", void 0, "missing-argument");
|
|
3337
|
+
if (s.length > 50) throw new M(`give at most 50 pairs in one call; this call has ${s.length}.`, void 0, "invalid-option-value");
|
|
3338
|
+
let l = a === !1, u = (e) => l ? na(e) : e, { data: d } = await J(o), f = n ?? "text";
|
|
3339
|
+
if (s.length > 0) {
|
|
3340
|
+
let e = sa(() => ra(d, s, f, r)).map(u), t = e.every((e) => e.allowed);
|
|
3341
|
+
return {
|
|
3342
|
+
command: "can",
|
|
3343
|
+
passed: t,
|
|
3344
|
+
status: +!t,
|
|
3345
|
+
body: {
|
|
3346
|
+
allowed: t,
|
|
3347
|
+
results: e
|
|
3348
|
+
},
|
|
3349
|
+
text: () => e.forEach((e) => Ua(e))
|
|
3350
|
+
};
|
|
3351
|
+
}
|
|
3352
|
+
let p = u(sa(() => ta(d, e, t, f, r)));
|
|
3067
3353
|
return {
|
|
3068
3354
|
command: "can",
|
|
3069
|
-
passed:
|
|
3070
|
-
status: +!
|
|
3071
|
-
body:
|
|
3072
|
-
text: () =>
|
|
3355
|
+
passed: p.allowed,
|
|
3356
|
+
status: +!p.allowed,
|
|
3357
|
+
body: p,
|
|
3358
|
+
text: () => Ua(p)
|
|
3073
3359
|
};
|
|
3074
3360
|
};
|
|
3075
|
-
function
|
|
3076
|
-
if (console.log(`\n ${e.allowed ?
|
|
3361
|
+
function Ua(e) {
|
|
3362
|
+
if (console.log(`\n ${e.allowed ? a.green("allowed") : a.red("denied")} ${e.fg} as ${e.role === "ui" ? "a non-text element (--role ui)" : "text"} on ${e.bg}${e.theme ? ` (theme ${e.theme})` : ""}`), console.log(` ${e.reason}`), e.checks && e.checks.length > 1) {
|
|
3077
3363
|
console.log();
|
|
3078
|
-
for (let t of e.checks) console.log(` ${t.rule === "contrast" && e.role === "text" ?
|
|
3364
|
+
for (let t of e.checks) console.log(` ${t.rule === "contrast" && e.role === "text" ? a.dim("info") : t.ok ? a.green("ok ") : a.red("no ")} ${t.message}`);
|
|
3079
3365
|
}
|
|
3080
3366
|
console.log();
|
|
3081
3367
|
}
|
|
3082
3368
|
// src/cli/handlers/fonts.ts
|
|
3083
|
-
var
|
|
3084
|
-
let { config: n, data: r } = await J(t), i =
|
|
3369
|
+
var Wa = async (e, { dir: t }) => {
|
|
3370
|
+
let { config: n, data: r } = await J(t), i = ia(r, n, t);
|
|
3085
3371
|
if (e.css === !0 || typeof e.base == "string") {
|
|
3086
3372
|
if (e.css !== !0) throw new M("blazon fonts: --base goes with --css.", "Add --css, or leave --base out.", "conflicting-options");
|
|
3087
|
-
let t =
|
|
3373
|
+
let t = aa(i, typeof e.base == "string" ? e.base : void 0);
|
|
3088
3374
|
return {
|
|
3089
3375
|
command: "fonts",
|
|
3090
3376
|
passed: !0,
|
|
@@ -3101,18 +3387,18 @@ var Sa = async (e, { dir: t }) => {
|
|
|
3101
3387
|
passed: !0,
|
|
3102
3388
|
status: 0,
|
|
3103
3389
|
body: i,
|
|
3104
|
-
text: () =>
|
|
3390
|
+
text: () => Ga(i)
|
|
3105
3391
|
};
|
|
3106
3392
|
};
|
|
3107
|
-
function
|
|
3108
|
-
console.log(`\n ${
|
|
3393
|
+
function Ga(e) {
|
|
3394
|
+
console.log(`\n ${a.bold("Loaded")}`), e.stylesheets.length + e.files.length === 0 && console.log(a.dim(" The config lists no fonts."));
|
|
3109
3395
|
for (let t of e.stylesheets) console.log(` stylesheet ${t}`);
|
|
3110
3396
|
for (let t of e.files) console.log(` file ${t.file} ${t.family}${t.weight === void 0 ? "" : `, weight ${t.weight}`}${t.style ? `, ${t.style}` : ""}`);
|
|
3111
|
-
console.log(`\n ${
|
|
3112
|
-
for (let [t, n] of Object.entries(e.roles)) console.log(` ${
|
|
3397
|
+
console.log(`\n ${a.bold("Named by the tokens")}`);
|
|
3398
|
+
for (let [t, n] of Object.entries(e.roles)) console.log(` ${a.dim(t.padEnd(11))} ${n.token ?? ""} ${n.value ?? ""}`);
|
|
3113
3399
|
for (let t of e.families) {
|
|
3114
3400
|
let e = t.system ? "system font" : t.loaded === !0 ? "loaded" : t.loaded === null ? "maybe loaded by a stylesheet blazon cannot read" : t.webFont === void 0 ? "not loaded" : "not loaded, as the token says";
|
|
3115
|
-
console.log(` ${t.family} ${
|
|
3401
|
+
console.log(` ${t.family} ${a.dim(`${e}; ${t.tokens.join(", ")}`)}`), t.stack && t.stack.length > 1 && console.log(a.dim(` stack: ${t.stack.join(", ")}`)), t.font?.role && console.log(a.dim(` role: ${t.font.role}${t.font.fallbackFor ? `, stands in for ${t.font.fallbackFor}` : ""}`)), t.font?.reason && console.log(a.dim(` why: ${t.font.reason}`));
|
|
3116
3402
|
}
|
|
3117
3403
|
console.log();
|
|
3118
3404
|
}
|
|
@@ -3121,22 +3407,22 @@ var $ = (e) => {
|
|
|
3121
3407
|
if (typeof e != "object" || !e) return String(e);
|
|
3122
3408
|
let t = e;
|
|
3123
3409
|
return t.units === void 0 ? t.value === void 0 ? [t.width !== void 0 && `width ${$(t.width)}`, t.height !== void 0 && `height ${$(t.height)}`].filter(Boolean).join(", ") : `${t.value}${t.unit}` : `${t.units} unit${t.units === 1 ? "" : "s"}`;
|
|
3124
|
-
},
|
|
3125
|
-
let { config: n, data: r } = await J(t), i =
|
|
3410
|
+
}, Ka = async (e, { dir: t }) => {
|
|
3411
|
+
let { config: n, data: r } = await J(t), i = oa(r, n, t);
|
|
3126
3412
|
return {
|
|
3127
3413
|
command: "logo",
|
|
3128
3414
|
passed: !0,
|
|
3129
3415
|
status: 0,
|
|
3130
3416
|
body: i,
|
|
3131
|
-
text: () =>
|
|
3417
|
+
text: () => qa(i)
|
|
3132
3418
|
};
|
|
3133
3419
|
};
|
|
3134
|
-
function
|
|
3135
|
-
console.log(`\n ${
|
|
3136
|
-
for (let t of e.variants) console.log(` ${t.variant.padEnd(8)} ${t.file}${t.found ? "" :
|
|
3420
|
+
function qa(e) {
|
|
3421
|
+
console.log(`\n ${a.bold("Variants")}`), e.variants.length === 0 && console.log(a.dim(" No logo is configured."));
|
|
3422
|
+
for (let t of e.variants) console.log(` ${t.variant.padEnd(8)} ${t.file}${t.found ? "" : a.red(" (not found)")}${t.ink ? ` ink ${t.ink}` : ""}${t.asset ? a.dim(` ${t.asset}`) : ""}`);
|
|
3137
3423
|
for (let t of e.assets) {
|
|
3138
3424
|
let e = t.rules;
|
|
3139
|
-
console.log(`\n ${
|
|
3425
|
+
console.log(`\n ${a.bold(t.id)} ${t.files.join(", ")}${t.variants.length ? a.dim(` used as ${t.variants.join(", ")}`) : ""}`);
|
|
3140
3426
|
let n = [
|
|
3141
3427
|
["lockup", e.lockup],
|
|
3142
3428
|
["ink", e.ink],
|
|
@@ -3150,18 +3436,18 @@ function Ta(e) {
|
|
|
3150
3436
|
["partnership", e.partnership && `gap ${$(e.partnership.gap)}${e.partnership.dividerHeight ? `, divider ${$(e.partnership.dividerHeight)}` : ""}`],
|
|
3151
3437
|
["initiative", e.initiative && `${e.initiative.name}, mark ${e.initiative.mark}, gap ${$(e.initiative.gap)}, ${e.initiative.position ?? "beside"}`]
|
|
3152
3438
|
];
|
|
3153
|
-
for (let [e, t] of n) t !== void 0 && console.log(` ${
|
|
3154
|
-
for (let t of e.do ?? []) console.log(` ${
|
|
3155
|
-
for (let t of e.dont ?? []) console.log(` ${
|
|
3439
|
+
for (let [e, t] of n) t !== void 0 && console.log(` ${a.dim(e.padEnd(12))} ${t}`);
|
|
3440
|
+
for (let t of e.do ?? []) console.log(` ${a.dim("do")} ${t}`);
|
|
3441
|
+
for (let t of e.dont ?? []) console.log(` ${a.dim("do not")} ${t}`);
|
|
3156
3442
|
}
|
|
3157
3443
|
if (e.forbidden.length > 0) {
|
|
3158
|
-
console.log(`\n ${
|
|
3159
|
-
for (let t of e.forbidden) console.log(` ${t.at} ${t.deny.join(", ")}${t.reason ? ` ${
|
|
3444
|
+
console.log(`\n ${a.bold("Forbidden on")}`);
|
|
3445
|
+
for (let t of e.forbidden) console.log(` ${t.at} ${t.deny.join(", ")}${t.reason ? ` ${a.dim(t.reason)}` : ""}`);
|
|
3160
3446
|
}
|
|
3161
3447
|
console.log();
|
|
3162
3448
|
}
|
|
3163
3449
|
// src/cli/handlers/brand.ts
|
|
3164
|
-
function
|
|
3450
|
+
function Ja(e, t) {
|
|
3165
3451
|
let n = e;
|
|
3166
3452
|
for (let e of t.split(".")) {
|
|
3167
3453
|
if (typeof n != "object" || !n || !Object.prototype.hasOwnProperty.call(n, e)) return;
|
|
@@ -3170,15 +3456,15 @@ function Ea(e, t) {
|
|
|
3170
3456
|
return n;
|
|
3171
3457
|
}
|
|
3172
3458
|
// src/cli/handlers/index.ts
|
|
3173
|
-
var
|
|
3174
|
-
get_token:
|
|
3175
|
-
list_tokens:
|
|
3176
|
-
get_rules:
|
|
3177
|
-
can_use:
|
|
3178
|
-
get_fonts:
|
|
3179
|
-
get_logo:
|
|
3459
|
+
var Ya = {
|
|
3460
|
+
get_token: La,
|
|
3461
|
+
list_tokens: za,
|
|
3462
|
+
get_rules: Ia,
|
|
3463
|
+
can_use: Ha,
|
|
3464
|
+
get_fonts: Wa,
|
|
3465
|
+
get_logo: Ka,
|
|
3180
3466
|
get_brand: async ({ key: e }, { dir: t }) => {
|
|
3181
|
-
let { config: n, data: r } = await J(t), i =
|
|
3467
|
+
let { config: n, data: r } = await J(t), i = xe(r, n, t), a = e === void 0 ? i : Ja(i, e);
|
|
3182
3468
|
if (a === void 0) throw new M(`brand.json has no "${String(e)}". Run blazon brand without --key to see the keys.`, void 0, "unknown-key");
|
|
3183
3469
|
return {
|
|
3184
3470
|
command: "brand",
|
|
@@ -3188,46 +3474,49 @@ var Da = {
|
|
|
3188
3474
|
text: () => void process.stdout.write(`${JSON.stringify(a, null, 2)}\n`)
|
|
3189
3475
|
};
|
|
3190
3476
|
}
|
|
3191
|
-
},
|
|
3192
|
-
function
|
|
3193
|
-
let t =
|
|
3477
|
+
}, Xa = (e) => e.cli, Za = (e) => e.replace(/[A-Z]/g, (e) => `-${e.toLowerCase()}`), Qa = Oa(Ea).filter((e) => Xa(e).options.some((e) => e.property === "json")).map((e) => Xa(e).command[0]);
|
|
3478
|
+
function $a(e) {
|
|
3479
|
+
let t = Xa(e), n = new Set(e.inputSchema.required ?? []);
|
|
3194
3480
|
return [...t.command, ...t.positional.map((e) => n.has(e) ? `<${e}>` : `[${e}]`)].join(" ");
|
|
3195
3481
|
}
|
|
3196
|
-
function
|
|
3197
|
-
|
|
3482
|
+
function eo(e, t) {
|
|
3483
|
+
if (t.property === "json") return "--json";
|
|
3484
|
+
let n = e.inputSchema.properties[t.property], r = t.flag ?? Za(t.property);
|
|
3485
|
+
return n?.type === "boolean" ? `--${r}` : `--${r} <${t.value ?? r}>`;
|
|
3198
3486
|
}
|
|
3199
|
-
var
|
|
3200
|
-
function
|
|
3201
|
-
for (let n of
|
|
3202
|
-
let r =
|
|
3487
|
+
var to = (e) => (e.flag ?? Za(e.property)).replace(/^no-/, "").replace(/-(.)/g, (e, t) => t.toUpperCase()), no = (e) => typeof e == "string" && /^\.|[\\/]/.test(e) && !!k.statSync(e, { throwIfNoEntry: !1 })?.isDirectory();
|
|
3488
|
+
function ro(e, t) {
|
|
3489
|
+
for (let n of Oa(Ea)) {
|
|
3490
|
+
let r = Xa(n), i = Ya[n.name];
|
|
3203
3491
|
if (!i) throw Error(`operation ${n.name} has a command and no handler`);
|
|
3204
|
-
let a = e.command(
|
|
3205
|
-
for (let e of r.options) a.option(
|
|
3492
|
+
let a = e.command($a(n), r.summary);
|
|
3493
|
+
for (let e of r.options) a.option(eo(n, e), e.description);
|
|
3206
3494
|
a.action(async (...e) => {
|
|
3207
|
-
let
|
|
3495
|
+
let a = e.pop() ?? {};
|
|
3208
3496
|
try {
|
|
3209
3497
|
let t = {};
|
|
3210
3498
|
r.positional.forEach((n, r) => t[n] = e[r]);
|
|
3211
|
-
for (let e of r.options) e.property !== "json" && (t[e.property] =
|
|
3212
|
-
let
|
|
3213
|
-
r.folder !== void 0 &&
|
|
3214
|
-
let o = await i(t, { dir:
|
|
3215
|
-
|
|
3216
|
-
} catch (
|
|
3217
|
-
|
|
3499
|
+
for (let e of r.options) e.property !== "json" && (t[e.property] = a[to(e)]);
|
|
3500
|
+
let n = t.dir;
|
|
3501
|
+
r.folder !== void 0 && n === void 0 && no(t[r.folder]) && (n = t[r.folder], t[r.folder] = void 0), delete t.dir;
|
|
3502
|
+
let o = await i(t, { dir: n ? String(n) : process.cwd() });
|
|
3503
|
+
a.json ? Y(o.command, o.passed, o.body) : o.text(), process.exitCode = o.status;
|
|
3504
|
+
} catch (i) {
|
|
3505
|
+
let a = Na(r.command, r.positional, e, new Set(n.inputSchema.required ?? []), i);
|
|
3506
|
+
a && i instanceof j && (i.hint = a), P(r.command.join(" "), i, t);
|
|
3218
3507
|
}
|
|
3219
3508
|
});
|
|
3220
3509
|
}
|
|
3221
3510
|
}
|
|
3222
3511
|
// src/cli/commands/mcp-check.ts
|
|
3223
|
-
var
|
|
3224
|
-
function
|
|
3512
|
+
var io = 3e4, ao = "This check starts blazon-mcp on the brand folder. The server runs blazon with no plugin and a limited environment, and reads the brand files as data. What the brand says reaches your agent as tool results, so check only a brand folder you trust.", oo = "npm ci && npm run build -w mcp", so = (e) => Se(e) ? `cd ${e} && ${oo}` : Me, co = () => Da(Ea).map((e) => e.name);
|
|
3513
|
+
function lo(e) {
|
|
3225
3514
|
let t = O.join(e, "mcp/dist/index.js"), n = k.existsSync(t);
|
|
3226
|
-
return !n && !
|
|
3515
|
+
return !n && !Se(e) ? {
|
|
3227
3516
|
name: "built",
|
|
3228
3517
|
passed: !1,
|
|
3229
|
-
detail:
|
|
3230
|
-
fix:
|
|
3518
|
+
detail: Ve,
|
|
3519
|
+
fix: Me,
|
|
3231
3520
|
entry: t
|
|
3232
3521
|
} : n ? {
|
|
3233
3522
|
name: "built",
|
|
@@ -3238,26 +3527,26 @@ function Ba(e) {
|
|
|
3238
3527
|
name: "built",
|
|
3239
3528
|
passed: !1,
|
|
3240
3529
|
detail: `${t} does not exist: blazon-mcp is not built`,
|
|
3241
|
-
fix:
|
|
3530
|
+
fix: so(e),
|
|
3242
3531
|
entry: t
|
|
3243
3532
|
};
|
|
3244
3533
|
}
|
|
3245
|
-
var
|
|
3534
|
+
var uo = (e) => {
|
|
3246
3535
|
try {
|
|
3247
3536
|
return k.statSync(e).isFile() ? (k.accessSync(e, k.constants.X_OK), !0) : !1;
|
|
3248
3537
|
} catch {
|
|
3249
3538
|
return !1;
|
|
3250
3539
|
}
|
|
3251
3540
|
};
|
|
3252
|
-
function
|
|
3541
|
+
function fo(e, t) {
|
|
3253
3542
|
let n = (t.PATH ?? "").split(O.delimiter).filter(Boolean), r = process.platform === "win32" ? ["", ...(t.PATHEXT ?? ".EXE;.CMD").split(";")].map((t) => e + t) : [e];
|
|
3254
|
-
for (let e of n) for (let t of r) if (
|
|
3543
|
+
for (let e of n) for (let t of r) if (uo(O.join(e, t))) return O.join(e, t);
|
|
3255
3544
|
}
|
|
3256
|
-
function
|
|
3545
|
+
function po(e, t, n) {
|
|
3257
3546
|
let r = O.join(n, "bin/blazon.js"), i = k.existsSync(r) ? k.existsSync(O.join(n, "dist/cli/index.js")) ? `export BLAZON_BIN=${r}` : `cd ${n} && npm run build && export BLAZON_BIN=${r}` : "put the blazon program on PATH, or export BLAZON_BIN=<path to the blazon executable>", a = e.BLAZON_BIN;
|
|
3258
3547
|
if (a) {
|
|
3259
|
-
let n = a.includes("/") || a.includes(O.sep) ? O.resolve(t, a) :
|
|
3260
|
-
return n &&
|
|
3548
|
+
let n = a.includes("/") || a.includes(O.sep) ? O.resolve(t, a) : fo(a, e);
|
|
3549
|
+
return n && uo(n) ? {
|
|
3261
3550
|
name: "blazon",
|
|
3262
3551
|
passed: !0,
|
|
3263
3552
|
detail: `BLAZON_BIN names ${n}`,
|
|
@@ -3271,14 +3560,14 @@ function Ua(e, t, n) {
|
|
|
3271
3560
|
source: "BLAZON_BIN"
|
|
3272
3561
|
};
|
|
3273
3562
|
}
|
|
3274
|
-
if (
|
|
3563
|
+
if (uo(r)) return {
|
|
3275
3564
|
name: "blazon",
|
|
3276
3565
|
passed: !0,
|
|
3277
3566
|
detail: `the server runs this package's own ${r}`,
|
|
3278
3567
|
source: "package",
|
|
3279
3568
|
path: r
|
|
3280
3569
|
};
|
|
3281
|
-
let o =
|
|
3570
|
+
let o = fo("blazon", e);
|
|
3282
3571
|
return o ? {
|
|
3283
3572
|
name: "blazon",
|
|
3284
3573
|
passed: !0,
|
|
@@ -3293,12 +3582,12 @@ function Ua(e, t, n) {
|
|
|
3293
3582
|
source: "none"
|
|
3294
3583
|
};
|
|
3295
3584
|
}
|
|
3296
|
-
var
|
|
3585
|
+
var mo = (e, t = 200) => {
|
|
3297
3586
|
let n = e.trim().split("\n").find((e) => e.trim() !== "") ?? "";
|
|
3298
3587
|
return n.length > t ? `${n.slice(0, t)}...` : n;
|
|
3299
3588
|
};
|
|
3300
|
-
async function
|
|
3301
|
-
let { entry: t, brand: n, env: r = process.env, timeoutMs: i =
|
|
3589
|
+
async function ho(e) {
|
|
3590
|
+
let { entry: t, brand: n, env: r = process.env, timeoutMs: i = io, expect: a = co() } = e, o = process.platform !== "win32", s = at(process.execPath, [
|
|
3302
3591
|
t,
|
|
3303
3592
|
"--brand",
|
|
3304
3593
|
n
|
|
@@ -3330,7 +3619,7 @@ async function Ga(e) {
|
|
|
3330
3619
|
m = setTimeout(() => {
|
|
3331
3620
|
p = !0, t(/* @__PURE__ */ Error(`no answer within ${i / 1e3} s`));
|
|
3332
3621
|
}, i);
|
|
3333
|
-
}), g = new Promise((e, t) => s.once("close", (e) => t(/* @__PURE__ */ Error(`the server exited (${e ?? "signal"}) before it answered${c ? `: ${
|
|
3622
|
+
}), g = new Promise((e, t) => s.once("close", (e) => t(/* @__PURE__ */ Error(`the server exited (${e ?? "signal"}) before it answered${c ? `: ${mo(c)}` : ""}`))));
|
|
3334
3623
|
g.catch(() => void 0), h.catch(() => void 0), u.catch(() => void 0);
|
|
3335
3624
|
let _ = 0, v = (e, t) => {
|
|
3336
3625
|
let n = ++_, r = new Promise((e) => d.set(n, e));
|
|
@@ -3355,7 +3644,7 @@ async function Ga(e) {
|
|
|
3355
3644
|
version: "0"
|
|
3356
3645
|
}
|
|
3357
3646
|
});
|
|
3358
|
-
if (e.error) throw Error(`initialize was refused: ${
|
|
3647
|
+
if (e.error) throw Error(`initialize was refused: ${mo(e.error.message ?? "")}`);
|
|
3359
3648
|
s.stdin.write(`${JSON.stringify({
|
|
3360
3649
|
jsonrpc: "2.0",
|
|
3361
3650
|
method: "notifications/initialized"
|
|
@@ -3364,8 +3653,8 @@ async function Ga(e) {
|
|
|
3364
3653
|
if (t.error || r.length > 0) return {
|
|
3365
3654
|
name: "handshake",
|
|
3366
3655
|
passed: !1,
|
|
3367
|
-
detail: t.error ? `tools/list failed: ${
|
|
3368
|
-
fix: `${
|
|
3656
|
+
detail: t.error ? `tools/list failed: ${mo(t.error.message ?? "")}` : `tools/list answered ${n.length} tool(s); missing ${r.join(", ")}`,
|
|
3657
|
+
fix: `${so(et())} (the server is older than this blazon), then run this check again`,
|
|
3369
3658
|
tools: n
|
|
3370
3659
|
};
|
|
3371
3660
|
let i = Date.now(), o = await v("tools/call", {
|
|
@@ -3375,7 +3664,7 @@ async function Ga(e) {
|
|
|
3375
3664
|
if (o.error || o.result?.isError) return {
|
|
3376
3665
|
name: "handshake",
|
|
3377
3666
|
passed: !1,
|
|
3378
|
-
detail: `check_brand failed: ${
|
|
3667
|
+
detail: `check_brand failed: ${mo(o.error?.message ?? l)}`,
|
|
3379
3668
|
fix: "run blazon check in the brand folder, and make sure the blazon program and the brand folder are the ones the server uses",
|
|
3380
3669
|
tools: n,
|
|
3381
3670
|
ms: c
|
|
@@ -3394,14 +3683,14 @@ async function Ga(e) {
|
|
|
3394
3683
|
name: "handshake",
|
|
3395
3684
|
passed: !1,
|
|
3396
3685
|
detail: `the handshake did not finish: ${e instanceof Error ? e.message : String(e)}${p ? "; the server was killed" : ""}`,
|
|
3397
|
-
fix: `${
|
|
3686
|
+
fix: `${so(et())}, then run this check again; on a hang, run the server by hand: node ${t} --brand ${n}`,
|
|
3398
3687
|
ms: Date.now() - y
|
|
3399
3688
|
};
|
|
3400
3689
|
} finally {
|
|
3401
|
-
clearTimeout(m), await
|
|
3690
|
+
clearTimeout(m), await go(s, l, o);
|
|
3402
3691
|
}
|
|
3403
3692
|
}
|
|
3404
|
-
async function
|
|
3693
|
+
async function go(e, t, n) {
|
|
3405
3694
|
let r = (t) => {
|
|
3406
3695
|
try {
|
|
3407
3696
|
n && e.pid !== void 0 ? process.kill(-e.pid, t) : e.kill(t);
|
|
@@ -3415,50 +3704,106 @@ async function Ka(e, t, n) {
|
|
|
3415
3704
|
let i;
|
|
3416
3705
|
await Promise.race([t, new Promise((e) => i = setTimeout(e, 2e3))]), clearTimeout(i), e.exitCode === null && e.signalCode === null ? (r("SIGKILL"), await t) : r("SIGKILL");
|
|
3417
3706
|
}
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3707
|
+
var _o = (e) => {
|
|
3708
|
+
try {
|
|
3709
|
+
return k.realpathSync(e);
|
|
3710
|
+
} catch {
|
|
3711
|
+
return O.resolve(e);
|
|
3712
|
+
}
|
|
3713
|
+
};
|
|
3714
|
+
function vo(e, t, n, r) {
|
|
3715
|
+
for (let i of e.args) {
|
|
3716
|
+
if (i.startsWith("-")) continue;
|
|
3717
|
+
let e = i.startsWith("~/") || i.startsWith(`~${O.sep}`) ? O.join(t, i.slice(1)) : i;
|
|
3718
|
+
if (!O.isAbsolute(e) && n === void 0) continue;
|
|
3719
|
+
let a = _o(O.resolve(n ?? "/", e));
|
|
3720
|
+
if (/\.m?js$/.test(a) && (a === r || k.existsSync(a))) return a;
|
|
3721
|
+
}
|
|
3722
|
+
}
|
|
3723
|
+
function yo(e, t, n, r = ot.homedir(), i = et()) {
|
|
3724
|
+
let a = Ie(e, t, r, process.platform, process.env.APPDATA), o = _o(we(i).args[0]), s = [], c = [], l = [], u = [];
|
|
3725
|
+
for (let e of a) {
|
|
3726
|
+
let n;
|
|
3422
3727
|
try {
|
|
3423
|
-
|
|
3728
|
+
n = k.readFileSync(e.path, "utf8");
|
|
3424
3729
|
} catch {
|
|
3425
3730
|
continue;
|
|
3426
3731
|
}
|
|
3427
|
-
let
|
|
3428
|
-
|
|
3732
|
+
let i = De(n, e);
|
|
3733
|
+
if (i === void 0) {
|
|
3734
|
+
l.push(e.path);
|
|
3735
|
+
continue;
|
|
3736
|
+
}
|
|
3737
|
+
if (c.push(e.path), !i.includes("blazon")) continue;
|
|
3738
|
+
s.push(e.path);
|
|
3739
|
+
let a = e.scope === "project" ? t.find((t) => e.path.startsWith(t + O.sep)) : void 0, d = Ne(n, e, "blazon") ?? [];
|
|
3740
|
+
d.length === 0 && u.push({
|
|
3741
|
+
file: e.path,
|
|
3742
|
+
script: void 0
|
|
3743
|
+
});
|
|
3744
|
+
for (let t of d) u.push({
|
|
3745
|
+
file: e.path,
|
|
3746
|
+
script: vo(t, r, a, o)
|
|
3747
|
+
});
|
|
3429
3748
|
}
|
|
3430
|
-
let
|
|
3431
|
-
|
|
3749
|
+
let d = l.length > 0 ? ` (not valid JSON, skipped: ${l.join(", ")})` : "", f = `blazon mcp --print-config --client ${e} --brand ${n}`;
|
|
3750
|
+
if (s.length === 0) return {
|
|
3432
3751
|
name: "registered",
|
|
3433
|
-
passed: !
|
|
3752
|
+
passed: !1,
|
|
3434
3753
|
advisory: !0,
|
|
3435
3754
|
client: e,
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3755
|
+
state: "none",
|
|
3756
|
+
found: !1,
|
|
3757
|
+
sameServer: null,
|
|
3758
|
+
detail: `no server named blazon in ${e}'s config; looked in ${c.length > 0 ? c.join(", ") : "no file that exists"}${d}`,
|
|
3759
|
+
fix: f,
|
|
3760
|
+
files: []
|
|
3761
|
+
};
|
|
3762
|
+
let p = {
|
|
3439
3763
|
name: "registered",
|
|
3440
|
-
passed: !1,
|
|
3441
3764
|
advisory: !0,
|
|
3442
3765
|
client: e,
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3766
|
+
found: !0,
|
|
3767
|
+
files: s,
|
|
3768
|
+
installPath: o
|
|
3769
|
+
}, m = u.find((e) => e.script !== void 0 && e.script !== o);
|
|
3770
|
+
return m?.script === void 0 ? u.some((e) => e.script === void 0) ? {
|
|
3771
|
+
...p,
|
|
3772
|
+
passed: !1,
|
|
3773
|
+
state: "unknown",
|
|
3774
|
+
sameServer: null,
|
|
3775
|
+
detail: `${e} has a server named blazon in ${s.join(", ")}, but this check could not tell which file it runs; this install's is ${o}, and blazon mcp --print-config prints the command that registers it${d}`,
|
|
3776
|
+
fix: f
|
|
3777
|
+
} : {
|
|
3778
|
+
...p,
|
|
3779
|
+
passed: !0,
|
|
3780
|
+
state: "same",
|
|
3781
|
+
sameServer: !0,
|
|
3782
|
+
detail: `${e} has a server named blazon in ${s.join(", ")}, and it runs this install's ${o}${d}`
|
|
3783
|
+
} : {
|
|
3784
|
+
...p,
|
|
3785
|
+
passed: !1,
|
|
3786
|
+
state: "different",
|
|
3787
|
+
sameServer: !1,
|
|
3788
|
+
registeredPath: m.script,
|
|
3789
|
+
detail: `${e} has a server named blazon in ${m.file}, but it runs ${m.script}, not this install's ${o}; blazon mcp --print-config prints the command that registers this install${d}`,
|
|
3790
|
+
fix: f
|
|
3446
3791
|
};
|
|
3447
3792
|
}
|
|
3448
|
-
async function
|
|
3449
|
-
let { client: t, brand: n, env: r = process.env, cwd: i = process.cwd(), home:
|
|
3450
|
-
entry:
|
|
3793
|
+
async function bo(e) {
|
|
3794
|
+
let { client: t, brand: n, env: r = process.env, cwd: i = process.cwd(), home: o = ot.homedir() } = e, s = e.root ?? et(), c = lo(s), l = po(r, n, s), u = c.passed ? await ho({
|
|
3795
|
+
entry: c.entry,
|
|
3451
3796
|
brand: n,
|
|
3452
3797
|
env: r,
|
|
3453
3798
|
...e.timeoutMs !== void 0 && { timeoutMs: e.timeoutMs }
|
|
3454
3799
|
}) : {
|
|
3455
3800
|
name: "handshake",
|
|
3456
3801
|
passed: !1,
|
|
3457
|
-
detail: `not run: ${
|
|
3458
|
-
fix:
|
|
3459
|
-
}, d =
|
|
3802
|
+
detail: `not run: ${Se(s) ? "the server is not built" : "the install is incomplete"}`,
|
|
3803
|
+
fix: c.fix
|
|
3804
|
+
}, d = yo(t, [.../* @__PURE__ */ new Set([i, n])], n, o, s), { entry: f, ...p } = c, m = [
|
|
3460
3805
|
p,
|
|
3461
|
-
|
|
3806
|
+
l,
|
|
3462
3807
|
u,
|
|
3463
3808
|
d
|
|
3464
3809
|
], h = m.filter((e) => !e.advisory).every((e) => e.passed);
|
|
@@ -3467,43 +3812,43 @@ async function Ja(e) {
|
|
|
3467
3812
|
client: t,
|
|
3468
3813
|
brand: n,
|
|
3469
3814
|
runsPlugins: !1,
|
|
3470
|
-
trust:
|
|
3471
|
-
registered: d.
|
|
3815
|
+
trust: ao,
|
|
3816
|
+
registered: d.found,
|
|
3472
3817
|
checks: m
|
|
3473
3818
|
}), +!h;
|
|
3474
|
-
console.log(`\n ${
|
|
3819
|
+
console.log(`\n ${a.bold(`blazon-mcp for ${t}, brand ${n}`)}\n ${a.yellow(ao)}\n`);
|
|
3475
3820
|
for (let e of m) {
|
|
3476
|
-
let t = e.passed ?
|
|
3477
|
-
console.log(` ${t} ${e.name.padEnd(10)} ${e.detail}`), !e.passed && e.fix && console.log(` ${" ".repeat(7)} ${" ".repeat(10)} ${
|
|
3821
|
+
let t = e.passed ? a.green("ok ") : e.advisory ? a.yellow("finding") : a.red("fail ");
|
|
3822
|
+
console.log(` ${t} ${e.name.padEnd(10)} ${e.detail}`), !e.passed && e.fix && console.log(` ${" ".repeat(7)} ${" ".repeat(10)} ${a.dim("fix:")} ${e.fix}`);
|
|
3478
3823
|
}
|
|
3479
|
-
return console.log(`\n ${h ?
|
|
3824
|
+
return console.log(`\n ${h ? a.green("The server is ready.") : a.red("The server is not ready.")}${d.found ? "" : " It is not registered in this client yet (a finding, not a failure)."}\n`), +!h;
|
|
3480
3825
|
}
|
|
3481
3826
|
// src/cli/commands/mcp.ts
|
|
3482
|
-
async function
|
|
3827
|
+
async function xo(e = {}) {
|
|
3483
3828
|
if (e.printConfig && e.check) throw new M("give --print-config or --check, not both. See blazon mcp --help.", void 0, "conflicting-options");
|
|
3484
3829
|
if (!e.printConfig && !e.check) throw new M("give --print-config to print the config that registers blazon-mcp in a client, or --check to test that it works; neither writes a file. See blazon mcp --help.", void 0, "missing-argument");
|
|
3485
3830
|
let t = e.client === void 0 ? "claude-code" : e.client;
|
|
3486
|
-
if (e.client !== void 0 && !
|
|
3831
|
+
if (e.client !== void 0 && !be(e.client)) throw new M(`unknown client "${e.client}"; the clients are ${ve.join(", ")}.`, void 0, "invalid-option-value");
|
|
3487
3832
|
let n = e.brand === void 0 ? void 0 : O.resolve(process.cwd(), e.brand);
|
|
3488
3833
|
if (e.check) {
|
|
3489
3834
|
let r = n ?? process.cwd();
|
|
3490
3835
|
if (!k.statSync(r, { throwIfNoEntry: !1 })?.isDirectory()) throw new M(`the brand folder ${r} does not exist.`, void 0, "no-folder");
|
|
3491
|
-
return
|
|
3836
|
+
return bo({
|
|
3492
3837
|
client: t,
|
|
3493
3838
|
brand: r,
|
|
3494
3839
|
...e.root && { root: e.root },
|
|
3495
3840
|
...e.json && { json: !0 }
|
|
3496
3841
|
});
|
|
3497
3842
|
}
|
|
3498
|
-
let r =
|
|
3499
|
-
if (!r.built && !
|
|
3843
|
+
let r = we(e.root);
|
|
3844
|
+
if (!r.built && !Se(e.root)) return e.json ? Y("mcp", !1, {
|
|
3500
3845
|
client: t,
|
|
3501
3846
|
built: !1,
|
|
3502
3847
|
...n && { brand: n },
|
|
3503
|
-
note:
|
|
3848
|
+
note: Ve,
|
|
3504
3849
|
snippets: []
|
|
3505
|
-
}) : console.error(`\n ${
|
|
3506
|
-
let i =
|
|
3850
|
+
}) : console.error(`\n ${a.yellow(Ve)}\n`), 1;
|
|
3851
|
+
let i = Ge(t, r, n);
|
|
3507
3852
|
if (e.json) return Y("mcp", !0, {
|
|
3508
3853
|
client: t,
|
|
3509
3854
|
built: i.built,
|
|
@@ -3511,13 +3856,13 @@ async function Ya(e = {}) {
|
|
|
3511
3856
|
...i.note && { note: i.note },
|
|
3512
3857
|
snippets: i.snippets
|
|
3513
3858
|
}), 0;
|
|
3514
|
-
console.log(`\n ${
|
|
3515
|
-
for (let e of i.snippets) console.log(`\n ${
|
|
3516
|
-
return i.note && console.log(`\n ${
|
|
3859
|
+
console.log(`\n ${a.bold(i.title)}`);
|
|
3860
|
+
for (let e of i.snippets) console.log(`\n ${a.dim(e.label)}\n\n${e.text.replace(/^/gm, " ")}`);
|
|
3861
|
+
return i.note && console.log(`\n ${a.yellow(i.note)}`), console.log(""), 0;
|
|
3517
3862
|
}
|
|
3518
3863
|
// src/cli/commands/explain.ts
|
|
3519
|
-
function
|
|
3520
|
-
let t =
|
|
3864
|
+
function So(e) {
|
|
3865
|
+
let t = Ye[e], n = Ke(e);
|
|
3521
3866
|
return {
|
|
3522
3867
|
code: e,
|
|
3523
3868
|
severity: t.severity,
|
|
@@ -3528,26 +3873,26 @@ function Xa(e) {
|
|
|
3528
3873
|
manual: t.manual
|
|
3529
3874
|
};
|
|
3530
3875
|
}
|
|
3531
|
-
function
|
|
3876
|
+
function Co(e) {
|
|
3532
3877
|
let [t = "", n] = e.split("#");
|
|
3533
3878
|
return `RFC ${t.padStart(4, "0")}${n ? `, section ${n}` : ""}`;
|
|
3534
3879
|
}
|
|
3535
|
-
function
|
|
3536
|
-
let t = Object.keys(
|
|
3880
|
+
function wo(e) {
|
|
3881
|
+
let t = Object.keys(Ye), n = [];
|
|
3537
3882
|
for (let r = 0; r < 3; r++) {
|
|
3538
|
-
let r =
|
|
3883
|
+
let r = D(e, t);
|
|
3539
3884
|
if (r === void 0) break;
|
|
3540
3885
|
n.push(r), t.splice(t.indexOf(r), 1);
|
|
3541
3886
|
}
|
|
3542
3887
|
return n;
|
|
3543
3888
|
}
|
|
3544
|
-
function
|
|
3545
|
-
let t = e.severity === "error" ?
|
|
3546
|
-
console.log(`\n ${
|
|
3889
|
+
function To(e) {
|
|
3890
|
+
let t = e.severity === "error" ? a.red : e.severity === "warning" ? a.yellow : a.dim;
|
|
3891
|
+
console.log(`\n ${a.bold(e.code)} ${t(e.severity)}\n`), console.log(` ${e.summary}`), e.fix !== void 0 && console.log(`\n ${a.bold("Fix")} ${e.fix}`), console.log(`\n ${a.bold("Read")} docs/manual/${e.manual}.md, ${Co(e.rfc)}\n`);
|
|
3547
3892
|
}
|
|
3548
|
-
function
|
|
3893
|
+
function Eo(e, t = {}) {
|
|
3549
3894
|
if (e === void 0) {
|
|
3550
|
-
let e = Object.keys(
|
|
3895
|
+
let e = Object.keys(Ye).sort().map((e) => So(e));
|
|
3551
3896
|
if (t.json) Y("explain", !0, { codes: e });
|
|
3552
3897
|
else {
|
|
3553
3898
|
let t = Math.max(...e.map((e) => e.code.length));
|
|
@@ -3557,26 +3902,26 @@ function eo(e, t = {}) {
|
|
|
3557
3902
|
}
|
|
3558
3903
|
return 0;
|
|
3559
3904
|
}
|
|
3560
|
-
if (!Object.hasOwn(
|
|
3561
|
-
let t =
|
|
3905
|
+
if (!Object.hasOwn(Ye, e)) {
|
|
3906
|
+
let t = wo(e);
|
|
3562
3907
|
throw new M(`unknown code "${e}"`, t.length > 0 ? `Did you mean ${t.map((e) => `"${e}"`).join(", ")}? Run blazon explain to list every code.` : "Run blazon explain to list every code.", "unknown-finding-code");
|
|
3563
3908
|
}
|
|
3564
|
-
let n =
|
|
3565
|
-
return t.json ? Y("explain", !0, n) :
|
|
3909
|
+
let n = So(e);
|
|
3910
|
+
return t.json ? Y("explain", !0, n) : To(n), 0;
|
|
3566
3911
|
}
|
|
3567
3912
|
// src/cli/options.ts
|
|
3568
|
-
var
|
|
3913
|
+
var Do = (e) => {
|
|
3569
3914
|
if (e.length === 1) return [`-${e}`];
|
|
3570
3915
|
let t = e.replace(/[A-Z]/g, (e) => `-${e.toLowerCase()}`);
|
|
3571
3916
|
return t === e ? [`--${e}`] : [`--${e}`, `--${t}`];
|
|
3572
3917
|
};
|
|
3573
|
-
function
|
|
3918
|
+
function Oo(e, t) {
|
|
3574
3919
|
let n = e.matchedCommand;
|
|
3575
3920
|
if (!n) return;
|
|
3576
3921
|
let r = [...n.options, ...e.globalCommand.options].filter((e) => e.required);
|
|
3577
3922
|
for (let i of r) {
|
|
3578
3923
|
if (typeof e.options[i.name] == "object") continue;
|
|
3579
|
-
let r = i.names.flatMap(
|
|
3924
|
+
let r = i.names.flatMap(Do);
|
|
3580
3925
|
for (let a = 2; a < t.length; a++) {
|
|
3581
3926
|
let o = t[a], s = r.find((e) => o === e || o.startsWith(`${e}=`));
|
|
3582
3927
|
if (s === void 0) continue;
|
|
@@ -3588,11 +3933,11 @@ function no(e, t) {
|
|
|
3588
3933
|
i.some((e, t) => e === "" && !(i[t - 1] ?? "").startsWith("-")) && N(`blazon ${n.name}: ${n.rawName.includes("[dir]") ? "the folder is an empty name; leave it out to use the current folder" : "an argument is empty"}.`, "empty-value", { fix: "Leave the empty argument out, or give it a value." });
|
|
3589
3934
|
}
|
|
3590
3935
|
// src/cli/json.ts
|
|
3591
|
-
var
|
|
3936
|
+
var ko = [
|
|
3592
3937
|
"error",
|
|
3593
3938
|
"warning",
|
|
3594
3939
|
"info"
|
|
3595
|
-
],
|
|
3940
|
+
], Ao = {
|
|
3596
3941
|
error: ["error"],
|
|
3597
3942
|
warning: ["error", "warning"],
|
|
3598
3943
|
info: [
|
|
@@ -3601,40 +3946,46 @@ var ro = [
|
|
|
3601
3946
|
"info"
|
|
3602
3947
|
]
|
|
3603
3948
|
};
|
|
3604
|
-
async function
|
|
3605
|
-
let
|
|
3949
|
+
async function jo(e, n, r, i = "info", a = process.cwd()) {
|
|
3950
|
+
let o = console.log;
|
|
3606
3951
|
console.log = (...e) => console.error(...e);
|
|
3607
|
-
let
|
|
3952
|
+
let s;
|
|
3608
3953
|
try {
|
|
3609
|
-
|
|
3954
|
+
s = (await r()).findings;
|
|
3610
3955
|
} catch (e) {
|
|
3611
|
-
if (!(e instanceof
|
|
3612
|
-
|
|
3956
|
+
if (!(e instanceof Dt)) throw e;
|
|
3957
|
+
s = e.findings;
|
|
3613
3958
|
} finally {
|
|
3614
|
-
console.log =
|
|
3959
|
+
console.log = o;
|
|
3615
3960
|
}
|
|
3616
|
-
let
|
|
3617
|
-
errors:
|
|
3618
|
-
warnings:
|
|
3619
|
-
info:
|
|
3961
|
+
let c = t(s, { strict: n }), l = {
|
|
3962
|
+
errors: c.errors.length,
|
|
3963
|
+
warnings: c.warnings.length,
|
|
3964
|
+
info: c.infos.length
|
|
3965
|
+
}, { mismatch: u } = _e(a), d = u && {
|
|
3966
|
+
pinned: u.pinned,
|
|
3967
|
+
running: u.running,
|
|
3968
|
+
message: u.message
|
|
3620
3969
|
};
|
|
3621
3970
|
process.stdout.write(`${JSON.stringify({
|
|
3622
3971
|
command: e,
|
|
3623
|
-
passed:
|
|
3624
|
-
strict:
|
|
3625
|
-
counts:
|
|
3626
|
-
|
|
3972
|
+
passed: c.passed,
|
|
3973
|
+
strict: n,
|
|
3974
|
+
counts: l,
|
|
3975
|
+
brandHasErrors: b(s).length > 0,
|
|
3976
|
+
...d && { pinMismatch: d },
|
|
3977
|
+
findings: c.all.filter((e) => Ao[i].includes(e.severity)).map((e) => ({
|
|
3627
3978
|
...e,
|
|
3628
|
-
|
|
3979
|
+
...$e(e) && { fix: $e(e) }
|
|
3629
3980
|
}))
|
|
3630
|
-
}, null, 2)}\n`), process.exitCode = +!
|
|
3981
|
+
}, null, 2)}\n`), process.exitCode = +!c.passed;
|
|
3631
3982
|
}
|
|
3632
|
-
async function
|
|
3983
|
+
async function Mo(e, t) {
|
|
3633
3984
|
let n = console.log;
|
|
3634
3985
|
console.log = (...e) => console.error(...e);
|
|
3635
3986
|
let r, i, a;
|
|
3636
3987
|
try {
|
|
3637
|
-
i = await
|
|
3988
|
+
i = await ii(e, {
|
|
3638
3989
|
...t,
|
|
3639
3990
|
input: !1,
|
|
3640
3991
|
report: (e) => r = e,
|
|
@@ -3647,18 +3998,18 @@ async function oo(e, t) {
|
|
|
3647
3998
|
command: "init",
|
|
3648
3999
|
passed: i === 0,
|
|
3649
4000
|
...r ?? {},
|
|
3650
|
-
...i !== 0 && { error: a ?
|
|
4001
|
+
...i !== 0 && { error: a ? gt(a.code, a.message) : gt("error", `init did not finish (exit status ${i}); the reason is on standard error`) }
|
|
3651
4002
|
};
|
|
3652
4003
|
return process.stdout.write(`${JSON.stringify(o)}\n`), i;
|
|
3653
4004
|
}
|
|
3654
4005
|
// src/cli/help.ts
|
|
3655
|
-
var
|
|
4006
|
+
var No = " 0 it did what it was asked (for check, no errors)\n 1 the check found errors (or warnings, with --strict), `blazon can` denied the combination, `blazon doctor` found a failing check, or the command failed\n 2 it was used wrongly: an unknown command or option, an unknown token, a bad port, no brand book in the folder. It did nothing, except `blazon init --from`, which copies the starter and then exits 2 when the site cannot be read", Po = " blazon explain <code> what a finding code means, the fix, and where to read more\n blazon explain list every code", Fo = " --cwd <dir> sets the folder every command works from, the same as running blazon there. A folder argument is then relative to it:\n `blazon --cwd ./brands check acme` checks ./brands/acme. A --cwd that is not a folder exits 2.\n `blazon doctor` checks the environment (Node, brand folder, plugin folder safety, Chrome, blazon.lock): one line each, ok, warn or fail, with a fix.", Io = {
|
|
3656
4007
|
check: "blazon plugin check <program> [--core] [--json]\n\nStarts the program the way blazon does and runs the protocol's core cases against it, then blazon's own cases for each role it declares and, for a shipped plugin's layout, the file name rule. Prints one line for each case: ok, skip or FAIL.\nIn a project whose config lists the plugin, case 10 also fails when the entry's env does not approve a variable the manifest lists.\nWith --core, only the core cases (1 to 5) run: no role cases, no case 10 and no layout line. Use it to check a plugin against the protocol alone.\n\nExit status:\n 0 every case passed\n 1 a case failed\n 2 no program was given\n\nExample:\n $ blazon plugin check ./blazon-acme.house-style",
|
|
3657
4008
|
pin: "blazon plugin pin <path> [--name <plugin>] [--digest <digest>] [--entry <path>]\n\nPrints the digest that pins a plugin: sha256: for a file, t1: for a directory.\nWith --name, records the pin in blazon.plugins.lock instead. --digest says what the bytes must be, and the pin is refused when they are not. --entry names the program inside a directory when it is not blazon-<plugin>.\n\nExit status:\n 0 printed, or recorded\n 1 the path is one a host must refuse, or the digest does not match\n 2 no path was given, or --digest or --entry without --name\n\nExample:\n $ blazon plugin pin ./blazon-acme.house-style --name acme.house-style",
|
|
3658
4009
|
profile: "blazon plugin profile\n\nPrints blazon's profile of the plugin protocol as JSON: the roles it defines and its limits. It is the same for every install.\n\nExit status:\n 0 printed"
|
|
3659
4010
|
};
|
|
3660
|
-
function
|
|
3661
|
-
if (t === "plugin" && n !== void 0 && Object.hasOwn(
|
|
4011
|
+
function Lo(e, t, n) {
|
|
4012
|
+
if (t === "plugin" && n !== void 0 && Object.hasOwn(Io, n)) return [{ body: Io[n] }];
|
|
3662
4013
|
let r = e.map((e) => ({
|
|
3663
4014
|
...e,
|
|
3664
4015
|
body: e.body.replace(/(--no-[a-z-]+[^\n]*?) *\(default: true\)/g, "$1")
|
|
@@ -3667,32 +4018,32 @@ function fo(e, t, n) {
|
|
|
3667
4018
|
...r,
|
|
3668
4019
|
{
|
|
3669
4020
|
title: "Finding codes",
|
|
3670
|
-
body:
|
|
4021
|
+
body: Po
|
|
3671
4022
|
},
|
|
3672
4023
|
{
|
|
3673
4024
|
title: "Working folder and environment",
|
|
3674
|
-
body:
|
|
4025
|
+
body: Fo
|
|
3675
4026
|
},
|
|
3676
4027
|
{
|
|
3677
4028
|
title: "Exit status",
|
|
3678
|
-
body:
|
|
4029
|
+
body: No
|
|
3679
4030
|
}
|
|
3680
4031
|
] : r;
|
|
3681
4032
|
}
|
|
3682
4033
|
// src/cli/index.ts
|
|
3683
|
-
function
|
|
4034
|
+
function Ro(e, t) {
|
|
3684
4035
|
if (t === void 0) return;
|
|
3685
4036
|
let n = String(t), r = /^\d+$/.test(n) ? Number(n) : NaN;
|
|
3686
4037
|
return r >= 1 && r <= 65535 || N(`blazon ${e}: the port must be a whole number from 1 to 65535, not "${n}".`, "invalid-port", { fix: "Give a whole number from 1 to 65535." }), r;
|
|
3687
4038
|
}
|
|
3688
|
-
var
|
|
3689
|
-
function
|
|
4039
|
+
var zo = (e) => typeof e == "number" ? String(e) : e;
|
|
4040
|
+
function Bo(e, t) {
|
|
3690
4041
|
t?.plugins === !1 && t.plugin !== void 0 && N(`blazon ${e}: --no-plugins runs no plugin, so it cannot be used with --plugin.`, "conflicting-options", { fix: "Leave out --no-plugins, or leave out --plugin." });
|
|
3691
4042
|
}
|
|
3692
|
-
function
|
|
3693
|
-
if (t !== void 0) return n || N(`blazon ${e}: --severity cuts the list that --json prints; add --json, or leave --severity out.`, "conflicting-options", { fix: "Add --json, or leave --severity out." }),
|
|
4043
|
+
function Vo(e, t, n) {
|
|
4044
|
+
if (t !== void 0) return n || N(`blazon ${e}: --severity cuts the list that --json prints; add --json, or leave --severity out.`, "conflicting-options", { fix: "Add --json, or leave --severity out." }), ko.includes(t) || N(`blazon ${e}: --severity must be error, warning or info, not "${String(t)}".`, "invalid-option-value", { fix: "Use --severity error, warning or info." }), t;
|
|
3694
4045
|
}
|
|
3695
|
-
var
|
|
4046
|
+
var Ho = (e) => {
|
|
3696
4047
|
let [t, n] = e.slice(2).filter((e, t, n) => !e.startsWith("-") && n[t - 1] !== "--cwd" && n[t - 1] !== "--allow-dir");
|
|
3697
4048
|
if (e.includes("--json") && t !== void 0) return t === "plugin" ? n === "check" ? "plugin check" : void 0 : [
|
|
3698
4049
|
"check",
|
|
@@ -3704,11 +4055,11 @@ var _o = (e) => {
|
|
|
3704
4055
|
"pin",
|
|
3705
4056
|
"explain",
|
|
3706
4057
|
"doctor",
|
|
3707
|
-
...
|
|
4058
|
+
...Qa,
|
|
3708
4059
|
"mcp"
|
|
3709
4060
|
].includes(t) ? t : void 0;
|
|
3710
4061
|
};
|
|
3711
|
-
function
|
|
4062
|
+
function Uo(e) {
|
|
3712
4063
|
if (e[2] !== "help") return e;
|
|
3713
4064
|
let t = e[3];
|
|
3714
4065
|
return t !== void 0 && !t.startsWith("-") ? [
|
|
@@ -3718,58 +4069,58 @@ function vo(e) {
|
|
|
3718
4069
|
...e.slice(4)
|
|
3719
4070
|
] : [...e.slice(0, 2), "--help"];
|
|
3720
4071
|
}
|
|
3721
|
-
async function
|
|
3722
|
-
let t =
|
|
3723
|
-
|
|
3724
|
-
let r =
|
|
4072
|
+
async function Wo(e = process.argv) {
|
|
4073
|
+
let t = Uo(e), n = t.includes("--debug");
|
|
4074
|
+
mt(Ho(t));
|
|
4075
|
+
let r = ct("blazon");
|
|
3725
4076
|
if (r.option("--debug", "Show the stack of an error"), r.option("--allow-dir <folder>", "Approve a folder outside the project for an asset category dir (repeat for more; or BLAZON_ALLOW_DIRS)"), r.option("--cwd <dir>", "Work from this folder, as if blazon were run there; a folder argument is then relative to it"), r.command("dev [dir]", "Start interactive Brand Book dev server with HMR").option("-p, --port <port>", "Port number to listen on (default: the port in blazon.json, else 3000)").option("--strict-port", "Exit 2 when the port is in use, instead of taking the next free one").option("--host [address]", "Listen on this address, or on every network interface with no address (default: localhost only)").action(async (e, t) => {
|
|
3726
4077
|
try {
|
|
3727
|
-
await
|
|
4078
|
+
await Et(e || process.cwd(), Ro("dev", t?.port), {
|
|
3728
4079
|
strictPort: t?.strictPort,
|
|
3729
|
-
host:
|
|
4080
|
+
host: zo(t?.host)
|
|
3730
4081
|
});
|
|
3731
4082
|
} catch (e) {
|
|
3732
4083
|
P("dev", e, n);
|
|
3733
4084
|
}
|
|
3734
4085
|
}), r.command("build [dir]", "Build static brand book site and compiled design tokens").option("-o, --outDir <dir>", "Output directory for static site").option("--plugin <program>", "Run a plugin program that the config does not allow or the lock does not pin, once, with a warning (repeat for more)").option("--no-plugins", "Run no plugin at all, whatever the config lists: the tokens and the book only (no browser needed)").option("--json", "Print the findings as JSON on standard output; everything else goes to standard error").option("--severity <level>", "With --json: list only the findings at this level or worse (error, warning or info); the counts stay whole").action(async (e, t) => {
|
|
3735
4086
|
try {
|
|
3736
|
-
|
|
3737
|
-
let n =
|
|
3738
|
-
t?.json ? await
|
|
4087
|
+
Bo("build", t);
|
|
4088
|
+
let n = Vo("build", t?.severity, t?.json), r = () => Ht(e || process.cwd(), t?.outDir === void 0 ? void 0 : O.resolve(process.cwd(), t.outDir), t);
|
|
4089
|
+
t?.json ? await jo("build", !1, r, n, e || process.cwd()) : await r();
|
|
3739
4090
|
} catch (e) {
|
|
3740
4091
|
P("build", e, n);
|
|
3741
4092
|
}
|
|
3742
4093
|
}), r.command("tokens [dir]", "Compile design tokens only (theme.css, tokens.ts, tokens.json)").option("--plugin <program>", "Run a plugin program that the config does not allow or the lock does not pin, once, with a warning (repeat for more)").option("--no-plugins", "Run no plugin at all, whatever the config lists: the tokens and the book only (no browser needed)").option("--json", "Print the findings as JSON on standard output; everything else goes to standard error").option("--severity <level>", "With --json: list only the findings at this level or worse (error, warning or info); the counts stay whole").action(async (e, t) => {
|
|
3743
4094
|
try {
|
|
3744
|
-
|
|
3745
|
-
let n =
|
|
3746
|
-
t?.json ? await
|
|
4095
|
+
Bo("tokens", t);
|
|
4096
|
+
let n = Vo("tokens", t?.severity, t?.json), r = () => Ut(e || process.cwd(), t);
|
|
4097
|
+
t?.json ? await jo("tokens", !1, r, n, e || process.cwd()) : await r();
|
|
3747
4098
|
} catch (e) {
|
|
3748
4099
|
P("tokens", e, n);
|
|
3749
4100
|
}
|
|
3750
4101
|
}), r.command("check [dir]", "Check tokens: aliases, types, usage rules, contrast pairs, duplicates and review flags").option("--strict", "Treat warnings as errors (useful for CI/CD pipelines)").option("--plugin <program>", "Run a plugin program that the config does not allow or the lock does not pin, once, with a warning (repeat for more)").option("--no-plugins", "Run no plugin at all, whatever the config lists: the tokens and the book only (no browser needed)").option("--json", "Print the findings as JSON on standard output; everything else goes to standard error").option("--severity <level>", "With --json: list only the findings at this level or worse (error, warning or info); the counts stay whole").action(async (e, t) => {
|
|
3751
4102
|
try {
|
|
3752
|
-
|
|
3753
|
-
let n =
|
|
3754
|
-
t?.json ? await
|
|
4103
|
+
Bo("check", t);
|
|
4104
|
+
let n = Vo("check", t?.severity, t?.json), r = () => Vt(e || process.cwd(), t?.strict, t);
|
|
4105
|
+
t?.json ? await jo("check", !!t.strict, r, n, e || process.cwd()) : (await r()).passed || (process.exitCode = 1);
|
|
3755
4106
|
} catch (e) {
|
|
3756
4107
|
P("check", e, n);
|
|
3757
4108
|
}
|
|
3758
|
-
}),
|
|
4109
|
+
}), ro(r, n), r.command("mcp", "Set up blazon-mcp, the MCP server for coding agents: --print-config prints what registers it in a client, --check tests that it works; neither writes a file").option("--print-config", "Print the config that registers blazon-mcp (stdio) in a client").option("--check", "Test that the server is built, finds blazon, answers a real MCP handshake and is registered in the client; runs no plugin").option("--client <client>", "With --print-config or --check: claude-code (default), claude-desktop, cursor or vscode").option("--brand <dir>", "The brand folder: with --print-config, written into the config as an absolute path; with --check, the folder the server starts on").option("--json", "Print the config or the check as JSON on standard output").action(async (e) => {
|
|
3759
4110
|
try {
|
|
3760
|
-
process.exitCode = await
|
|
4111
|
+
process.exitCode = await xo(e);
|
|
3761
4112
|
} catch (e) {
|
|
3762
4113
|
P("mcp", e, n);
|
|
3763
4114
|
}
|
|
3764
4115
|
}), r.command("drift [target]", "Find tokens that have drifted from the live site: compare each token that names a source.cssVar with a page (http or https address) or a CSS file").option("--json", "Print the findings as JSON").option("--tokens <dir>", "Read the tokens from this folder instead of the one the config names").action(async (e, t) => {
|
|
3765
4116
|
try {
|
|
3766
|
-
process.exitCode = await
|
|
4117
|
+
process.exitCode = await xi(e, t);
|
|
3767
4118
|
} catch (e) {
|
|
3768
4119
|
P("drift", e, n);
|
|
3769
4120
|
}
|
|
3770
4121
|
}), r.command("approvals [dir]", "List the tokens and assets marked review ok with the fingerprint of their value today, to record in review.value so `blazon check` sees a later change").option("--json", "Print the list as JSON on standard output").action(async (e, t) => {
|
|
3771
4122
|
try {
|
|
3772
|
-
process.exitCode = await
|
|
4123
|
+
process.exitCode = await Si(e || process.cwd(), { json: t?.json });
|
|
3773
4124
|
} catch (e) {
|
|
3774
4125
|
P("approvals", e, n);
|
|
3775
4126
|
}
|
|
@@ -3780,72 +4131,72 @@ async function yo(e = process.argv) {
|
|
|
3780
4131
|
"digest",
|
|
3781
4132
|
"entry"
|
|
3782
4133
|
]) r?.[t] !== void 0 && N(`blazon plugin: --${t} is for \`blazon plugin pin\`; \`${e ?? "check"}\` does not take it.`, "conflicting-options", { fix: `Leave out --${t}, or use it with \`blazon plugin pin\`.` });
|
|
3783
|
-
e === "profile" && t !== void 0 && N("blazon plugin: `profile` takes no target.", "conflicting-options", { fix: "Run `blazon plugin profile` on its own." }), process.exitCode = await
|
|
4134
|
+
e === "profile" && t !== void 0 && N("blazon plugin: `profile` takes no target.", "conflicting-options", { fix: "Run `blazon plugin profile` on its own." }), process.exitCode = await yi(e, t, r);
|
|
3784
4135
|
} catch (e) {
|
|
3785
4136
|
P("plugin", e, n);
|
|
3786
4137
|
}
|
|
3787
4138
|
}), r.command("explain [code]", "Explain a finding code: its severity, what it means, the fix and where to read more; with no code, list every code").option("--json", "Print the explanation as JSON on standard output").action((e, t) => {
|
|
3788
4139
|
try {
|
|
3789
|
-
process.exitCode =
|
|
4140
|
+
process.exitCode = Eo(e, { json: t?.json });
|
|
3790
4141
|
} catch (e) {
|
|
3791
4142
|
P("explain", e, n);
|
|
3792
4143
|
}
|
|
3793
4144
|
}), r.command("pin [dir]", "Pin the blazon you build with: write blazon.lock with the commit of the blazon that runs this, so check, tokens and build refuse any other").option("--json", "Print the pinned commit as JSON on standard output").action((e, t) => {
|
|
3794
4145
|
try {
|
|
3795
|
-
process.exitCode =
|
|
4146
|
+
process.exitCode = bi(e || process.cwd(), { json: t?.json });
|
|
3796
4147
|
} catch (e) {
|
|
3797
4148
|
P("pin", e, n);
|
|
3798
4149
|
}
|
|
3799
4150
|
}), r.command("init [dir]", "Scaffold a new Blazon brand book and design token structure").option("--from <url>", "Start from a live site: read its stylesheets and page for the brand colors, fonts, logo and title (all marked needs-review)").option("--name <text>", "With `init`: the brand book title, as given").option("--description <text>", "With `init`: one sentence on the brand: the config description").option("--color <hex>", "With `init`: the primary color as hex, with or without the #: #2563eb, 2563eb or #26e").option("--font <family>", "With `init`: the font family, a Google Fonts name").option("--logo <file>", "With `init`: an SVG or PNG file to use as the logo").option("--dev", "With `init`: start `blazon dev` when it is done").option("--json", "Print what init made as JSON on standard output; everything else goes to standard error (never asks)").option("--yes", "With `init`: accept every default and never ask").option("--no-input", "With `init`: same as --yes; implied when stdin or stdout is not a terminal").action(async (e, t) => {
|
|
3800
4151
|
try {
|
|
3801
|
-
t?.json ? (t.dev && N("blazon init: --dev starts a server that never ends, so it cannot be used with --json.", "conflicting-options", { fix: "Leave out --dev, or leave out --json." }), process.exitCode = await
|
|
4152
|
+
t?.json ? (t.dev && N("blazon init: --dev starts a server that never ends, so it cannot be used with --json.", "conflicting-options", { fix: "Leave out --dev, or leave out --json." }), process.exitCode = await Mo(e || ".", t)) : process.exitCode = await ii(e || ".", { ...t });
|
|
3802
4153
|
} catch (e) {
|
|
3803
4154
|
P("init", e, n);
|
|
3804
4155
|
}
|
|
3805
4156
|
}), r.command("preview [dir]", "Preview the static production brand book build").option("-p, --port <port>", "Port number to listen on (default: the port in blazon.json, else 3000)").option("--strict-port", "Exit 2 when the port is in use, instead of taking the next free one").option("--host [address]", "Listen on this address, or on every network interface with no address (default: localhost only)").action(async (e, t) => {
|
|
3806
4157
|
try {
|
|
3807
|
-
await
|
|
4158
|
+
await ci(e || process.cwd(), Ro("preview", t?.port), {
|
|
3808
4159
|
strictPort: t?.strictPort,
|
|
3809
|
-
host:
|
|
4160
|
+
host: zo(t?.host)
|
|
3810
4161
|
});
|
|
3811
4162
|
} catch (e) {
|
|
3812
4163
|
P("preview", e, n);
|
|
3813
4164
|
}
|
|
3814
4165
|
}), r.command("doctor", "Check this machine and folder: Node version, brand folder, plugin folder safety, Chrome (if a plugin needs it) and blazon.lock; writes nothing").option("--json", "Print the checks as JSON on standard output").action(async (e) => {
|
|
3815
4166
|
try {
|
|
3816
|
-
process.exitCode = await
|
|
4167
|
+
process.exitCode = await xa(process.cwd(), { json: e?.json });
|
|
3817
4168
|
} catch (e) {
|
|
3818
4169
|
P("doctor", e, n);
|
|
3819
4170
|
}
|
|
3820
|
-
}), r.example(" $ blazon init my-brand"), r.example(" $ blazon check my-brand --json"), r.example(" $ blazon build my-brand"), r.example(" $ blazon list ./my-brand --type color"), r.example(" $ blazon get color.brand.primary my-brand --json"), r.example(" $ blazon can text.primary surface.canvas my-brand"), r.help((e) =>
|
|
4171
|
+
}), r.example(" $ blazon init my-brand"), r.example(" $ blazon check my-brand --json"), r.example(" $ blazon build my-brand"), r.example(" $ blazon list ./my-brand --type color"), r.example(" $ blazon get color.brand.primary my-brand --json"), r.example(" $ blazon can text.primary surface.canvas my-brand"), r.help((e) => Lo(e, r.matchedCommand?.name, r.args[0])), r.version(re), t.slice(2).length === 0) return r.outputHelp();
|
|
3821
4172
|
r.addEventListener("command:*", (e) => {
|
|
3822
4173
|
if (r.options.help || r.options.version) return;
|
|
3823
|
-
let t = String(e.detail), n =
|
|
4174
|
+
let t = String(e.detail), n = D(t, r.commands.map((e) => e.name).filter(Boolean));
|
|
3824
4175
|
N(`blazon: unknown command "${t}"${n ? `; did you mean "${n}"?` : "."} Run blazon --help for the commands.`, "unknown-command", { fix: n ? `Run blazon ${n}, or blazon --help for the commands.` : "Run blazon --help for the commands." });
|
|
3825
4176
|
});
|
|
3826
4177
|
try {
|
|
3827
|
-
r.parse(t, { run: !1 }),
|
|
4178
|
+
r.parse(t, { run: !1 }), Oo(r, t);
|
|
3828
4179
|
try {
|
|
3829
|
-
|
|
4180
|
+
wi(r.options.allowDir), Ci(r.options.cwd);
|
|
3830
4181
|
} catch (e) {
|
|
3831
4182
|
P(r.matchedCommand?.name ?? "", e, n);
|
|
3832
4183
|
}
|
|
3833
4184
|
await r.runMatchedCommand();
|
|
3834
4185
|
} catch (e) {
|
|
3835
|
-
if (!
|
|
4186
|
+
if (!yt(e)) return P("", e, n);
|
|
3836
4187
|
let t = r.matchedCommand?.name, i = t ? `blazon ${t}` : "blazon", [, a = "", o] = /^Unknown option `(-{1,2})([^`]+)`$/.exec(e.message) ?? [], s = n ? e.stack : void 0;
|
|
3837
4188
|
o !== void 0 && /^\d+$/.test(o) && (t === "dev" || t === "preview") && N(`blazon ${t}: the port must be a whole number from 1 to 65535, not "-${o}".`, "invalid-port", { fix: "Give a whole number from 1 to 65535." }), t === "get" && /^missing required args/i.test(e.message) && N("blazon get: give a token path, such as blazon get color.brand.primary; blazon list shows the token paths.", "missing-argument", {
|
|
3838
4189
|
stack: s,
|
|
3839
4190
|
fix: "Run blazon list to see the token paths."
|
|
3840
|
-
}), o === void 0 && N(`${i}: ${
|
|
4191
|
+
}), o === void 0 && N(`${i}: ${vt(e.message)}. Run ${i} --help for the options.`, "missing-argument", {
|
|
3841
4192
|
stack: s,
|
|
3842
4193
|
fix: `Run ${i} --help for the options.`
|
|
3843
4194
|
});
|
|
3844
|
-
let c = [...r.matchedCommand?.options ?? [], ...r.globalCommand.options].map((e) => e.name), l =
|
|
4195
|
+
let c = [...r.matchedCommand?.options ?? [], ...r.globalCommand.options].map((e) => e.name), l = D(o, c);
|
|
3845
4196
|
N(`${i}: unknown option "${a}${o}"${l ? `; did you mean "--${l}"?` : "."} Run ${i} --help for the options.`, "unknown-option", {
|
|
3846
4197
|
stack: s,
|
|
3847
4198
|
fix: l ? `Use --${l}, or run ${i} --help for the options.` : `Run ${i} --help for the options.`
|
|
3848
4199
|
});
|
|
3849
4200
|
}
|
|
3850
4201
|
}
|
|
3851
|
-
export {
|
|
4202
|
+
export { Wo as runCli };
|