@iksnerd/blazon 0.2.2 → 0.3.2
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/README.md +7 -6
- package/dist/chunks/{site-builder-CsBH_ocA.js → site-builder-NRN9UNyn.js} +2490 -2406
- package/dist/cli/commands/mcp-check.d.ts +3 -1
- package/dist/cli/commands/mcp-check.d.ts.map +1 -1
- package/dist/cli/commands/mcp.d.ts +2 -1
- package/dist/cli/commands/mcp.d.ts.map +1 -1
- package/dist/cli/index.js +1153 -1126
- package/dist/core/brand/export.d.ts +3 -1
- package/dist/core/brand/export.d.ts.map +1 -1
- package/dist/core/brand/schema.d.ts +21 -0
- package/dist/core/brand/schema.d.ts.map +1 -1
- package/dist/core/checker/catalogue.d.ts +8 -0
- package/dist/core/checker/catalogue.d.ts.map +1 -1
- package/dist/core/fonts.d.ts +10 -1
- package/dist/core/fonts.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/inputs.d.ts.map +1 -1
- package/dist/core/mcp-config.d.ts +12 -6
- package/dist/core/mcp-config.d.ts.map +1 -1
- package/dist/core/operations/list.d.ts.map +1 -1
- package/dist/index.js +32 -32
- package/dist/types/data.d.ts +10 -0
- package/dist/types/data.d.ts.map +1 -1
- package/dist/ui/assets/index-Biy1hkeq.css +2 -0
- package/dist/ui/assets/{index-CLKH0m9J.js → index-BpdgjM9E.js} +7 -0
- package/dist/ui/index.html +2 -2
- package/mcp/dist/index.js +22748 -0
- package/package.json +7 -4
- package/plugins/blazon.office-template/bin/blazon-blazon.office-template./360/237/224/214 +1 -1
- package/plugins/blazon.platform-tokens/README.md +58 -2
- package/plugins/blazon.platform-tokens/bin/blazon-blazon.platform-tokens./360/237/224/214 +57 -12
- package/plugins/blazon.press-kit/README.md +54 -3
- package/plugins/blazon.press-kit/bin/blazon-blazon.press-kit./360/237/224/214 +247 -49
- package/plugins/blazon.print-book/README.md +6 -0
- package/plugins/shipped.lock +4 -4
- package/template/AGENTS.md +1 -1
- package/template/docs/01-principles.md +1 -1
- package/dist/ui/assets/index-DluSqfla.css +0 -2
package/dist/cli/index.js
CHANGED
|
@@ -1,152 +1,152 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { spawn as
|
|
5
|
-
import
|
|
6
|
-
import { preview as
|
|
7
|
-
import { cac as
|
|
8
|
-
import * as
|
|
1
|
+
import { $t as e, A as t, At as n, Bt as r, C as i, Ct as a, D as o, Dn as s, Dt as c, E as l, Ft as u, G as d, It as f, Jt as p, K as m, M as h, Mt as g, Nt as _, O as v, On as y, Pt as b, Qt as x, R as S, Rt as ee, S as C, T as w, Tt as T, Ut as te, Vt as ne, W as re, Xt as ie, Zt as ae, _ as oe, _n as se, _t as ce, a as le, an as ue, b as de, bt as fe, c as pe, cn as me, d as he, dn as E, en as ge, f as _e, fn as ve, g as ye, gt as be, h as xe, hn as Se, ht as Ce, i as we, j as Te, jt as Ee, k as De, l as Oe, ln as ke, m as Ae, mn as je, mt as D, on as Me, p as Ne, pn as Pe, q as Fe, s as Ie, sn as Le, t as Re, tn as ze, u as Be, un as Ve, ut as He, v as Ue, vt as We, w as Ge, wt as Ke, x as qe, y as Je, yt as Ye, z as Xe, zt as Ze } from "../chunks/site-builder-NRN9UNyn.js";
|
|
2
|
+
import O from "node:path";
|
|
3
|
+
import k from "node:fs";
|
|
4
|
+
import { spawn as Qe } from "node:child_process";
|
|
5
|
+
import $e from "node:os";
|
|
6
|
+
import { preview as et } from "vite";
|
|
7
|
+
import { cac as tt } from "cac";
|
|
8
|
+
import * as A from "@clack/prompts";
|
|
9
9
|
// src/cli/errors.ts
|
|
10
|
-
var
|
|
10
|
+
var j = class extends Error {
|
|
11
11
|
fix;
|
|
12
12
|
code;
|
|
13
13
|
constructor(e, t, n = "error") {
|
|
14
14
|
super(e), this.fix = t, this.code = n;
|
|
15
15
|
}
|
|
16
|
-
},
|
|
17
|
-
function
|
|
16
|
+
}, M = class extends j {}, nt = (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"), rt = (e) => e.replace(/^./, (e) => e.toLowerCase()).replace(/\.$/, "");
|
|
17
|
+
function it(e, t, n) {
|
|
18
18
|
return `blazon${e ? ` ${e}` : ""}: ${t}${n ? `\n ${n}` : ""}`;
|
|
19
19
|
}
|
|
20
|
-
var
|
|
21
|
-
function
|
|
22
|
-
|
|
20
|
+
var at = (e, t) => t ? `${e}; ${rt(t)}` : e, ot;
|
|
21
|
+
function st(e) {
|
|
22
|
+
ot = e;
|
|
23
23
|
}
|
|
24
|
-
function
|
|
25
|
-
console.error(e.replace(/^blazon(?: [a-z]+)*:/, (e) =>
|
|
24
|
+
function ct(e) {
|
|
25
|
+
console.error(e.replace(/^blazon(?: [a-z]+)*:/, (e) => l.red(e)));
|
|
26
26
|
}
|
|
27
|
-
var
|
|
27
|
+
var lt = (e, t, n) => ({
|
|
28
28
|
code: e,
|
|
29
29
|
message: t,
|
|
30
30
|
...n !== void 0 && { fix: n }
|
|
31
31
|
});
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
command:
|
|
32
|
+
function ut(e, t, n) {
|
|
33
|
+
ot !== void 0 && process.stdout.write(`${JSON.stringify({
|
|
34
|
+
command: ot,
|
|
35
35
|
passed: !1,
|
|
36
|
-
error:
|
|
36
|
+
error: lt(e, t, n)
|
|
37
37
|
})}\n`);
|
|
38
38
|
}
|
|
39
|
-
function
|
|
40
|
-
return
|
|
39
|
+
function N(e, t, n = {}) {
|
|
40
|
+
return ct(e), n.stack && console.error(n.stack), ut(t, n.json ?? e.replace(/^blazon(?: [a-z]+)?: /, ""), n.fix), process.exit(2);
|
|
41
41
|
}
|
|
42
|
-
var
|
|
43
|
-
function
|
|
44
|
-
let
|
|
45
|
-
if (t instanceof
|
|
46
|
-
stack:
|
|
47
|
-
json:
|
|
48
|
-
fix:
|
|
42
|
+
var dt = (e) => e.replace(/`([^`]*)`/g, "\"$1\"").replace(/^./, (e) => e.toLowerCase()), ft = (e) => e instanceof Error && e.name === "CACError";
|
|
43
|
+
function P(e, t, n) {
|
|
44
|
+
let r = t instanceof j ? t.fix : void 0;
|
|
45
|
+
if (t instanceof M) return N(it(e, t.message, r), t.code, {
|
|
46
|
+
stack: n ? t.stack : void 0,
|
|
47
|
+
json: at(t.message, r),
|
|
48
|
+
fix: r
|
|
49
49
|
});
|
|
50
|
-
let
|
|
51
|
-
return console.error(),
|
|
50
|
+
let i = t instanceof Error ? t.message : String(t);
|
|
51
|
+
return console.error(), ct(it(e, i, r ?? (n || t instanceof j ? void 0 : l.dim("Run again with --debug for the stack.")))), n && t instanceof Error && t.stack && console.error(t.stack), ut(t instanceof j ? t.code : "error", at(i, r), r), process.exit(1);
|
|
52
52
|
}
|
|
53
53
|
// src/cli/where.ts
|
|
54
|
-
function
|
|
55
|
-
let n =
|
|
56
|
-
return n === "" ? "" : n.startsWith("..") ||
|
|
54
|
+
function F(e, t = process.cwd()) {
|
|
55
|
+
let n = O.relative(t, O.resolve(t, e));
|
|
56
|
+
return n === "" ? "" : n.startsWith("..") || O.isAbsolute(n) ? O.resolve(t, e) : n.split(O.sep).join("/");
|
|
57
57
|
}
|
|
58
|
-
var
|
|
59
|
-
function
|
|
60
|
-
if (!
|
|
58
|
+
var I = (e, t) => e ? `${e}/${t}` : t, pt = (e) => /^[\w./@%+=:,-]+$/.test(e) ? e : `'${e.replace(/'/g, "'\\''")}'`, L = (e, t) => `blazon ${e}${t ? ` ${pt(t)}` : ""}`, mt = (e) => k.statSync(e, { throwIfNoEntry: !1 })?.isDirectory() ?? !1, ht = (e) => `Run ${L("init", F(e))} to start a brand book there`;
|
|
59
|
+
function gt(e) {
|
|
60
|
+
if (!mt(e)) throw new M(`no folder "${e}"`, `${ht(e)}.`, "no-folder");
|
|
61
61
|
}
|
|
62
|
-
function
|
|
63
|
-
if (!
|
|
62
|
+
function _t(e, t) {
|
|
63
|
+
if (!mt(O.resolve(e, t))) throw new M(`no tokens folder (${t.replace(/^\.\//, "").replace(/\/$/, "")}) in "${e}"`, `${ht(e)}, or set tokensDir in blazon.json.`, "no-tokens-folder");
|
|
64
64
|
}
|
|
65
|
-
async function
|
|
66
|
-
|
|
67
|
-
let n = await
|
|
68
|
-
return
|
|
65
|
+
async function R(e, t) {
|
|
66
|
+
gt(e);
|
|
67
|
+
let n = await ae(e, t);
|
|
68
|
+
return _t(e, n.tokensDir), n;
|
|
69
69
|
}
|
|
70
70
|
// src/cli/commands/dev.ts
|
|
71
|
-
var
|
|
72
|
-
async function
|
|
73
|
-
let r = await
|
|
71
|
+
var vt = /* @__PURE__ */ y({ runDev: () => yt });
|
|
72
|
+
async function yt(e = process.cwd(), t, n = {}) {
|
|
73
|
+
let r = await R(e, t ? { port: t } : void 0);
|
|
74
74
|
try {
|
|
75
|
-
await
|
|
75
|
+
await we(r, e, n);
|
|
76
76
|
} catch (e) {
|
|
77
|
-
throw n.strictPort && e instanceof Error && /already in use/.test(e.message) ?
|
|
77
|
+
throw n.strictPort && e instanceof Error && /already in use/.test(e.message) ? nt(r.port) : e;
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
// src/cli/commands/check.ts
|
|
81
|
-
var
|
|
81
|
+
var bt = class extends j {
|
|
82
82
|
findings;
|
|
83
83
|
constructor(e, t, n, r = "check-failed") {
|
|
84
84
|
super(e, n, r), this.findings = t;
|
|
85
85
|
}
|
|
86
|
-
},
|
|
87
|
-
function
|
|
86
|
+
}, xt = (e) => e?.plugins === !1, St = (e) => e?.plugin === void 0 ? [] : [e.plugin].flat();
|
|
87
|
+
function Ct(e) {
|
|
88
88
|
return e.context ? `${e.path} (${e.context})` : e.path;
|
|
89
89
|
}
|
|
90
|
-
var
|
|
91
|
-
function
|
|
92
|
-
let t = e.slice(0,
|
|
93
|
-
return e.length >
|
|
94
|
-
}
|
|
95
|
-
var
|
|
96
|
-
function
|
|
97
|
-
let
|
|
98
|
-
for (let t of e) t.code === "starter-file-unchanged" &&
|
|
99
|
-
for (let
|
|
100
|
-
if (
|
|
101
|
-
let e =
|
|
102
|
-
if (
|
|
90
|
+
var wt = 5;
|
|
91
|
+
function Tt(e) {
|
|
92
|
+
let t = e.slice(0, wt).join(", ");
|
|
93
|
+
return e.length > wt ? `${t} and ${e.length - wt} more` : t;
|
|
94
|
+
}
|
|
95
|
+
var Et = (e) => e.path.split("/")[0];
|
|
96
|
+
function Dt(e, t) {
|
|
97
|
+
let n = [], r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), o = e.filter((e) => e.code === "page-review-pending");
|
|
98
|
+
for (let t of e) t.code === "starter-file-unchanged" && i.set(Et(t), [...i.get(Et(t)) ?? [], t]), t.code === "review-pending" && a.set(t.message, [...a.get(t.message) ?? [], t]);
|
|
99
|
+
for (let s of e) {
|
|
100
|
+
if (r.has(s)) continue;
|
|
101
|
+
let e = s.code === "starter-file-unchanged" ? i.get(Et(s)) : void 0, c = s.code === "review-pending" ? a.get(s.message) : void 0;
|
|
102
|
+
if (s.code === "page-review-pending" && o.length > 1) o.forEach((e) => r.add(e)), n.push(`${l.bold(`page-review-pending (${o.length} pages)`)}: ${Tt(o.map(Ct))}: show assets still marked needs-review ${l.dim("[page-review-pending]")}`);
|
|
103
103
|
else if (e && e.length > 1) {
|
|
104
|
-
e.forEach((e) =>
|
|
105
|
-
let t =
|
|
106
|
-
|
|
107
|
-
} else if (
|
|
104
|
+
e.forEach((e) => r.add(e));
|
|
105
|
+
let t = Et(s), i = e.map((e) => e.path.slice(t.length + 1));
|
|
106
|
+
n.push(`${l.bold(`${t}/`)}: ${e.length} files are still the starter's text (${Tt(i)}) ${l.dim("[starter-file-unchanged]")}`);
|
|
107
|
+
} else if (c && c.length > 1) c.forEach((e) => r.add(e)), n.push(`${l.bold(`review-pending (${c.length})`)}: ${Tt(c.map(Ct))}: ${s.message} ${l.dim("[review-pending]")}`);
|
|
108
108
|
else {
|
|
109
|
-
let e =
|
|
110
|
-
|
|
109
|
+
let e = ye(s, t), r = e === void 0 ? l.bold(Ct(s)) : s.path === s.file ? l.bold(e) : `${l.bold(e)} ${Ct(s)}`;
|
|
110
|
+
n.push(`${r}: ${s.message} ${l.dim(`[${s.code}]`)}`);
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
|
-
return
|
|
113
|
+
return n;
|
|
114
114
|
}
|
|
115
|
-
function
|
|
116
|
-
for (let
|
|
117
|
-
for (let
|
|
118
|
-
for (let
|
|
115
|
+
function Ot(e, t = "") {
|
|
116
|
+
for (let n of Dt(e.errors, t)) console.log(` ${l.bgRed(l.white(" ERROR "))} ${n}`);
|
|
117
|
+
for (let n of Dt(e.warnings, t)) console.log(` ${l.bgYellow(l.black(" WARN "))} ${n}`);
|
|
118
|
+
for (let n of Dt(e.infos, t)) console.log(` ${l.bgCyan(l.black(" NOTE "))} ${n}`);
|
|
119
119
|
}
|
|
120
|
-
var
|
|
121
|
-
function
|
|
122
|
-
e.infos.filter((e) => e.code === "starter-file-unchanged").length <
|
|
120
|
+
var kt = 5;
|
|
121
|
+
function At(e, t = "") {
|
|
122
|
+
e.infos.filter((e) => e.code === "starter-file-unchanged").length < kt || (console.log(l.bold("Next:")), console.log(` 1. Edit ${l.cyan(I(t, "tokens/colors.json"))} with your colors`), console.log(` 2. Run ${l.cyan(L("dev", t))} to see the book`), console.log(` 3. Replace blazon's artwork in ${l.cyan(I(t, "assets/"))} and the text in ${l.cyan(I(t, "docs/"))}`), console.log());
|
|
123
123
|
}
|
|
124
|
-
var
|
|
125
|
-
function
|
|
126
|
-
let
|
|
124
|
+
var jt = 3;
|
|
125
|
+
function Mt(e, t = "") {
|
|
126
|
+
let n = /* @__PURE__ */ new Map();
|
|
127
127
|
for (let t of e.errors) {
|
|
128
|
-
let e =
|
|
129
|
-
e && !
|
|
128
|
+
let e = Ue(t);
|
|
129
|
+
e && !n.has(`${t.code}\n${e}`) && n.set(`${t.code}\n${e}`, {
|
|
130
130
|
code: t.code,
|
|
131
131
|
fix: e
|
|
132
132
|
});
|
|
133
133
|
}
|
|
134
|
-
let
|
|
135
|
-
console.log(
|
|
134
|
+
let r = [...n.values()].slice(0, jt);
|
|
135
|
+
console.log(l.bold("Next:")), r.forEach(({ code: e, fix: t }, n) => console.log(` ${n + 1}. ${l.cyan(e)}: ${t}`)), console.log(` ${r.length + 1}. Run ${l.cyan(L("check", t))} again`), console.log();
|
|
136
136
|
}
|
|
137
|
-
function
|
|
138
|
-
let n =
|
|
137
|
+
function Nt(e, t = process.cwd()) {
|
|
138
|
+
let n = c(e.findings);
|
|
139
139
|
if (n.all.length === 0) return;
|
|
140
|
-
let r =
|
|
141
|
-
if (console.log(),
|
|
142
|
-
}
|
|
143
|
-
async function
|
|
144
|
-
let
|
|
145
|
-
console.log(
|
|
146
|
-
let a = await D(
|
|
147
|
-
a.findings.push(...
|
|
148
|
-
let o =
|
|
149
|
-
if (o.all.length === 0) return console.log(
|
|
140
|
+
let r = F(t);
|
|
141
|
+
if (console.log(), Ot(n, r), console.log(), n.errors.length > 0) throw new bt(`blazon check found ${n.errors.length} error(s)`, e.findings, `Fix them, or run ${L("check", r)} for details.`);
|
|
142
|
+
}
|
|
143
|
+
async function Pt(e = process.cwd(), t = !1, n) {
|
|
144
|
+
let r = await R(e);
|
|
145
|
+
console.log(l.cyan("\n[blazon] Checking design tokens..."));
|
|
146
|
+
let a = await D(r, e);
|
|
147
|
+
a.findings.push(...We(e)), xt(n) || await i(a, r, e, new Je(r, e, { named: St(n) }));
|
|
148
|
+
let o = c(a.findings, { strict: t });
|
|
149
|
+
if (o.all.length === 0) return console.log(l.green(`\n ✔ ${a.tokens.items.length} tokens, no findings.\n`)), {
|
|
150
150
|
findings: o.all,
|
|
151
151
|
passed: !0
|
|
152
152
|
};
|
|
@@ -154,88 +154,88 @@ async function kt(e = process.cwd(), t = !1, r) {
|
|
|
154
154
|
o.errors.length > 0 && `${o.errors.length} error(s)`,
|
|
155
155
|
o.warnings.length > 0 && `${o.warnings.length} warning(s)`,
|
|
156
156
|
o.infos.length > 0 && `${o.infos.length} note(s)`
|
|
157
|
-
].filter(Boolean),
|
|
158
|
-
return console.log(`\nFound ${
|
|
157
|
+
].filter(Boolean), u = o.errors.length + o.warnings.length > 0 ? `${o.errors.length} error(s) and ${o.warnings.length} warning(s)${o.infos.length > 0 ? ` and ${o.infos.length} note(s)` : ""}` : s.join(" and "), d = F(e);
|
|
158
|
+
return console.log(`\nFound ${u}:\n`), Ot(o, d), console.log(), o.errors.length > 0 ? Mt(o, d) : At(o, d), o.passed ? (console.log(o.warnings.length > 0 ? l.yellow("✔ Check passed with warnings.\n") : l.green("✔ Check passed.\n")), {
|
|
159
159
|
findings: o.all,
|
|
160
160
|
passed: !0
|
|
161
|
-
}) : (console.error(
|
|
161
|
+
}) : (console.error(l.red(`✖ Check failed${t ? " (--strict treats warnings as errors)" : ""}.\n`)), {
|
|
162
162
|
findings: o.all,
|
|
163
163
|
passed: !1
|
|
164
164
|
});
|
|
165
165
|
}
|
|
166
166
|
// src/cli/commands/build.ts
|
|
167
|
-
async function
|
|
168
|
-
let
|
|
169
|
-
a.findings.push(...
|
|
170
|
-
let o = new
|
|
171
|
-
|
|
172
|
-
let { siteOutDir: s } = await Re(
|
|
173
|
-
if (
|
|
174
|
-
let
|
|
175
|
-
if (console.log(),
|
|
176
|
-
return console.log(
|
|
167
|
+
async function Ft(e = process.cwd(), t, n) {
|
|
168
|
+
let r = await R(e, t ? { outDir: t } : void 0), a = await D(r, e);
|
|
169
|
+
a.findings.push(...We(e));
|
|
170
|
+
let o = new Je(r, e, { named: St(n) });
|
|
171
|
+
xt(n) || await i(a, r, e, o), Nt(a, e);
|
|
172
|
+
let { siteOutDir: s } = await Re(r, e, { data: a }), u = xt(n) ? [] : await C(a, r, e, o, s);
|
|
173
|
+
if (u.length === 0) return { findings: a.findings };
|
|
174
|
+
let d = c(u);
|
|
175
|
+
if (console.log(), Ot(d, F(e)), console.log(), d.errors.length > 0) throw new bt(`a build plugin reported ${d.errors.length} error(s)`, [...a.findings, ...u], "The site is built; the plugin's findings above say what to fix.", "plugin-failed");
|
|
176
|
+
return console.log(l.dim(" Build plugins finished.")), { findings: [...a.findings, ...u] };
|
|
177
177
|
}
|
|
178
178
|
// src/cli/commands/tokens.ts
|
|
179
|
-
async function
|
|
180
|
-
let
|
|
181
|
-
console.log(
|
|
182
|
-
let
|
|
183
|
-
|
|
184
|
-
let a = new
|
|
185
|
-
|
|
186
|
-
let o = await
|
|
179
|
+
async function It(e = process.cwd(), t) {
|
|
180
|
+
let n = await R(e);
|
|
181
|
+
console.log(l.cyan("\n[blazon] Compiling design tokens..."));
|
|
182
|
+
let r = await D(n, e);
|
|
183
|
+
r.findings.push(...We(e));
|
|
184
|
+
let a = new Je(n, e, { named: St(t) });
|
|
185
|
+
xt(t) || await i(r, n, e, a), Nt(r, e);
|
|
186
|
+
let o = await Ce(r, n, e);
|
|
187
187
|
for (let e of [
|
|
188
188
|
o.cssPath,
|
|
189
189
|
o.typographyPath,
|
|
190
190
|
o.tsPath,
|
|
191
191
|
o.jsonPath
|
|
192
|
-
]) e && console.log(` ${
|
|
192
|
+
]) e && console.log(` ${l.green("✔")} Emitted ${l.bold(e)}`);
|
|
193
193
|
console.log();
|
|
194
|
-
let s =
|
|
195
|
-
if (s.length === 0) return { findings:
|
|
196
|
-
let
|
|
197
|
-
if (
|
|
198
|
-
return { findings: [...
|
|
194
|
+
let s = xt(t) ? [] : await C(r, n, e, a);
|
|
195
|
+
if (s.length === 0) return { findings: r.findings };
|
|
196
|
+
let u = c(s);
|
|
197
|
+
if (Ot(u, F(e)), console.log(), u.errors.length > 0) throw new bt(`a build plugin reported ${u.errors.length} error(s)`, [...r.findings, ...s], "The token files are written; the plugin's findings above say what to fix.", "plugin-failed");
|
|
198
|
+
return { findings: [...r.findings, ...s] };
|
|
199
199
|
}
|
|
200
200
|
// src/core/drift/compare.ts
|
|
201
|
-
var
|
|
202
|
-
function
|
|
201
|
+
var Lt = /^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i, Rt = /^(-?(?:\d+\.?\d*|\.\d+))(px|rem)$/i, zt = (e) => e.trim().toLowerCase().replace(/\s+/g, " ");
|
|
202
|
+
function Bt(e) {
|
|
203
203
|
let t = e.trim();
|
|
204
|
-
if (!
|
|
204
|
+
if (!Lt.test(t)) return zt(t);
|
|
205
205
|
let n = t.slice(1).toLowerCase();
|
|
206
206
|
return `#${n.length <= 4 ? [...n].map((e) => e + e).join("") : n}`;
|
|
207
207
|
}
|
|
208
|
-
function
|
|
209
|
-
let t = e.trim().match(
|
|
210
|
-
return t ? `${Number(t[1])}${t[2].toLowerCase()}` :
|
|
208
|
+
function Vt(e) {
|
|
209
|
+
let t = e.trim().match(Rt);
|
|
210
|
+
return t ? `${Number(t[1])}${t[2].toLowerCase()}` : zt(e);
|
|
211
211
|
}
|
|
212
|
-
function
|
|
213
|
-
return e === "color" ?
|
|
212
|
+
function Ht(e, t) {
|
|
213
|
+
return e === "color" ? Bt(t) : e === "dimension" ? Vt(t) : zt(t);
|
|
214
214
|
}
|
|
215
|
-
var
|
|
216
|
-
function
|
|
215
|
+
var Ut = /\/\*[\s\S]*?\*\//g, Wt = /([^{}]*)\{([^{}]*)\}/g, Gt = /(--[A-Za-z0-9_-]+)\s*:\s*([^;]*?)\s*(?:;|$)/g, Kt = /(^|,)\s*(:root|html)\s*(,|$)/, qt = /^var\(\s*(--[A-Za-z0-9_-]+)\s*\)$/;
|
|
216
|
+
function Jt(e) {
|
|
217
217
|
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(
|
|
218
|
+
for (let r of e.replace(Ut, "").matchAll(Wt)) {
|
|
219
|
+
let e = Kt.test(r[1].trim()) ? t : n;
|
|
220
|
+
for (let t of r[2].matchAll(Gt)) e.set(t[1], t[2]);
|
|
221
221
|
}
|
|
222
222
|
let r = new Map([...n, ...t]);
|
|
223
223
|
for (let [e, t] of r) {
|
|
224
224
|
let n = t, i = /* @__PURE__ */ new Set([e]);
|
|
225
|
-
for (let e = n.match(
|
|
225
|
+
for (let e = n.match(qt); e && r.has(e[1]) && !i.has(e[1]); e = n.match(qt)) i.add(e[1]), n = r.get(e[1]);
|
|
226
226
|
r.set(e, n);
|
|
227
227
|
}
|
|
228
228
|
return r;
|
|
229
229
|
}
|
|
230
|
-
function
|
|
231
|
-
let r =
|
|
230
|
+
function Yt(e, t, n) {
|
|
231
|
+
let r = Ht(e.type, String(e.value)), i = n.get(t);
|
|
232
232
|
if (i === void 0) return {
|
|
233
233
|
path: e.path,
|
|
234
234
|
cssVar: t,
|
|
235
235
|
status: "missing",
|
|
236
236
|
expected: r
|
|
237
237
|
};
|
|
238
|
-
let a =
|
|
238
|
+
let a = Ht(e.type, i);
|
|
239
239
|
return {
|
|
240
240
|
path: e.path,
|
|
241
241
|
cssVar: t,
|
|
@@ -244,21 +244,21 @@ function Wt(e, t, n) {
|
|
|
244
244
|
actual: a
|
|
245
245
|
};
|
|
246
246
|
}
|
|
247
|
-
var
|
|
248
|
-
function
|
|
247
|
+
var Xt = 1e4;
|
|
248
|
+
function Zt(e) {
|
|
249
249
|
let t = e instanceof Error ? e.message : String(e), n = e instanceof Error ? e.cause : void 0;
|
|
250
250
|
return n instanceof Error && n.message && n.message !== t ? `${t}: ${n.message}` : t;
|
|
251
251
|
}
|
|
252
|
-
async function
|
|
252
|
+
async function Qt(e) {
|
|
253
253
|
let t;
|
|
254
254
|
try {
|
|
255
255
|
t = await fetch(e, {
|
|
256
|
-
signal: AbortSignal.timeout(
|
|
256
|
+
signal: AbortSignal.timeout(Xt),
|
|
257
257
|
redirect: "follow"
|
|
258
258
|
});
|
|
259
259
|
} catch (t) {
|
|
260
260
|
let n = t instanceof Error && (t.name === "TimeoutError" || t.name === "AbortError");
|
|
261
|
-
throw Error(`could not fetch ${e}: ${n ? `no answer in ${
|
|
261
|
+
throw Error(`could not fetch ${e}: ${n ? `no answer in ${Xt / 1e3} s` : Zt(t)}`, { cause: t });
|
|
262
262
|
}
|
|
263
263
|
if (!t.ok) throw Error(`could not fetch ${e}: ${t.status} ${t.statusText}`.trim());
|
|
264
264
|
let n = [], r = 0;
|
|
@@ -272,10 +272,10 @@ async function qt(e) {
|
|
|
272
272
|
}
|
|
273
273
|
return Buffer.concat(n);
|
|
274
274
|
}
|
|
275
|
-
async function
|
|
276
|
-
return (await
|
|
275
|
+
async function $t(e) {
|
|
276
|
+
return (await Qt(e)).toString("utf8");
|
|
277
277
|
}
|
|
278
|
-
function
|
|
278
|
+
function en(e, t) {
|
|
279
279
|
let n = [];
|
|
280
280
|
for (let [r] of e.replace(/<!--[\s\S]*?-->/g, "").matchAll(/<link\b[^>]*>/gi)) {
|
|
281
281
|
let e = (e) => r.match(RegExp(`\\s${e}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`, "i")), i = e("rel"), a = e("href");
|
|
@@ -286,19 +286,19 @@ function Yt(e, t) {
|
|
|
286
286
|
}
|
|
287
287
|
return n;
|
|
288
288
|
}
|
|
289
|
-
async function
|
|
289
|
+
async function tn(e) {
|
|
290
290
|
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(e)) {
|
|
291
291
|
if (!/^https?:\/\//i.test(e)) throw Error(`${e} is not an http(s) address or a file`);
|
|
292
|
-
let t =
|
|
292
|
+
let t = en(await $t(e), e).slice(0, 20);
|
|
293
293
|
return {
|
|
294
|
-
css: (await Promise.all(t.map(
|
|
294
|
+
css: (await Promise.all(t.map($t))).join("\n"),
|
|
295
295
|
sources: t
|
|
296
296
|
};
|
|
297
297
|
}
|
|
298
|
-
let t =
|
|
298
|
+
let t = O.resolve(e), n;
|
|
299
299
|
try {
|
|
300
|
-
if (
|
|
301
|
-
n =
|
|
300
|
+
if (k.statSync(t).size > 5242880) throw Error(`${t} is larger than 5 MB`);
|
|
301
|
+
n = k.readFileSync(t, "utf8");
|
|
302
302
|
} catch (e) {
|
|
303
303
|
throw Error(e instanceof Error && e.message.endsWith("5 MB") ? e.message : `could not read ${t}: ${e instanceof Error ? e.message : String(e)}`, { cause: e });
|
|
304
304
|
}
|
|
@@ -307,60 +307,60 @@ async function Xt(e) {
|
|
|
307
307
|
sources: [t]
|
|
308
308
|
};
|
|
309
309
|
}
|
|
310
|
-
async function
|
|
310
|
+
async function nn(e) {
|
|
311
311
|
if (!/^https?:\/\//i.test(e)) throw Error(`${e} is not an http(s) address`);
|
|
312
|
-
let t = await
|
|
312
|
+
let t = await $t(e), n = en(t, e).slice(0, 20);
|
|
313
313
|
return {
|
|
314
314
|
html: t,
|
|
315
|
-
css: (await Promise.all(n.map(
|
|
315
|
+
css: (await Promise.all(n.map($t))).join("\n"),
|
|
316
316
|
sources: n
|
|
317
317
|
};
|
|
318
318
|
}
|
|
319
319
|
// src/core/init/from-site/tree.ts
|
|
320
|
-
var
|
|
321
|
-
function
|
|
322
|
-
return JSON.parse(
|
|
320
|
+
var rn = (e) => typeof e == "object" && !!e && "$value" in e;
|
|
321
|
+
function an(e) {
|
|
322
|
+
return JSON.parse(k.readFileSync(e, "utf-8"));
|
|
323
323
|
}
|
|
324
|
-
function
|
|
325
|
-
|
|
324
|
+
function on(e, t) {
|
|
325
|
+
k.writeFileSync(e, `${JSON.stringify(t, null, 2)}\n`);
|
|
326
326
|
}
|
|
327
|
-
var
|
|
328
|
-
function
|
|
327
|
+
var sn = (e) => ({ "dev.blazon": e });
|
|
328
|
+
function cn(e, t = []) {
|
|
329
329
|
let n = [];
|
|
330
|
-
for (let [r, i] of Object.entries(e)) !r.startsWith("$") && typeof i == "object" && i && (
|
|
330
|
+
for (let [r, i] of Object.entries(e)) !r.startsWith("$") && typeof i == "object" && i && (rn(i) ? n.push([...t, r].join(".")) : n.push(...cn(i, [...t, r])));
|
|
331
331
|
return n;
|
|
332
332
|
}
|
|
333
|
-
var
|
|
333
|
+
var ln = (e, t) => {
|
|
334
334
|
let n = e;
|
|
335
335
|
for (let e of t.split(".")) {
|
|
336
336
|
if (typeof n != "object" || !n) return;
|
|
337
337
|
n = n[e];
|
|
338
338
|
}
|
|
339
|
-
return
|
|
340
|
-
},
|
|
341
|
-
function
|
|
342
|
-
return
|
|
343
|
-
let r =
|
|
344
|
-
return n.isDirectory() ?
|
|
339
|
+
return rn(n) ? n : void 0;
|
|
340
|
+
}, un = (e) => [...JSON.stringify(e).matchAll(/\{([A-Za-z0-9_.-]+)\}/g)].map((e) => e[1]);
|
|
341
|
+
function dn(e, t) {
|
|
342
|
+
return k.existsSync(e) ? k.readdirSync(e, { withFileTypes: !0 }).flatMap((n) => {
|
|
343
|
+
let r = O.join(e, n.name);
|
|
344
|
+
return n.isDirectory() ? dn(r, t) : t.some((e) => n.name.endsWith(e)) ? [r] : [];
|
|
345
345
|
}) : [];
|
|
346
346
|
}
|
|
347
|
-
function
|
|
347
|
+
function fn(e, t) {
|
|
348
348
|
let n = t.split("."), r = [e];
|
|
349
349
|
for (let e of n.slice(0, -1)) r.push(r.at(-1)[e]);
|
|
350
350
|
delete r.at(-1)[n.at(-1)];
|
|
351
351
|
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
352
|
}
|
|
353
353
|
// src/core/init/from-site/clean-colors.ts
|
|
354
|
-
function
|
|
354
|
+
function pn(e) {
|
|
355
355
|
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 =
|
|
356
|
+
let r = ln(t, `${e}.${n}`)?.$value, o = typeof r == "string" ? r.match(/^\{(.+)\}$/)?.[1] : void 0;
|
|
357
357
|
return o && i.has(o) && !a.has(o) ? o : void 0;
|
|
358
358
|
}, d = (e, n, r, i = {}) => {
|
|
359
|
-
let [a, c] = e.split("."), u =
|
|
359
|
+
let [a, c] = e.split("."), u = ln(t, e), d = String(u.$value);
|
|
360
360
|
t[a][c] = {
|
|
361
361
|
$value: `{${n}}`,
|
|
362
362
|
...typeof u.$description == "string" && { $description: u.$description },
|
|
363
|
-
$extensions:
|
|
363
|
+
$extensions: sn({
|
|
364
364
|
...i,
|
|
365
365
|
review: r ? {
|
|
366
366
|
...s,
|
|
@@ -391,20 +391,20 @@ function cn(e) {
|
|
|
391
391
|
let [n, r] = e.split("."), i = p(t);
|
|
392
392
|
i && u(n, r) && d(e, f(i), "", { source: c(`:root { ${i.cssVar} }`, i.exact ? i.cssVar : void 0) });
|
|
393
393
|
}
|
|
394
|
-
let m = t.color, { color: h, ...g } = t, _ = new Set(
|
|
395
|
-
for (let e of
|
|
396
|
-
let v = [
|
|
394
|
+
let m = t.color, { color: h, ...g } = t, _ = new Set(un(g));
|
|
395
|
+
for (let e of dn(O.join(n, "tokens"), [".json"])) if (O.basename(e) !== "colors.json") for (let t of un(an(e))) _.add(t);
|
|
396
|
+
let v = [O.join(n, "blazon.json"), ...dn(O.join(n, "docs"), [".md", ".mdx"])].filter((e) => k.existsSync(e)).map((e) => k.readFileSync(e, "utf-8")).join("\n");
|
|
397
397
|
for (let e of v.matchAll(/(?<![\w.-])color(?:\.[A-Za-z0-9_-]+)+/g)) _.add(e[0]);
|
|
398
398
|
let y = [..._];
|
|
399
399
|
for (; y.length > 0;) {
|
|
400
|
-
let e =
|
|
401
|
-
for (let t of e ?
|
|
400
|
+
let e = ln(t, y.pop());
|
|
401
|
+
for (let t of e ? un(e.$value) : []) _.has(t) || (_.add(t), y.push(t));
|
|
402
402
|
}
|
|
403
|
-
for (let e of [...i].filter((e) => !a.has(e) && !_.has(e)))
|
|
403
|
+
for (let e of [...i].filter((e) => !a.has(e) && !_.has(e))) ln({ color: m }, e) && (fn({ color: m }, e), l.removed.push(`${e} (a starter color nothing uses)`));
|
|
404
404
|
}
|
|
405
405
|
// src/core/init/palette.ts
|
|
406
|
-
var
|
|
407
|
-
function
|
|
406
|
+
var mn = "#ffffff", hn = "#0b1120";
|
|
407
|
+
function gn(e) {
|
|
408
408
|
let t = e.trim().match(/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i);
|
|
409
409
|
if (!t) return;
|
|
410
410
|
let n = t[1].length === 3 ? [...t[1]].map((e) => e + e).join("") : t[1];
|
|
@@ -414,38 +414,38 @@ function dn(e) {
|
|
|
414
414
|
4
|
|
415
415
|
].map((e) => parseInt(n.slice(e, e + 2), 16) / 255);
|
|
416
416
|
}
|
|
417
|
-
var
|
|
418
|
-
function
|
|
419
|
-
let t =
|
|
417
|
+
var _n = (e) => e <= .04045 ? e / 12.92 : ((e + .055) / 1.055) ** 2.4;
|
|
418
|
+
function vn(e) {
|
|
419
|
+
let t = gn(e);
|
|
420
420
|
if (!t) throw Error(`not a hex color: ${e}`);
|
|
421
421
|
return t;
|
|
422
422
|
}
|
|
423
|
-
function
|
|
424
|
-
let [t, n, r] =
|
|
423
|
+
function yn(e) {
|
|
424
|
+
let [t, n, r] = vn(e).map(_n);
|
|
425
425
|
return .2126 * t + .7152 * n + .0722 * r;
|
|
426
426
|
}
|
|
427
|
-
function
|
|
428
|
-
let [n, r] = [
|
|
427
|
+
function z(e, t) {
|
|
428
|
+
let [n, r] = [yn(e), yn(t)];
|
|
429
429
|
return (Math.max(n, r) + .05) / (Math.min(n, r) + .05);
|
|
430
430
|
}
|
|
431
|
-
var
|
|
432
|
-
function
|
|
433
|
-
let t =
|
|
431
|
+
var bn = (e) => e >= 7 ? "AAA" : e >= 4.5 ? "AA" : e >= 3 ? "AA-large" : "fail";
|
|
432
|
+
function xn(e) {
|
|
433
|
+
let t = z(e, mn), n = z(e, hn);
|
|
434
434
|
return {
|
|
435
435
|
onWhite: {
|
|
436
436
|
ratio: t,
|
|
437
|
-
level:
|
|
437
|
+
level: bn(t)
|
|
438
438
|
},
|
|
439
439
|
onNearBlack: {
|
|
440
440
|
ratio: n,
|
|
441
|
-
level:
|
|
441
|
+
level: bn(n)
|
|
442
442
|
},
|
|
443
443
|
carriesWhiteText: t >= 4.5
|
|
444
444
|
};
|
|
445
445
|
}
|
|
446
|
-
var
|
|
447
|
-
function
|
|
448
|
-
let t =
|
|
446
|
+
var Sn = "#1E1F21", Cn = "#F2F0EB";
|
|
447
|
+
function wn(e) {
|
|
448
|
+
let t = z(e, Sn), n = z(e, Cn);
|
|
449
449
|
return t >= n ? {
|
|
450
450
|
ink: "graphite",
|
|
451
451
|
ratio: t,
|
|
@@ -457,42 +457,42 @@ function yn(e) {
|
|
|
457
457
|
};
|
|
458
458
|
}
|
|
459
459
|
// src/core/init/vocabulary.ts
|
|
460
|
-
var
|
|
461
|
-
function
|
|
460
|
+
var Tn = "color.signal.orange", En = "color.signal.primary", Dn = "color.signal.hazard", On = (e) => typeof e == "object" && !!e && "$value" in e;
|
|
461
|
+
function B(e, t) {
|
|
462
462
|
let n = e;
|
|
463
463
|
for (let e of t.split(".")) {
|
|
464
464
|
if (typeof n != "object" || !n) return;
|
|
465
465
|
n = n[e];
|
|
466
466
|
}
|
|
467
|
-
return
|
|
467
|
+
return On(n) ? n : void 0;
|
|
468
468
|
}
|
|
469
|
-
function
|
|
469
|
+
function kn(e, t) {
|
|
470
470
|
let n = e.$extensions ??= {}, r = n["dev.blazon"] ??= {};
|
|
471
471
|
r.review === void 0 && (r.review = {
|
|
472
472
|
status: "needs-review",
|
|
473
473
|
note: t
|
|
474
474
|
});
|
|
475
475
|
}
|
|
476
|
-
function
|
|
476
|
+
function An(e, t) {
|
|
477
477
|
let n = [], r = e.color, i = r?.signal, a = i?.orange;
|
|
478
|
-
if (!i || !
|
|
478
|
+
if (!i || !On(a)) throw Error(`${Tn} is not in the tokens`);
|
|
479
479
|
let o = {};
|
|
480
480
|
for (let [e, t] of Object.entries(i)) o[e === "orange" ? "primary" : e] = t;
|
|
481
481
|
r.signal = o;
|
|
482
|
-
let s = JSON.parse(JSON.stringify(e).split(`{${
|
|
482
|
+
let s = JSON.parse(JSON.stringify(e).split(`{${Tn}}`).join(`{${En}}`));
|
|
483
483
|
for (let t of Object.keys(e)) e[t] = s[t];
|
|
484
|
-
let c =
|
|
484
|
+
let c = B(e, En);
|
|
485
485
|
c.$value = t, c.$description = "Primary signal color";
|
|
486
|
-
let l =
|
|
486
|
+
let l = jn(e, t, `{${En}}`);
|
|
487
487
|
n.push(...l.hints);
|
|
488
|
-
let u =
|
|
489
|
-
return u && (
|
|
488
|
+
let u = B(e, Dn);
|
|
489
|
+
return u && (kn(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(`${Dn} is still blazon's hazard yellow and is marked needs-review: set the brand's own or remove it`)), {
|
|
490
490
|
hints: n,
|
|
491
491
|
label: l.label
|
|
492
492
|
};
|
|
493
493
|
}
|
|
494
|
-
function
|
|
495
|
-
let i = [], a =
|
|
494
|
+
function jn(e, t, n, r = !1) {
|
|
495
|
+
let i = [], a = z(t, Sn), o = z(t, Cn), s = B(e, "text.onSignal"), c = a < 4.5 && o >= 4.5 && s !== void 0;
|
|
496
496
|
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
497
|
let t = e.text?.$extensions?.["dev.blazon"];
|
|
498
498
|
for (let e of t?.pairs ?? []) e.bg === "{color.signal.*}" && (e.bg = n);
|
|
@@ -502,16 +502,16 @@ function En(e, t, n, r = !1) {
|
|
|
502
502
|
label: c ? "bone" : "graphite"
|
|
503
503
|
};
|
|
504
504
|
}
|
|
505
|
-
var
|
|
506
|
-
function
|
|
505
|
+
var Mn = (e) => JSON.parse(k.readFileSync(e, "utf-8")), Nn = (e, t) => k.writeFileSync(e, `${JSON.stringify(t, null, 2)}\n`);
|
|
506
|
+
function Pn(e, t) {
|
|
507
507
|
return [...t, ...Array.isArray(e) ? e.filter((e) => typeof e == "object" && !!e) : []];
|
|
508
508
|
}
|
|
509
|
-
var
|
|
509
|
+
var Fn = ["blazon-graphite", "blazon-bone"], In = [...Fn, "blazon-mark"];
|
|
510
510
|
// src/core/init/shared/hex.ts
|
|
511
|
-
function
|
|
511
|
+
function Ln(e) {
|
|
512
512
|
let t = e.trim();
|
|
513
513
|
if (/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(t)) return {
|
|
514
|
-
hex:
|
|
514
|
+
hex: Bt(t),
|
|
515
515
|
exact: !0
|
|
516
516
|
};
|
|
517
517
|
let n = t.match(/^rgba?\(\s*([\d.]+)(%?)[\s,]+([\d.]+)%?[\s,]+([\d.]+)%?(?:\s*[,/]\s*([\d.]+)(%?))?\s*\)$/i);
|
|
@@ -527,12 +527,12 @@ function Mn(e) {
|
|
|
527
527
|
};
|
|
528
528
|
}
|
|
529
529
|
// src/core/init/from-site/colors.ts
|
|
530
|
-
var
|
|
531
|
-
function
|
|
530
|
+
var Rn = 40, zn = /brand|primary|secondary|accent|background|foreground|surface/i;
|
|
531
|
+
function Bn(e) {
|
|
532
532
|
let t = [], n = /* @__PURE__ */ new Set();
|
|
533
533
|
for (let [r, i] of e) {
|
|
534
|
-
if (!
|
|
535
|
-
let e =
|
|
534
|
+
if (!zn.test(r)) continue;
|
|
535
|
+
let e = Ln(i);
|
|
536
536
|
if (!e || e.hex.length !== 7) continue;
|
|
537
537
|
let a = r.slice(2).toLowerCase().split(/[-_]+/).filter(Boolean);
|
|
538
538
|
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 +541,20 @@ function Fn(e) {
|
|
|
541
541
|
segments: a
|
|
542
542
|
}));
|
|
543
543
|
}
|
|
544
|
-
return t.slice(0,
|
|
544
|
+
return t.slice(0, Rn);
|
|
545
545
|
}
|
|
546
|
-
function
|
|
546
|
+
function Vn(e, t, n = []) {
|
|
547
547
|
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
548
|
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
549
|
}
|
|
550
550
|
// src/core/init/from-site/context.ts
|
|
551
|
-
var
|
|
551
|
+
var Hn = (...e) => e.join("/");
|
|
552
552
|
// 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 =
|
|
553
|
+
function Un(e, t) {
|
|
554
|
+
let { destDir: n, vars: r, result: i, note: a, review: o, source: s, mayChange: c } = e, l = Bn(r).filter((e) => !t?.has(e.cssVar));
|
|
555
555
|
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 =
|
|
556
|
+
else if (c(Hn("tokens", "colors.json"))) {
|
|
557
|
+
let e = O.join(n, "tokens", "colors.json"), t = an(e), r = t.color ??= {}, c = new Set(cn(r, ["color"])), u = /* @__PURE__ */ new Set(), d = new Set(l.map((e) => e.segments.join(".")));
|
|
558
558
|
for (let e of l) {
|
|
559
559
|
let t = e.segments;
|
|
560
560
|
[...d].some((e) => e.startsWith(`${t.join(".")}.`)) && (t = [...t, "base"]);
|
|
@@ -563,37 +563,37 @@ function Rn(e, t) {
|
|
|
563
563
|
let t = n[r];
|
|
564
564
|
if (t === void 0) {
|
|
565
565
|
let t = {};
|
|
566
|
-
e === 0 && (t.$extensions =
|
|
567
|
-
} else if (
|
|
566
|
+
e === 0 && (t.$extensions = sn({ review: o }), a = !0), n[r] = t, n = t;
|
|
567
|
+
} else if (rn(t) || typeof t != "object" || !t) {
|
|
568
568
|
c = !1;
|
|
569
569
|
break;
|
|
570
570
|
} else n = t;
|
|
571
571
|
}
|
|
572
572
|
let l = t.at(-1);
|
|
573
|
-
!c || typeof n[l] == "object" && n[l] !== null && !
|
|
573
|
+
!c || typeof n[l] == "object" && n[l] !== null && !rn(n[l]) ? i.missing.push(`${e.cssVar} was not written: color.${t.join(".")} clashes with a starter token`) : (n[l] = {
|
|
574
574
|
$value: e.hex,
|
|
575
|
-
$extensions:
|
|
575
|
+
$extensions: sn({
|
|
576
576
|
source: s(`:root { ${e.cssVar} }`, e.exact ? e.cssVar : void 0),
|
|
577
577
|
...a ? {} : { review: o }
|
|
578
578
|
})
|
|
579
579
|
}, e.segments = t, u.add(e));
|
|
580
580
|
}
|
|
581
|
-
let f = new Set([...u].map((e) => `color.${e.segments.join(".")}`)), p =
|
|
581
|
+
let f = new Set([...u].map((e) => `color.${e.segments.join(".")}`)), p = Vn(l, "primary"), m = t.interactive, h = ln(t, "interactive.primary");
|
|
582
582
|
if (!p) i.missing.push("no primary color: interactive.primary keeps the starter's value");
|
|
583
583
|
else if (m && h) {
|
|
584
584
|
let e = `color.${p.segments.join(".")}`;
|
|
585
585
|
m.primary = {
|
|
586
586
|
$value: `{${e}}`,
|
|
587
587
|
...typeof h.$description == "string" && { $description: h.$description },
|
|
588
|
-
$extensions:
|
|
588
|
+
$extensions: sn({
|
|
589
589
|
source: s(`:root { ${p.cssVar} }`, p.exact ? p.cssVar : void 0),
|
|
590
590
|
review: o
|
|
591
591
|
})
|
|
592
592
|
}, i.repointed.push(`interactive.primary to {${e}}`);
|
|
593
|
-
let n =
|
|
593
|
+
let n = jn(t, p.hex, `{${e}}`, !0);
|
|
594
594
|
for (let e of n.hints) i.missing.push(e);
|
|
595
595
|
} else i.missing.push("interactive.primary was not found in tokens/colors.json, so the primary color was not set");
|
|
596
|
-
|
|
596
|
+
pn({
|
|
597
597
|
tree: t,
|
|
598
598
|
destDir: n,
|
|
599
599
|
picks: [...u],
|
|
@@ -603,53 +603,53 @@ function Rn(e, t) {
|
|
|
603
603
|
review: o,
|
|
604
604
|
source: s,
|
|
605
605
|
result: i
|
|
606
|
-
}),
|
|
606
|
+
}), on(e, t), i.written.push(Hn("tokens", "colors.json"));
|
|
607
607
|
}
|
|
608
608
|
}
|
|
609
609
|
// src/core/init/from-site/html.ts
|
|
610
|
-
function
|
|
610
|
+
function Wn(e) {
|
|
611
611
|
return e.replace(/&/g, "&").replace(/"/g, "\"").replace(/�?39;|'/g, "'").replace(/</g, "<").replace(/>/g, ">").replace(/ /g, " ").replace(/\s+/g, " ").trim().split(/ [|:–—-] /)[0].trim();
|
|
612
612
|
}
|
|
613
|
-
var
|
|
613
|
+
var V = (e, t) => {
|
|
614
614
|
let n = e.match(RegExp(`\\s${t}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`, "i"));
|
|
615
615
|
return n ? n[1] ?? n[2] ?? n[3] : void 0;
|
|
616
616
|
};
|
|
617
|
-
function
|
|
618
|
-
for (let n of e.match(/<meta\b[^>]*>/gi) ?? []) if ((
|
|
619
|
-
let e =
|
|
617
|
+
function H(e, t) {
|
|
618
|
+
for (let n of e.match(/<meta\b[^>]*>/gi) ?? []) if ((V(n, "property") ?? V(n, "name"))?.toLowerCase() === t) {
|
|
619
|
+
let e = V(n, "content")?.replace(/&/g, "&").trim();
|
|
620
620
|
if (e) return e;
|
|
621
621
|
}
|
|
622
622
|
}
|
|
623
|
-
function
|
|
624
|
-
let t =
|
|
623
|
+
function Gn(e) {
|
|
624
|
+
let t = H(e, "og:site_name") ?? H(e, "application-name");
|
|
625
625
|
if (t) return t;
|
|
626
626
|
let n = e.match(/<title\b[^>]*>([\s\S]*?)<\/title>/i);
|
|
627
|
-
return (n ?
|
|
627
|
+
return (n ? Wn(n[1]) : "") || void 0;
|
|
628
628
|
}
|
|
629
|
-
async function
|
|
630
|
-
let n = (e.match(/<link\b[^>]*>/gi) ?? []).find((e) =>
|
|
629
|
+
async function Kn(e, t) {
|
|
630
|
+
let n = (e.match(/<link\b[^>]*>/gi) ?? []).find((e) => V(e, "rel")?.toLowerCase() === "manifest"), r = n && V(n, "href");
|
|
631
631
|
if (r) try {
|
|
632
632
|
let e = new URL(r, t);
|
|
633
633
|
if (e.protocol !== "http:" && e.protocol !== "https:") return;
|
|
634
|
-
let n = JSON.parse(await
|
|
634
|
+
let n = JSON.parse(await $t(e.href)), i = typeof n.short_name == "string" ? n.short_name.trim() : "", a = typeof n.name == "string" ? Wn(n.name) : "";
|
|
635
635
|
return i || a || void 0;
|
|
636
636
|
} catch {
|
|
637
637
|
return;
|
|
638
638
|
}
|
|
639
639
|
}
|
|
640
640
|
// 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 =
|
|
641
|
+
async function qn(e, t, n) {
|
|
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 Kn(a.html, i) ?? Gn(a.html), d = H(a.html, "description");
|
|
643
643
|
u || o.missing.push("no <title> on the page: the config title keeps the folder name");
|
|
644
644
|
let f = !1;
|
|
645
645
|
if ((u || d || t.single || t.onLight || c.length > 0) && s(l)) {
|
|
646
|
-
let e =
|
|
646
|
+
let e = O.join(r, l), n = Mn(e);
|
|
647
647
|
u && (n.title = u), d && (n.description = d);
|
|
648
648
|
let i = t.single ?? (t.onLight ? {
|
|
649
649
|
onLight: t.onLight,
|
|
650
650
|
...t.onDark ? { onDark: t.onDark } : {}
|
|
651
651
|
} : void 0);
|
|
652
|
-
i && (n.logo = i), c.length > 0 && (n.fonts =
|
|
652
|
+
i && (n.logo = i), c.length > 0 && (n.fonts = Pn(n.fonts, c)), Nn(e, n), o.written.push(l), f = !!i;
|
|
653
653
|
}
|
|
654
654
|
return {
|
|
655
655
|
title: u,
|
|
@@ -658,23 +658,23 @@ async function Hn(e, t, n) {
|
|
|
658
658
|
};
|
|
659
659
|
}
|
|
660
660
|
// src/core/init/from-site/sections/directives.ts
|
|
661
|
-
var
|
|
662
|
-
function
|
|
663
|
-
let { destDir:
|
|
664
|
-
if (!
|
|
665
|
-
let
|
|
666
|
-
for (let e of
|
|
661
|
+
var Jn = /^[ \t]*<!--\s*blazon:tokens\b([^>]*?)-->[ \t]*\r?\n?/gm;
|
|
662
|
+
function Yn(e) {
|
|
663
|
+
let { destDir: t, created: n, result: r } = e, i = O.join(t, "docs");
|
|
664
|
+
if (!k.existsSync(i)) return;
|
|
665
|
+
let a = te(ie(O.join(t, "tokens"), t), "--").items, o = (e) => a.some((t) => t.path === e || t.path.startsWith(`${e}.`));
|
|
666
|
+
for (let e of k.readdirSync(i).filter((e) => e.endsWith(".md"))) {
|
|
667
667
|
let t = `docs/${e}`;
|
|
668
|
-
if (!
|
|
669
|
-
let
|
|
670
|
-
let n = t.split(/\s+/).filter(Boolean), r = n.filter(
|
|
671
|
-
return c.push(...n.filter((e) => !
|
|
668
|
+
if (!n.has(t)) continue;
|
|
669
|
+
let a = O.join(i, e), s = k.readFileSync(a, "utf-8"), c = [], l = s.replace(Jn, (e, t) => {
|
|
670
|
+
let n = t.split(/\s+/).filter(Boolean), r = n.filter(o);
|
|
671
|
+
return c.push(...n.filter((e) => !o(e))), r.length === n.length ? e : r.length === 0 ? "" : `<!-- blazon:tokens ${r.join(" ")} -->\n`;
|
|
672
672
|
}).replace(/\n{3,}/g, "\n\n");
|
|
673
|
-
l !==
|
|
673
|
+
l !== s && (k.writeFileSync(a, l), r.removed.push(`${c.join(", ")} in ${t} (the site has no such token to show)`));
|
|
674
674
|
}
|
|
675
675
|
}
|
|
676
676
|
// src/core/init/shared/google-fonts.ts
|
|
677
|
-
var
|
|
677
|
+
var Xn = [
|
|
678
678
|
"Inter",
|
|
679
679
|
"Roboto",
|
|
680
680
|
"Open Sans",
|
|
@@ -692,12 +692,12 @@ var Gn = [
|
|
|
692
692
|
"Playfair Display",
|
|
693
693
|
"JetBrains Mono"
|
|
694
694
|
];
|
|
695
|
-
function
|
|
696
|
-
let t =
|
|
695
|
+
function Zn(e) {
|
|
696
|
+
let t = Xn.find((t) => t.toLowerCase() === e.toLowerCase());
|
|
697
697
|
return t ? `https://fonts.googleapis.com/css2?family=${t.replace(/ /g, "+")}:wght@400;500;600;700&display=swap` : void 0;
|
|
698
698
|
}
|
|
699
699
|
// src/core/init/from-site/fonts.ts
|
|
700
|
-
var
|
|
700
|
+
var Qn = /* @__PURE__ */ new Set([
|
|
701
701
|
"serif",
|
|
702
702
|
"sans-serif",
|
|
703
703
|
"monospace",
|
|
@@ -717,19 +717,19 @@ var qn = /* @__PURE__ */ new Set([
|
|
|
717
717
|
"-apple-system",
|
|
718
718
|
"blinkmacsystemfont",
|
|
719
719
|
"segoe ui"
|
|
720
|
-
]),
|
|
720
|
+
]), $n = /* @__PURE__ */ new Set([
|
|
721
721
|
"serif",
|
|
722
722
|
"sans-serif",
|
|
723
723
|
"monospace",
|
|
724
724
|
"cursive",
|
|
725
725
|
"fantasy"
|
|
726
726
|
]);
|
|
727
|
-
function
|
|
727
|
+
function er(e) {
|
|
728
728
|
let t = [], n = "", r = "";
|
|
729
729
|
for (let i of e) r ? i === r ? r = "" : n += i : i === "\"" || i === "'" ? r = i : i === "," ? (t.push(n.trim()), n = "") : n += i;
|
|
730
730
|
return t.push(n.trim()), t.filter(Boolean);
|
|
731
731
|
}
|
|
732
|
-
function
|
|
732
|
+
function tr(e, t, n) {
|
|
733
733
|
let r;
|
|
734
734
|
for (let i of e.replace(/\/\*[\s\S]*?\*\//g, "").matchAll(/([^{}]*)\{([^{}]*)\}/g)) {
|
|
735
735
|
let e = i[1].split(",").map((e) => e.trim().toLowerCase()).find((e) => n.test(e));
|
|
@@ -741,7 +741,7 @@ function Xn(e, t, n) {
|
|
|
741
741
|
let e = t.get(c[1]);
|
|
742
742
|
o = e ?? c[2] ?? "", e !== void 0 && (s = c[1]);
|
|
743
743
|
}
|
|
744
|
-
let l =
|
|
744
|
+
let l = er(o), u = l.find((e) => !Qn.has(e.toLowerCase()) && !e.startsWith("var("));
|
|
745
745
|
u && (r = {
|
|
746
746
|
family: u,
|
|
747
747
|
stack: l,
|
|
@@ -751,21 +751,21 @@ function Xn(e, t, n) {
|
|
|
751
751
|
}
|
|
752
752
|
return r;
|
|
753
753
|
}
|
|
754
|
-
function
|
|
755
|
-
let t = e.stack.find((e) =>
|
|
754
|
+
function nr(e) {
|
|
755
|
+
let t = e.stack.find((e) => $n.has(e.toLowerCase()));
|
|
756
756
|
return [e.family, (t ?? "sans-serif").toLowerCase()];
|
|
757
757
|
}
|
|
758
758
|
// 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 =
|
|
759
|
+
function rr(e) {
|
|
760
|
+
let { destDir: t, page: n, vars: r, result: i, note: a, review: o, source: s, mayChange: c } = e, l = tr(n.css, r, /^(body|html)$/), u = tr(n.css, r, /^h[1-6]$/), d = [];
|
|
761
761
|
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 =
|
|
762
|
+
else if (c(Hn("tokens", "typography.json"))) {
|
|
763
|
+
let e = O.join(t, "tokens", "typography.json"), n = an(e), r = (n.font ??= {}).family ??= {}, c = l ?? u, f = [["body", c], ["display", u ?? c]];
|
|
764
764
|
for (let [e, t] of f) {
|
|
765
|
-
let n =
|
|
765
|
+
let n = Zn(t.family);
|
|
766
766
|
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:
|
|
767
|
+
$value: nr(t),
|
|
768
|
+
$extensions: sn({
|
|
769
769
|
source: s(t.cssVar ? `${t.locator}, from ${t.cssVar}` : t.locator),
|
|
770
770
|
review: n ? o : {
|
|
771
771
|
status: "needs-review",
|
|
@@ -775,25 +775,25 @@ function Qn(e) {
|
|
|
775
775
|
};
|
|
776
776
|
}
|
|
777
777
|
let p = r.mono;
|
|
778
|
-
p &&
|
|
778
|
+
p && kn(p, `${a} Still blazon's mono font: the site's stylesheets named no monospace font. Set the brand's own.`), on(e, n), i.written.push(Hn("tokens", "typography.json"));
|
|
779
779
|
}
|
|
780
780
|
return { fontUrls: d };
|
|
781
781
|
}
|
|
782
782
|
// src/core/init/from-site/sections/intro.ts
|
|
783
|
-
var
|
|
784
|
-
function
|
|
783
|
+
var ir = (e) => e.length === 1 && e[0] === "logo", ar = (e) => e.length < 2 ? e.join("") : `${e.slice(0, -1).join(", ")} and ${e[e.length - 1]}`;
|
|
784
|
+
function or(e) {
|
|
785
785
|
let { url: t, date: n, result: r } = e, i = {
|
|
786
786
|
colors: r.written.includes("tokens/colors.json"),
|
|
787
787
|
fonts: r.written.includes("tokens/typography.json"),
|
|
788
788
|
logo: r.written.some((e) => e.startsWith("assets/logos/"))
|
|
789
789
|
}, a = Object.entries(i).filter(([, e]) => e).map(([e]) => e), o = Object.entries(i).filter(([, e]) => !e).map(([e]) => e);
|
|
790
790
|
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 ${
|
|
791
|
+
let s = `The ${ar(a)} in this brand book ${ir(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.`;
|
|
792
|
+
return o.length === 0 ? s : `${s} The ${ar(o)} ${ir(o) ? "was" : "were"} not found, so ${ir(o) ? "it is" : "they are"} still blazon's own starter: replace ${ir(o) ? "it" : "them"}.`;
|
|
793
793
|
}
|
|
794
|
-
function
|
|
794
|
+
function sr(e, t, n) {
|
|
795
795
|
let { destDir: r, url: i, created: a, result: o } = e, s = "docs/01-principles.md";
|
|
796
|
-
if (a.has(s) &&
|
|
796
|
+
if (a.has(s) && k.existsSync(O.join(r, s))) {
|
|
797
797
|
let a = t ?? new URL(i).hostname.replace(/^www\./, ""), c = [
|
|
798
798
|
"---",
|
|
799
799
|
"title: Introduction",
|
|
@@ -806,24 +806,24 @@ function nr(e, t, n) {
|
|
|
806
806
|
`# ${a}`,
|
|
807
807
|
"",
|
|
808
808
|
...n ? [n, ""] : [],
|
|
809
|
-
|
|
809
|
+
or(e),
|
|
810
810
|
""
|
|
811
811
|
];
|
|
812
|
-
|
|
812
|
+
k.writeFileSync(O.join(r, s), c.join("\n")), o.written.push(s);
|
|
813
813
|
}
|
|
814
814
|
}
|
|
815
815
|
// src/core/init/shared/svg.ts
|
|
816
|
-
function
|
|
816
|
+
function cr(e) {
|
|
817
817
|
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
818
|
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
819
|
}
|
|
820
820
|
// src/core/init/from-site/logo.ts
|
|
821
|
-
function
|
|
821
|
+
function lr(e, t) {
|
|
822
822
|
let n = e.replace(/<!--[\s\S]*?-->/g, "").match(/<header\b[^>]*>([\s\S]*?)<\/header>/i)?.[1];
|
|
823
823
|
if (!n) return;
|
|
824
824
|
let r = [];
|
|
825
825
|
for (let e of n.matchAll(/<a\b([^>]*)>([\s\S]*?)<\/a>/gi)) {
|
|
826
|
-
let n =
|
|
826
|
+
let n = V(`<a${e[1]}>`, "href");
|
|
827
827
|
if (n !== void 0) try {
|
|
828
828
|
let i = new URL(n.trim(), t);
|
|
829
829
|
i.origin === new URL(t).origin && i.pathname === "/" && r.push(e[2]);
|
|
@@ -831,7 +831,7 @@ function ir(e, t) {
|
|
|
831
831
|
}
|
|
832
832
|
let i = (e) => e.match(/<svg\b[\s\S]*?<\/svg>/i)?.[0], a = (e) => {
|
|
833
833
|
for (let n of e.matchAll(/<img\b[^>]*>/gi)) {
|
|
834
|
-
let e =
|
|
834
|
+
let e = V(n[0], "src");
|
|
835
835
|
if (e && /\.svg(?:[?#]|$)/i.test(e)) try {
|
|
836
836
|
let n = new URL(e.trim(), t);
|
|
837
837
|
if (n.protocol === "http:" || n.protocol === "https:") return n.href;
|
|
@@ -867,16 +867,16 @@ function ir(e, t) {
|
|
|
867
867
|
locator: "header img"
|
|
868
868
|
} : void 0;
|
|
869
869
|
}
|
|
870
|
-
function
|
|
870
|
+
function ur(e, t) {
|
|
871
871
|
let n = [];
|
|
872
872
|
for (let [r] of e.replace(/<!--[\s\S]*?-->/g, "").matchAll(/<link\b[^>]*>/gi)) {
|
|
873
|
-
let e = (
|
|
873
|
+
let e = (V(r, "rel") ?? "").toLowerCase().split(/\s+/), i = e.includes("apple-touch-icon") || e.includes("apple-touch-icon-precomposed");
|
|
874
874
|
if (!i && !e.includes("icon")) continue;
|
|
875
|
-
let a =
|
|
875
|
+
let a = V(r, "href");
|
|
876
876
|
if (a) try {
|
|
877
877
|
let o = new URL(a.trim(), t);
|
|
878
878
|
if (o.protocol !== "http:" && o.protocol !== "https:") continue;
|
|
879
|
-
let s =
|
|
879
|
+
let s = O.extname(o.pathname).toLowerCase() || (V(r, "type") === "image/svg+xml" ? ".svg" : ".png");
|
|
880
880
|
n.push({
|
|
881
881
|
url: o.href,
|
|
882
882
|
svg: s === ".svg",
|
|
@@ -888,14 +888,14 @@ function ar(e, t) {
|
|
|
888
888
|
}
|
|
889
889
|
return n.find((e) => e.svg) ?? n.find((e) => e.apple) ?? n[0];
|
|
890
890
|
}
|
|
891
|
-
function
|
|
891
|
+
function dr(e) {
|
|
892
892
|
let t = new URL(e).hostname.replace(/^www\./, "");
|
|
893
893
|
return /^[\d.]+$/.test(t) || t.includes(":") || t.startsWith("[") ? "site" : t.split(".")[0].replace(/[^a-z0-9-]/gi, "-").toLowerCase() || "site";
|
|
894
894
|
}
|
|
895
895
|
// 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
|
-
|
|
896
|
+
async function fr(e) {
|
|
897
|
+
let { destDir: t, url: n, date: r, page: i, result: a, note: o, review: s } = e, c = {}, l = dr(n), u = (e, i, c) => {
|
|
898
|
+
on(O.join(t, e.replace(/\.[a-z]+$/, ".json")), {
|
|
899
899
|
description: o,
|
|
900
900
|
...c,
|
|
901
901
|
source: {
|
|
@@ -905,26 +905,26 @@ async function sr(e) {
|
|
|
905
905
|
review: s
|
|
906
906
|
}), a.written.push(e.replace(/\.[a-z]+$/, ".json"));
|
|
907
907
|
}, d = (e, n) => {
|
|
908
|
-
let r =
|
|
909
|
-
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) : (
|
|
910
|
-
}, f =
|
|
908
|
+
let r = O.join(t, e), i = [e, e.replace(/\.[a-z]+$/, ".json")].filter((e) => k.existsSync(O.join(t, e)));
|
|
909
|
+
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 = lr(i.html, n), p, m = "";
|
|
911
911
|
if (f?.kind === "inline") p = f.svg, m = f.locator;
|
|
912
912
|
else if (f?.kind === "url") {
|
|
913
913
|
try {
|
|
914
|
-
p = (await
|
|
914
|
+
p = (await Qt(f.url)).toString("utf8"), m = `${f.locator} (${f.url})`;
|
|
915
915
|
} catch (e) {
|
|
916
916
|
a.missing.push(`the header logo could not be read: ${e instanceof Error ? e.message : String(e)}`);
|
|
917
917
|
}
|
|
918
918
|
p !== void 0 && !/<svg\b/i.test(p) && (p = void 0, a.missing.push(`${f.url} is not an SVG`));
|
|
919
919
|
}
|
|
920
920
|
let h;
|
|
921
|
-
if (p === void 0 && (h =
|
|
922
|
-
p = (await
|
|
921
|
+
if (p === void 0 && (h = ur(i.html, n), h?.svg)) try {
|
|
922
|
+
p = (await Qt(h.url)).toString("utf8"), m = `${h.locator} (${h.url})`, /<svg\b/i.test(p) || (p = void 0);
|
|
923
923
|
} catch (e) {
|
|
924
924
|
a.missing.push(`the icon could not be read: ${e instanceof Error ? e.message : String(e)}`);
|
|
925
925
|
}
|
|
926
926
|
if (p !== void 0) {
|
|
927
|
-
let e =
|
|
927
|
+
let e = cr(p);
|
|
928
928
|
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
929
|
let t = `assets/logos/${l}.svg`, n = `assets/logos/${l}-white.svg`;
|
|
930
930
|
d(t, e.replace(/currentColor/gi, "#111111")) && (u(t, m, {
|
|
@@ -951,7 +951,7 @@ async function sr(e) {
|
|
|
951
951
|
].includes(h.ext)) a.missing.push(`only a ${h.ext} icon was found (${h.url}), which blazon cannot show: no logo was written`);
|
|
952
952
|
else try {
|
|
953
953
|
let e = `assets/logos/${l}${h.ext === ".jpeg" ? ".jpg" : h.ext}`;
|
|
954
|
-
d(e, await
|
|
954
|
+
d(e, await Qt(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
955
|
} catch (e) {
|
|
956
956
|
a.missing.push(`the icon could not be read: ${e instanceof Error ? e.message : String(e)}`);
|
|
957
957
|
}
|
|
@@ -959,28 +959,28 @@ async function sr(e) {
|
|
|
959
959
|
return c;
|
|
960
960
|
}
|
|
961
961
|
// src/core/init/from-site/sections/placeholder.ts
|
|
962
|
-
function
|
|
962
|
+
function pr(e, t, n) {
|
|
963
963
|
let { destDir: r, created: i, result: a } = e, o = t.single ?? t.onLight;
|
|
964
964
|
if (n && o) {
|
|
965
|
-
let e =
|
|
966
|
-
if (i.has(`assets/logos/${
|
|
967
|
-
let { description: n, background: i, ...a } =
|
|
965
|
+
let e = O.join(r, `assets/logos/${Fn[0]}.json`), t = O.join(r, o.replace(/^\.\//, "").replace(/\.[a-z]+$/, ".json"));
|
|
966
|
+
if (i.has(`assets/logos/${Fn[0]}.json`) && k.existsSync(e) && k.existsSync(t)) {
|
|
967
|
+
let { description: n, background: i, ...a } = an(e), s = an(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
968
|
l && Number(l) > 0 && (a.clearSpace = {
|
|
969
969
|
value: Math.max(1, Math.round(Number(l) * .3 * 100) / 100),
|
|
970
970
|
unit: "px"
|
|
971
971
|
});
|
|
972
972
|
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.`,
|
|
973
|
+
s.description = `${String(s.description)} Clear space, minimum size, lockup, placement and partnership are blazon's, not the brand's: set them.`, on(t, s);
|
|
974
974
|
}
|
|
975
|
-
for (let e of
|
|
975
|
+
for (let e of In) for (let t of ["svg", "json"]) {
|
|
976
976
|
let n = `assets/logos/${e}.${t}`;
|
|
977
|
-
i.has(n) && (
|
|
977
|
+
i.has(n) && (k.rmSync(O.join(r, n), { force: !0 }), a.removed.push(`${n} (blazon's own logo)`));
|
|
978
978
|
}
|
|
979
979
|
}
|
|
980
980
|
}
|
|
981
981
|
// src/core/init/from-site/apply.ts
|
|
982
|
-
async function
|
|
983
|
-
let a = r.toISOString().slice(0, 10), o = i.page ?? await
|
|
982
|
+
async function mr(e, t, n, r = /* @__PURE__ */ new Date(), i = {}) {
|
|
983
|
+
let a = r.toISOString().slice(0, 10), o = i.page ?? await nn(t), s = {
|
|
984
984
|
written: [],
|
|
985
985
|
missing: [],
|
|
986
986
|
removed: [],
|
|
@@ -991,7 +991,7 @@ async function lr(e, t, n, r = /* @__PURE__ */ new Date(), i = {}) {
|
|
|
991
991
|
date: a,
|
|
992
992
|
created: n,
|
|
993
993
|
page: o,
|
|
994
|
-
vars:
|
|
994
|
+
vars: Jt(o.css),
|
|
995
995
|
result: s,
|
|
996
996
|
note: c,
|
|
997
997
|
review: {
|
|
@@ -1005,27 +1005,27 @@ async function lr(e, t, n, r = /* @__PURE__ */ new Date(), i = {}) {
|
|
|
1005
1005
|
}),
|
|
1006
1006
|
mayChange: (e) => n.has(e) ? !0 : (s.missing.push(`${e} already existed, so it was kept as it was`), !1)
|
|
1007
1007
|
};
|
|
1008
|
-
|
|
1009
|
-
let u =
|
|
1010
|
-
return
|
|
1008
|
+
Un(l, i.skipVars);
|
|
1009
|
+
let u = rr(l), d = await fr(l), { title: f, description: p, configLogo: m } = await qn(l, d, u);
|
|
1010
|
+
return pr(l, d, m), sr(l, f, p), Yn(l), s;
|
|
1011
1011
|
}
|
|
1012
1012
|
// src/core/init/from-site/inspect.ts
|
|
1013
|
-
async function
|
|
1014
|
-
let t = await
|
|
1013
|
+
async function hr(e) {
|
|
1014
|
+
let t = await nn(e), n = Jt(t.css), r = Bn(n), i = tr(t.css, n, /^(body|html)$/), a = tr(t.css, n, /^h[1-6]$/), o = [];
|
|
1015
1015
|
i && o.push({
|
|
1016
1016
|
family: i.family,
|
|
1017
1017
|
role: "body",
|
|
1018
|
-
stylesheet: !!
|
|
1018
|
+
stylesheet: !!Zn(i.family)
|
|
1019
1019
|
}), a && a.family.toLowerCase() !== i?.family.toLowerCase() && o.push({
|
|
1020
1020
|
family: a.family,
|
|
1021
1021
|
role: "headings",
|
|
1022
|
-
stylesheet: !!
|
|
1022
|
+
stylesheet: !!Zn(a.family)
|
|
1023
1023
|
});
|
|
1024
|
-
let s =
|
|
1024
|
+
let s = lr(t.html, e), c = ur(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 Kn(t.html, e) ?? Gn(t.html), d = [];
|
|
1025
1025
|
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
1026
|
page: t,
|
|
1027
1027
|
name: u,
|
|
1028
|
-
description:
|
|
1028
|
+
description: H(t.html, "description"),
|
|
1029
1029
|
colors: r.map((e) => ({
|
|
1030
1030
|
cssVar: e.cssVar,
|
|
1031
1031
|
hex: e.hex
|
|
@@ -1036,92 +1036,92 @@ async function ur(e) {
|
|
|
1036
1036
|
};
|
|
1037
1037
|
}
|
|
1038
1038
|
// src/core/init/answers.ts
|
|
1039
|
-
var
|
|
1039
|
+
var gr = [
|
|
1040
1040
|
".svg",
|
|
1041
1041
|
".png",
|
|
1042
1042
|
".jpg",
|
|
1043
1043
|
".jpeg",
|
|
1044
1044
|
".webp"
|
|
1045
|
-
],
|
|
1046
|
-
function
|
|
1047
|
-
let t = e.trim(), n = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.test(t) ?
|
|
1045
|
+
], _r = (e) => e.trim() ? { value: e.trim() } : { hint: "A name cannot be empty." }, vr = (e) => e.trim().length <= 240 ? { value: e.trim() } : { hint: "Keep the description to one sentence, 240 characters at most." };
|
|
1046
|
+
function yr(e) {
|
|
1047
|
+
let t = e.trim(), n = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.test(t) ? Ln(t.startsWith("#") ? t : `#${t}`) : void 0;
|
|
1048
1048
|
return n ? { value: n.hex } : { hint: "Give the color as hex, for example #2563eb or #26e." };
|
|
1049
1049
|
}
|
|
1050
|
-
var
|
|
1051
|
-
function
|
|
1052
|
-
let n =
|
|
1053
|
-
return
|
|
1050
|
+
var br = (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." };
|
|
1051
|
+
function xr(e, t = process.cwd()) {
|
|
1052
|
+
let n = O.resolve(t, e.trim());
|
|
1053
|
+
return gr.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
1054
|
}
|
|
1055
|
-
function
|
|
1056
|
-
let t =
|
|
1055
|
+
function Sr(e) {
|
|
1056
|
+
let t = k.readFileSync(e), n = O.extname(e).toLowerCase() === ".svg";
|
|
1057
1057
|
return {
|
|
1058
1058
|
bytes: t.length,
|
|
1059
1059
|
svg: n,
|
|
1060
1060
|
usesCurrentColor: n && /currentColor/i.test(t.toString("utf8"))
|
|
1061
1061
|
};
|
|
1062
1062
|
}
|
|
1063
|
-
var
|
|
1064
|
-
function
|
|
1063
|
+
var Cr = (e) => /^https?:\/\/[^\s/]/i.test(e);
|
|
1064
|
+
function wr(e, t, n) {
|
|
1065
1065
|
let r = {
|
|
1066
1066
|
set: [],
|
|
1067
1067
|
hints: [],
|
|
1068
1068
|
files: []
|
|
1069
|
-
}, i = (e) => r.hints.push(`${e} already existed, so it was kept as it was`), a =
|
|
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") ? Mn(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
1070
|
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
|
-
let a =
|
|
1071
|
+
let a = O.join(e, "tokens", "colors.json");
|
|
1072
1072
|
if (!n.has("tokens/colors.json")) i("tokens/colors.json");
|
|
1073
1073
|
else {
|
|
1074
|
-
let e = JSON.parse(
|
|
1075
|
-
if (
|
|
1076
|
-
let n =
|
|
1077
|
-
|
|
1074
|
+
let e = JSON.parse(k.readFileSync(a, "utf-8"));
|
|
1075
|
+
if (B(e, "color.signal.orange")) {
|
|
1076
|
+
let n = An(e, t.color);
|
|
1077
|
+
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
1078
|
} else r.hints.push("color.signal.orange was not found in tokens/colors.json, so the color was not set");
|
|
1079
1079
|
}
|
|
1080
1080
|
}
|
|
1081
1081
|
if (t.font !== void 0) {
|
|
1082
|
-
let a =
|
|
1082
|
+
let a = O.join(e, "tokens", "typography.json");
|
|
1083
1083
|
if (!n.has("tokens/typography.json")) i("tokens/typography.json");
|
|
1084
1084
|
else {
|
|
1085
|
-
let e = JSON.parse(
|
|
1085
|
+
let e = JSON.parse(k.readFileSync(a, "utf-8")), n = B(e, "font.family.display"), i = B(e, "font.family.body");
|
|
1086
1086
|
if (n && i) {
|
|
1087
1087
|
n.$value = [t.font, "sans-serif"], i.$value = [t.font, "sans-serif"];
|
|
1088
|
-
let s =
|
|
1089
|
-
s &&
|
|
1090
|
-
let l =
|
|
1091
|
-
l && c("font stylesheet") ? (o.fonts =
|
|
1088
|
+
let s = B(e, "font.family.mono");
|
|
1089
|
+
s && kn(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");
|
|
1090
|
+
let l = Zn(t.font);
|
|
1091
|
+
l && c("font stylesheet") ? (o.fonts = Pn(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
1092
|
} 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
1093
|
}
|
|
1094
1094
|
}
|
|
1095
1095
|
if (t.logo !== void 0 && c("logo")) {
|
|
1096
|
-
let a =
|
|
1096
|
+
let a = O.basename(t.logo).replace(/[^A-Za-z0-9._-]/g, "-"), s = a.replace(/\.[^.]+$/, ""), c = O.join(e, "assets", "logos"), l = [a, `${s}.json`].filter((e) => !n.has(`assets/logos/${e}`) && k.existsSync(O.join(c, e)));
|
|
1097
1097
|
if (l.length) {
|
|
1098
1098
|
for (let e of l) i(`assets/logos/${e}`);
|
|
1099
1099
|
r.hints.push(`the logo ${t.logo} was not copied: pick another file name, or remove the existing file`);
|
|
1100
1100
|
} else {
|
|
1101
|
-
let e =
|
|
1102
|
-
if (n.has(`assets/logos/${
|
|
1103
|
-
let { description: t, background: n, ...r } = JSON.parse(
|
|
1101
|
+
let e = O.join(c, `${Fn[0]}.json`), i = {};
|
|
1102
|
+
if (n.has(`assets/logos/${Fn[0]}.json`) && k.existsSync(e)) {
|
|
1103
|
+
let { description: t, background: n, ...r } = JSON.parse(k.readFileSync(e, "utf-8"));
|
|
1104
1104
|
i = r;
|
|
1105
1105
|
}
|
|
1106
|
-
for (let e of
|
|
1107
|
-
|
|
1108
|
-
let l =
|
|
1109
|
-
|
|
1106
|
+
for (let e of In) for (let t of ["svg", "json"]) n.has(`assets/logos/${e}.${t}`) && k.rmSync(O.join(c, `${e}.${t}`), { force: !0 });
|
|
1107
|
+
k.mkdirSync(c, { recursive: !0 });
|
|
1108
|
+
let l = k.readFileSync(t.logo);
|
|
1109
|
+
k.writeFileSync(O.join(c, a), a.toLowerCase().endsWith(".svg") ? cr(l.toString("utf8")) : l), k.writeFileSync(O.join(c, `${s}.json`), `${JSON.stringify({
|
|
1110
1110
|
title: "Logo",
|
|
1111
1111
|
description: "The brand's logo. Clear space, minimum size, lockup, placement and partnership are blazon's, not the brand's: set them.",
|
|
1112
1112
|
...i
|
|
1113
1113
|
}, null, 2)}\n`), o.logo = `./assets/logos/${a}`, r.files.push(`assets/logos/${a}`, `assets/logos/${s}.json`), r.set.push(`logo ${a}`);
|
|
1114
1114
|
}
|
|
1115
1115
|
}
|
|
1116
|
-
return o !== void 0 && JSON.stringify(o) !== s && (
|
|
1116
|
+
return o !== void 0 && JSON.stringify(o) !== s && (Nn(a, o), r.files.push("blazon.json")), r;
|
|
1117
1117
|
}
|
|
1118
1118
|
// src/core/init/prompts.ts
|
|
1119
|
-
var
|
|
1119
|
+
var Tr = class extends Error {
|
|
1120
1120
|
constructor() {
|
|
1121
1121
|
super("cancelled"), this.name = "PromptCancelled";
|
|
1122
1122
|
}
|
|
1123
1123
|
};
|
|
1124
|
-
function
|
|
1124
|
+
function U(e, t) {
|
|
1125
1125
|
return e.split("\n").map((e) => {
|
|
1126
1126
|
if (e.length <= t || e.includes("\x1B")) return e;
|
|
1127
1127
|
let n = [], r = "";
|
|
@@ -1129,66 +1129,66 @@ function G(e, t) {
|
|
|
1129
1129
|
return n.push(r), n.join("\n");
|
|
1130
1130
|
}).join("\n");
|
|
1131
1131
|
}
|
|
1132
|
-
var
|
|
1133
|
-
function
|
|
1134
|
-
if (
|
|
1132
|
+
var W = () => Math.max(30, (process.stdout.columns ?? 80) - 6);
|
|
1133
|
+
function Er(e) {
|
|
1134
|
+
if (A.isCancel(e)) throw new Tr();
|
|
1135
1135
|
return e;
|
|
1136
1136
|
}
|
|
1137
|
-
function
|
|
1137
|
+
function Dr() {
|
|
1138
1138
|
return {
|
|
1139
|
-
intro: (e) =>
|
|
1140
|
-
outro: (e) =>
|
|
1141
|
-
cancel: (e) =>
|
|
1142
|
-
text: async (e) =>
|
|
1139
|
+
intro: (e) => A.intro(e),
|
|
1140
|
+
outro: (e) => A.outro(e),
|
|
1141
|
+
cancel: (e) => A.cancel(e),
|
|
1142
|
+
text: async (e) => Er(await A.text({
|
|
1143
1143
|
message: e.message,
|
|
1144
1144
|
placeholder: e.placeholder,
|
|
1145
1145
|
defaultValue: e.defaultValue,
|
|
1146
1146
|
validate: e.validate && ((t) => e.validate(t ?? ""))
|
|
1147
1147
|
})) ?? "",
|
|
1148
|
-
select: async (e) =>
|
|
1148
|
+
select: async (e) => Er(await A.select({
|
|
1149
1149
|
message: e.message,
|
|
1150
1150
|
options: e.options,
|
|
1151
1151
|
initialValue: e.initialValue
|
|
1152
1152
|
})),
|
|
1153
|
-
multiselect: async (e) =>
|
|
1153
|
+
multiselect: async (e) => Er(await A.multiselect({
|
|
1154
1154
|
message: e.message,
|
|
1155
1155
|
options: e.options,
|
|
1156
1156
|
initialValues: e.initialValues,
|
|
1157
1157
|
required: !1
|
|
1158
1158
|
})),
|
|
1159
|
-
confirm: async (e) =>
|
|
1159
|
+
confirm: async (e) => Er(await A.confirm({
|
|
1160
1160
|
message: e.message,
|
|
1161
1161
|
initialValue: e.initialValue
|
|
1162
1162
|
})),
|
|
1163
1163
|
spinner: () => {
|
|
1164
|
-
let e =
|
|
1164
|
+
let e = A.spinner();
|
|
1165
1165
|
return {
|
|
1166
1166
|
start: (t) => e.start(t),
|
|
1167
1167
|
stop: (t) => e.stop(t),
|
|
1168
1168
|
error: (t) => e.error(t)
|
|
1169
1169
|
};
|
|
1170
1170
|
},
|
|
1171
|
-
note: (e, t) =>
|
|
1171
|
+
note: (e, t) => A.note(e, t),
|
|
1172
1172
|
log: {
|
|
1173
|
-
message: (e) =>
|
|
1174
|
-
info: (e) =>
|
|
1175
|
-
success: (e) =>
|
|
1176
|
-
warn: (e) =>
|
|
1177
|
-
error: (e) =>
|
|
1178
|
-
step: (e) =>
|
|
1173
|
+
message: (e) => A.log.message(U(e, W())),
|
|
1174
|
+
info: (e) => A.log.info(U(e, W())),
|
|
1175
|
+
success: (e) => A.log.success(U(e, W())),
|
|
1176
|
+
warn: (e) => A.log.warn(U(e, W())),
|
|
1177
|
+
error: (e) => A.log.error(U(e, W())),
|
|
1178
|
+
step: (e) => A.log.step(U(e, W()))
|
|
1179
1179
|
}
|
|
1180
1180
|
};
|
|
1181
1181
|
}
|
|
1182
1182
|
// src/cli/init-ui.ts
|
|
1183
|
-
function
|
|
1184
|
-
let n =
|
|
1183
|
+
function Or(e = process.env, t = !!process.stdout.isTTY) {
|
|
1184
|
+
let n = w(e, t, []);
|
|
1185
1185
|
return {
|
|
1186
1186
|
color: n,
|
|
1187
1187
|
truecolor: n && /^(truecolor|24bit)$/i.test(e.COLORTERM ?? "")
|
|
1188
1188
|
};
|
|
1189
1189
|
}
|
|
1190
|
-
function
|
|
1191
|
-
let [n, r, i] = (
|
|
1190
|
+
function kr(e, t) {
|
|
1191
|
+
let [n, r, i] = (gn(e) ?? [
|
|
1192
1192
|
0,
|
|
1193
1193
|
0,
|
|
1194
1194
|
0
|
|
@@ -1197,63 +1197,63 @@ function Tr(e, t) {
|
|
|
1197
1197
|
let a = (e) => Math.round(e / 255 * 5);
|
|
1198
1198
|
return `\x1b[48;5;${16 + 36 * a(n) + 6 * a(r) + a(i)}m`;
|
|
1199
1199
|
}
|
|
1200
|
-
function
|
|
1201
|
-
return t.color ? `${
|
|
1200
|
+
function Ar(e, t, n = 2) {
|
|
1201
|
+
return t.color ? `${kr(e, t)}${" ".repeat(n)}\x1b[0m` : `[${e}]`;
|
|
1202
1202
|
}
|
|
1203
|
-
var
|
|
1203
|
+
var jr = {
|
|
1204
1204
|
AAA: "AAA",
|
|
1205
1205
|
AA: "AA",
|
|
1206
1206
|
"AA-large": "AA for large text only",
|
|
1207
1207
|
fail: "below AA"
|
|
1208
|
-
},
|
|
1209
|
-
function
|
|
1208
|
+
}, Mr = (e) => `${e.toFixed(1)}:1`;
|
|
1209
|
+
function Nr(e, t, n = xn(e)) {
|
|
1210
1210
|
let r = (e) => e === "AAA" || e === "AA" ? "yes" : "no";
|
|
1211
1211
|
return [
|
|
1212
|
-
`${
|
|
1213
|
-
`AA for text on white: ${r(n.onWhite.level)} (${
|
|
1214
|
-
`AA for text on near-black: ${r(n.onNearBlack.level)} (${
|
|
1212
|
+
`${Ar(e, t, 4)} ${e}`,
|
|
1213
|
+
`AA for text on white: ${r(n.onWhite.level)} (${Mr(n.onWhite.ratio)}, ${jr[n.onWhite.level]})`,
|
|
1214
|
+
`AA for text on near-black: ${r(n.onNearBlack.level)} (${Mr(n.onNearBlack.ratio)}, ${jr[n.onNearBlack.level]})`
|
|
1215
1215
|
];
|
|
1216
1216
|
}
|
|
1217
|
-
function
|
|
1218
|
-
let { ink: t, ratio: n, aa: r } =
|
|
1217
|
+
function Pr(e) {
|
|
1218
|
+
let { ink: t, ratio: n, aa: r } = wn(e);
|
|
1219
1219
|
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
1220
|
}
|
|
1221
|
-
var
|
|
1222
|
-
function
|
|
1221
|
+
var Fr = (e, t, n) => `${e} of ${t} ${n}`;
|
|
1222
|
+
function Ir(e) {
|
|
1223
1223
|
return e < 1024 ? `${e} bytes` : `${(e / 1024).toFixed(1)} KB`;
|
|
1224
1224
|
}
|
|
1225
1225
|
// src/cli/init-flow.ts
|
|
1226
|
-
var
|
|
1227
|
-
function
|
|
1228
|
-
return e.log.message(
|
|
1226
|
+
var Lr = 4;
|
|
1227
|
+
function G(e, t, n, r) {
|
|
1228
|
+
return e.log.message(r.color ? l.dim(n) : n), t;
|
|
1229
1229
|
}
|
|
1230
|
-
function
|
|
1230
|
+
function Rr(e) {
|
|
1231
1231
|
return (t) => {
|
|
1232
1232
|
if (t.trim() === "") return;
|
|
1233
1233
|
let n = e(t);
|
|
1234
1234
|
return "hint" in n ? n.hint : void 0;
|
|
1235
1235
|
};
|
|
1236
1236
|
}
|
|
1237
|
-
var
|
|
1237
|
+
var zr = (e, t) => {
|
|
1238
1238
|
let n = t.trim() === "" ? void 0 : e(t);
|
|
1239
1239
|
return n && "value" in n ? n.value : void 0;
|
|
1240
1240
|
};
|
|
1241
|
-
async function
|
|
1242
|
-
let { prompter: t, look:
|
|
1243
|
-
t.intro(
|
|
1244
|
-
let
|
|
1245
|
-
message:
|
|
1241
|
+
async function Br(e) {
|
|
1242
|
+
let { prompter: t, look: n } = e, r = {};
|
|
1243
|
+
t.intro(n.color ? l.bold(`blazon init ${l.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(Fr(1, Lr, "Brand"));
|
|
1244
|
+
let i = (await t.text({
|
|
1245
|
+
message: G(t, "Brand name", "The title of the brand book. Enter keeps the name taken from the folder.", n),
|
|
1246
1246
|
placeholder: "from the folder name",
|
|
1247
1247
|
validate: () => void 0
|
|
1248
1248
|
})).trim();
|
|
1249
|
-
|
|
1250
|
-
let
|
|
1251
|
-
message:
|
|
1249
|
+
i && (r.name = i);
|
|
1250
|
+
let a = (await t.text({
|
|
1251
|
+
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
1252
|
placeholder: "what the brand is, in one sentence",
|
|
1253
|
-
validate: (e) => "hint" in
|
|
1253
|
+
validate: (e) => "hint" in vr(e) ? "Keep it to one sentence, 240 characters at most." : void 0
|
|
1254
1254
|
})).trim();
|
|
1255
|
-
if (
|
|
1256
|
-
message:
|
|
1255
|
+
if (a && (r.description = a), await t.select({
|
|
1256
|
+
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
1257
|
options: [{
|
|
1258
1258
|
value: "manual",
|
|
1259
1259
|
label: "I will give them here",
|
|
@@ -1264,50 +1264,50 @@ async function Ir(e) {
|
|
|
1264
1264
|
hint: "you review what was found first"
|
|
1265
1265
|
}]
|
|
1266
1266
|
}) === "site") {
|
|
1267
|
-
let n = await
|
|
1267
|
+
let n = await Vr(e);
|
|
1268
1268
|
if (n) return {
|
|
1269
|
-
answers:
|
|
1269
|
+
answers: r,
|
|
1270
1270
|
site: n
|
|
1271
1271
|
};
|
|
1272
1272
|
t.log.info("Nothing from a site will be written. Giving the values here instead.");
|
|
1273
1273
|
}
|
|
1274
|
-
t.log.step(
|
|
1275
|
-
let
|
|
1276
|
-
message:
|
|
1274
|
+
t.log.step(Fr(2, Lr, "Colors"));
|
|
1275
|
+
let o = zr(yr, (await t.text({
|
|
1276
|
+
message: G(t, "Primary color", "Hex, for example #2563eb. Buttons and links use it. Enter keeps the orange it starts with.", n),
|
|
1277
1277
|
placeholder: "#2563eb",
|
|
1278
|
-
validate:
|
|
1278
|
+
validate: Rr(yr)
|
|
1279
1279
|
})).trim());
|
|
1280
|
-
|
|
1281
|
-
let
|
|
1282
|
-
message:
|
|
1280
|
+
o && (r.color = o, t.log.info(Nr(o, n).join("\n")), t.log.info(Pr(o))), t.log.step(Fr(3, Lr, "Type"));
|
|
1281
|
+
let s = zr(br, (await t.text({
|
|
1282
|
+
message: G(t, "Font family", "A Google Fonts name, for example Inter. Enter keeps the fonts it starts with.", n),
|
|
1283
1283
|
placeholder: "Inter",
|
|
1284
|
-
validate:
|
|
1284
|
+
validate: Rr(br)
|
|
1285
1285
|
})).trim());
|
|
1286
|
-
|
|
1287
|
-
let
|
|
1288
|
-
message:
|
|
1286
|
+
s && (r.font = s, Zn(s) ? t.log.success(`${s} is on Google Fonts. Its stylesheet will be added to fonts in blazon.json.`) : t.log.warn(`${s} 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(Fr(4, Lr, "Logo"));
|
|
1287
|
+
let c = zr((e) => xr(e), (await t.text({
|
|
1288
|
+
message: G(t, "Logo file", "The path to an SVG or PNG. Enter skips it and keeps the logo it starts with.", n),
|
|
1289
1289
|
placeholder: "./logo.svg",
|
|
1290
|
-
validate:
|
|
1290
|
+
validate: Rr((e) => xr(e))
|
|
1291
1291
|
})).trim());
|
|
1292
|
-
if (
|
|
1293
|
-
|
|
1294
|
-
let e =
|
|
1292
|
+
if (c) {
|
|
1293
|
+
r.logo = c;
|
|
1294
|
+
let e = Sr(c), n = O.basename(c);
|
|
1295
1295
|
t.log.info([
|
|
1296
|
-
`${n}: ${e.svg ? "SVG" : "raster image"}, ${
|
|
1296
|
+
`${n}: ${e.svg ? "SVG" : "raster image"}, ${Ir(e.bytes)}.`,
|
|
1297
1297
|
"It will be copied to assets/logos/ and replace the starter's placeholder.",
|
|
1298
1298
|
...e.usesCurrentColor ? ["It draws in currentColor, so it takes the text color of the page it is on."] : [],
|
|
1299
1299
|
...e.svg ? [] : ["A raster logo cannot be recolored; an SVG is better if you have one."]
|
|
1300
1300
|
].join("\n"));
|
|
1301
1301
|
}
|
|
1302
|
-
return { answers:
|
|
1302
|
+
return { answers: r };
|
|
1303
1303
|
}
|
|
1304
|
-
async function
|
|
1305
|
-
let { prompter: t, look: n } = e, r = e.inspect ??
|
|
1304
|
+
async function Vr(e) {
|
|
1305
|
+
let { prompter: t, look: n } = e, r = e.inspect ?? hr;
|
|
1306
1306
|
for (;;) {
|
|
1307
1307
|
let i = (await t.text({
|
|
1308
|
-
message:
|
|
1308
|
+
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
1309
|
placeholder: "https://example.com (leave empty to enter the values by hand)",
|
|
1310
|
-
validate: (e) => e.trim() === "" ||
|
|
1310
|
+
validate: (e) => e.trim() === "" || Cr(e.trim()) ? void 0 : "Give the full address, starting with http:// or https://, or leave it empty to enter the values by hand."
|
|
1311
1311
|
})).trim();
|
|
1312
1312
|
if (i === "") {
|
|
1313
1313
|
t.log.info("No address given: you can enter the values by hand.");
|
|
@@ -1322,7 +1322,7 @@ async function Lr(e) {
|
|
|
1322
1322
|
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
1323
|
}
|
|
1324
1324
|
if (o) {
|
|
1325
|
-
let t = await
|
|
1325
|
+
let t = await Hr(e, i, o);
|
|
1326
1326
|
return t ? {
|
|
1327
1327
|
url: i,
|
|
1328
1328
|
findings: o,
|
|
@@ -1335,7 +1335,7 @@ async function Lr(e) {
|
|
|
1335
1335
|
})) return;
|
|
1336
1336
|
}
|
|
1337
1337
|
}
|
|
1338
|
-
async function
|
|
1338
|
+
async function Hr(e, t, n) {
|
|
1339
1339
|
let { prompter: r, look: i } = e, a = [];
|
|
1340
1340
|
n.name && a.push(`Name: ${n.name}`), n.description && a.push(`Description: ${n.description}`);
|
|
1341
1341
|
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"}`);
|
|
@@ -1344,10 +1344,10 @@ async function Rr(e, t, n) {
|
|
|
1344
1344
|
let o = /* @__PURE__ */ new Set();
|
|
1345
1345
|
if (n.colors.length > 0) {
|
|
1346
1346
|
let e = await r.multiselect({
|
|
1347
|
-
message:
|
|
1347
|
+
message: G(r, "Brand colors found", "Untick any you do not want. Everything written is marked needs-review.", i),
|
|
1348
1348
|
options: n.colors.map((e) => ({
|
|
1349
1349
|
value: e.cssVar,
|
|
1350
|
-
label: `${
|
|
1350
|
+
label: `${Ar(e.hex, i)} ${e.hex} ${e.cssVar}`
|
|
1351
1351
|
})),
|
|
1352
1352
|
initialValues: n.colors.map((e) => e.cssVar)
|
|
1353
1353
|
});
|
|
@@ -1359,70 +1359,70 @@ async function Rr(e, t, n) {
|
|
|
1359
1359
|
}) ? o : void 0;
|
|
1360
1360
|
}
|
|
1361
1361
|
// src/cli/commands/init.ts
|
|
1362
|
-
var
|
|
1363
|
-
function
|
|
1362
|
+
var Ur = (e, t, n) => `${e} ${e === 1 ? t : n}`;
|
|
1363
|
+
function Wr(e, t) {
|
|
1364
1364
|
let n = t.map((e) => e.split("/").slice(1));
|
|
1365
1365
|
if (n.length === 0) return;
|
|
1366
|
-
if (e === "docs") return `${
|
|
1367
|
-
if (e === "tokens") return `${
|
|
1366
|
+
if (e === "docs") return `${Ur(n.length, "page", "pages")}, ${n[0][0]} to ${n[n.length - 1][0]}`;
|
|
1367
|
+
if (e === "tokens") return `${Ur(n.length, "file", "files")}: ${n.map((e) => e.join("/")).join(", ")}`;
|
|
1368
1368
|
let r = [...new Set(n.filter((e) => e.length > 1).map((e) => e[0]))];
|
|
1369
|
-
return r.length > 0 ? `${
|
|
1369
|
+
return r.length > 0 ? `${Ur(n.length, "file", "files")} in ${Ur(r.length, "folder", "folders")}: ${r.join(", ")}` : `${Ur(n.length, "file", "files")}: ${n.map((e) => e[0]).join(", ")}`;
|
|
1370
1370
|
}
|
|
1371
|
-
var
|
|
1372
|
-
function
|
|
1373
|
-
let t =
|
|
1374
|
-
for (; t.length > 0 &&
|
|
1371
|
+
var Gr = /^(brand|book|guidelines|guide)$/i;
|
|
1372
|
+
function Kr(e) {
|
|
1373
|
+
let t = O.basename(e).split(/[-_\s]+/).filter(Boolean), n = t.length > 0;
|
|
1374
|
+
for (; t.length > 0 && Gr.test(t[t.length - 1]);) t = t.slice(0, -1);
|
|
1375
1375
|
let r = t.map((e) => e.charAt(0).toUpperCase() + e.slice(1)).join(" ");
|
|
1376
1376
|
return r ? `${r} Brand Book` : n ? "Brand Book" : "Blazon Brand Book";
|
|
1377
1377
|
}
|
|
1378
|
-
var
|
|
1378
|
+
var qr = [
|
|
1379
1379
|
[
|
|
1380
1380
|
"--name",
|
|
1381
1381
|
"name",
|
|
1382
|
-
|
|
1382
|
+
_r
|
|
1383
1383
|
],
|
|
1384
1384
|
[
|
|
1385
1385
|
"--description",
|
|
1386
1386
|
"description",
|
|
1387
|
-
|
|
1387
|
+
vr
|
|
1388
1388
|
],
|
|
1389
1389
|
[
|
|
1390
1390
|
"--color",
|
|
1391
1391
|
"color",
|
|
1392
|
-
|
|
1392
|
+
yr
|
|
1393
1393
|
],
|
|
1394
1394
|
[
|
|
1395
1395
|
"--font",
|
|
1396
1396
|
"font",
|
|
1397
|
-
|
|
1397
|
+
br
|
|
1398
1398
|
],
|
|
1399
1399
|
[
|
|
1400
1400
|
"--logo",
|
|
1401
1401
|
"logo",
|
|
1402
|
-
(e) =>
|
|
1402
|
+
(e) => xr(e)
|
|
1403
1403
|
]
|
|
1404
1404
|
];
|
|
1405
|
-
async function
|
|
1405
|
+
async function Jr(e = ".", t = {}) {
|
|
1406
1406
|
if (t.from !== void 0 && !/^https?:\/\/[^\s/]/i.test(t.from)) {
|
|
1407
1407
|
let e = `--from needs an http(s) address, got ${JSON.stringify(t.from)}`;
|
|
1408
|
-
return console.error(
|
|
1408
|
+
return console.error(l.red(`blazon init: ${e}`)), t.failure?.({
|
|
1409
1409
|
code: "invalid-option-value",
|
|
1410
1410
|
message: e
|
|
1411
1411
|
}), 2;
|
|
1412
1412
|
}
|
|
1413
|
-
let
|
|
1414
|
-
for (let [e,
|
|
1415
|
-
let
|
|
1416
|
-
if (
|
|
1417
|
-
let
|
|
1418
|
-
if ("hint" in
|
|
1413
|
+
let n = {};
|
|
1414
|
+
for (let [e, r, i] of qr) {
|
|
1415
|
+
let a = t[r];
|
|
1416
|
+
if (a === void 0) continue;
|
|
1417
|
+
let o = i(String(a));
|
|
1418
|
+
if ("hint" in o) return console.error(l.red(`blazon init: ${e}: ${o.hint}`)), t.failure?.({
|
|
1419
1419
|
code: "invalid-option-value",
|
|
1420
|
-
message: `${e}: ${
|
|
1420
|
+
message: `${e}: ${o.hint}`
|
|
1421
1421
|
}), 2;
|
|
1422
|
-
r
|
|
1422
|
+
n[r] = o.value;
|
|
1423
1423
|
}
|
|
1424
|
-
let
|
|
1425
|
-
if (!
|
|
1424
|
+
let r = O.resolve(process.cwd(), e), i = Ke();
|
|
1425
|
+
if (!k.existsSync(i)) throw Error(`Template directory not found at ${i}`);
|
|
1426
1426
|
let o = t.tty ?? !!(process.stdin.isTTY && process.stdout.isTTY), s = [
|
|
1427
1427
|
t.from,
|
|
1428
1428
|
t.name,
|
|
@@ -1430,233 +1430,233 @@ async function Wr(e = ".", t = {}) {
|
|
|
1430
1430
|
t.color,
|
|
1431
1431
|
t.font,
|
|
1432
1432
|
t.logo
|
|
1433
|
-
].some((e) => e !== void 0), c = o && !s && !t.yes && t.input !== !1,
|
|
1434
|
-
c || console.log(
|
|
1435
|
-
let
|
|
1433
|
+
].some((e) => e !== void 0), c = o && !s && !t.yes && t.input !== !1, u = c ? t.prompter ?? Dr() : void 0, d = t.look ?? Or(process.env, o);
|
|
1434
|
+
c || console.log(l.cyan(`\n✨ Initializing Blazon Brand Book in ${l.bold(r)}...\n`));
|
|
1435
|
+
let f = O.join(r, "blazon.json"), p = k.existsSync(f), m = a(r, i), h = m.kept, g = m.written.map((e) => O.relative(r, e).split(O.sep).join("/")).sort(), _ = new Set(g);
|
|
1436
1436
|
t.report?.({
|
|
1437
|
-
dir:
|
|
1438
|
-
created:
|
|
1439
|
-
kept:
|
|
1440
|
-
}), !
|
|
1441
|
-
...
|
|
1442
|
-
title:
|
|
1437
|
+
dir: r,
|
|
1438
|
+
created: g,
|
|
1439
|
+
kept: h.map((e) => O.relative(r, e).split(O.sep).join("/")).sort()
|
|
1440
|
+
}), !p && k.existsSync(f) && Nn(f, {
|
|
1441
|
+
...Mn(f),
|
|
1442
|
+
title: Kr(r),
|
|
1443
1443
|
description: "Brand guidelines, built from design tokens"
|
|
1444
1444
|
});
|
|
1445
|
-
let
|
|
1445
|
+
let v = [];
|
|
1446
1446
|
for (let e of [
|
|
1447
1447
|
"tokens",
|
|
1448
1448
|
"assets",
|
|
1449
1449
|
"docs"
|
|
1450
1450
|
]) {
|
|
1451
|
-
let t =
|
|
1452
|
-
t &&
|
|
1453
|
-
}
|
|
1454
|
-
|
|
1455
|
-
let
|
|
1456
|
-
if (
|
|
1457
|
-
|
|
1458
|
-
prompter:
|
|
1459
|
-
look:
|
|
1460
|
-
dir:
|
|
1461
|
-
kept:
|
|
1451
|
+
let t = Wr(e, g.filter((t) => t.startsWith(`${e}/`)));
|
|
1452
|
+
t && v.push(`${e}/ (${t})`);
|
|
1453
|
+
}
|
|
1454
|
+
g.includes("blazon.json") && v.push("blazon.json"), g.includes("blazon.resolver.json") && v.push("blazon.resolver.json");
|
|
1455
|
+
let y = { answers: n };
|
|
1456
|
+
if (u) try {
|
|
1457
|
+
y = await Br({
|
|
1458
|
+
prompter: u,
|
|
1459
|
+
look: d,
|
|
1460
|
+
dir: r,
|
|
1461
|
+
kept: h.length
|
|
1462
1462
|
});
|
|
1463
1463
|
} catch (e) {
|
|
1464
|
-
if (e instanceof
|
|
1464
|
+
if (e instanceof Tr) return u.cancel("Stopped. The starter was copied as it is, and nothing else was changed."), 130;
|
|
1465
1465
|
throw e;
|
|
1466
1466
|
}
|
|
1467
1467
|
else {
|
|
1468
|
-
for (let e of
|
|
1469
|
-
|
|
1470
|
-
}
|
|
1471
|
-
let
|
|
1472
|
-
if (
|
|
1473
|
-
if (
|
|
1474
|
-
page:
|
|
1475
|
-
skipVars:
|
|
1476
|
-
}), !
|
|
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(
|
|
1468
|
+
for (let e of v) console.log(` ${l.green("✔")} Created ${e}`);
|
|
1469
|
+
h.length > 0 && console.log(` ${l.yellow("!")} ${h.length} starter files were already here and are kept as they are`), console.log();
|
|
1470
|
+
}
|
|
1471
|
+
let b = y.site?.url ?? t.from, x = 0, S, ee = u?.spinner();
|
|
1472
|
+
if (ee?.start("Writing the brand book"), b !== void 0) try {
|
|
1473
|
+
if (S = await mr(r, b, _, /* @__PURE__ */ new Date(), {
|
|
1474
|
+
page: y.site?.findings.page,
|
|
1475
|
+
skipVars: y.site?.skipVars
|
|
1476
|
+
}), !u) {
|
|
1477
|
+
console.log(l.bold(`Read from ${b}:`));
|
|
1478
|
+
for (let e of S.written) console.log(` ${l.green("✔")} Wrote ${e}`);
|
|
1479
|
+
for (let e of S.removed) console.log(` ${l.green("✔")} Removed ${e}`);
|
|
1480
|
+
for (let e of S.repointed) console.log(` ${l.green("✔")} Re-pointed ${e}`);
|
|
1481
|
+
for (let e of S.missing) console.log(` ${l.yellow("!")} ${e}`);
|
|
1482
|
+
console.log(l.dim("\n All of it is marked needs-review: it is a starting point, so confirm it with the brand owner.\n"));
|
|
1483
1483
|
}
|
|
1484
1484
|
} catch (e) {
|
|
1485
|
-
let
|
|
1485
|
+
let n = e instanceof Error ? e.message : String(e);
|
|
1486
1486
|
t.failure?.({
|
|
1487
1487
|
code: "site-unreadable",
|
|
1488
|
-
message:
|
|
1489
|
-
}),
|
|
1488
|
+
message: n
|
|
1489
|
+
}), u ? u.log.error(`Could not read ${b}: ${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(l.red(`blazon init: ${n}`)), console.error(l.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"))), x = 2;
|
|
1490
1490
|
}
|
|
1491
1491
|
let C;
|
|
1492
1492
|
try {
|
|
1493
|
-
C =
|
|
1493
|
+
C = wr(r, y.answers, _);
|
|
1494
1494
|
} catch (e) {
|
|
1495
|
-
throw
|
|
1496
|
-
}
|
|
1497
|
-
|
|
1498
|
-
let w = (e) =>
|
|
1499
|
-
`Run ${w(
|
|
1500
|
-
`Replace blazon's artwork in ${w(
|
|
1501
|
-
`Run ${w(
|
|
1502
|
-
`Point a coding agent at ${w(
|
|
1495
|
+
throw ee?.error("Could not write the brand book"), e;
|
|
1496
|
+
}
|
|
1497
|
+
ee?.stop("Wrote the brand book");
|
|
1498
|
+
let w = (e) => d.color ? l.cyan(e) : e, T = F(r), te = [
|
|
1499
|
+
`Run ${w(L("dev", T))} to see the book`,
|
|
1500
|
+
`Replace blazon's artwork in ${w(I(T, "assets/"))} and the text in ${w(I(T, "docs/"))}`,
|
|
1501
|
+
`Run ${w(L("check", T))} to see what is left`,
|
|
1502
|
+
`Point a coding agent at ${w(I(T, "AGENTS.md"))}: it is the guide for editing this brand`
|
|
1503
1503
|
];
|
|
1504
|
-
|
|
1505
|
-
let
|
|
1506
|
-
if (
|
|
1507
|
-
let e = [...
|
|
1508
|
-
|
|
1504
|
+
S && !S.written.some((e) => e.startsWith("assets/logos/")) && te.splice(1, 0, `Add your logo: the book still shows blazon's own. Put it in ${w(I(T, "assets/logos/"))} and point ${w("logo")} in ${w(I(T, "blazon.json"))} at it`);
|
|
1505
|
+
let ne = w(I(T, "tokens/colors.json")), re = C.set.some((e) => e.startsWith("primary color")) ? `Finish the palette in ${ne}: the primary color is set, the rest is still blazon's` : S?.written.includes("tokens/colors.json") ? `Confirm the colors read from the site in ${ne} with the brand owner` : `Edit ${ne} with your colors`;
|
|
1506
|
+
if (u) {
|
|
1507
|
+
let e = [...v.map((e) => `Created ${e}`)];
|
|
1508
|
+
S && e.push(`Read from ${b}: ${S.written.length} files written, ${S.removed.length} starter files removed`, ...S.missing.map((e) => `Not found: ${e}`));
|
|
1509
1509
|
for (let t of C.set) e.push(`Set ${t}`);
|
|
1510
|
-
e.push(...C.hints.map((e) => `Note: ${e}`)),
|
|
1510
|
+
e.push(...C.hints.map((e) => `Note: ${e}`)), u.note(e.join("\n"), "What was written"), x === 0 && u.note(te.map((e, t) => `${t + 1}. ${e}`).join("\n"), "Next steps");
|
|
1511
1511
|
let n;
|
|
1512
1512
|
try {
|
|
1513
|
-
n = t.dev ?? await
|
|
1513
|
+
n = t.dev ?? await u.confirm({
|
|
1514
1514
|
message: "Start the dev server now?",
|
|
1515
1515
|
initialValue: !1
|
|
1516
1516
|
});
|
|
1517
1517
|
} catch (e) {
|
|
1518
|
-
if (!(e instanceof
|
|
1519
|
-
return
|
|
1518
|
+
if (!(e instanceof Tr)) throw e;
|
|
1519
|
+
return u.cancel("Stopped. Everything above was written."), x === 0 ? 130 : x;
|
|
1520
1520
|
}
|
|
1521
|
-
return
|
|
1521
|
+
return u.outro(n ? "Starting blazon dev. Press Ctrl-C to stop it." : `Done. Run ${w(L("dev", T))} when you are ready.`), n && await (t.startDev ?? Yr)(r), x;
|
|
1522
1522
|
}
|
|
1523
|
-
for (let e of C.hints) console.log(` ${
|
|
1524
|
-
return C.set.length > 0 && console.log(` ${
|
|
1523
|
+
for (let e of C.hints) console.log(` ${l.yellow("!")} ${e}`);
|
|
1524
|
+
return C.set.length > 0 && console.log(` ${l.green("✔")} Set ${C.set.join(", ")}\n`), x === 0 && (console.log(l.bold("Next steps:")), console.log(` 1. ${re}`), te.forEach((e, t) => console.log(` ${t + 2}. ${e}`))), console.log(), t.dev && await (t.startDev ?? Yr)(r), x;
|
|
1525
1525
|
}
|
|
1526
|
-
async function
|
|
1527
|
-
let { runDev: t } = await Promise.resolve().then(() =>
|
|
1526
|
+
async function Yr(e) {
|
|
1527
|
+
let { runDev: t } = await Promise.resolve().then(() => vt);
|
|
1528
1528
|
await t(e);
|
|
1529
1529
|
}
|
|
1530
1530
|
// src/server/preview-guard.ts
|
|
1531
|
-
function
|
|
1532
|
-
return (
|
|
1533
|
-
let
|
|
1531
|
+
function Xr(t) {
|
|
1532
|
+
return (n, r, i) => {
|
|
1533
|
+
let a;
|
|
1534
1534
|
try {
|
|
1535
|
-
|
|
1535
|
+
a = decodeURIComponent((n.url ?? "").split("?")[0]);
|
|
1536
1536
|
} catch {
|
|
1537
|
-
return
|
|
1537
|
+
return i();
|
|
1538
1538
|
}
|
|
1539
|
-
if (
|
|
1540
|
-
let
|
|
1541
|
-
if (
|
|
1542
|
-
|
|
1539
|
+
if (a.includes("\0")) return i();
|
|
1540
|
+
let o = O.join(t, O.normalize(`/${a}`));
|
|
1541
|
+
if (e(x(t), x(o))) return i();
|
|
1542
|
+
r.statusCode = 403, r.setHeader("Content-Type", "text/plain"), r.end("blazon preview serves only files inside the built site: this path is a link that leaves it");
|
|
1543
1543
|
};
|
|
1544
1544
|
}
|
|
1545
|
-
var
|
|
1545
|
+
var Zr = (e) => ({
|
|
1546
1546
|
name: "blazon-site-link-guard",
|
|
1547
1547
|
configurePreviewServer(t) {
|
|
1548
|
-
t.middlewares.use(
|
|
1548
|
+
t.middlewares.use(Xr(e));
|
|
1549
1549
|
}
|
|
1550
1550
|
});
|
|
1551
1551
|
// src/cli/commands/preview.ts
|
|
1552
|
-
async function
|
|
1553
|
-
|
|
1554
|
-
let
|
|
1555
|
-
if (!
|
|
1556
|
-
let
|
|
1552
|
+
async function Qr(e = process.cwd(), t, n = {}) {
|
|
1553
|
+
gt(e);
|
|
1554
|
+
let r = await ae(e, t ? { port: t } : void 0), i = O.resolve(e, r.outDir);
|
|
1555
|
+
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 a;
|
|
1557
1557
|
try {
|
|
1558
|
-
|
|
1559
|
-
plugins: [
|
|
1560
|
-
build: { outDir:
|
|
1558
|
+
a = await et({
|
|
1559
|
+
plugins: [le(), Zr(i)],
|
|
1560
|
+
build: { outDir: i },
|
|
1561
1561
|
preview: {
|
|
1562
|
-
port:
|
|
1563
|
-
strictPort:
|
|
1564
|
-
host:
|
|
1562
|
+
port: r.port,
|
|
1563
|
+
strictPort: n.strictPort ?? !1,
|
|
1564
|
+
host: n.host ?? "localhost",
|
|
1565
1565
|
open: !1
|
|
1566
1566
|
}
|
|
1567
1567
|
});
|
|
1568
1568
|
} catch (e) {
|
|
1569
|
-
throw
|
|
1569
|
+
throw n.strictPort && e instanceof Error && /already in use/.test(e.message) ? nt(r.port) : e;
|
|
1570
1570
|
}
|
|
1571
|
-
let
|
|
1572
|
-
console.log(`\n ${
|
|
1573
|
-
for (let e of
|
|
1574
|
-
return console.log(` ${
|
|
1571
|
+
let o = a.resolvedUrls, s = o?.local[0] || `http://localhost:${r.port}/`;
|
|
1572
|
+
console.log(`\n ${l.bold(l.blue("blazon preview"))}`), console.log(` ${l.dim("➜")} ${l.bold("Local:")} ${l.cyan(s)}`);
|
|
1573
|
+
for (let e of o?.network ?? []) console.log(` ${l.dim("➜")} ${l.bold("Network:")} ${l.cyan(e)}`);
|
|
1574
|
+
return console.log(` ${l.dim("➜")} ${l.bold("Dist:")} ${l.dim(i)}\n`), a;
|
|
1575
1575
|
}
|
|
1576
1576
|
// src/plugins/roles/check-cases.ts
|
|
1577
|
-
var
|
|
1578
|
-
function
|
|
1579
|
-
let t =
|
|
1580
|
-
return
|
|
1581
|
-
}
|
|
1582
|
-
function
|
|
1583
|
-
return
|
|
1584
|
-
}
|
|
1585
|
-
function
|
|
1586
|
-
let
|
|
1587
|
-
return async (e,
|
|
1588
|
-
let i =
|
|
1589
|
-
exit: `a valid request is answered with exit ${
|
|
1590
|
-
limit: `the answer is at most ${
|
|
1577
|
+
var $r = "docs/manual/12-plugins.md (\"What a plugin can look at, and where it writes\")";
|
|
1578
|
+
function ei(e) {
|
|
1579
|
+
let t = O.basename(e), n = je(t) ?? t.replace(/^blazon-/, "");
|
|
1580
|
+
return Pe(n) ? n : void 0;
|
|
1581
|
+
}
|
|
1582
|
+
function ti(e, t) {
|
|
1583
|
+
return k.readdirSync(e, { recursive: !0 }).filter((n) => O.join(e, n) !== t && !O.join(e, n).startsWith(t + O.sep)).sort();
|
|
1584
|
+
}
|
|
1585
|
+
function ni(e) {
|
|
1586
|
+
let n = ei(e);
|
|
1587
|
+
return async (e, r) => {
|
|
1588
|
+
let i = t(e), a = i.answers.join(" or "), o = i.stdoutLimit ?? 65536, s = [], c = {
|
|
1589
|
+
exit: `a valid request is answered with exit ${a}`,
|
|
1590
|
+
limit: `the answer is at most ${o} bytes`,
|
|
1591
1591
|
shape: `the answer is one the ${e} role accepts: a findings list of at most 500, each with the plugin's code, a severity, a path and a message`,
|
|
1592
1592
|
folder: "the plugin writes into out_dir and nothing beside it"
|
|
1593
|
-
},
|
|
1593
|
+
}, l = JSON.parse(De()[e]), u = k.mkdtempSync(O.join($e.tmpdir(), "blazon-plugin-check-")), d = O.join(u, "tokens"), f = O.join(d, n ?? "plugin");
|
|
1594
1594
|
try {
|
|
1595
|
-
e === "build" && (
|
|
1596
|
-
site_dir:
|
|
1597
|
-
tokens_dir:
|
|
1598
|
-
out_dir:
|
|
1595
|
+
e === "build" && (k.mkdirSync(O.join(u, "site")), k.mkdirSync(f, { recursive: !0 }), Object.assign(l, {
|
|
1596
|
+
site_dir: O.join(u, "site"),
|
|
1597
|
+
tokens_dir: d,
|
|
1598
|
+
out_dir: f
|
|
1599
1599
|
}));
|
|
1600
|
-
let
|
|
1601
|
-
|
|
1600
|
+
let t = await r(Buffer.from(JSON.stringify(l)), o), p = !t.answered && t.breakReason.startsWith("output over the limit");
|
|
1601
|
+
p ? s.push(h(6, c.exit, e, {
|
|
1602
1602
|
skipped: !0,
|
|
1603
1603
|
detail: "the output went over the limit before the plugin exited (case 7)"
|
|
1604
|
-
})) :
|
|
1604
|
+
})) : t.answered && i.answers.includes(t.code) ? s.push(h(6, c.exit, e, { passed: !0 })) : t.answered && t.code === 1 ? s.push(h(6, c.exit, e, { detail: `got exit 1, and exit 1 is a break in blazon: the ${e} 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(h(6, c.exit, e, { detail: t.answered ? `got exit ${t.code}` : `a break: ${t.breakReason}` }));
|
|
1605
1605
|
let m = i.stdoutLimit === void 0 ? "the core's limit, which the role does not raise" : `the ${e} role's limit (stdout_limit_bytes)`;
|
|
1606
|
-
if (
|
|
1606
|
+
if (s.push(p ? h(7, c.limit, e, { detail: `the plugin printed more than ${o} bytes, ${m}` }) : h(7, c.limit, e, { passed: !0 })), !t.answered || t.code !== 0) s.push(h(8, c.shape, e, {
|
|
1607
1607
|
skipped: !0,
|
|
1608
1608
|
detail: "the plugin did not answer with exit 0"
|
|
1609
1609
|
}));
|
|
1610
|
-
else if (
|
|
1610
|
+
else if (n === void 0) s.push(h(8, c.shape, e, {
|
|
1611
1611
|
skipped: !0,
|
|
1612
1612
|
detail: "the program's file name is not blazon-<plugin name>, so the check does not know the plugin's code prefix"
|
|
1613
1613
|
}));
|
|
1614
1614
|
else {
|
|
1615
|
-
let
|
|
1616
|
-
|
|
1615
|
+
let r = de(e, n, t.stdout, []);
|
|
1616
|
+
s.push("problem" in r ? h(8, c.shape, e, { detail: r.problem }) : h(8, c.shape, e, { passed: !0 }));
|
|
1617
1617
|
}
|
|
1618
1618
|
if (e === "build") {
|
|
1619
|
-
let t =
|
|
1620
|
-
|
|
1619
|
+
let t = ti(d, f);
|
|
1620
|
+
s.push(t.length === 0 ? h(9, c.folder, e, { passed: !0 }) : h(9, c.folder, e, {
|
|
1621
1621
|
passed: !0,
|
|
1622
1622
|
warning: !0,
|
|
1623
|
-
detail: `it wrote ${t.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 ${
|
|
1623
|
+
detail: `it wrote ${t.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 ${$r}`
|
|
1624
1624
|
}));
|
|
1625
1625
|
}
|
|
1626
1626
|
} finally {
|
|
1627
|
-
|
|
1627
|
+
k.rmSync(u, {
|
|
1628
1628
|
recursive: !0,
|
|
1629
1629
|
force: !0
|
|
1630
1630
|
});
|
|
1631
1631
|
}
|
|
1632
|
-
return
|
|
1632
|
+
return s;
|
|
1633
1633
|
};
|
|
1634
1634
|
}
|
|
1635
1635
|
// src/cli/commands/plugin.ts
|
|
1636
|
-
var
|
|
1636
|
+
var ri = {
|
|
1637
1637
|
plugin: "usage: blazon plugin check <program> [--core] | blazon plugin pin <path> [--name <plugin name>] | blazon plugin profile",
|
|
1638
1638
|
check: "usage: blazon plugin check <program> [--core]",
|
|
1639
1639
|
pin: "usage: blazon plugin pin <path> [--name <plugin name> [--digest <digest>] [--entry <path>]]"
|
|
1640
1640
|
};
|
|
1641
|
-
function
|
|
1642
|
-
let t = e.warning ?
|
|
1643
|
-
return ` ${t} ${e.case} ${
|
|
1644
|
-
}
|
|
1645
|
-
async function
|
|
1646
|
-
if (!e) throw new
|
|
1647
|
-
let
|
|
1648
|
-
t.json || (console.log(`${
|
|
1649
|
-
let
|
|
1650
|
-
...
|
|
1651
|
-
host:
|
|
1652
|
-
profile:
|
|
1641
|
+
function ii(e) {
|
|
1642
|
+
let t = e.warning ? l.yellow("warn") : e.passed ? l.green("ok ") : e.skipped ? l.dim("skip") : l.red("FAIL"), n = e.role ? `${e.role}: ` : "", r = e.detail ? ` (${e.detail})` : "";
|
|
1643
|
+
return ` ${t} ${e.case} ${n}${e.name}${r}`;
|
|
1644
|
+
}
|
|
1645
|
+
async function ai(e, t = {}) {
|
|
1646
|
+
if (!e) throw new M(ri.check, void 0, "missing-argument");
|
|
1647
|
+
let n = t.core === !0;
|
|
1648
|
+
t.json || (console.log(`${v.host} plugin check: host ${v.host}, adopts: ${v.adopts.length > 0 ? v.adopts.join(", ") : "none"}`), n && console.log("core cases only (1 to 5): no role cases, no layout line"));
|
|
1649
|
+
let r = await Te({
|
|
1650
|
+
...n ? {} : { approvals: await oi(e) },
|
|
1651
|
+
host: v.host,
|
|
1652
|
+
profile: o,
|
|
1653
1653
|
program: e,
|
|
1654
1654
|
validate: !1,
|
|
1655
|
-
requests:
|
|
1656
|
-
...
|
|
1657
|
-
}),
|
|
1655
|
+
requests: De(),
|
|
1656
|
+
...n ? {} : { roleCases: ni(e) }
|
|
1657
|
+
}), i = r.filter((e) => e.warning).length, a = r.filter((e) => !e.passed && !e.skipped), s = n ? void 0 : Se(O.resolve(e));
|
|
1658
1658
|
if (t.json) {
|
|
1659
|
-
let e = (e) => e.warning ? "warn" : e.passed ? "ok" : e.skipped ? "skip" : "fail", t =
|
|
1659
|
+
let e = (e) => e.warning ? "warn" : e.passed ? "ok" : e.skipped ? "skip" : "fail", t = r.map((t) => ({
|
|
1660
1660
|
case: t.case,
|
|
1661
1661
|
name: t.name,
|
|
1662
1662
|
role: t.role,
|
|
@@ -1665,128 +1665,128 @@ async function ti(e, t = {}) {
|
|
|
1665
1665
|
}));
|
|
1666
1666
|
return process.stdout.write(`${JSON.stringify({
|
|
1667
1667
|
command: "plugin check",
|
|
1668
|
-
passed:
|
|
1669
|
-
host:
|
|
1670
|
-
adopts:
|
|
1671
|
-
...
|
|
1668
|
+
passed: a.length === 0 && !s,
|
|
1669
|
+
host: v.host,
|
|
1670
|
+
adopts: v.adopts,
|
|
1671
|
+
...n ? { core: !0 } : {},
|
|
1672
1672
|
cases: t,
|
|
1673
|
-
...
|
|
1674
|
-
})}\n`),
|
|
1673
|
+
...s ? { layout: s } : {}
|
|
1674
|
+
})}\n`), a.length === 0 && !s ? 0 : 1;
|
|
1675
1675
|
}
|
|
1676
|
-
for (let e of
|
|
1677
|
-
return
|
|
1676
|
+
for (let e of r) console.log(ii(e));
|
|
1677
|
+
return s && console.log(` ${l.red("FAIL")} layout: ${s}`), a.length > 0 ? console.log(l.red(`\n${a.length} case${a.length === 1 ? "" : "s"} failed`)) : console.log(s ? l.red("\nFailed: the file name does not follow the layout of a shipped plugin") : l.green(`\nPassed${i > 0 ? `, with ${i} warning${i === 1 ? "" : "s"}` : ""}`)), a.length === 0 && !s ? 0 : 1;
|
|
1678
1678
|
}
|
|
1679
|
-
async function
|
|
1679
|
+
async function oi(e) {
|
|
1680
1680
|
let t;
|
|
1681
1681
|
try {
|
|
1682
|
-
t = (await
|
|
1682
|
+
t = (await R(process.cwd())).plugins ?? [];
|
|
1683
1683
|
} catch {
|
|
1684
1684
|
return;
|
|
1685
1685
|
}
|
|
1686
|
-
let n =
|
|
1686
|
+
let n = O.basename(e), r = je(n) ?? n.replace(/^blazon-/, "");
|
|
1687
1687
|
return t.flatMap((e, t) => e.name === r ? [{
|
|
1688
1688
|
key: `plugins[${t}].env`,
|
|
1689
1689
|
approved: e.env ?? []
|
|
1690
1690
|
}] : []);
|
|
1691
1691
|
}
|
|
1692
|
-
function
|
|
1693
|
-
if (!e) throw new
|
|
1694
|
-
if (!t.name && (t.digest || t.entry)) throw new
|
|
1695
|
-
if (!
|
|
1692
|
+
function si(e, t = {}, n = process.cwd()) {
|
|
1693
|
+
if (!e) throw new M(ri.pin, void 0, "missing-argument");
|
|
1694
|
+
if (!t.name && (t.digest || t.entry)) throw new M(`--digest and --entry say what to record, so they need --name; ${ri.pin}`, void 0, "conflicting-options");
|
|
1695
|
+
if (!k.existsSync(e)) return console.error(`blazon plugin pin: there is nothing at ${e}.`), 2;
|
|
1696
1696
|
try {
|
|
1697
1697
|
if (t.name) {
|
|
1698
|
-
let r =
|
|
1698
|
+
let r = Xe(n, t.name, e, {
|
|
1699
1699
|
digest: t.digest,
|
|
1700
1700
|
entry: t.entry
|
|
1701
1701
|
});
|
|
1702
|
-
return console.log(`pinned ${t.name}: ${r.digest} (${r.source}) in ${
|
|
1702
|
+
return console.log(`pinned ${t.name}: ${r.digest} (${r.source}) in ${S}`), 0;
|
|
1703
1703
|
}
|
|
1704
|
-
let r =
|
|
1705
|
-
return console.log(r.isDirectory() && !r.isSymbolicLink() ?
|
|
1704
|
+
let r = k.lstatSync(e);
|
|
1705
|
+
return console.log(r.isDirectory() && !r.isSymbolicLink() ? m(e) : d(e)), 0;
|
|
1706
1706
|
} catch (t) {
|
|
1707
|
-
return console.error(t instanceof
|
|
1707
|
+
return console.error(t instanceof re ? t.message : `cannot read ${e}: ${t instanceof Error ? t.message : String(t)}`), 1;
|
|
1708
1708
|
}
|
|
1709
1709
|
}
|
|
1710
|
-
function
|
|
1711
|
-
return console.log(JSON.stringify(
|
|
1710
|
+
function ci() {
|
|
1711
|
+
return console.log(JSON.stringify(v, null, 2)), 0;
|
|
1712
1712
|
}
|
|
1713
|
-
async function
|
|
1714
|
-
if (e === "check") return
|
|
1713
|
+
async function li(e, t, n = {}) {
|
|
1714
|
+
if (e === "check") return ai(t, {
|
|
1715
1715
|
json: n.json,
|
|
1716
1716
|
core: n.core
|
|
1717
1717
|
});
|
|
1718
|
-
if (e === "pin") return
|
|
1719
|
-
if (e === "profile") return
|
|
1720
|
-
throw new
|
|
1718
|
+
if (e === "pin") return si(t, n);
|
|
1719
|
+
if (e === "profile") return ci();
|
|
1720
|
+
throw new M(ri.plugin, void 0, "missing-argument");
|
|
1721
1721
|
}
|
|
1722
1722
|
// src/cli/commands/pin.ts
|
|
1723
|
-
function
|
|
1724
|
-
|
|
1723
|
+
function ui(e = process.cwd(), t = {}) {
|
|
1724
|
+
gt(e);
|
|
1725
1725
|
try {
|
|
1726
|
-
let
|
|
1726
|
+
let n = t.identity === void 0 ? Ye(e) : Ye(e, t.identity);
|
|
1727
1727
|
return t.json ? process.stdout.write(`${JSON.stringify({
|
|
1728
1728
|
command: "pin",
|
|
1729
1729
|
passed: !0,
|
|
1730
|
-
commit:
|
|
1731
|
-
file:
|
|
1732
|
-
})}\n`) : console.log(`pinned blazon ${
|
|
1730
|
+
commit: n,
|
|
1731
|
+
file: be
|
|
1732
|
+
})}\n`) : console.log(`pinned blazon ${l.bold(n)} in ${be}; commit the file with the book`), 0;
|
|
1733
1733
|
} catch (e) {
|
|
1734
1734
|
if (t.json) throw e;
|
|
1735
1735
|
return console.error(e instanceof Error ? e.message : String(e)), 1;
|
|
1736
1736
|
}
|
|
1737
1737
|
}
|
|
1738
1738
|
// src/cli/commands/drift.ts
|
|
1739
|
-
async function
|
|
1740
|
-
let
|
|
1739
|
+
async function di(e, t = {}) {
|
|
1740
|
+
let n = (e, n, r) => (console.error(it("drift", n, r).replace(/^blazon drift:/, (e) => l.red(e))), t.json && console.log(JSON.stringify({
|
|
1741
1741
|
command: "drift",
|
|
1742
1742
|
passed: !1,
|
|
1743
|
-
error: { ...
|
|
1743
|
+
error: { ...lt(e, at(n, r), r) }
|
|
1744
1744
|
})), 2);
|
|
1745
|
-
if (!e) return
|
|
1746
|
-
let
|
|
1747
|
-
if (!/^[a-z][a-z0-9+.-]*:\/\//i.test(e) && !
|
|
1748
|
-
let
|
|
1745
|
+
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
|
+
let r = t.cwd ?? process.cwd();
|
|
1747
|
+
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, a;
|
|
1749
1749
|
try {
|
|
1750
|
-
let n = await
|
|
1751
|
-
|
|
1752
|
-
let c =
|
|
1753
|
-
|
|
1750
|
+
let n = await R(r, t.tokens ? { tokensDir: t.tokens } : void 0), o = await D(n, r), s = await tn(e);
|
|
1751
|
+
i = s.sources;
|
|
1752
|
+
let c = Jt(s.css);
|
|
1753
|
+
a = o.tokens.items.flatMap((e) => {
|
|
1754
1754
|
let t = e.blazon.source?.cssVar;
|
|
1755
|
-
return typeof t == "string" ? [
|
|
1755
|
+
return typeof t == "string" ? [Yt(e, t, c)] : [];
|
|
1756
1756
|
});
|
|
1757
1757
|
} catch (e) {
|
|
1758
|
-
return
|
|
1759
|
-
}
|
|
1760
|
-
if (
|
|
1761
|
-
let
|
|
1762
|
-
ok:
|
|
1763
|
-
drift:
|
|
1764
|
-
missing:
|
|
1765
|
-
},
|
|
1758
|
+
return n(e instanceof j ? e.code : "error", e instanceof Error ? e.message : String(e), e instanceof j ? e.fix : void 0);
|
|
1759
|
+
}
|
|
1760
|
+
if (a.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).");
|
|
1761
|
+
let o = (e) => a.filter((t) => t.status === e).length, s = {
|
|
1762
|
+
ok: o("ok"),
|
|
1763
|
+
drift: o("drift"),
|
|
1764
|
+
missing: o("missing")
|
|
1765
|
+
}, c = +(s.drift + s.missing > 0);
|
|
1766
1766
|
if (t.json) return console.log(JSON.stringify({
|
|
1767
1767
|
target: e,
|
|
1768
|
-
sources:
|
|
1769
|
-
summary:
|
|
1770
|
-
tokens:
|
|
1771
|
-
}, null, 2)),
|
|
1772
|
-
let u = Math.max(...
|
|
1773
|
-
for (let e of
|
|
1768
|
+
sources: i,
|
|
1769
|
+
summary: s,
|
|
1770
|
+
tokens: a
|
|
1771
|
+
}, null, 2)), c;
|
|
1772
|
+
let u = Math.max(...a.map((e) => e.path.length));
|
|
1773
|
+
for (let e of a) {
|
|
1774
1774
|
let t = e.path.padEnd(u);
|
|
1775
|
-
e.status === "ok" ? console.log(`${
|
|
1775
|
+
e.status === "ok" ? console.log(`${l.green("ok ")} ${t} ${l.dim(e.cssVar)}`) : e.status === "drift" ? console.log(`${l.red("drift ")} ${t} ${e.cssVar}: token ${e.expected}, site ${e.actual}`) : console.log(`${l.yellow("missing")} ${t} ${e.cssVar} is not declared (token ${e.expected})`);
|
|
1776
1776
|
}
|
|
1777
|
-
return console.log(`\n${
|
|
1777
|
+
return console.log(`\n${s.ok} ok, ${s.drift} drifted, ${s.missing} missing`), c;
|
|
1778
1778
|
}
|
|
1779
1779
|
// src/cli/commands/approvals.ts
|
|
1780
|
-
async function
|
|
1781
|
-
let
|
|
1782
|
-
assetsDir:
|
|
1783
|
-
dirs:
|
|
1784
|
-
}),
|
|
1780
|
+
async function fi(e = process.cwd(), t = {}) {
|
|
1781
|
+
let n = await R(e), r = await D(n, e), i = T(r.tokens, r.assets.all, {
|
|
1782
|
+
assetsDir: O.resolve(e, n.assetsDir),
|
|
1783
|
+
dirs: ne(n.assets, e)
|
|
1784
|
+
}), a = (e) => e.review.value === void 0 ? "not recorded" : e.review.value === e.current ? "recorded" : "stale";
|
|
1785
1785
|
if (t.json) {
|
|
1786
|
-
let e =
|
|
1786
|
+
let e = i.map((e) => ({
|
|
1787
1787
|
path: e.path,
|
|
1788
1788
|
fingerprint: e.current ?? null,
|
|
1789
|
-
state:
|
|
1789
|
+
state: a(e)
|
|
1790
1790
|
}));
|
|
1791
1791
|
return process.stdout.write(`${JSON.stringify({
|
|
1792
1792
|
command: "approvals",
|
|
@@ -1794,60 +1794,60 @@ async function ci(e = process.cwd(), t = {}) {
|
|
|
1794
1794
|
approvals: e
|
|
1795
1795
|
})}\n`), 0;
|
|
1796
1796
|
}
|
|
1797
|
-
if (
|
|
1798
|
-
let
|
|
1797
|
+
if (i.length === 0) return console.log(l.dim("\n No token or asset is marked review.status: ok.\n")), 0;
|
|
1798
|
+
let o = Math.max(...i.map((e) => e.path.length));
|
|
1799
1799
|
console.log();
|
|
1800
|
-
for (let e of
|
|
1801
|
-
let t =
|
|
1802
|
-
console.log(` ${e.path.padEnd(
|
|
1800
|
+
for (let e of i) {
|
|
1801
|
+
let t = a(e), n = t === "recorded" ? l.green : t === "stale" ? l.yellow : l.dim;
|
|
1802
|
+
console.log(` ${e.path.padEnd(o)} ${(e.current ?? "(no value)").padEnd(12)} ${n(t)}`);
|
|
1803
1803
|
}
|
|
1804
|
-
return console.log(), console.log(
|
|
1804
|
+
return console.log(), console.log(l.dim(" Set review.value to the fingerprint once a person has confirmed the value.\n")), 0;
|
|
1805
1805
|
}
|
|
1806
1806
|
// src/cli/commands/cwd.ts
|
|
1807
|
-
function
|
|
1807
|
+
function pi(e) {
|
|
1808
1808
|
if (e === void 0) return;
|
|
1809
|
-
if (typeof e != "string" || e === "") throw new
|
|
1810
|
-
let t =
|
|
1811
|
-
|
|
1809
|
+
if (typeof e != "string" || e === "") throw new M("--cwd needs a folder", "Give one, such as blazon --cwd ./my-brand check.");
|
|
1810
|
+
let t = O.resolve(process.cwd(), e);
|
|
1811
|
+
gt(t), process.chdir(t);
|
|
1812
1812
|
}
|
|
1813
|
-
function
|
|
1813
|
+
function mi(e, t = process.env) {
|
|
1814
1814
|
let n = (Array.isArray(e) ? e : e === void 0 ? [] : [e]).map((e) => typeof e == "string" || typeof e == "number" ? String(e) : "");
|
|
1815
|
-
if (n.some((e) => e.trim() === "")) throw new
|
|
1816
|
-
|
|
1815
|
+
if (n.some((e) => e.trim() === "")) throw new M("--allow-dir needs a folder", "Give one, such as blazon dev --allow-dir ../shared.");
|
|
1816
|
+
ze(ge(n, t, process.cwd()));
|
|
1817
1817
|
}
|
|
1818
1818
|
// src/core/read/lookup.ts
|
|
1819
|
-
var
|
|
1820
|
-
function
|
|
1821
|
-
let n =
|
|
1819
|
+
var K = class extends Error {}, hi = (e) => e.trim().replace(/^\{(.*)\}$/, "$1").trim();
|
|
1820
|
+
function gi(e, t) {
|
|
1821
|
+
let n = hi(t), r = e.tokens.byPath.get(n);
|
|
1822
1822
|
if (r) return r;
|
|
1823
1823
|
let i = E(n, e.tokens.items.map((e) => e.path));
|
|
1824
|
-
throw new
|
|
1824
|
+
throw new K(e.tokens.items.some((e) => e.path.startsWith(`${n}.`)) ? `"${n}" is a group, not a token; \`blazon rules ${n}\` shows its rules.` : `no token "${n}"${i ? `; did you mean "${i}"?` : "."}`);
|
|
1825
1825
|
}
|
|
1826
1826
|
// src/core/read/rules.ts
|
|
1827
|
-
var
|
|
1828
|
-
function
|
|
1829
|
-
return
|
|
1827
|
+
var _i = (e) => e.extensions?.["dev.blazon"] ?? {};
|
|
1828
|
+
function vi(e, t, n) {
|
|
1829
|
+
return _i(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
1830
|
}
|
|
1831
|
-
var
|
|
1832
|
-
function
|
|
1833
|
-
let n = t.blazon.usage, r =
|
|
1831
|
+
var q = (e) => Array.isArray(e) ? e.filter((e) => typeof e == "string") : void 0;
|
|
1832
|
+
function yi(e, t) {
|
|
1833
|
+
let n = t.blazon.usage, r = vi(e, t, "usage");
|
|
1834
1834
|
if (!n || typeof n != "object" || r === void 0) return;
|
|
1835
|
-
let i =
|
|
1835
|
+
let i = q(n.allow), a = q(n.deny);
|
|
1836
1836
|
return {
|
|
1837
1837
|
...i && { allow: i },
|
|
1838
1838
|
...a && { deny: a },
|
|
1839
1839
|
from: r
|
|
1840
1840
|
};
|
|
1841
1841
|
}
|
|
1842
|
-
function
|
|
1843
|
-
let n = t.blazon.logo, r =
|
|
1842
|
+
function bi(e, t) {
|
|
1843
|
+
let n = t.blazon.logo, r = vi(e, t, "logo"), i = q(n?.deny);
|
|
1844
1844
|
if (n && i && r !== void 0) return {
|
|
1845
1845
|
deny: i,
|
|
1846
1846
|
...typeof n.reason == "string" && { reason: n.reason },
|
|
1847
1847
|
from: r
|
|
1848
1848
|
};
|
|
1849
1849
|
}
|
|
1850
|
-
function
|
|
1850
|
+
function xi(e) {
|
|
1851
1851
|
return e.tokens.groupMeta.flatMap((e) => (e.blazon.pairs ?? []).map((t) => ({
|
|
1852
1852
|
fg: t.fg,
|
|
1853
1853
|
bg: t.bg,
|
|
@@ -1855,19 +1855,19 @@ function _i(e) {
|
|
|
1855
1855
|
from: e.path
|
|
1856
1856
|
})));
|
|
1857
1857
|
}
|
|
1858
|
-
function
|
|
1858
|
+
function Si(e, t) {
|
|
1859
1859
|
let n = [];
|
|
1860
|
-
for (let r of
|
|
1860
|
+
for (let r of xi(e)) b(r.fg, e.tokens.items).some((e) => e.path === t.path) && n.push({
|
|
1861
1861
|
...r,
|
|
1862
1862
|
as: "fg"
|
|
1863
|
-
}),
|
|
1863
|
+
}), b(r.bg, e.tokens.items).some((e) => e.path === t.path) && n.push({
|
|
1864
1864
|
...r,
|
|
1865
1865
|
as: "bg"
|
|
1866
1866
|
});
|
|
1867
1867
|
return n;
|
|
1868
1868
|
}
|
|
1869
|
-
function
|
|
1870
|
-
let n =
|
|
1869
|
+
function Ci(e, t) {
|
|
1870
|
+
let n = _i(t).review, r = n ? t.path : vi(e, t, "review"), i = n ?? e.tokens.groupMeta.find((e) => e.path === r)?.blazon.review;
|
|
1871
1871
|
if (i && r !== void 0) return {
|
|
1872
1872
|
status: i.status,
|
|
1873
1873
|
...i.note && { note: i.note },
|
|
@@ -1876,8 +1876,8 @@ function yi(e, t) {
|
|
|
1876
1876
|
from: r
|
|
1877
1877
|
};
|
|
1878
1878
|
}
|
|
1879
|
-
function
|
|
1880
|
-
let n =
|
|
1879
|
+
function wi(e, t) {
|
|
1880
|
+
let n = yi(e, t), r = bi(e, t), i = Ci(e, t), a = t.blazon.role === void 0 ? void 0 : vi(e, t, "role");
|
|
1881
1881
|
return {
|
|
1882
1882
|
...t.blazon.role !== void 0 && a !== void 0 && { role: {
|
|
1883
1883
|
value: t.blazon.role,
|
|
@@ -1885,15 +1885,15 @@ function bi(e, t) {
|
|
|
1885
1885
|
} },
|
|
1886
1886
|
...n && { usage: n },
|
|
1887
1887
|
...r && { logo: r },
|
|
1888
|
-
pairs:
|
|
1888
|
+
pairs: Si(e, t),
|
|
1889
1889
|
...i && { review: i }
|
|
1890
1890
|
};
|
|
1891
1891
|
}
|
|
1892
|
-
function
|
|
1892
|
+
function Ti(e, t, n) {
|
|
1893
1893
|
let r = n.usage && typeof n.usage == "object" ? {
|
|
1894
|
-
...
|
|
1895
|
-
...
|
|
1896
|
-
} : void 0, i =
|
|
1894
|
+
...q(n.usage.allow) && { allow: q(n.usage.allow) },
|
|
1895
|
+
...q(n.usage.deny) && { deny: q(n.usage.deny) }
|
|
1896
|
+
} : void 0, i = q(n.logo?.deny), a = {
|
|
1897
1897
|
at: e,
|
|
1898
1898
|
kind: t,
|
|
1899
1899
|
...typeof n.role == "string" && { role: n.role },
|
|
@@ -1910,37 +1910,37 @@ function xi(e, t, n) {
|
|
|
1910
1910
|
};
|
|
1911
1911
|
return Object.keys(a).length > 2 ? a : void 0;
|
|
1912
1912
|
}
|
|
1913
|
-
function
|
|
1914
|
-
let n =
|
|
1913
|
+
function Ei(e, t) {
|
|
1914
|
+
let n = hi(t), r = (e) => n === "" || e === n || e.startsWith(`${n}.`);
|
|
1915
1915
|
if (!(n === "" || e.tokens.items.some((e) => r(e.path)))) {
|
|
1916
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 = E(n, [...t, ...e.tokens.items.map((e) => e.path)]);
|
|
1917
|
-
throw new
|
|
1917
|
+
throw new K(`no token or group "${n}"${r ? `; did you mean "${r}"?` : "."}`);
|
|
1918
1918
|
}
|
|
1919
1919
|
return [
|
|
1920
|
-
...e.tokens.groupMeta.filter((e) => n !== "" && n.startsWith(`${e.path}.`)).map((e) =>
|
|
1920
|
+
...e.tokens.groupMeta.filter((e) => n !== "" && n.startsWith(`${e.path}.`)).map((e) => Ti(e.path, "group", {
|
|
1921
1921
|
...e.blazon,
|
|
1922
1922
|
pairs: void 0
|
|
1923
1923
|
})).map((e) => e && {
|
|
1924
1924
|
...e,
|
|
1925
1925
|
inherited: !0
|
|
1926
1926
|
}),
|
|
1927
|
-
...e.tokens.groupMeta.filter((e) => r(e.path)).map((e) =>
|
|
1928
|
-
...e.tokens.items.filter((e) => r(e.path)).map((e) =>
|
|
1927
|
+
...e.tokens.groupMeta.filter((e) => r(e.path)).map((e) => Ti(e.path, "group", e.blazon)),
|
|
1928
|
+
...e.tokens.items.filter((e) => r(e.path)).map((e) => Ti(e.path, "token", _i(e)))
|
|
1929
1929
|
].filter((e) => e !== void 0);
|
|
1930
1930
|
}
|
|
1931
1931
|
// src/core/read/token.ts
|
|
1932
|
-
function
|
|
1933
|
-
let [
|
|
1932
|
+
function Di(e, t) {
|
|
1933
|
+
let [r, ...i] = n(t);
|
|
1934
1934
|
return {
|
|
1935
1935
|
theme: {
|
|
1936
|
-
variable:
|
|
1937
|
-
...t.parts && { parts: Object.fromEntries(Object.keys(t.parts).map((e, t) => [e,
|
|
1936
|
+
variable: r,
|
|
1937
|
+
...t.parts && { parts: Object.fromEntries(Object.keys(t.parts).map((e, t) => [e, i[t]])) }
|
|
1938
1938
|
},
|
|
1939
|
-
...t.type === "typography" && { typographyClass:
|
|
1939
|
+
...t.type === "typography" && { typographyClass: p(t.path) }
|
|
1940
1940
|
};
|
|
1941
1941
|
}
|
|
1942
|
-
function
|
|
1943
|
-
let n =
|
|
1942
|
+
function Oi(e, t) {
|
|
1943
|
+
let n = gi(e, t), r = (e.tokens.contexts ?? []).flatMap((e) => e.tokens.filter((e) => e.path === n.path).map((t) => ({
|
|
1944
1944
|
modifier: e.modifier,
|
|
1945
1945
|
context: e.context,
|
|
1946
1946
|
selector: e.selector,
|
|
@@ -1955,14 +1955,14 @@ function wi(e, t) {
|
|
|
1955
1955
|
...n.deprecated && { deprecated: n.deprecated },
|
|
1956
1956
|
...n.aliasOf && { aliasOf: n.aliasOf },
|
|
1957
1957
|
...n.blazon.tier && { tier: n.blazon.tier },
|
|
1958
|
-
names:
|
|
1959
|
-
rules:
|
|
1958
|
+
names: Di(e, n),
|
|
1959
|
+
rules: wi(e, n),
|
|
1960
1960
|
...r.length > 0 && { contexts: r },
|
|
1961
1961
|
sourceFile: n.file.replace(/ \(inline\)$/, "")
|
|
1962
1962
|
};
|
|
1963
1963
|
}
|
|
1964
1964
|
// src/core/read/list.ts
|
|
1965
|
-
function
|
|
1965
|
+
function ki(e) {
|
|
1966
1966
|
let t = /* @__PURE__ */ new Set();
|
|
1967
1967
|
for (let { path: n } of e.tokens.items) {
|
|
1968
1968
|
let e = n.split(".");
|
|
@@ -1970,20 +1970,20 @@ function Ti(e) {
|
|
|
1970
1970
|
}
|
|
1971
1971
|
return t;
|
|
1972
1972
|
}
|
|
1973
|
-
function
|
|
1974
|
-
let n =
|
|
1975
|
-
return !e.tokens.byPath.has(n) &&
|
|
1973
|
+
function Ai(e, t) {
|
|
1974
|
+
let n = hi(t);
|
|
1975
|
+
return !e.tokens.byPath.has(n) && ki(e).has(n);
|
|
1976
1976
|
}
|
|
1977
|
-
function
|
|
1977
|
+
function ji(e, t = {}) {
|
|
1978
1978
|
let n;
|
|
1979
|
-
if (t.type !== void 0 && (n =
|
|
1979
|
+
if (t.type !== void 0 && (n = s.find((e) => e === t.type), !n)) throw new K(`no token type "${t.type}"; the types are ${s.join(", ")}.`);
|
|
1980
1980
|
let r;
|
|
1981
1981
|
if (t.group !== void 0) {
|
|
1982
|
-
r =
|
|
1983
|
-
let n =
|
|
1982
|
+
r = hi(t.group);
|
|
1983
|
+
let n = ki(e);
|
|
1984
1984
|
if (!n.has(r)) {
|
|
1985
1985
|
let e = E(r, [...n]);
|
|
1986
|
-
throw new
|
|
1986
|
+
throw new K(`no group "${r}"${e ? `; did you mean "${e}"?` : "."}`);
|
|
1987
1987
|
}
|
|
1988
1988
|
}
|
|
1989
1989
|
let i = e.tokens.items.filter((e) => (r === void 0 || e.path.startsWith(`${r}.`)) && (n === void 0 || e.type === n)).map((e) => ({
|
|
@@ -1999,24 +1999,24 @@ function Di(e, t = {}) {
|
|
|
1999
1999
|
};
|
|
2000
2000
|
}
|
|
2001
2001
|
// src/core/read/can.ts
|
|
2002
|
-
var
|
|
2002
|
+
var Mi = ["text", "ui"], Ni = g["AA-large"], Pi = [
|
|
2003
2003
|
"border",
|
|
2004
2004
|
"icon",
|
|
2005
2005
|
"interactive"
|
|
2006
|
-
],
|
|
2006
|
+
], Fi = [
|
|
2007
2007
|
"AAA",
|
|
2008
2008
|
"AA",
|
|
2009
2009
|
"AA-large"
|
|
2010
2010
|
];
|
|
2011
|
-
function
|
|
2011
|
+
function Ii(e, t) {
|
|
2012
2012
|
let n = [];
|
|
2013
2013
|
for (let r = t; r && !n.includes(r); r = r.aliasOf ? e.tokens.byPath.get(r.aliasOf) : void 0) n.push(r);
|
|
2014
2014
|
return n;
|
|
2015
2015
|
}
|
|
2016
|
-
function
|
|
2017
|
-
for (let r of
|
|
2018
|
-
if (
|
|
2019
|
-
let t =
|
|
2016
|
+
function Li(e, t, n) {
|
|
2017
|
+
for (let r of Ii(e, t)) {
|
|
2018
|
+
if (Ee(r, n)) continue;
|
|
2019
|
+
let t = yi(e, r), i = t.deny?.includes(n) ? `denies "${n}"` : `allows only ${(t.allow ?? []).map((e) => `"${e}"`).join(", ")}, not "${n}"`;
|
|
2020
2020
|
return {
|
|
2021
2021
|
rule: "usage",
|
|
2022
2022
|
ok: !1,
|
|
@@ -2024,15 +2024,15 @@ function Ni(e, t, n) {
|
|
|
2024
2024
|
from: t.from
|
|
2025
2025
|
};
|
|
2026
2026
|
}
|
|
2027
|
-
let r =
|
|
2027
|
+
let r = Ii(e, t).find((t) => yi(e, t));
|
|
2028
2028
|
return {
|
|
2029
2029
|
rule: "usage",
|
|
2030
2030
|
ok: !0,
|
|
2031
2031
|
message: r ? `usage rules on {${r.path}} leave "${n}" open` : `{${t.path}} has no usage rule against "${n}"`
|
|
2032
2032
|
};
|
|
2033
2033
|
}
|
|
2034
|
-
function
|
|
2035
|
-
let n =
|
|
2034
|
+
function Ri(e, t) {
|
|
2035
|
+
let n = Pi.map((n) => Li(e, t, n)), r = Pi.filter((e, t) => n[t].ok);
|
|
2036
2036
|
return r.length > 0 ? {
|
|
2037
2037
|
rule: "usage",
|
|
2038
2038
|
ok: !0,
|
|
@@ -2044,12 +2044,12 @@ function Pi(e, t) {
|
|
|
2044
2044
|
from: n[0].from
|
|
2045
2045
|
};
|
|
2046
2046
|
}
|
|
2047
|
-
var
|
|
2048
|
-
function
|
|
2049
|
-
let n = e.tokens.modifiers?.find((e) => e.name ===
|
|
2050
|
-
if (!n) throw new
|
|
2051
|
-
if (!n.contexts.includes(t)) throw new
|
|
2052
|
-
let r = (e.tokens.contexts ?? []).filter((e) => e.modifier === "theme" && e.context === t), i =
|
|
2047
|
+
var zi = "theme";
|
|
2048
|
+
function Bi(e, t) {
|
|
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
2053
|
return {
|
|
2054
2054
|
...e,
|
|
2055
2055
|
tokens: {
|
|
@@ -2059,22 +2059,22 @@ function Ii(e, t) {
|
|
|
2059
2059
|
}
|
|
2060
2060
|
};
|
|
2061
2061
|
}
|
|
2062
|
-
var
|
|
2063
|
-
let n = e.type === "color" ?
|
|
2064
|
-
if (!n) throw new
|
|
2062
|
+
var Vi = (e, t) => {
|
|
2063
|
+
let n = e.type === "color" ? f(String(e.value)) : void 0;
|
|
2064
|
+
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
2065
|
return n;
|
|
2066
2066
|
};
|
|
2067
|
-
function
|
|
2068
|
-
if (
|
|
2069
|
-
...
|
|
2070
|
-
theme:
|
|
2067
|
+
function Hi(e, t, n, r = "text", i) {
|
|
2068
|
+
if (i !== void 0) return {
|
|
2069
|
+
...Hi(Bi(e, i), t, n, r),
|
|
2070
|
+
theme: i
|
|
2071
2071
|
};
|
|
2072
|
-
if (!
|
|
2073
|
-
let
|
|
2074
|
-
if (
|
|
2075
|
-
let
|
|
2076
|
-
|
|
2077
|
-
|
|
2072
|
+
if (!Mi.includes(r)) throw new K(`"${String(r)}" is not a role blazon can judge. Use ${Mi.map((e) => `"${e}"`).join(" or ")}.`);
|
|
2073
|
+
let a = gi(e, t), o = gi(e, n), s = _(Vi(a, "foreground"), Vi(o, "background")), c = Fi.find((e) => s >= g[e]) ?? "fail", l = `${s.toFixed(2)}:1`, d = Math.round(s * 100) / 100;
|
|
2074
|
+
if (r === "ui") {
|
|
2075
|
+
let t = [
|
|
2076
|
+
Ri(e, a),
|
|
2077
|
+
Li(e, o, "background"),
|
|
2078
2078
|
{
|
|
2079
2079
|
rule: "pairs",
|
|
2080
2080
|
ok: !0,
|
|
@@ -2082,38 +2082,38 @@ function Ri(t, n, r, i = "text", a) {
|
|
|
2082
2082
|
},
|
|
2083
2083
|
{
|
|
2084
2084
|
rule: "contrast",
|
|
2085
|
-
ok:
|
|
2086
|
-
message: `non-text contrast needs ${
|
|
2085
|
+
ok: s >= Ni,
|
|
2086
|
+
message: `non-text contrast needs ${Ni}:1, this is ${l}`
|
|
2087
2087
|
}
|
|
2088
|
-
], n =
|
|
2088
|
+
], n = t.find((e) => !e.ok), i = n ? n.message : t[t.length - 1].message;
|
|
2089
2089
|
return {
|
|
2090
|
-
fg:
|
|
2091
|
-
bg:
|
|
2092
|
-
role:
|
|
2090
|
+
fg: a.path,
|
|
2091
|
+
bg: o.path,
|
|
2092
|
+
role: r,
|
|
2093
2093
|
allowed: n === void 0,
|
|
2094
|
-
reason:
|
|
2095
|
-
checks:
|
|
2094
|
+
reason: i,
|
|
2095
|
+
checks: t,
|
|
2096
2096
|
contrast: {
|
|
2097
2097
|
ratio: d,
|
|
2098
|
-
level:
|
|
2099
|
-
threshold:
|
|
2098
|
+
level: c,
|
|
2099
|
+
threshold: Ni
|
|
2100
2100
|
}
|
|
2101
2101
|
};
|
|
2102
2102
|
}
|
|
2103
|
-
let f = [
|
|
2104
|
-
if (
|
|
2105
|
-
let t =
|
|
2103
|
+
let f = [Li(e, a, "text"), Li(e, o, "background")], p = xi(e), m = u(e.tokens.items, p, a.path, o.path);
|
|
2104
|
+
if (m.length > 0) for (let e of m) {
|
|
2105
|
+
let t = g[e.min];
|
|
2106
2106
|
f.push({
|
|
2107
2107
|
rule: "pairs",
|
|
2108
|
-
ok:
|
|
2109
|
-
message: `pairs on ${e.from} list ${e.fg} on ${e.bg}: ${e.min} needs ${t}:1, this is ${
|
|
2108
|
+
ok: s >= t,
|
|
2109
|
+
message: `pairs on ${e.from} list ${e.fg} on ${e.bg}: ${e.min} needs ${t}:1, this is ${l}`,
|
|
2110
2110
|
from: e.from
|
|
2111
2111
|
});
|
|
2112
2112
|
}
|
|
2113
2113
|
else p.length > 0 ? f.push({
|
|
2114
2114
|
rule: "pairs",
|
|
2115
2115
|
ok: !1,
|
|
2116
|
-
message: `no pair lists {${
|
|
2116
|
+
message: `no pair lists {${a.path}} on {${o.path}}; the brand lists ${p.length} pair${p.length === 1 ? "" : "s"} and only those may sit together`
|
|
2117
2117
|
}) : f.push({
|
|
2118
2118
|
rule: "pairs",
|
|
2119
2119
|
ok: !0,
|
|
@@ -2122,34 +2122,34 @@ function Ri(t, n, r, i = "text", a) {
|
|
|
2122
2122
|
f.push({
|
|
2123
2123
|
rule: "contrast",
|
|
2124
2124
|
ok: !0,
|
|
2125
|
-
message: `contrast is ${
|
|
2125
|
+
message: `contrast is ${l}${c === "fail" ? ", below every WCAG level" : `, which meets ${c}`} (reported, never a rule of its own)`
|
|
2126
2126
|
});
|
|
2127
|
-
let
|
|
2127
|
+
let h = f.find((e) => !e.ok && e.rule !== "contrast") ?? void 0, v = h === void 0, y = h ? h.message : (f.find((e) => e.rule === "pairs" && e.from) ?? f[f.length - 1]).message;
|
|
2128
2128
|
return {
|
|
2129
|
-
fg:
|
|
2130
|
-
bg:
|
|
2131
|
-
role:
|
|
2132
|
-
allowed:
|
|
2133
|
-
reason:
|
|
2129
|
+
fg: a.path,
|
|
2130
|
+
bg: o.path,
|
|
2131
|
+
role: r,
|
|
2132
|
+
allowed: v,
|
|
2133
|
+
reason: y,
|
|
2134
2134
|
checks: f,
|
|
2135
2135
|
contrast: {
|
|
2136
2136
|
ratio: d,
|
|
2137
|
-
level:
|
|
2137
|
+
level: c
|
|
2138
2138
|
}
|
|
2139
2139
|
};
|
|
2140
2140
|
}
|
|
2141
2141
|
// src/core/read/fonts.ts
|
|
2142
|
-
function
|
|
2143
|
-
let r = t.fonts ?? [], i =
|
|
2142
|
+
function Ui(e, t, n) {
|
|
2143
|
+
let r = t.fonts ?? [], i = Ve(t.fonts, n), a = /* @__PURE__ */ new Map();
|
|
2144
2144
|
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" ?
|
|
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" ? Me(e) : t.type === "typography" && typeof e == "object" && e ? Me(e.fontFamily) : void 0;
|
|
2146
2146
|
if (!r) continue;
|
|
2147
2147
|
let o = r.toLowerCase(), s = a.get(o);
|
|
2148
2148
|
s ? (s.tokens.push(t.path), !s.stack && n && (s.stack = n)) : a.set(o, {
|
|
2149
2149
|
family: r,
|
|
2150
2150
|
tokens: [t.path],
|
|
2151
2151
|
...n && { stack: n },
|
|
2152
|
-
system:
|
|
2152
|
+
system: ue.has(o),
|
|
2153
2153
|
loaded: i.families.has(o) ? !0 : i.opaque ? null : !1,
|
|
2154
2154
|
...t.blazon.webFont !== void 0 && { webFont: t.blazon.webFont },
|
|
2155
2155
|
...t.blazon.font && { font: t.blazon.font }
|
|
@@ -2160,8 +2160,8 @@ function zi(e, t, n) {
|
|
|
2160
2160
|
value: e.theme[t]
|
|
2161
2161
|
} : void 0;
|
|
2162
2162
|
return {
|
|
2163
|
-
stylesheets: r.filter((e) => !
|
|
2164
|
-
files: r.filter(
|
|
2163
|
+
stylesheets: r.filter((e) => !ke(e)),
|
|
2164
|
+
files: r.filter(ke).map((e) => ({
|
|
2165
2165
|
family: e.family,
|
|
2166
2166
|
file: e.file,
|
|
2167
2167
|
...e.weight !== void 0 && { weight: e.weight },
|
|
@@ -2174,45 +2174,45 @@ function zi(e, t, n) {
|
|
|
2174
2174
|
families: [...a.values()]
|
|
2175
2175
|
};
|
|
2176
2176
|
}
|
|
2177
|
-
function
|
|
2177
|
+
function Wi(e, t) {
|
|
2178
2178
|
let n = e.stylesheets.map((e) => `/* Stylesheet, not fetched by blazon: ${e.replace(/\*\//g, "*%2F")} */`);
|
|
2179
2179
|
for (let r of e.files) {
|
|
2180
|
-
let e =
|
|
2180
|
+
let e = me(r.file);
|
|
2181
2181
|
if (!e) {
|
|
2182
2182
|
n.push(`/* ${r.file.replace(/\*\//g, "*%2F")}: not a font file blazon embeds, so no rule */`);
|
|
2183
2183
|
continue;
|
|
2184
2184
|
}
|
|
2185
2185
|
let i = t === void 0 ? r.file : `${t.endsWith("/") ? t : `${t}/`}${r.file.split("/").pop()}`;
|
|
2186
|
-
n.push(
|
|
2186
|
+
n.push(Le(r, `url("${encodeURI(i).replace(/"/g, "%22")}") format("${e}")`, !0));
|
|
2187
2187
|
}
|
|
2188
2188
|
return n.length === 0 ? "/* The config lists no fonts. */\n" : `${n.join("\n\n")}\n`;
|
|
2189
2189
|
}
|
|
2190
2190
|
// src/core/read/logo.ts
|
|
2191
|
-
function
|
|
2192
|
-
let
|
|
2193
|
-
let n =
|
|
2191
|
+
function Gi(e, t, n) {
|
|
2192
|
+
let i = ee(t), a = O.resolve(n, t.assetsDir), o = ne(t.assets, n), s = (e) => O.relative(n, r(e, a, o)).split(O.sep).join("/"), c = ["onLight", "onDark"].flatMap((t) => {
|
|
2193
|
+
let n = i[t];
|
|
2194
2194
|
if (!n) return [];
|
|
2195
|
-
let
|
|
2195
|
+
let r = t === "onLight" ? e.logo?.onLightAsset : e.logo?.onDarkAsset, a = t === "onLight" ? e.logo?.onLightInk : e.logo?.onDarkInk;
|
|
2196
2196
|
return [{
|
|
2197
2197
|
variant: t,
|
|
2198
2198
|
file: n,
|
|
2199
2199
|
found: !!(t === "onLight" ? e.logo?.onLight : e.logo?.onDark),
|
|
2200
|
-
...
|
|
2200
|
+
...r && { asset: r },
|
|
2201
2201
|
...a && { ink: a }
|
|
2202
2202
|
}];
|
|
2203
2203
|
});
|
|
2204
2204
|
return {
|
|
2205
2205
|
variants: c,
|
|
2206
2206
|
assets: e.assets.logos.map((e) => {
|
|
2207
|
-
let t =
|
|
2207
|
+
let t = r(e, a, o);
|
|
2208
2208
|
return {
|
|
2209
2209
|
id: e.id,
|
|
2210
|
-
file:
|
|
2211
|
-
variants: c.filter((e) =>
|
|
2210
|
+
file: s(e),
|
|
2211
|
+
variants: c.filter((e) => i[e.variant] ? Ze(O.resolve(n, i[e.variant]), t) : !1).map((e) => e.variant),
|
|
2212
2212
|
rules: e.meta ?? {}
|
|
2213
2213
|
};
|
|
2214
2214
|
}),
|
|
2215
|
-
forbidden:
|
|
2215
|
+
forbidden: Ei(e, "").flatMap((e) => e.logo ? [{
|
|
2216
2216
|
at: e.at,
|
|
2217
2217
|
deny: e.logo.deny,
|
|
2218
2218
|
...e.logo.reason && { reason: e.logo.reason }
|
|
@@ -2220,33 +2220,33 @@ function Vi(e, t, n) {
|
|
|
2220
2220
|
};
|
|
2221
2221
|
}
|
|
2222
2222
|
// src/cli/read.ts
|
|
2223
|
-
async function
|
|
2224
|
-
let t = await
|
|
2225
|
-
return
|
|
2223
|
+
async function J(e) {
|
|
2224
|
+
let t = await R(e), n = await D(t, e), { errors: r } = c(n.findings);
|
|
2225
|
+
return r.length > 0 && console.error(l.yellow(`blazon: this brand has ${r.length} error(s), so a value below may be wrong; run blazon check.`)), {
|
|
2226
2226
|
config: t,
|
|
2227
|
-
data:
|
|
2227
|
+
data: n
|
|
2228
2228
|
};
|
|
2229
2229
|
}
|
|
2230
|
-
function
|
|
2230
|
+
function Ki(e) {
|
|
2231
2231
|
try {
|
|
2232
2232
|
return e();
|
|
2233
2233
|
} catch (e) {
|
|
2234
|
-
throw e instanceof
|
|
2234
|
+
throw e instanceof K ? new M(e.message, void 0, "unknown-token") : e;
|
|
2235
2235
|
}
|
|
2236
2236
|
}
|
|
2237
|
-
function
|
|
2237
|
+
function Y(e, t, n) {
|
|
2238
2238
|
process.stdout.write(`${JSON.stringify({
|
|
2239
2239
|
command: e,
|
|
2240
2240
|
passed: t,
|
|
2241
2241
|
...n
|
|
2242
2242
|
}, null, 2)}\n`);
|
|
2243
2243
|
}
|
|
2244
|
-
function
|
|
2245
|
-
let
|
|
2246
|
-
for (let [e,
|
|
2244
|
+
function qi(e, t = " ") {
|
|
2245
|
+
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}${l.dim(e.padEnd(r))} ${i}`);
|
|
2247
2247
|
}
|
|
2248
2248
|
// src/cli/commands/doctor.ts
|
|
2249
|
-
var
|
|
2249
|
+
var Ji = [
|
|
2250
2250
|
"blazon.brand-deck",
|
|
2251
2251
|
"blazon.favicons",
|
|
2252
2252
|
"blazon.logo-geometry",
|
|
@@ -2254,36 +2254,36 @@ var Gi = [
|
|
|
2254
2254
|
"blazon.press-kit",
|
|
2255
2255
|
"blazon.print-book",
|
|
2256
2256
|
"blazon.social-cards"
|
|
2257
|
-
],
|
|
2257
|
+
], Yi = (e) => {
|
|
2258
2258
|
try {
|
|
2259
|
-
return
|
|
2259
|
+
return k.accessSync(e, k.constants.X_OK), k.statSync(e).isFile();
|
|
2260
2260
|
} catch {
|
|
2261
2261
|
return !1;
|
|
2262
2262
|
}
|
|
2263
2263
|
};
|
|
2264
|
-
function
|
|
2265
|
-
if (e.BLAZON_CHROME) return
|
|
2264
|
+
function Xi(e = process.env) {
|
|
2265
|
+
if (e.BLAZON_CHROME) return Yi(e.BLAZON_CHROME);
|
|
2266
2266
|
let t = [];
|
|
2267
2267
|
if (process.platform === "darwin") t.push("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome");
|
|
2268
2268
|
else if (process.platform === "win32") for (let n of [
|
|
2269
2269
|
e.PROGRAMFILES,
|
|
2270
2270
|
e["PROGRAMFILES(X86)"],
|
|
2271
2271
|
e.LOCALAPPDATA
|
|
2272
|
-
]) n && t.push(
|
|
2273
|
-
else t.push("/opt/google/chrome/chrome", ...(e.PATH ?? "").split(
|
|
2274
|
-
return t.some(
|
|
2272
|
+
]) n && t.push(O.join(n, "Google", "Chrome", "Application", "chrome.exe"));
|
|
2273
|
+
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(Yi);
|
|
2275
2275
|
}
|
|
2276
|
-
var
|
|
2277
|
-
let e = JSON.parse(
|
|
2276
|
+
var Zi = () => {
|
|
2277
|
+
let e = JSON.parse(k.readFileSync(O.join(ve(), "package.json"), "utf-8"));
|
|
2278
2278
|
return {
|
|
2279
2279
|
nodeVersion: process.version,
|
|
2280
2280
|
engine: e.engines?.node,
|
|
2281
|
-
hostProblem: (e) =>
|
|
2282
|
-
chrome: () =>
|
|
2283
|
-
identity:
|
|
2281
|
+
hostProblem: (e) => Fe(e, { final: "dir" }),
|
|
2282
|
+
chrome: () => Xi(),
|
|
2283
|
+
identity: ce()
|
|
2284
2284
|
};
|
|
2285
2285
|
};
|
|
2286
|
-
function
|
|
2286
|
+
function Qi(e, t) {
|
|
2287
2287
|
let n = /^>=\s*v?(\d+)(?:\.(\d+))?(?:\.(\d+))?$/.exec(t.trim()), r = /^v?(\d+)\.(\d+)\.(\d+)/.exec(e);
|
|
2288
2288
|
if (!n || !r) return;
|
|
2289
2289
|
let i = [
|
|
@@ -2298,14 +2298,14 @@ function Yi(e, t) {
|
|
|
2298
2298
|
for (let e = 0; e < 3; e++) if (a[e] !== i[e]) return a[e] > i[e];
|
|
2299
2299
|
return !0;
|
|
2300
2300
|
}
|
|
2301
|
-
function
|
|
2301
|
+
function $i(e) {
|
|
2302
2302
|
if (!e.engine) return {
|
|
2303
2303
|
id: "node",
|
|
2304
2304
|
status: "warn",
|
|
2305
2305
|
message: `Node ${e.nodeVersion}; blazon's package.json names no engines range to compare`,
|
|
2306
2306
|
fix: "Reinstall blazon."
|
|
2307
2307
|
};
|
|
2308
|
-
let t =
|
|
2308
|
+
let t = Qi(e.nodeVersion, e.engine);
|
|
2309
2309
|
return t === void 0 ? {
|
|
2310
2310
|
id: "node",
|
|
2311
2311
|
status: "warn",
|
|
@@ -2322,9 +2322,9 @@ function Xi(e) {
|
|
|
2322
2322
|
fix: `Install Node ${e.engine.replace(/^>=\s*/, "")} or newer, such as with nvm install ${e.engine.replace(/^>=\s*v?(\d+).*$/, "$1")}.`
|
|
2323
2323
|
};
|
|
2324
2324
|
}
|
|
2325
|
-
async function
|
|
2325
|
+
async function ea(e) {
|
|
2326
2326
|
try {
|
|
2327
|
-
let t = await
|
|
2327
|
+
let t = await R(e);
|
|
2328
2328
|
return {
|
|
2329
2329
|
check: {
|
|
2330
2330
|
id: "brand",
|
|
@@ -2338,18 +2338,18 @@ async function Zi(e) {
|
|
|
2338
2338
|
id: "brand",
|
|
2339
2339
|
status: "fail",
|
|
2340
2340
|
message: e instanceof Error ? e.message : String(e),
|
|
2341
|
-
fix: e instanceof
|
|
2341
|
+
fix: e instanceof j && e.fix ? e.fix : "Fix the error in blazon.json, then run blazon doctor again."
|
|
2342
2342
|
} };
|
|
2343
2343
|
}
|
|
2344
2344
|
}
|
|
2345
|
-
function
|
|
2345
|
+
function ta(e, t, n) {
|
|
2346
2346
|
let r = t.hostProblem(e);
|
|
2347
2347
|
if (!r) return {
|
|
2348
2348
|
id: "plugin-host",
|
|
2349
2349
|
status: "ok",
|
|
2350
2350
|
message: `${e} is a folder blazon will run plugins from`
|
|
2351
2351
|
};
|
|
2352
|
-
let i = /written by group or others/.test(r) ?
|
|
2352
|
+
let i = /written by group or others/.test(r) ? qe(e) : "Run blazon from a folder under your own home folder that only you can write.";
|
|
2353
2353
|
return {
|
|
2354
2354
|
id: "plugin-host",
|
|
2355
2355
|
status: n > 0 ? "fail" : "warn",
|
|
@@ -2357,8 +2357,8 @@ function Qi(e, t, n) {
|
|
|
2357
2357
|
fix: i
|
|
2358
2358
|
};
|
|
2359
2359
|
}
|
|
2360
|
-
function
|
|
2361
|
-
let n = [...new Set((t?.plugins ?? []).map((e) => e.name).filter((e) =>
|
|
2360
|
+
function na(e, t) {
|
|
2361
|
+
let n = [...new Set((t?.plugins ?? []).map((e) => e.name).filter((e) => Ji.includes(e)))];
|
|
2362
2362
|
return n.length === 0 ? {
|
|
2363
2363
|
id: "chrome",
|
|
2364
2364
|
status: "ok",
|
|
@@ -2374,53 +2374,53 @@ function $i(e, t) {
|
|
|
2374
2374
|
fix: "Install Google Chrome, or set BLAZON_CHROME to a Chrome or Chromium program; or take the plugin out of blazon.json."
|
|
2375
2375
|
};
|
|
2376
2376
|
}
|
|
2377
|
-
function
|
|
2378
|
-
if (!
|
|
2377
|
+
function ra(e, t) {
|
|
2378
|
+
if (!k.existsSync(O.join(e, "blazon.lock"))) return {
|
|
2379
2379
|
id: "lock",
|
|
2380
2380
|
status: "ok",
|
|
2381
2381
|
message: "no blazon.lock: this book is not pinned to a blazon build"
|
|
2382
2382
|
};
|
|
2383
|
-
let n =
|
|
2383
|
+
let n = We(e, t.identity)[0];
|
|
2384
2384
|
return n ? {
|
|
2385
2385
|
id: "lock",
|
|
2386
2386
|
status: "fail",
|
|
2387
2387
|
message: n.message,
|
|
2388
|
-
fix: n.fix ??
|
|
2388
|
+
fix: n.fix ?? se[n.code].fix
|
|
2389
2389
|
} : {
|
|
2390
2390
|
id: "lock",
|
|
2391
2391
|
status: "ok",
|
|
2392
2392
|
message: "blazon.lock matches the blazon that is running"
|
|
2393
2393
|
};
|
|
2394
2394
|
}
|
|
2395
|
-
async function
|
|
2396
|
-
let n = await
|
|
2395
|
+
async function ia(e, t = Zi()) {
|
|
2396
|
+
let n = await ea(e);
|
|
2397
2397
|
return [
|
|
2398
|
-
|
|
2398
|
+
$i(t),
|
|
2399
2399
|
n.check,
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2400
|
+
ta(e, t, n.config?.plugins?.length ?? 0),
|
|
2401
|
+
na(t, n.config),
|
|
2402
|
+
ra(e, t)
|
|
2403
2403
|
];
|
|
2404
2404
|
}
|
|
2405
|
-
var
|
|
2406
|
-
ok:
|
|
2407
|
-
warn:
|
|
2408
|
-
fail:
|
|
2405
|
+
var aa = {
|
|
2406
|
+
ok: l.green,
|
|
2407
|
+
warn: l.yellow,
|
|
2408
|
+
fail: l.red
|
|
2409
2409
|
};
|
|
2410
|
-
async function
|
|
2411
|
-
let
|
|
2412
|
-
if (t.json) return
|
|
2410
|
+
async function oa(e = process.cwd(), t = {}) {
|
|
2411
|
+
let n = await ia(e), r = !n.some((e) => e.status === "fail");
|
|
2412
|
+
if (t.json) return Y("doctor", r, { checks: n }), +!r;
|
|
2413
2413
|
console.log();
|
|
2414
|
-
for (let e of
|
|
2415
|
-
return console.log(), +!
|
|
2414
|
+
for (let e of n) console.log(` ${aa[e.status](e.status.padEnd(4))} ${e.id.padEnd(11)} ${e.message}`), e.status !== "ok" && e.fix && console.log(l.dim(` fix: ${e.fix}`));
|
|
2415
|
+
return console.log(), +!r;
|
|
2416
2416
|
}
|
|
2417
2417
|
// src/core/operations/limits.ts
|
|
2418
|
-
var
|
|
2418
|
+
var sa = 4e4, X = {
|
|
2419
2419
|
readOnlyHint: !0,
|
|
2420
2420
|
destructiveHint: !1,
|
|
2421
2421
|
idempotentHint: !0,
|
|
2422
2422
|
openWorldHint: !1
|
|
2423
|
-
},
|
|
2423
|
+
}, ca = {
|
|
2424
2424
|
type: "string",
|
|
2425
2425
|
description: "The brand folder. Default: the current folder"
|
|
2426
2426
|
}, Z = (e, t) => ({
|
|
@@ -2428,7 +2428,7 @@ var ia = 4e4, X = {
|
|
|
2428
2428
|
properties: e,
|
|
2429
2429
|
...t.length > 0 && { required: t },
|
|
2430
2430
|
additionalProperties: !1
|
|
2431
|
-
}),
|
|
2431
|
+
}), la = {
|
|
2432
2432
|
warnings: {
|
|
2433
2433
|
type: "array",
|
|
2434
2434
|
items: { type: "string" },
|
|
@@ -2449,7 +2449,7 @@ var ia = 4e4, X = {
|
|
|
2449
2449
|
}, Q = (e, t) => ({
|
|
2450
2450
|
type: "object",
|
|
2451
2451
|
properties: {
|
|
2452
|
-
...
|
|
2452
|
+
...la,
|
|
2453
2453
|
...e
|
|
2454
2454
|
},
|
|
2455
2455
|
required: [
|
|
@@ -2458,11 +2458,11 @@ var ia = 4e4, X = {
|
|
|
2458
2458
|
...t
|
|
2459
2459
|
],
|
|
2460
2460
|
additionalProperties: {}
|
|
2461
|
-
}),
|
|
2461
|
+
}), ua = [
|
|
2462
2462
|
{
|
|
2463
2463
|
name: "check_brand",
|
|
2464
2464
|
title: "Check the brand",
|
|
2465
|
-
description: "Runs blazon check on the brand, without plugins, and returns its findings and counts. `passed` is false when the brand has errors, and values read from such a brand can be wrong. Returns at most `limit` findings (default 50, at most 500); `counts` stay whole. Not for reading a value: use get_token.",
|
|
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. Returns at most `limit` findings (default 50, at most 500); `counts` stay whole. Not for reading a value: use get_token.",
|
|
2466
2466
|
annotations: X,
|
|
2467
2467
|
inputSchema: Z({
|
|
2468
2468
|
severity: {
|
|
@@ -2541,6 +2541,11 @@ var ia = 4e4, X = {
|
|
|
2541
2541
|
findingsTotal: {
|
|
2542
2542
|
description: "How many findings there are before `limit` cut the list",
|
|
2543
2543
|
type: "number"
|
|
2544
|
+
},
|
|
2545
|
+
pluginsSkipped: {
|
|
2546
|
+
type: "array",
|
|
2547
|
+
items: { type: "string" },
|
|
2548
|
+
description: "Every plugin blazon.json lists, which did not run because the server never starts a plugin. Only one with a check role can make `blazon check` report more findings than `counts`; the server cannot tell which without starting it. Absent when the config lists none"
|
|
2544
2549
|
}
|
|
2545
2550
|
}, [
|
|
2546
2551
|
"passed",
|
|
@@ -2559,7 +2564,7 @@ var ia = 4e4, X = {
|
|
|
2559
2564
|
{
|
|
2560
2565
|
name: "list_tokens",
|
|
2561
2566
|
title: "List the tokens",
|
|
2562
|
-
description: `Lists the design tokens of the brand, or of one group, or of one type, each with its path, type and value, in the order the token files write them. Use it to find a path or to read many values at once. For a token's CSS variable names and rules use get_token; for the brand's usage rules use get_rules. An answer over ${
|
|
2567
|
+
description: `Lists the design tokens of the brand, or of one group, or of one type, each with its path, type and value, in the order the token files write them. Use it to find a path or to read many values at once. For a token's CSS variable names and rules use get_token; for the brand's usage rules use get_rules. An answer over ${sa} characters is cut to whole tokens, and \`tokensTotal\` says how many matched: narrow with \`group\` or \`type\`.`,
|
|
2563
2568
|
annotations: X,
|
|
2564
2569
|
inputSchema: Z({
|
|
2565
2570
|
group: {
|
|
@@ -2683,7 +2688,7 @@ var ia = 4e4, X = {
|
|
|
2683
2688
|
{
|
|
2684
2689
|
name: "get_rules",
|
|
2685
2690
|
title: "Read the brand rules",
|
|
2686
|
-
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 (${
|
|
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 (${sa} characters): give a path, or read the resource blazon://rules, which is not cut.`,
|
|
2687
2692
|
annotations: X,
|
|
2688
2693
|
inputSchema: Z({
|
|
2689
2694
|
path: {
|
|
@@ -2931,7 +2936,7 @@ var ia = 4e4, X = {
|
|
|
2931
2936
|
type: "string",
|
|
2932
2937
|
description: "Only this part of the document, by its dotted path, such as theme.roles"
|
|
2933
2938
|
},
|
|
2934
|
-
dir:
|
|
2939
|
+
dir: ca
|
|
2935
2940
|
}, []),
|
|
2936
2941
|
cli: {
|
|
2937
2942
|
rank: 7,
|
|
@@ -2947,10 +2952,10 @@ var ia = 4e4, X = {
|
|
|
2947
2952
|
},
|
|
2948
2953
|
mcp: !1
|
|
2949
2954
|
}
|
|
2950
|
-
],
|
|
2955
|
+
], da = (e) => e.filter((e) => e.mcp !== !1), fa = (e) => e.filter((e) => e.cli !== !1).sort((e, t) => e.cli.rank - t.cli.rank);
|
|
2951
2956
|
// src/cli/handlers/rules.ts
|
|
2952
|
-
function
|
|
2953
|
-
let t = (e) =>
|
|
2957
|
+
function pa(e) {
|
|
2958
|
+
let t = (e) => l.dim(`(on ${e})`);
|
|
2954
2959
|
return [
|
|
2955
2960
|
...e.role ? [`role ${e.role.value} ${t(e.role.from)}`] : [],
|
|
2956
2961
|
...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)}`] : [],
|
|
@@ -2959,7 +2964,7 @@ function ua(e) {
|
|
|
2959
2964
|
...e.review ? [`review ${e.review.status}${e.review.by ? ` by ${e.review.by}` : ""}${e.review.at ? ` on ${e.review.at}` : ""} ${t(e.review.from)}`] : []
|
|
2960
2965
|
];
|
|
2961
2966
|
}
|
|
2962
|
-
function
|
|
2967
|
+
function ma(e) {
|
|
2963
2968
|
return [
|
|
2964
2969
|
...e.role ? [`role ${e.role}`] : [],
|
|
2965
2970
|
...e.usage ? [`usage ${[e.usage.deny && `deny ${e.usage.deny.join(", ")}`, e.usage.allow && `allow ${e.usage.allow.join(", ")}`].filter(Boolean).join("; ")}`] : [],
|
|
@@ -2967,51 +2972,51 @@ function da(e) {
|
|
|
2967
2972
|
...e.logo ? [`logo deny ${e.logo.deny.join(", ")}${e.logo.reason ? `: ${e.logo.reason}` : ""}`] : []
|
|
2968
2973
|
];
|
|
2969
2974
|
}
|
|
2970
|
-
var
|
|
2971
|
-
let { data:
|
|
2972
|
-
path:
|
|
2975
|
+
var ha = async ({ path: e }, { dir: t }) => {
|
|
2976
|
+
let { data: n } = await J(t), r = hi(e ?? ""), i = r !== "" && n.tokens.byPath.has(r), a = Ki(() => i ? {
|
|
2977
|
+
path: r,
|
|
2973
2978
|
kind: "token",
|
|
2974
|
-
rules:
|
|
2979
|
+
rules: wi(n, gi(n, r))
|
|
2975
2980
|
} : {
|
|
2976
|
-
path:
|
|
2977
|
-
kind:
|
|
2978
|
-
entries:
|
|
2981
|
+
path: r,
|
|
2982
|
+
kind: r === "" ? "brand" : "group",
|
|
2983
|
+
entries: Ei(n, r)
|
|
2979
2984
|
});
|
|
2980
2985
|
return {
|
|
2981
2986
|
command: "rules",
|
|
2982
2987
|
passed: !0,
|
|
2983
2988
|
status: 0,
|
|
2984
|
-
body:
|
|
2989
|
+
body: a,
|
|
2985
2990
|
text: () => {
|
|
2986
|
-
if (console.log(),
|
|
2987
|
-
let e =
|
|
2988
|
-
console.log(` ${
|
|
2991
|
+
if (console.log(), a.kind === "token") {
|
|
2992
|
+
let e = pa(a.rules);
|
|
2993
|
+
console.log(` ${l.bold(a.path)}`), e.length === 0 && console.log(l.dim(" no rules apply to this token"));
|
|
2989
2994
|
for (let t of e) console.log(` ${t}`);
|
|
2990
2995
|
} else {
|
|
2991
|
-
|
|
2992
|
-
for (let e of
|
|
2993
|
-
console.log(` ${
|
|
2994
|
-
for (let t of
|
|
2996
|
+
a.entries.length === 0 && console.log(l.dim(` No rules are written ${r === "" ? "in this brand" : `at or under ${r}`}.`));
|
|
2997
|
+
for (let e of a.entries) {
|
|
2998
|
+
console.log(` ${l.bold(e.at)} ${l.dim(e.kind === "group" ? "group" : "token")}${e.inherited ? l.dim(", passes its rules down") : ""}`);
|
|
2999
|
+
for (let t of ma(e)) console.log(` ${t}`);
|
|
2995
3000
|
}
|
|
2996
3001
|
}
|
|
2997
3002
|
console.log();
|
|
2998
3003
|
}
|
|
2999
3004
|
};
|
|
3000
|
-
},
|
|
3001
|
-
let { data: n } = await
|
|
3002
|
-
if (
|
|
3003
|
-
let r =
|
|
3005
|
+
}, ga = async ({ path: e }, { dir: t }) => {
|
|
3006
|
+
let { data: n } = await J(t);
|
|
3007
|
+
if (Ai(n, 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");
|
|
3008
|
+
let r = Ki(() => Oi(n, String(e)));
|
|
3004
3009
|
return {
|
|
3005
3010
|
command: "get",
|
|
3006
3011
|
passed: !0,
|
|
3007
3012
|
status: 0,
|
|
3008
3013
|
body: { token: r },
|
|
3009
|
-
text: () =>
|
|
3014
|
+
text: () => _a(r)
|
|
3010
3015
|
};
|
|
3011
3016
|
};
|
|
3012
|
-
function
|
|
3017
|
+
function _a(e) {
|
|
3013
3018
|
let { names: t } = e;
|
|
3014
|
-
console.log(`\n ${
|
|
3019
|
+
console.log(`\n ${l.bold(e.path)}${e.deprecated ? l.yellow(" deprecated") : ""}`), qi([
|
|
3015
3020
|
["value", String(e.value)],
|
|
3016
3021
|
["type", e.type],
|
|
3017
3022
|
["alias of", e.aliasOf && `{${e.aliasOf}}`],
|
|
@@ -3021,15 +3026,15 @@ function ma(e) {
|
|
|
3021
3026
|
["typography.css", t.typographyClass && `.${t.typographyClass}`],
|
|
3022
3027
|
["written in", e.sourceFile]
|
|
3023
3028
|
]);
|
|
3024
|
-
for (let t of e.contexts ?? []) console.log(` ${
|
|
3025
|
-
let
|
|
3026
|
-
console.log(`\n ${
|
|
3027
|
-
for (let e of
|
|
3029
|
+
for (let t of e.contexts ?? []) console.log(` ${l.dim(`${t.modifier}=${t.context}`.padEnd(12))} ${String(t.value)} ${l.dim(t.selector)}`);
|
|
3030
|
+
let n = pa(e.rules);
|
|
3031
|
+
console.log(`\n ${l.bold("Rules")}`), n.length === 0 && console.log(l.dim(" none written for this token"));
|
|
3032
|
+
for (let e of n) console.log(` ${e}`);
|
|
3028
3033
|
console.log();
|
|
3029
3034
|
}
|
|
3030
3035
|
// src/cli/handlers/list.ts
|
|
3031
|
-
var
|
|
3032
|
-
let { data: r } = await
|
|
3036
|
+
var va = async ({ group: e, type: t }, { dir: n }) => {
|
|
3037
|
+
let { data: r } = await J(n), i = Ki(() => ji(r, {
|
|
3033
3038
|
group: e,
|
|
3034
3039
|
type: t
|
|
3035
3040
|
}));
|
|
@@ -3042,44 +3047,44 @@ var ha = async ({ group: e, type: t }, { dir: n }) => {
|
|
|
3042
3047
|
...i.type && { type: i.type },
|
|
3043
3048
|
tokens: i.tokens
|
|
3044
3049
|
},
|
|
3045
|
-
text: () =>
|
|
3050
|
+
text: () => ya(i)
|
|
3046
3051
|
};
|
|
3047
3052
|
};
|
|
3048
|
-
function
|
|
3049
|
-
if (e.tokens.length === 0) return console.log(
|
|
3050
|
-
let t = Math.max(...e.tokens.map((e) => e.path.length)),
|
|
3051
|
-
for (let
|
|
3052
|
-
let e =
|
|
3053
|
-
e !==
|
|
3054
|
-
let
|
|
3055
|
-
console.log(` ${
|
|
3053
|
+
function ya(e) {
|
|
3054
|
+
if (e.tokens.length === 0) return console.log(l.dim(`\n no tokens${e.type ? ` of type ${e.type}` : ""}${e.group ? ` in ${e.group}` : ""}\n`));
|
|
3055
|
+
let t = Math.max(...e.tokens.map((e) => e.path.length)), n = Math.max(...e.tokens.map((e) => (e.type ?? "").length)), r;
|
|
3056
|
+
for (let i of e.tokens) {
|
|
3057
|
+
let e = i.path.split(".")[0];
|
|
3058
|
+
e !== r && console.log(`\n ${l.dim(e)}`), r = e;
|
|
3059
|
+
let a = i.aliasOf ? ` ${l.dim(`-> ${i.aliasOf}`)}` : "";
|
|
3060
|
+
console.log(` ${i.path.padEnd(t)} ${l.dim((i.type ?? "").padEnd(n))} ${String(i.value)}${a}`);
|
|
3056
3061
|
}
|
|
3057
|
-
console.log(`\n ${
|
|
3062
|
+
console.log(`\n ${l.dim(`${e.tokens.length} token${e.tokens.length === 1 ? "" : "s"}; blazon get <path> shows one in full`)}\n`);
|
|
3058
3063
|
}
|
|
3059
3064
|
// src/cli/handlers/can.ts
|
|
3060
|
-
var
|
|
3061
|
-
let { data: a } = await
|
|
3065
|
+
var ba = async ({ fg: e, bg: t, role: n, theme: r }, { dir: i }) => {
|
|
3066
|
+
let { data: a } = await J(i), o = Ki(() => Hi(a, e, t, n ?? "text", r));
|
|
3062
3067
|
return {
|
|
3063
3068
|
command: "can",
|
|
3064
3069
|
passed: o.allowed,
|
|
3065
3070
|
status: +!o.allowed,
|
|
3066
3071
|
body: o,
|
|
3067
|
-
text: () =>
|
|
3072
|
+
text: () => xa(o)
|
|
3068
3073
|
};
|
|
3069
3074
|
};
|
|
3070
|
-
function
|
|
3071
|
-
if (console.log(`\n ${e.allowed ?
|
|
3075
|
+
function xa(e) {
|
|
3076
|
+
if (console.log(`\n ${e.allowed ? l.green("allowed") : l.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.length > 1) {
|
|
3072
3077
|
console.log();
|
|
3073
|
-
for (let t of e.checks) console.log(` ${t.rule === "contrast" && e.role === "text" ?
|
|
3078
|
+
for (let t of e.checks) console.log(` ${t.rule === "contrast" && e.role === "text" ? l.dim("info") : t.ok ? l.green("ok ") : l.red("no ")} ${t.message}`);
|
|
3074
3079
|
}
|
|
3075
3080
|
console.log();
|
|
3076
3081
|
}
|
|
3077
3082
|
// src/cli/handlers/fonts.ts
|
|
3078
|
-
var
|
|
3079
|
-
let { config: n, data: r } = await
|
|
3083
|
+
var Sa = async (e, { dir: t }) => {
|
|
3084
|
+
let { config: n, data: r } = await J(t), i = Ui(r, n, t);
|
|
3080
3085
|
if (e.css === !0 || typeof e.base == "string") {
|
|
3081
|
-
if (e.css !== !0) throw new
|
|
3082
|
-
let t =
|
|
3086
|
+
if (e.css !== !0) throw new M("blazon fonts: --base goes with --css.", "Add --css, or leave --base out.", "conflicting-options");
|
|
3087
|
+
let t = Wi(i, typeof e.base == "string" ? e.base : void 0);
|
|
3083
3088
|
return {
|
|
3084
3089
|
command: "fonts",
|
|
3085
3090
|
passed: !0,
|
|
@@ -3096,18 +3101,18 @@ var ya = async (e, { dir: t }) => {
|
|
|
3096
3101
|
passed: !0,
|
|
3097
3102
|
status: 0,
|
|
3098
3103
|
body: i,
|
|
3099
|
-
text: () =>
|
|
3104
|
+
text: () => Ca(i)
|
|
3100
3105
|
};
|
|
3101
3106
|
};
|
|
3102
|
-
function
|
|
3103
|
-
console.log(`\n ${
|
|
3107
|
+
function Ca(e) {
|
|
3108
|
+
console.log(`\n ${l.bold("Loaded")}`), e.stylesheets.length + e.files.length === 0 && console.log(l.dim(" The config lists no fonts."));
|
|
3104
3109
|
for (let t of e.stylesheets) console.log(` stylesheet ${t}`);
|
|
3105
3110
|
for (let t of e.files) console.log(` file ${t.file} ${t.family}${t.weight === void 0 ? "" : `, weight ${t.weight}`}${t.style ? `, ${t.style}` : ""}`);
|
|
3106
|
-
console.log(`\n ${
|
|
3107
|
-
for (let [t,
|
|
3111
|
+
console.log(`\n ${l.bold("Named by the tokens")}`);
|
|
3112
|
+
for (let [t, n] of Object.entries(e.roles)) console.log(` ${l.dim(t.padEnd(11))} ${n.token ?? ""} ${n.value ?? ""}`);
|
|
3108
3113
|
for (let t of e.families) {
|
|
3109
3114
|
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";
|
|
3110
|
-
console.log(` ${t.family} ${
|
|
3115
|
+
console.log(` ${t.family} ${l.dim(`${e}; ${t.tokens.join(", ")}`)}`), t.stack && t.stack.length > 1 && console.log(l.dim(` stack: ${t.stack.join(", ")}`));
|
|
3111
3116
|
}
|
|
3112
3117
|
console.log();
|
|
3113
3118
|
}
|
|
@@ -3116,23 +3121,23 @@ var $ = (e) => {
|
|
|
3116
3121
|
if (typeof e != "object" || !e) return String(e);
|
|
3117
3122
|
let t = e;
|
|
3118
3123
|
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"}`;
|
|
3119
|
-
},
|
|
3120
|
-
let { config: n, data: r } = await
|
|
3124
|
+
}, wa = async (e, { dir: t }) => {
|
|
3125
|
+
let { config: n, data: r } = await J(t), i = Gi(r, n, t);
|
|
3121
3126
|
return {
|
|
3122
3127
|
command: "logo",
|
|
3123
3128
|
passed: !0,
|
|
3124
3129
|
status: 0,
|
|
3125
3130
|
body: i,
|
|
3126
|
-
text: () =>
|
|
3131
|
+
text: () => Ta(i)
|
|
3127
3132
|
};
|
|
3128
3133
|
};
|
|
3129
|
-
function
|
|
3130
|
-
console.log(`\n ${
|
|
3131
|
-
for (let t of e.variants) console.log(` ${t.variant.padEnd(8)} ${t.file}${t.found ? "" :
|
|
3134
|
+
function Ta(e) {
|
|
3135
|
+
console.log(`\n ${l.bold("Variants")}`), e.variants.length === 0 && console.log(l.dim(" No logo is configured."));
|
|
3136
|
+
for (let t of e.variants) console.log(` ${t.variant.padEnd(8)} ${t.file}${t.found ? "" : l.red(" (not found)")}${t.ink ? ` ink ${t.ink}` : ""}${t.asset ? l.dim(` ${t.asset}`) : ""}`);
|
|
3132
3137
|
for (let t of e.assets) {
|
|
3133
3138
|
let e = t.rules;
|
|
3134
|
-
console.log(`\n ${
|
|
3135
|
-
let
|
|
3139
|
+
console.log(`\n ${l.bold(t.id)} ${t.file}${t.variants.length ? l.dim(` used as ${t.variants.join(", ")}`) : ""}`);
|
|
3140
|
+
let n = [
|
|
3136
3141
|
["lockup", e.lockup],
|
|
3137
3142
|
["ink", e.ink],
|
|
3138
3143
|
["background", e.background],
|
|
@@ -3145,18 +3150,18 @@ function Sa(e) {
|
|
|
3145
3150
|
["partnership", e.partnership && `gap ${$(e.partnership.gap)}${e.partnership.dividerHeight ? `, divider ${$(e.partnership.dividerHeight)}` : ""}`],
|
|
3146
3151
|
["initiative", e.initiative && `${e.initiative.name}, mark ${e.initiative.mark}, gap ${$(e.initiative.gap)}, ${e.initiative.position ?? "beside"}`]
|
|
3147
3152
|
];
|
|
3148
|
-
for (let [e, t] of
|
|
3149
|
-
for (let t of e.do ?? []) console.log(` ${
|
|
3150
|
-
for (let t of e.dont ?? []) console.log(` ${
|
|
3153
|
+
for (let [e, t] of n) t !== void 0 && console.log(` ${l.dim(e.padEnd(12))} ${t}`);
|
|
3154
|
+
for (let t of e.do ?? []) console.log(` ${l.dim("do")} ${t}`);
|
|
3155
|
+
for (let t of e.dont ?? []) console.log(` ${l.dim("do not")} ${t}`);
|
|
3151
3156
|
}
|
|
3152
3157
|
if (e.forbidden.length > 0) {
|
|
3153
|
-
console.log(`\n ${
|
|
3154
|
-
for (let t of e.forbidden) console.log(` ${t.at} ${t.deny.join(", ")}${t.reason ? ` ${
|
|
3158
|
+
console.log(`\n ${l.bold("Forbidden on")}`);
|
|
3159
|
+
for (let t of e.forbidden) console.log(` ${t.at} ${t.deny.join(", ")}${t.reason ? ` ${l.dim(t.reason)}` : ""}`);
|
|
3155
3160
|
}
|
|
3156
3161
|
console.log();
|
|
3157
3162
|
}
|
|
3158
3163
|
// src/cli/handlers/brand.ts
|
|
3159
|
-
function
|
|
3164
|
+
function Ea(e, t) {
|
|
3160
3165
|
let n = e;
|
|
3161
3166
|
for (let e of t.split(".")) {
|
|
3162
3167
|
if (typeof n != "object" || !n || !Object.prototype.hasOwnProperty.call(n, e)) return;
|
|
@@ -3165,16 +3170,16 @@ function Ca(e, t) {
|
|
|
3165
3170
|
return n;
|
|
3166
3171
|
}
|
|
3167
3172
|
// src/cli/handlers/index.ts
|
|
3168
|
-
var
|
|
3169
|
-
get_token:
|
|
3170
|
-
list_tokens:
|
|
3171
|
-
get_rules:
|
|
3172
|
-
can_use:
|
|
3173
|
-
get_fonts:
|
|
3174
|
-
get_logo:
|
|
3173
|
+
var Da = {
|
|
3174
|
+
get_token: ga,
|
|
3175
|
+
list_tokens: va,
|
|
3176
|
+
get_rules: ha,
|
|
3177
|
+
can_use: ba,
|
|
3178
|
+
get_fonts: Sa,
|
|
3179
|
+
get_logo: wa,
|
|
3175
3180
|
get_brand: async ({ key: e }, { dir: t }) => {
|
|
3176
|
-
let { config: n, data: r } = await
|
|
3177
|
-
if (a === void 0) throw new
|
|
3181
|
+
let { config: n, data: r } = await J(t), i = He(r, n, t), a = e === void 0 ? i : Ea(i, e);
|
|
3182
|
+
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");
|
|
3178
3183
|
return {
|
|
3179
3184
|
command: "brand",
|
|
3180
3185
|
passed: !0,
|
|
@@ -3183,21 +3188,21 @@ var wa = {
|
|
|
3183
3188
|
text: () => void process.stdout.write(`${JSON.stringify(a, null, 2)}\n`)
|
|
3184
3189
|
};
|
|
3185
3190
|
}
|
|
3186
|
-
},
|
|
3187
|
-
function
|
|
3188
|
-
let t =
|
|
3191
|
+
}, Oa = (e) => e.cli, ka = (e) => e.replace(/[A-Z]/g, (e) => `-${e.toLowerCase()}`), Aa = fa(ua).filter((e) => Oa(e).options.some((e) => e.property === "json")).map((e) => Oa(e).command[0]);
|
|
3192
|
+
function ja(e) {
|
|
3193
|
+
let t = Oa(e), n = new Set(e.inputSchema.required ?? []);
|
|
3189
3194
|
return [...t.command, ...t.positional.map((e) => n.has(e) ? `<${e}>` : `[${e}]`)].join(" ");
|
|
3190
3195
|
}
|
|
3191
|
-
function
|
|
3192
|
-
return t.property === "json" ? "--json" : e.inputSchema.properties[t.property]?.type === "boolean" ? `--${
|
|
3196
|
+
function Ma(e, t) {
|
|
3197
|
+
return t.property === "json" ? "--json" : e.inputSchema.properties[t.property]?.type === "boolean" ? `--${ka(t.property)}` : `--${ka(t.property)} <${t.value ?? ka(t.property)}>`;
|
|
3193
3198
|
}
|
|
3194
|
-
var
|
|
3195
|
-
function
|
|
3196
|
-
for (let n of
|
|
3197
|
-
let r =
|
|
3199
|
+
var Na = (e) => typeof e == "string" && /^\.|[\\/]/.test(e) && !!k.statSync(e, { throwIfNoEntry: !1 })?.isDirectory();
|
|
3200
|
+
function Pa(e, t) {
|
|
3201
|
+
for (let n of fa(ua)) {
|
|
3202
|
+
let r = Oa(n), i = Da[n.name];
|
|
3198
3203
|
if (!i) throw Error(`operation ${n.name} has a command and no handler`);
|
|
3199
|
-
let a = e.command(
|
|
3200
|
-
for (let e of r.options) a.option(
|
|
3204
|
+
let a = e.command(ja(n), r.summary);
|
|
3205
|
+
for (let e of r.options) a.option(Ma(n, e), e.description);
|
|
3201
3206
|
a.action(async (...e) => {
|
|
3202
3207
|
let n = e.pop() ?? {};
|
|
3203
3208
|
try {
|
|
@@ -3205,20 +3210,26 @@ function ja(e, t) {
|
|
|
3205
3210
|
r.positional.forEach((n, r) => t[n] = e[r]);
|
|
3206
3211
|
for (let e of r.options) e.property !== "json" && (t[e.property] = n[e.property]);
|
|
3207
3212
|
let a = t.dir;
|
|
3208
|
-
r.folder !== void 0 && a === void 0 &&
|
|
3213
|
+
r.folder !== void 0 && a === void 0 && Na(t[r.folder]) && (a = t[r.folder], t[r.folder] = void 0), delete t.dir;
|
|
3209
3214
|
let o = await i(t, { dir: a ? String(a) : process.cwd() });
|
|
3210
|
-
n.json ?
|
|
3215
|
+
n.json ? Y(o.command, o.passed, o.body) : o.text(), process.exitCode = o.status;
|
|
3211
3216
|
} catch (e) {
|
|
3212
|
-
|
|
3217
|
+
P(r.command.join(" "), e, t);
|
|
3213
3218
|
}
|
|
3214
3219
|
});
|
|
3215
3220
|
}
|
|
3216
3221
|
}
|
|
3217
3222
|
// src/cli/commands/mcp-check.ts
|
|
3218
|
-
var
|
|
3219
|
-
function
|
|
3220
|
-
let t =
|
|
3221
|
-
return
|
|
3223
|
+
var Fa = 3e4, Ia = "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.", La = "npm ci && npm run build -w mcp", Ra = (e) => _e(e) ? `cd ${e} && ${La}` : Oe, za = () => da(ua).map((e) => e.name);
|
|
3224
|
+
function Ba(e) {
|
|
3225
|
+
let t = O.join(e, "mcp/dist/index.js"), n = k.existsSync(t);
|
|
3226
|
+
return !n && !_e(e) ? {
|
|
3227
|
+
name: "built",
|
|
3228
|
+
passed: !1,
|
|
3229
|
+
detail: Ie,
|
|
3230
|
+
fix: Oe,
|
|
3231
|
+
entry: t
|
|
3232
|
+
} : n ? {
|
|
3222
3233
|
name: "built",
|
|
3223
3234
|
passed: !0,
|
|
3224
3235
|
detail: `${t} exists`,
|
|
@@ -3227,26 +3238,26 @@ function Ia(e) {
|
|
|
3227
3238
|
name: "built",
|
|
3228
3239
|
passed: !1,
|
|
3229
3240
|
detail: `${t} does not exist: blazon-mcp is not built`,
|
|
3230
|
-
fix:
|
|
3241
|
+
fix: Ra(e),
|
|
3231
3242
|
entry: t
|
|
3232
3243
|
};
|
|
3233
3244
|
}
|
|
3234
|
-
var
|
|
3245
|
+
var Va = (e) => {
|
|
3235
3246
|
try {
|
|
3236
|
-
return
|
|
3247
|
+
return k.statSync(e).isFile() ? (k.accessSync(e, k.constants.X_OK), !0) : !1;
|
|
3237
3248
|
} catch {
|
|
3238
3249
|
return !1;
|
|
3239
3250
|
}
|
|
3240
3251
|
};
|
|
3241
|
-
function
|
|
3242
|
-
let n = (t.PATH ?? "").split(
|
|
3243
|
-
for (let e of n) for (let t of r) if (
|
|
3252
|
+
function Ha(e, t) {
|
|
3253
|
+
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 (Va(O.join(e, t))) return O.join(e, t);
|
|
3244
3255
|
}
|
|
3245
|
-
function
|
|
3246
|
-
let r =
|
|
3256
|
+
function Ua(e, t, n) {
|
|
3257
|
+
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;
|
|
3247
3258
|
if (a) {
|
|
3248
|
-
let n = a.includes("/") || a.includes(
|
|
3249
|
-
return n &&
|
|
3259
|
+
let n = a.includes("/") || a.includes(O.sep) ? O.resolve(t, a) : Ha(a, e);
|
|
3260
|
+
return n && Va(n) ? {
|
|
3250
3261
|
name: "blazon",
|
|
3251
3262
|
passed: !0,
|
|
3252
3263
|
detail: `BLAZON_BIN names ${n}`,
|
|
@@ -3260,7 +3271,14 @@ function za(e, t, n) {
|
|
|
3260
3271
|
source: "BLAZON_BIN"
|
|
3261
3272
|
};
|
|
3262
3273
|
}
|
|
3263
|
-
|
|
3274
|
+
if (Va(r)) return {
|
|
3275
|
+
name: "blazon",
|
|
3276
|
+
passed: !0,
|
|
3277
|
+
detail: `the server runs this package's own ${r}`,
|
|
3278
|
+
source: "package",
|
|
3279
|
+
path: r
|
|
3280
|
+
};
|
|
3281
|
+
let o = Ha("blazon", e);
|
|
3264
3282
|
return o ? {
|
|
3265
3283
|
name: "blazon",
|
|
3266
3284
|
passed: !0,
|
|
@@ -3275,12 +3293,12 @@ function za(e, t, n) {
|
|
|
3275
3293
|
source: "none"
|
|
3276
3294
|
};
|
|
3277
3295
|
}
|
|
3278
|
-
var
|
|
3296
|
+
var Wa = (e, t = 200) => {
|
|
3279
3297
|
let n = e.trim().split("\n").find((e) => e.trim() !== "") ?? "";
|
|
3280
3298
|
return n.length > t ? `${n.slice(0, t)}...` : n;
|
|
3281
3299
|
};
|
|
3282
|
-
async function
|
|
3283
|
-
let { entry: t, brand: n, env: r = process.env, timeoutMs: i =
|
|
3300
|
+
async function Ga(e) {
|
|
3301
|
+
let { entry: t, brand: n, env: r = process.env, timeoutMs: i = Fa, expect: a = za() } = e, o = process.platform !== "win32", s = Qe(process.execPath, [
|
|
3284
3302
|
t,
|
|
3285
3303
|
"--brand",
|
|
3286
3304
|
n
|
|
@@ -3312,7 +3330,7 @@ async function Va(e) {
|
|
|
3312
3330
|
m = setTimeout(() => {
|
|
3313
3331
|
p = !0, t(/* @__PURE__ */ Error(`no answer within ${i / 1e3} s`));
|
|
3314
3332
|
}, i);
|
|
3315
|
-
}), g = new Promise((e, t) => s.once("close", (e) => t(/* @__PURE__ */ Error(`the server exited (${e ?? "signal"}) before it answered${c ? `: ${
|
|
3333
|
+
}), g = new Promise((e, t) => s.once("close", (e) => t(/* @__PURE__ */ Error(`the server exited (${e ?? "signal"}) before it answered${c ? `: ${Wa(c)}` : ""}`))));
|
|
3316
3334
|
g.catch(() => void 0), h.catch(() => void 0), u.catch(() => void 0);
|
|
3317
3335
|
let _ = 0, v = (e, t) => {
|
|
3318
3336
|
let n = ++_, r = new Promise((e) => d.set(n, e));
|
|
@@ -3337,7 +3355,7 @@ async function Va(e) {
|
|
|
3337
3355
|
version: "0"
|
|
3338
3356
|
}
|
|
3339
3357
|
});
|
|
3340
|
-
if (e.error) throw Error(`initialize was refused: ${
|
|
3358
|
+
if (e.error) throw Error(`initialize was refused: ${Wa(e.error.message ?? "")}`);
|
|
3341
3359
|
s.stdin.write(`${JSON.stringify({
|
|
3342
3360
|
jsonrpc: "2.0",
|
|
3343
3361
|
method: "notifications/initialized"
|
|
@@ -3346,8 +3364,8 @@ async function Va(e) {
|
|
|
3346
3364
|
if (t.error || r.length > 0) return {
|
|
3347
3365
|
name: "handshake",
|
|
3348
3366
|
passed: !1,
|
|
3349
|
-
detail: t.error ? `tools/list failed: ${
|
|
3350
|
-
fix:
|
|
3367
|
+
detail: t.error ? `tools/list failed: ${Wa(t.error.message ?? "")}` : `tools/list answered ${n.length} tool(s); missing ${r.join(", ")}`,
|
|
3368
|
+
fix: `${Ra(ve())} (the server is older than this blazon), then run this check again`,
|
|
3351
3369
|
tools: n
|
|
3352
3370
|
};
|
|
3353
3371
|
let i = Date.now(), o = await v("tools/call", {
|
|
@@ -3357,7 +3375,7 @@ async function Va(e) {
|
|
|
3357
3375
|
if (o.error || o.result?.isError) return {
|
|
3358
3376
|
name: "handshake",
|
|
3359
3377
|
passed: !1,
|
|
3360
|
-
detail: `check_brand failed: ${
|
|
3378
|
+
detail: `check_brand failed: ${Wa(o.error?.message ?? l)}`,
|
|
3361
3379
|
fix: "run blazon check in the brand folder, and make sure the blazon program and the brand folder are the ones the server uses",
|
|
3362
3380
|
tools: n,
|
|
3363
3381
|
ms: c
|
|
@@ -3376,14 +3394,14 @@ async function Va(e) {
|
|
|
3376
3394
|
name: "handshake",
|
|
3377
3395
|
passed: !1,
|
|
3378
3396
|
detail: `the handshake did not finish: ${e instanceof Error ? e.message : String(e)}${p ? "; the server was killed" : ""}`,
|
|
3379
|
-
fix:
|
|
3397
|
+
fix: `${Ra(ve())}, then run this check again; on a hang, run the server by hand: node ${t} --brand ${n}`,
|
|
3380
3398
|
ms: Date.now() - y
|
|
3381
3399
|
};
|
|
3382
3400
|
} finally {
|
|
3383
|
-
clearTimeout(m), await
|
|
3401
|
+
clearTimeout(m), await Ka(s, l, o);
|
|
3384
3402
|
}
|
|
3385
3403
|
}
|
|
3386
|
-
async function
|
|
3404
|
+
async function Ka(e, t, n) {
|
|
3387
3405
|
let r = (t) => {
|
|
3388
3406
|
try {
|
|
3389
3407
|
n && e.pid !== void 0 ? process.kill(-e.pid, t) : e.kill(t);
|
|
@@ -3397,16 +3415,16 @@ async function Ha(e, t, n) {
|
|
|
3397
3415
|
let i;
|
|
3398
3416
|
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");
|
|
3399
3417
|
}
|
|
3400
|
-
function
|
|
3401
|
-
let i =
|
|
3418
|
+
function qa(e, t, n, r = $e.homedir()) {
|
|
3419
|
+
let i = Ne(e, t, r, process.platform, process.env.APPDATA), a = [], o = [], s = [];
|
|
3402
3420
|
for (let e of i) {
|
|
3403
3421
|
let t;
|
|
3404
3422
|
try {
|
|
3405
|
-
t =
|
|
3423
|
+
t = k.readFileSync(e.path, "utf8");
|
|
3406
3424
|
} catch {
|
|
3407
3425
|
continue;
|
|
3408
3426
|
}
|
|
3409
|
-
let n =
|
|
3427
|
+
let n = Ae(t, e);
|
|
3410
3428
|
n === void 0 ? s.push(e.path) : (o.push(e.path), n.includes("blazon") && a.push(e.path));
|
|
3411
3429
|
}
|
|
3412
3430
|
let c = s.length > 0 ? ` (not valid JSON, skipped: ${s.join(", ")})` : "", l = `blazon mcp --print-config --client ${e} --brand ${n}`;
|
|
@@ -3427,70 +3445,79 @@ function Ua(e, t, n, r = Je.homedir()) {
|
|
|
3427
3445
|
files: []
|
|
3428
3446
|
};
|
|
3429
3447
|
}
|
|
3430
|
-
async function
|
|
3431
|
-
let { client: t, brand:
|
|
3432
|
-
entry:
|
|
3433
|
-
brand:
|
|
3434
|
-
env:
|
|
3448
|
+
async function Ja(e) {
|
|
3449
|
+
let { client: t, brand: n, env: r = process.env, cwd: i = process.cwd(), home: a = $e.homedir() } = e, o = e.root ?? ve(), s = Ba(o), c = Ua(r, n, o), u = s.passed ? await Ga({
|
|
3450
|
+
entry: s.entry,
|
|
3451
|
+
brand: n,
|
|
3452
|
+
env: r,
|
|
3435
3453
|
...e.timeoutMs !== void 0 && { timeoutMs: e.timeoutMs }
|
|
3436
3454
|
}) : {
|
|
3437
3455
|
name: "handshake",
|
|
3438
3456
|
passed: !1,
|
|
3439
|
-
detail:
|
|
3440
|
-
fix:
|
|
3441
|
-
}, d =
|
|
3457
|
+
detail: `not run: ${_e(o) ? "the server is not built" : "the install is incomplete"}`,
|
|
3458
|
+
fix: s.fix
|
|
3459
|
+
}, d = qa(t, [.../* @__PURE__ */ new Set([i, n])], n, a), { entry: f, ...p } = s, m = [
|
|
3442
3460
|
p,
|
|
3443
|
-
|
|
3461
|
+
c,
|
|
3444
3462
|
u,
|
|
3445
3463
|
d
|
|
3446
3464
|
], h = m.filter((e) => !e.advisory).every((e) => e.passed);
|
|
3447
|
-
if (e.json) return
|
|
3465
|
+
if (e.json) return Y("mcp", h, {
|
|
3448
3466
|
mode: "check",
|
|
3449
3467
|
client: t,
|
|
3450
|
-
brand:
|
|
3468
|
+
brand: n,
|
|
3451
3469
|
runsPlugins: !1,
|
|
3452
|
-
trust:
|
|
3470
|
+
trust: Ia,
|
|
3453
3471
|
registered: d.passed,
|
|
3454
3472
|
checks: m
|
|
3455
3473
|
}), +!h;
|
|
3456
|
-
console.log(`\n ${
|
|
3474
|
+
console.log(`\n ${l.bold(`blazon-mcp for ${t}, brand ${n}`)}\n ${l.yellow(Ia)}\n`);
|
|
3457
3475
|
for (let e of m) {
|
|
3458
|
-
let t = e.passed ?
|
|
3459
|
-
console.log(` ${t} ${e.name.padEnd(10)} ${e.detail}`), !e.passed && e.fix && console.log(` ${" ".repeat(7)} ${" ".repeat(10)} ${
|
|
3476
|
+
let t = e.passed ? l.green("ok ") : e.advisory ? l.yellow("finding") : l.red("fail ");
|
|
3477
|
+
console.log(` ${t} ${e.name.padEnd(10)} ${e.detail}`), !e.passed && e.fix && console.log(` ${" ".repeat(7)} ${" ".repeat(10)} ${l.dim("fix:")} ${e.fix}`);
|
|
3460
3478
|
}
|
|
3461
|
-
return console.log(`\n ${h ?
|
|
3479
|
+
return console.log(`\n ${h ? l.green("The server is ready.") : l.red("The server is not ready.")}${d.passed ? "" : " It is not registered in this client yet (a finding, not a failure)."}\n`), +!h;
|
|
3462
3480
|
}
|
|
3463
3481
|
// src/cli/commands/mcp.ts
|
|
3464
|
-
async function
|
|
3465
|
-
if (e.printConfig && e.check) throw new
|
|
3466
|
-
if (!e.printConfig && !e.check) throw new
|
|
3482
|
+
async function Ya(e = {}) {
|
|
3483
|
+
if (e.printConfig && e.check) throw new M("give --print-config or --check, not both. See blazon mcp --help.", void 0, "conflicting-options");
|
|
3484
|
+
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");
|
|
3467
3485
|
let t = e.client === void 0 ? "claude-code" : e.client;
|
|
3468
|
-
if (e.client !== void 0 && !
|
|
3469
|
-
let
|
|
3486
|
+
if (e.client !== void 0 && !he(e.client)) throw new M(`unknown client "${e.client}"; the clients are ${pe.join(", ")}.`, void 0, "invalid-option-value");
|
|
3487
|
+
let n = e.brand === void 0 ? void 0 : O.resolve(process.cwd(), e.brand);
|
|
3470
3488
|
if (e.check) {
|
|
3471
|
-
let
|
|
3472
|
-
if (!
|
|
3473
|
-
return
|
|
3489
|
+
let r = n ?? process.cwd();
|
|
3490
|
+
if (!k.statSync(r, { throwIfNoEntry: !1 })?.isDirectory()) throw new M(`the brand folder ${r} does not exist.`, void 0, "no-folder");
|
|
3491
|
+
return Ja({
|
|
3474
3492
|
client: t,
|
|
3475
|
-
brand:
|
|
3493
|
+
brand: r,
|
|
3494
|
+
...e.root && { root: e.root },
|
|
3476
3495
|
...e.json && { json: !0 }
|
|
3477
3496
|
});
|
|
3478
3497
|
}
|
|
3479
|
-
let
|
|
3480
|
-
if (e.
|
|
3498
|
+
let r = xe(e.root);
|
|
3499
|
+
if (!r.built && !_e(e.root)) return e.json ? Y("mcp", !1, {
|
|
3500
|
+
client: t,
|
|
3501
|
+
built: !1,
|
|
3502
|
+
...n && { brand: n },
|
|
3503
|
+
note: Ie,
|
|
3504
|
+
snippets: []
|
|
3505
|
+
}) : console.error(`\n ${l.yellow(Ie)}\n`), 1;
|
|
3506
|
+
let i = Be(t, r, n);
|
|
3507
|
+
if (e.json) return Y("mcp", !0, {
|
|
3481
3508
|
client: t,
|
|
3482
3509
|
built: i.built,
|
|
3483
|
-
...
|
|
3510
|
+
...n && { brand: n },
|
|
3484
3511
|
...i.note && { note: i.note },
|
|
3485
3512
|
snippets: i.snippets
|
|
3486
3513
|
}), 0;
|
|
3487
|
-
console.log(`\n ${
|
|
3488
|
-
for (let e of i.snippets) console.log(`\n ${
|
|
3489
|
-
return i.note && console.log(`\n ${
|
|
3514
|
+
console.log(`\n ${l.bold(i.title)}`);
|
|
3515
|
+
for (let e of i.snippets) console.log(`\n ${l.dim(e.label)}\n\n${e.text.replace(/^/gm, " ")}`);
|
|
3516
|
+
return i.note && console.log(`\n ${l.yellow(i.note)}`), console.log(""), 0;
|
|
3490
3517
|
}
|
|
3491
3518
|
// src/cli/commands/explain.ts
|
|
3492
|
-
function
|
|
3493
|
-
let t =
|
|
3519
|
+
function Xa(e) {
|
|
3520
|
+
let t = se[e], n = oe(e);
|
|
3494
3521
|
return {
|
|
3495
3522
|
code: e,
|
|
3496
3523
|
severity: t.severity,
|
|
@@ -3501,12 +3528,12 @@ function Ka(e) {
|
|
|
3501
3528
|
manual: t.manual
|
|
3502
3529
|
};
|
|
3503
3530
|
}
|
|
3504
|
-
function
|
|
3531
|
+
function Za(e) {
|
|
3505
3532
|
let [t = "", n] = e.split("#");
|
|
3506
3533
|
return `RFC ${t.padStart(4, "0")}${n ? `, section ${n}` : ""}`;
|
|
3507
3534
|
}
|
|
3508
|
-
function
|
|
3509
|
-
let t = Object.keys(
|
|
3535
|
+
function Qa(e) {
|
|
3536
|
+
let t = Object.keys(se), n = [];
|
|
3510
3537
|
for (let r = 0; r < 3; r++) {
|
|
3511
3538
|
let r = E(e, t);
|
|
3512
3539
|
if (r === void 0) break;
|
|
@@ -3514,14 +3541,14 @@ function Ja(e) {
|
|
|
3514
3541
|
}
|
|
3515
3542
|
return n;
|
|
3516
3543
|
}
|
|
3517
|
-
function
|
|
3518
|
-
let t = e.severity === "error" ?
|
|
3519
|
-
console.log(`\n ${
|
|
3544
|
+
function $a(e) {
|
|
3545
|
+
let t = e.severity === "error" ? l.red : e.severity === "warning" ? l.yellow : l.dim;
|
|
3546
|
+
console.log(`\n ${l.bold(e.code)} ${t(e.severity)}\n`), console.log(` ${e.summary}`), e.fix !== void 0 && console.log(`\n ${l.bold("Fix")} ${e.fix}`), console.log(`\n ${l.bold("Read")} docs/manual/${e.manual}.md, ${Za(e.rfc)}\n`);
|
|
3520
3547
|
}
|
|
3521
|
-
function
|
|
3548
|
+
function eo(e, t = {}) {
|
|
3522
3549
|
if (e === void 0) {
|
|
3523
|
-
let e = Object.keys(
|
|
3524
|
-
if (t.json)
|
|
3550
|
+
let e = Object.keys(se).sort().map((e) => Xa(e));
|
|
3551
|
+
if (t.json) Y("explain", !0, { codes: e });
|
|
3525
3552
|
else {
|
|
3526
3553
|
let t = Math.max(...e.map((e) => e.code.length));
|
|
3527
3554
|
console.log();
|
|
@@ -3530,42 +3557,42 @@ function Xa(e, t = {}) {
|
|
|
3530
3557
|
}
|
|
3531
3558
|
return 0;
|
|
3532
3559
|
}
|
|
3533
|
-
if (!Object.hasOwn(
|
|
3534
|
-
let t =
|
|
3535
|
-
throw new
|
|
3560
|
+
if (!Object.hasOwn(se, e)) {
|
|
3561
|
+
let t = Qa(e);
|
|
3562
|
+
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");
|
|
3536
3563
|
}
|
|
3537
|
-
let n =
|
|
3538
|
-
return t.json ?
|
|
3564
|
+
let n = Xa(e);
|
|
3565
|
+
return t.json ? Y("explain", !0, n) : $a(n), 0;
|
|
3539
3566
|
}
|
|
3540
3567
|
// src/cli/options.ts
|
|
3541
|
-
var
|
|
3568
|
+
var to = (e) => {
|
|
3542
3569
|
if (e.length === 1) return [`-${e}`];
|
|
3543
3570
|
let t = e.replace(/[A-Z]/g, (e) => `-${e.toLowerCase()}`);
|
|
3544
3571
|
return t === e ? [`--${e}`] : [`--${e}`, `--${t}`];
|
|
3545
3572
|
};
|
|
3546
|
-
function
|
|
3573
|
+
function no(e, t) {
|
|
3547
3574
|
let n = e.matchedCommand;
|
|
3548
3575
|
if (!n) return;
|
|
3549
3576
|
let r = [...n.options, ...e.globalCommand.options].filter((e) => e.required);
|
|
3550
3577
|
for (let i of r) {
|
|
3551
3578
|
if (typeof e.options[i.name] == "object") continue;
|
|
3552
|
-
let r = i.names.flatMap(
|
|
3579
|
+
let r = i.names.flatMap(to);
|
|
3553
3580
|
for (let a = 2; a < t.length; a++) {
|
|
3554
3581
|
let o = t[a], s = r.find((e) => o === e || o.startsWith(`${e}=`));
|
|
3555
3582
|
if (s === void 0) continue;
|
|
3556
3583
|
let c = o === s ? t[a + 1] : o.slice(s.length + 1);
|
|
3557
|
-
if (c !== void 0 && (c === "" &&
|
|
3584
|
+
if (c !== void 0 && (c === "" && N(`blazon ${n.name}: ${s} needs a value, not an empty one.`, "empty-value", { fix: `Give ${s} a value, or leave it out.` }), i.name !== "port")) for (let t of i.names) t in e.options && (e.options[t] = c);
|
|
3558
3585
|
}
|
|
3559
3586
|
}
|
|
3560
3587
|
let i = t.slice(2);
|
|
3561
|
-
i.some((e, t) => e === "" && !(i[t - 1] ?? "").startsWith("-")) &&
|
|
3588
|
+
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." });
|
|
3562
3589
|
}
|
|
3563
3590
|
// src/cli/json.ts
|
|
3564
|
-
var
|
|
3591
|
+
var ro = [
|
|
3565
3592
|
"error",
|
|
3566
3593
|
"warning",
|
|
3567
3594
|
"info"
|
|
3568
|
-
],
|
|
3595
|
+
], io = {
|
|
3569
3596
|
error: ["error"],
|
|
3570
3597
|
warning: ["error", "warning"],
|
|
3571
3598
|
info: [
|
|
@@ -3574,19 +3601,19 @@ var $a = [
|
|
|
3574
3601
|
"info"
|
|
3575
3602
|
]
|
|
3576
3603
|
};
|
|
3577
|
-
async function
|
|
3604
|
+
async function ao(e, t, n, r = "info") {
|
|
3578
3605
|
let i = console.log;
|
|
3579
3606
|
console.log = (...e) => console.error(...e);
|
|
3580
3607
|
let a;
|
|
3581
3608
|
try {
|
|
3582
3609
|
a = (await n()).findings;
|
|
3583
3610
|
} catch (e) {
|
|
3584
|
-
if (!(e instanceof
|
|
3611
|
+
if (!(e instanceof bt)) throw e;
|
|
3585
3612
|
a = e.findings;
|
|
3586
3613
|
} finally {
|
|
3587
3614
|
console.log = i;
|
|
3588
3615
|
}
|
|
3589
|
-
let o =
|
|
3616
|
+
let o = c(a, { strict: t }), s = {
|
|
3590
3617
|
errors: o.errors.length,
|
|
3591
3618
|
warnings: o.warnings.length,
|
|
3592
3619
|
info: o.infos.length
|
|
@@ -3596,18 +3623,18 @@ async function to(e, t, n, r = "info") {
|
|
|
3596
3623
|
passed: o.passed,
|
|
3597
3624
|
strict: t,
|
|
3598
3625
|
counts: s,
|
|
3599
|
-
findings: o.all.filter((e) =>
|
|
3626
|
+
findings: o.all.filter((e) => io[r].includes(e.severity)).map((e) => ({
|
|
3600
3627
|
...e,
|
|
3601
|
-
...
|
|
3628
|
+
...Ue(e) && { fix: Ue(e) }
|
|
3602
3629
|
}))
|
|
3603
3630
|
}, null, 2)}\n`), process.exitCode = +!o.passed;
|
|
3604
3631
|
}
|
|
3605
|
-
async function
|
|
3632
|
+
async function oo(e, t) {
|
|
3606
3633
|
let n = console.log;
|
|
3607
3634
|
console.log = (...e) => console.error(...e);
|
|
3608
3635
|
let r, i, a;
|
|
3609
3636
|
try {
|
|
3610
|
-
i = await
|
|
3637
|
+
i = await Jr(e, {
|
|
3611
3638
|
...t,
|
|
3612
3639
|
input: !1,
|
|
3613
3640
|
report: (e) => r = e,
|
|
@@ -3620,18 +3647,18 @@ async function no(e, t) {
|
|
|
3620
3647
|
command: "init",
|
|
3621
3648
|
passed: i === 0,
|
|
3622
3649
|
...r ?? {},
|
|
3623
|
-
...i !== 0 && { error: a ?
|
|
3650
|
+
...i !== 0 && { error: a ? lt(a.code, a.message) : lt("error", `init did not finish (exit status ${i}); the reason is on standard error`) }
|
|
3624
3651
|
};
|
|
3625
3652
|
return process.stdout.write(`${JSON.stringify(o)}\n`), i;
|
|
3626
3653
|
}
|
|
3627
3654
|
// src/cli/help.ts
|
|
3628
|
-
var
|
|
3655
|
+
var so = " 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", co = " blazon explain <code> what a finding code means, the fix, and where to read more\n blazon explain list every code", lo = " --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.", uo = {
|
|
3629
3656
|
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",
|
|
3630
3657
|
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",
|
|
3631
3658
|
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"
|
|
3632
3659
|
};
|
|
3633
|
-
function
|
|
3634
|
-
if (t === "plugin" && n !== void 0 && Object.hasOwn(
|
|
3660
|
+
function fo(e, t, n) {
|
|
3661
|
+
if (t === "plugin" && n !== void 0 && Object.hasOwn(uo, n)) return [{ body: uo[n] }];
|
|
3635
3662
|
let r = e.map((e) => ({
|
|
3636
3663
|
...e,
|
|
3637
3664
|
body: e.body.replace(/(--no-[a-z-]+[^\n]*?) *\(default: true\)/g, "$1")
|
|
@@ -3640,32 +3667,32 @@ function so(e, t, n) {
|
|
|
3640
3667
|
...r,
|
|
3641
3668
|
{
|
|
3642
3669
|
title: "Finding codes",
|
|
3643
|
-
body:
|
|
3670
|
+
body: co
|
|
3644
3671
|
},
|
|
3645
3672
|
{
|
|
3646
3673
|
title: "Working folder and environment",
|
|
3647
|
-
body:
|
|
3674
|
+
body: lo
|
|
3648
3675
|
},
|
|
3649
3676
|
{
|
|
3650
3677
|
title: "Exit status",
|
|
3651
|
-
body:
|
|
3678
|
+
body: so
|
|
3652
3679
|
}
|
|
3653
3680
|
] : r;
|
|
3654
3681
|
}
|
|
3655
3682
|
// src/cli/index.ts
|
|
3656
|
-
function
|
|
3683
|
+
function po(e, t) {
|
|
3657
3684
|
if (t === void 0) return;
|
|
3658
3685
|
let n = String(t), r = /^\d+$/.test(n) ? Number(n) : NaN;
|
|
3659
|
-
return r >= 1 && r <= 65535 ||
|
|
3686
|
+
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;
|
|
3660
3687
|
}
|
|
3661
|
-
var
|
|
3662
|
-
function
|
|
3663
|
-
t?.plugins === !1 && t.plugin !== void 0 &&
|
|
3688
|
+
var mo = (e) => typeof e == "number" ? String(e) : e;
|
|
3689
|
+
function ho(e, t) {
|
|
3690
|
+
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." });
|
|
3664
3691
|
}
|
|
3665
|
-
function
|
|
3666
|
-
if (t !== void 0) return n ||
|
|
3692
|
+
function go(e, t, n) {
|
|
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." }), ro.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;
|
|
3667
3694
|
}
|
|
3668
|
-
var
|
|
3695
|
+
var _o = (e) => {
|
|
3669
3696
|
let [t, n] = e.slice(2).filter((e, t, n) => !e.startsWith("-") && n[t - 1] !== "--cwd" && n[t - 1] !== "--allow-dir");
|
|
3670
3697
|
if (e.includes("--json") && t !== void 0) return t === "plugin" ? n === "check" ? "plugin check" : void 0 : [
|
|
3671
3698
|
"check",
|
|
@@ -3677,11 +3704,11 @@ var po = (e) => {
|
|
|
3677
3704
|
"pin",
|
|
3678
3705
|
"explain",
|
|
3679
3706
|
"doctor",
|
|
3680
|
-
...
|
|
3707
|
+
...Aa,
|
|
3681
3708
|
"mcp"
|
|
3682
3709
|
].includes(t) ? t : void 0;
|
|
3683
3710
|
};
|
|
3684
|
-
function
|
|
3711
|
+
function vo(e) {
|
|
3685
3712
|
if (e[2] !== "help") return e;
|
|
3686
3713
|
let t = e[3];
|
|
3687
3714
|
return t !== void 0 && !t.startsWith("-") ? [
|
|
@@ -3691,134 +3718,134 @@ function mo(e) {
|
|
|
3691
3718
|
...e.slice(4)
|
|
3692
3719
|
] : [...e.slice(0, 2), "--help"];
|
|
3693
3720
|
}
|
|
3694
|
-
async function
|
|
3695
|
-
let t =
|
|
3696
|
-
|
|
3697
|
-
let r =
|
|
3721
|
+
async function yo(e = process.argv) {
|
|
3722
|
+
let t = vo(e), n = t.includes("--debug");
|
|
3723
|
+
st(_o(t));
|
|
3724
|
+
let r = tt("blazon");
|
|
3698
3725
|
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) => {
|
|
3699
3726
|
try {
|
|
3700
|
-
await
|
|
3727
|
+
await yt(e || process.cwd(), po("dev", t?.port), {
|
|
3701
3728
|
strictPort: t?.strictPort,
|
|
3702
|
-
host:
|
|
3729
|
+
host: mo(t?.host)
|
|
3703
3730
|
});
|
|
3704
3731
|
} catch (e) {
|
|
3705
|
-
|
|
3732
|
+
P("dev", e, n);
|
|
3706
3733
|
}
|
|
3707
3734
|
}), 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) => {
|
|
3708
3735
|
try {
|
|
3709
|
-
|
|
3710
|
-
let n =
|
|
3711
|
-
t?.json ? await
|
|
3736
|
+
ho("build", t);
|
|
3737
|
+
let n = go("build", t?.severity, t?.json), r = () => Ft(e || process.cwd(), t?.outDir === void 0 ? void 0 : O.resolve(process.cwd(), t.outDir), t);
|
|
3738
|
+
t?.json ? await ao("build", !1, r, n) : await r();
|
|
3712
3739
|
} catch (e) {
|
|
3713
|
-
|
|
3740
|
+
P("build", e, n);
|
|
3714
3741
|
}
|
|
3715
3742
|
}), 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) => {
|
|
3716
3743
|
try {
|
|
3717
|
-
|
|
3718
|
-
let n =
|
|
3719
|
-
t?.json ? await
|
|
3744
|
+
ho("tokens", t);
|
|
3745
|
+
let n = go("tokens", t?.severity, t?.json), r = () => It(e || process.cwd(), t);
|
|
3746
|
+
t?.json ? await ao("tokens", !1, r, n) : await r();
|
|
3720
3747
|
} catch (e) {
|
|
3721
|
-
|
|
3748
|
+
P("tokens", e, n);
|
|
3722
3749
|
}
|
|
3723
3750
|
}), 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) => {
|
|
3724
3751
|
try {
|
|
3725
|
-
|
|
3726
|
-
let n =
|
|
3727
|
-
t?.json ? await
|
|
3752
|
+
ho("check", t);
|
|
3753
|
+
let n = go("check", t?.severity, t?.json), r = () => Pt(e || process.cwd(), t?.strict, t);
|
|
3754
|
+
t?.json ? await ao("check", !!t.strict, r, n) : (await r()).passed || (process.exitCode = 1);
|
|
3728
3755
|
} catch (e) {
|
|
3729
|
-
|
|
3756
|
+
P("check", e, n);
|
|
3730
3757
|
}
|
|
3731
|
-
}),
|
|
3758
|
+
}), Pa(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) => {
|
|
3732
3759
|
try {
|
|
3733
|
-
process.exitCode = await
|
|
3760
|
+
process.exitCode = await Ya(e);
|
|
3734
3761
|
} catch (e) {
|
|
3735
|
-
|
|
3762
|
+
P("mcp", e, n);
|
|
3736
3763
|
}
|
|
3737
3764
|
}), 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) => {
|
|
3738
3765
|
try {
|
|
3739
|
-
process.exitCode = await
|
|
3766
|
+
process.exitCode = await di(e, t);
|
|
3740
3767
|
} catch (e) {
|
|
3741
|
-
|
|
3768
|
+
P("drift", e, n);
|
|
3742
3769
|
}
|
|
3743
3770
|
}), 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) => {
|
|
3744
3771
|
try {
|
|
3745
|
-
process.exitCode = await
|
|
3772
|
+
process.exitCode = await fi(e || process.cwd(), { json: t?.json });
|
|
3746
3773
|
} catch (e) {
|
|
3747
|
-
|
|
3774
|
+
P("approvals", e, n);
|
|
3748
3775
|
}
|
|
3749
3776
|
}), r.command("plugin [action] [target]", "Plugins: `check <program>` checks that a program follows the plugin protocol, `pin <path>` prints the digest that pins it, `profile` prints the profile blazon enforces").option("--name <name>", "With `pin`: record the pin in blazon.plugins.lock under this plugin name").option("--digest <digest>", "With `pin --name`: the digest you vouch for; the bytes must be those").option("--entry <path>", "With `pin --name` on a directory: the program inside it, when it is not blazon-<name>").option("--json", "With `check`: print the cases as JSON on standard output").option("--core", "With `check`: run only the core cases of the protocol (1 to 5), not blazon's role cases or the layout of a shipped plugin").action(async (e, t, r) => {
|
|
3750
3777
|
try {
|
|
3751
|
-
if (r?.json && e !== "check" &&
|
|
3778
|
+
if (r?.json && e !== "check" && N("blazon plugin: --json is for `blazon plugin check`; `pin` prints a digest and `profile` prints JSON already.", "conflicting-options", { fix: "Leave out --json, or use it with `blazon plugin check`." }), r?.core && e !== "check" && N("blazon plugin: --core is for `blazon plugin check`; `pin` and `profile` run no cases.", "conflicting-options", { fix: "Leave out --core, or use it with `blazon plugin check`." }), e !== "pin") for (let t of [
|
|
3752
3779
|
"name",
|
|
3753
3780
|
"digest",
|
|
3754
3781
|
"entry"
|
|
3755
|
-
]) r?.[t] !== void 0 &&
|
|
3756
|
-
e === "profile" && t !== void 0 &&
|
|
3782
|
+
]) 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 li(e, t, r);
|
|
3757
3784
|
} catch (e) {
|
|
3758
|
-
|
|
3785
|
+
P("plugin", e, n);
|
|
3759
3786
|
}
|
|
3760
3787
|
}), 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) => {
|
|
3761
3788
|
try {
|
|
3762
|
-
process.exitCode =
|
|
3789
|
+
process.exitCode = eo(e, { json: t?.json });
|
|
3763
3790
|
} catch (e) {
|
|
3764
|
-
|
|
3791
|
+
P("explain", e, n);
|
|
3765
3792
|
}
|
|
3766
3793
|
}), 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) => {
|
|
3767
3794
|
try {
|
|
3768
|
-
process.exitCode =
|
|
3795
|
+
process.exitCode = ui(e || process.cwd(), { json: t?.json });
|
|
3769
3796
|
} catch (e) {
|
|
3770
|
-
|
|
3797
|
+
P("pin", e, n);
|
|
3771
3798
|
}
|
|
3772
3799
|
}), 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) => {
|
|
3773
3800
|
try {
|
|
3774
|
-
t?.json ? (t.dev &&
|
|
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 oo(e || ".", t)) : process.exitCode = await Jr(e || ".", { ...t });
|
|
3775
3802
|
} catch (e) {
|
|
3776
|
-
|
|
3803
|
+
P("init", e, n);
|
|
3777
3804
|
}
|
|
3778
3805
|
}), 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) => {
|
|
3779
3806
|
try {
|
|
3780
|
-
await
|
|
3807
|
+
await Qr(e || process.cwd(), po("preview", t?.port), {
|
|
3781
3808
|
strictPort: t?.strictPort,
|
|
3782
|
-
host:
|
|
3809
|
+
host: mo(t?.host)
|
|
3783
3810
|
});
|
|
3784
3811
|
} catch (e) {
|
|
3785
|
-
|
|
3812
|
+
P("preview", e, n);
|
|
3786
3813
|
}
|
|
3787
3814
|
}), 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) => {
|
|
3788
3815
|
try {
|
|
3789
|
-
process.exitCode = await
|
|
3816
|
+
process.exitCode = await oa(process.cwd(), { json: e?.json });
|
|
3790
3817
|
} catch (e) {
|
|
3791
|
-
|
|
3818
|
+
P("doctor", e, n);
|
|
3792
3819
|
}
|
|
3793
|
-
}), 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) =>
|
|
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) => fo(e, r.matchedCommand?.name, r.args[0])), r.version(Ge), t.slice(2).length === 0) return r.outputHelp();
|
|
3794
3821
|
r.addEventListener("command:*", (e) => {
|
|
3795
3822
|
if (r.options.help || r.options.version) return;
|
|
3796
3823
|
let t = String(e.detail), n = E(t, r.commands.map((e) => e.name).filter(Boolean));
|
|
3797
|
-
|
|
3824
|
+
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." });
|
|
3798
3825
|
});
|
|
3799
3826
|
try {
|
|
3800
|
-
r.parse(t, { run: !1 }),
|
|
3827
|
+
r.parse(t, { run: !1 }), no(r, t);
|
|
3801
3828
|
try {
|
|
3802
|
-
|
|
3829
|
+
mi(r.options.allowDir), pi(r.options.cwd);
|
|
3803
3830
|
} catch (e) {
|
|
3804
|
-
|
|
3831
|
+
P(r.matchedCommand?.name ?? "", e, n);
|
|
3805
3832
|
}
|
|
3806
3833
|
await r.runMatchedCommand();
|
|
3807
3834
|
} catch (e) {
|
|
3808
|
-
if (!
|
|
3835
|
+
if (!ft(e)) return P("", e, n);
|
|
3809
3836
|
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;
|
|
3810
|
-
o !== void 0 && /^\d+$/.test(o) && (t === "dev" || t === "preview") &&
|
|
3837
|
+
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", {
|
|
3811
3838
|
stack: s,
|
|
3812
3839
|
fix: "Run blazon list to see the token paths."
|
|
3813
|
-
}), o === void 0 &&
|
|
3840
|
+
}), o === void 0 && N(`${i}: ${dt(e.message)}. Run ${i} --help for the options.`, "missing-argument", {
|
|
3814
3841
|
stack: s,
|
|
3815
3842
|
fix: `Run ${i} --help for the options.`
|
|
3816
3843
|
});
|
|
3817
3844
|
let c = [...r.matchedCommand?.options ?? [], ...r.globalCommand.options].map((e) => e.name), l = E(o, c);
|
|
3818
|
-
|
|
3845
|
+
N(`${i}: unknown option "${a}${o}"${l ? `; did you mean "--${l}"?` : "."} Run ${i} --help for the options.`, "unknown-option", {
|
|
3819
3846
|
stack: s,
|
|
3820
3847
|
fix: l ? `Use --${l}, or run ${i} --help for the options.` : `Run ${i} --help for the options.`
|
|
3821
3848
|
});
|
|
3822
3849
|
}
|
|
3823
3850
|
}
|
|
3824
|
-
export {
|
|
3851
|
+
export { yo as runCli };
|