@emailens/cli 0.12.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +186 -165
- package/dist/chunk-55EWHWWT.js +648 -0
- package/dist/chunk-55EWHWWT.js.map +1 -0
- package/dist/index.js +39 -626
- package/dist/index.js.map +1 -1
- package/dist/test.d.ts +34 -0
- package/dist/test.js +35 -0
- package/dist/test.js.map +1 -0
- package/package.json +6 -2
package/dist/index.js
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
TARGETING_POLICY_ARG,
|
|
4
|
+
lint_default,
|
|
5
|
+
parseTargetingPolicy,
|
|
6
|
+
positionsApply,
|
|
7
|
+
readInput,
|
|
8
|
+
resolveClients,
|
|
9
|
+
resolveFormat,
|
|
10
|
+
toFramework
|
|
11
|
+
} from "./chunk-55EWHWWT.js";
|
|
2
12
|
import {
|
|
3
13
|
__require
|
|
4
14
|
} from "./chunk-7OCVIDC7.js";
|
|
5
15
|
|
|
6
16
|
// src/index.ts
|
|
7
|
-
import { defineCommand as
|
|
17
|
+
import { defineCommand as defineCommand8, runMain } from "citty";
|
|
8
18
|
|
|
9
19
|
// src/meta.ts
|
|
10
20
|
import { EMAIL_CLIENTS } from "@emailens/engine";
|
|
@@ -12,7 +22,7 @@ import { EMAIL_CLIENTS } from "@emailens/engine";
|
|
|
12
22
|
// package.json
|
|
13
23
|
var package_default = {
|
|
14
24
|
name: "@emailens/cli",
|
|
15
|
-
version: "0.
|
|
25
|
+
version: "0.13.1",
|
|
16
26
|
description: "CLI tool for email compatibility analysis: lint, preview and export HTML, MJML, Maizzle and React Email rendering across 21 email clients.",
|
|
17
27
|
type: "module",
|
|
18
28
|
bin: {
|
|
@@ -22,6 +32,10 @@ var package_default = {
|
|
|
22
32
|
".": {
|
|
23
33
|
types: "./dist/index.d.ts",
|
|
24
34
|
import: "./dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./test": {
|
|
37
|
+
types: "./dist/test.d.ts",
|
|
38
|
+
import: "./dist/test.js"
|
|
25
39
|
}
|
|
26
40
|
},
|
|
27
41
|
main: "./dist/index.js",
|
|
@@ -39,7 +53,7 @@ var package_default = {
|
|
|
39
53
|
prepublishOnly: "bun run build"
|
|
40
54
|
},
|
|
41
55
|
dependencies: {
|
|
42
|
-
"@emailens/engine": "^0.18.
|
|
56
|
+
"@emailens/engine": "^0.18.4",
|
|
43
57
|
citty: "^0.1.6",
|
|
44
58
|
"cli-table3": "^0.6.5",
|
|
45
59
|
ora: "^8.2.0",
|
|
@@ -101,100 +115,13 @@ import {
|
|
|
101
115
|
generateCompatibilityScore,
|
|
102
116
|
CompileError
|
|
103
117
|
} from "@emailens/engine";
|
|
104
|
-
|
|
105
|
-
// src/utils.ts
|
|
106
|
-
import { readFileSync } from "fs";
|
|
107
|
-
import { EMAIL_CLIENTS as EMAIL_CLIENTS2 } from "@emailens/engine";
|
|
108
|
-
import { detectFormat } from "@emailens/engine/compile";
|
|
109
|
-
var VALID_FORMATS = /* @__PURE__ */ new Set(["html", "jsx", "mjml", "maizzle"]);
|
|
110
|
-
async function readInput(pathOrStdin) {
|
|
111
|
-
if (pathOrStdin === "-") {
|
|
112
|
-
try {
|
|
113
|
-
return readFileSync("/dev/stdin", "utf-8");
|
|
114
|
-
} catch {
|
|
115
|
-
}
|
|
116
|
-
return new Promise((resolve3, reject) => {
|
|
117
|
-
const chunks = [];
|
|
118
|
-
process.stdin.resume();
|
|
119
|
-
process.stdin.on("data", (chunk) => chunks.push(Buffer.from(chunk)));
|
|
120
|
-
process.stdin.on("end", () => {
|
|
121
|
-
const data = Buffer.concat(chunks).toString("utf-8");
|
|
122
|
-
if (!data.trim()) {
|
|
123
|
-
reject(new Error("No input received from stdin. Pipe HTML or provide a file path."));
|
|
124
|
-
} else {
|
|
125
|
-
resolve3(data);
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
process.stdin.on("error", () => {
|
|
129
|
-
reject(new Error("No input received from stdin. Pipe HTML or provide a file path."));
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
try {
|
|
134
|
-
return readFileSync(pathOrStdin, "utf-8");
|
|
135
|
-
} catch (err) {
|
|
136
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
137
|
-
throw new Error(`Failed to read file "${pathOrStdin}": ${message}`);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
function resolveClients(ids) {
|
|
141
|
-
const validIds = new Set(EMAIL_CLIENTS2.map((c) => c.id));
|
|
142
|
-
if (!ids) {
|
|
143
|
-
return EMAIL_CLIENTS2.map((c) => c.id);
|
|
144
|
-
}
|
|
145
|
-
const requested = ids.split(",").map((s) => s.trim()).filter(Boolean);
|
|
146
|
-
const invalid = requested.filter((id) => !validIds.has(id));
|
|
147
|
-
if (invalid.length > 0) {
|
|
148
|
-
throw new Error(
|
|
149
|
-
`Unknown client ID(s): ${invalid.join(", ")}.
|
|
150
|
-
Valid IDs: ${Array.from(validIds).join(", ")}`
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
return requested;
|
|
154
|
-
}
|
|
155
|
-
function isVueSfc(source) {
|
|
156
|
-
return /<template[\s>]/i.test(source) && /<\/template>/i.test(source);
|
|
157
|
-
}
|
|
158
|
-
function resolveFormat(formatFlag, filePath, source) {
|
|
159
|
-
if (formatFlag) {
|
|
160
|
-
if (!VALID_FORMATS.has(formatFlag)) {
|
|
161
|
-
throw new Error(
|
|
162
|
-
`Unknown format "${formatFlag}". Valid formats: ${Array.from(VALID_FORMATS).join(", ")}`
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
return formatFlag;
|
|
166
|
-
}
|
|
167
|
-
if (filePath && filePath !== "-") {
|
|
168
|
-
return detectFormat(filePath);
|
|
169
|
-
}
|
|
170
|
-
if (source && isVueSfc(source)) return "maizzle";
|
|
171
|
-
return "html";
|
|
172
|
-
}
|
|
173
|
-
function toFramework(format) {
|
|
174
|
-
if (format === "jsx" || format === "mjml" || format === "maizzle") return format;
|
|
175
|
-
return void 0;
|
|
176
|
-
}
|
|
177
|
-
function positionsApply(format) {
|
|
178
|
-
return format === "html";
|
|
179
|
-
}
|
|
180
|
-
var TARGETING_POLICY_ARG = {
|
|
181
|
-
type: "string",
|
|
182
|
-
description: "Client-targeting policy: progressive (default), strict, or lenient"
|
|
183
|
-
};
|
|
184
|
-
function parseTargetingPolicy(raw) {
|
|
185
|
-
if (raw == null || raw === "") return void 0;
|
|
186
|
-
if (raw === "progressive" || raw === "strict" || raw === "lenient") return raw;
|
|
187
|
-
throw new Error(`Unknown targeting policy "${raw}". Valid: progressive, strict, lenient`);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// src/commands/analyze.ts
|
|
191
118
|
import { compile } from "@emailens/engine/compile";
|
|
192
119
|
|
|
193
120
|
// src/output/terminal.ts
|
|
194
121
|
import pc from "picocolors";
|
|
195
122
|
import Table from "cli-table3";
|
|
196
123
|
import {
|
|
197
|
-
EMAIL_CLIENTS as
|
|
124
|
+
EMAIL_CLIENTS as EMAIL_CLIENTS2
|
|
198
125
|
} from "@emailens/engine";
|
|
199
126
|
|
|
200
127
|
// src/output/json.ts
|
|
@@ -284,7 +211,7 @@ function printScoreTable(scores, warnings, options) {
|
|
|
284
211
|
console.log(pc.bold(" Emailens: Compatibility Report"));
|
|
285
212
|
console.log();
|
|
286
213
|
}
|
|
287
|
-
const clientMap = new Map(
|
|
214
|
+
const clientMap = new Map(EMAIL_CLIENTS2.map((c) => [c.id, c.name]));
|
|
288
215
|
const warningsByClient = /* @__PURE__ */ new Map();
|
|
289
216
|
for (const w of warnings) {
|
|
290
217
|
const existing = warningsByClient.get(w.client) ?? [];
|
|
@@ -330,7 +257,7 @@ function printWarnings(warnings, options) {
|
|
|
330
257
|
existing.push(w);
|
|
331
258
|
byClient.set(w.client, existing);
|
|
332
259
|
}
|
|
333
|
-
const clientMap = new Map(
|
|
260
|
+
const clientMap = new Map(EMAIL_CLIENTS2.map((c) => [c.id, c.name]));
|
|
334
261
|
for (const [clientId, clientWarnings] of byClient) {
|
|
335
262
|
const clientName = clientMap.get(clientId) ?? clientId;
|
|
336
263
|
const worst = worstSeverity(clientWarnings);
|
|
@@ -555,7 +482,7 @@ var preview_default = defineCommand2({
|
|
|
555
482
|
import { defineCommand as defineCommand3 } from "citty";
|
|
556
483
|
import pc2 from "picocolors";
|
|
557
484
|
import Table2 from "cli-table3";
|
|
558
|
-
import { EMAIL_CLIENTS as
|
|
485
|
+
import { EMAIL_CLIENTS as EMAIL_CLIENTS3 } from "@emailens/engine";
|
|
559
486
|
var clients_default = defineCommand3({
|
|
560
487
|
meta: {
|
|
561
488
|
name: "clients",
|
|
@@ -569,7 +496,7 @@ var clients_default = defineCommand3({
|
|
|
569
496
|
},
|
|
570
497
|
run({ args }) {
|
|
571
498
|
if (args.json) {
|
|
572
|
-
const data =
|
|
499
|
+
const data = EMAIL_CLIENTS3.map((c) => ({
|
|
573
500
|
id: c.id,
|
|
574
501
|
name: c.name,
|
|
575
502
|
category: c.category,
|
|
@@ -592,7 +519,7 @@ var clients_default = defineCommand3({
|
|
|
592
519
|
],
|
|
593
520
|
style: { head: [], border: [] }
|
|
594
521
|
});
|
|
595
|
-
for (const client of
|
|
522
|
+
for (const client of EMAIL_CLIENTS3) {
|
|
596
523
|
table.push([
|
|
597
524
|
client.id,
|
|
598
525
|
client.name,
|
|
@@ -603,7 +530,7 @@ var clients_default = defineCommand3({
|
|
|
603
530
|
}
|
|
604
531
|
console.log(table.toString());
|
|
605
532
|
console.log();
|
|
606
|
-
console.log(pc2.dim(` ${
|
|
533
|
+
console.log(pc2.dim(` ${EMAIL_CLIENTS3.length} clients supported`));
|
|
607
534
|
console.log();
|
|
608
535
|
}
|
|
609
536
|
});
|
|
@@ -623,9 +550,9 @@ import {
|
|
|
623
550
|
import { compile as compile3 } from "@emailens/engine/compile";
|
|
624
551
|
|
|
625
552
|
// src/output/html-report.ts
|
|
626
|
-
import { EMAIL_CLIENTS as
|
|
553
|
+
import { EMAIL_CLIENTS as EMAIL_CLIENTS4 } from "@emailens/engine";
|
|
627
554
|
function generateHtmlReport(opts) {
|
|
628
|
-
const clientMap = new Map(
|
|
555
|
+
const clientMap = new Map(EMAIL_CLIENTS4.map((c) => [c.id, c]));
|
|
629
556
|
const overallScore = worstClientScore(opts.scores);
|
|
630
557
|
const scoreColor = (s) => s >= 90 ? "#22c55e" : s >= 70 ? "#eab308" : "#ef4444";
|
|
631
558
|
const clientCards = Object.entries(opts.scores).sort(([, a], [, b]) => a.score - b.score).map(([clientId, { score, errors, warnings: warns, info }]) => {
|
|
@@ -1208,523 +1135,9 @@ function printQualitySummary(report, skip, options) {
|
|
|
1208
1135
|
console.log();
|
|
1209
1136
|
}
|
|
1210
1137
|
|
|
1211
|
-
// src/commands/
|
|
1138
|
+
// src/commands/inbox.ts
|
|
1212
1139
|
import { defineCommand as defineCommand7 } from "citty";
|
|
1213
1140
|
import pc5 from "picocolors";
|
|
1214
|
-
import { compile as compile6 } from "@emailens/engine/compile";
|
|
1215
|
-
import {
|
|
1216
|
-
auditEmail as auditEmail2,
|
|
1217
|
-
CompileError as CompileError6,
|
|
1218
|
-
MAX_WARNING_LOCATIONS
|
|
1219
|
-
} from "@emailens/engine";
|
|
1220
|
-
|
|
1221
|
-
// src/project-config.ts
|
|
1222
|
-
import { existsSync, readFileSync as readFileSync2 } from "fs";
|
|
1223
|
-
import { dirname, join as join2, parse } from "path";
|
|
1224
|
-
var SEVERITIES = ["error", "warning", "info", "off"];
|
|
1225
|
-
function parseRules(value) {
|
|
1226
|
-
const rules = {};
|
|
1227
|
-
const invalid = [];
|
|
1228
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return { rules, invalid };
|
|
1229
|
-
for (const [rule, severity] of Object.entries(value)) {
|
|
1230
|
-
if (typeof severity === "string" && SEVERITIES.includes(severity)) {
|
|
1231
|
-
rules[rule] = severity;
|
|
1232
|
-
} else {
|
|
1233
|
-
invalid.push(`${rule}: ${JSON.stringify(severity)}`);
|
|
1234
|
-
}
|
|
1235
|
-
}
|
|
1236
|
-
return { rules, invalid };
|
|
1237
|
-
}
|
|
1238
|
-
function parseProjectConfig(source, from) {
|
|
1239
|
-
let parsed;
|
|
1240
|
-
try {
|
|
1241
|
-
parsed = JSON.parse(source);
|
|
1242
|
-
} catch {
|
|
1243
|
-
return void 0;
|
|
1244
|
-
}
|
|
1245
|
-
if (!parsed || typeof parsed !== "object") return void 0;
|
|
1246
|
-
const body = from === "package.json" ? parsed.emailens : parsed;
|
|
1247
|
-
if (!body || typeof body !== "object") return void 0;
|
|
1248
|
-
const config = { invalid: [] };
|
|
1249
|
-
const skip = body.skip;
|
|
1250
|
-
if (Array.isArray(skip) && skip.every((s) => typeof s === "string")) config.skip = skip;
|
|
1251
|
-
const { rules, invalid } = parseRules(body.rules);
|
|
1252
|
-
if (Object.keys(rules).length) config.rules = rules;
|
|
1253
|
-
config.invalid = invalid;
|
|
1254
|
-
return config.skip || config.rules || invalid.length ? config : void 0;
|
|
1255
|
-
}
|
|
1256
|
-
function loadProjectConfig(from = process.cwd()) {
|
|
1257
|
-
const root = parse(from).root;
|
|
1258
|
-
for (let dir = from; ; dir = dirname(dir)) {
|
|
1259
|
-
for (const [name, kind] of [
|
|
1260
|
-
[".emailensrc", "emailensrc"],
|
|
1261
|
-
["package.json", "package.json"]
|
|
1262
|
-
]) {
|
|
1263
|
-
const path = join2(dir, name);
|
|
1264
|
-
if (!existsSync(path)) continue;
|
|
1265
|
-
let body;
|
|
1266
|
-
try {
|
|
1267
|
-
body = readFileSync2(path, "utf-8");
|
|
1268
|
-
} catch {
|
|
1269
|
-
continue;
|
|
1270
|
-
}
|
|
1271
|
-
const config = parseProjectConfig(body, kind);
|
|
1272
|
-
if (config) return { ...config, source: path };
|
|
1273
|
-
}
|
|
1274
|
-
if (dir === root) return void 0;
|
|
1275
|
-
}
|
|
1276
|
-
}
|
|
1277
|
-
function applySeverities(issues, rules) {
|
|
1278
|
-
if (!rules || !Object.keys(rules).length) return issues;
|
|
1279
|
-
const out = [];
|
|
1280
|
-
for (const issue of issues) {
|
|
1281
|
-
const severity = rules[issue.rule];
|
|
1282
|
-
if (severity === "off") continue;
|
|
1283
|
-
out.push(severity ? { ...issue, severity } : issue);
|
|
1284
|
-
}
|
|
1285
|
-
return out;
|
|
1286
|
-
}
|
|
1287
|
-
|
|
1288
|
-
// src/commands/lint.ts
|
|
1289
|
-
import { readdir } from "fs/promises";
|
|
1290
|
-
import { resolve as resolve2, relative } from "path";
|
|
1291
|
-
var VALID_SKIPS2 = /* @__PURE__ */ new Set([
|
|
1292
|
-
"spam",
|
|
1293
|
-
"links",
|
|
1294
|
-
"accessibility",
|
|
1295
|
-
"images",
|
|
1296
|
-
"compatibility",
|
|
1297
|
-
"inboxPreview",
|
|
1298
|
-
"size",
|
|
1299
|
-
"templateVariables",
|
|
1300
|
-
"overflow",
|
|
1301
|
-
"visual",
|
|
1302
|
-
"darkContrast",
|
|
1303
|
-
"mobileContrast",
|
|
1304
|
-
"design",
|
|
1305
|
-
"vml",
|
|
1306
|
-
"styleSurvival",
|
|
1307
|
-
"targeting"
|
|
1308
|
-
]);
|
|
1309
|
-
var lint_default = defineCommand7({
|
|
1310
|
-
meta: {
|
|
1311
|
-
name: "lint",
|
|
1312
|
-
description: "Lint HTML emails for compatibility, spam, accessibility, and more. CI/CD-friendly with structured exit codes."
|
|
1313
|
-
},
|
|
1314
|
-
args: {
|
|
1315
|
-
input: {
|
|
1316
|
-
type: "positional",
|
|
1317
|
-
description: "HTML file path or glob pattern",
|
|
1318
|
-
required: true
|
|
1319
|
-
},
|
|
1320
|
-
format: {
|
|
1321
|
-
type: "string",
|
|
1322
|
-
alias: "f",
|
|
1323
|
-
description: "Input format: html, jsx, mjml, maizzle"
|
|
1324
|
-
},
|
|
1325
|
-
json: {
|
|
1326
|
-
type: "boolean",
|
|
1327
|
-
description: "Output as JSON"
|
|
1328
|
-
},
|
|
1329
|
-
info: {
|
|
1330
|
-
type: "boolean",
|
|
1331
|
-
description: "List info findings too: safe fallbacks, not problems (counted, not listed, by default)"
|
|
1332
|
-
},
|
|
1333
|
-
failOnWarning: {
|
|
1334
|
-
type: "boolean",
|
|
1335
|
-
description: "Exit 2 if warnings found"
|
|
1336
|
-
},
|
|
1337
|
-
skip: {
|
|
1338
|
-
type: "string",
|
|
1339
|
-
description: "Comma-separated checks to skip: spam,links,accessibility,images,compatibility,inboxPreview,size,templateVariables,overflow,visual,vml,styleSurvival,targeting"
|
|
1340
|
-
},
|
|
1341
|
-
targetingPolicy: TARGETING_POLICY_ARG,
|
|
1342
|
-
maxWarnings: {
|
|
1343
|
-
type: "string",
|
|
1344
|
-
description: "Fail if more than n warnings"
|
|
1345
|
-
},
|
|
1346
|
-
quiet: {
|
|
1347
|
-
type: "boolean",
|
|
1348
|
-
alias: "q",
|
|
1349
|
-
description: "Suppress decorations: no hosted-preview line after a failure"
|
|
1350
|
-
}
|
|
1351
|
-
},
|
|
1352
|
-
async run({ args }) {
|
|
1353
|
-
try {
|
|
1354
|
-
if (args.format) resolveFormat(args.format);
|
|
1355
|
-
const project = loadProjectConfig();
|
|
1356
|
-
if (project?.invalid.length && !args.json) {
|
|
1357
|
-
console.error(
|
|
1358
|
-
pc5.yellow(
|
|
1359
|
-
`${project.source}: ignoring ${project.invalid.join(", ")}, a severity must be "error", "warning", "info" or "off".`
|
|
1360
|
-
)
|
|
1361
|
-
);
|
|
1362
|
-
}
|
|
1363
|
-
const skip = [];
|
|
1364
|
-
if (!args.skip) {
|
|
1365
|
-
for (const s of project?.skip ?? []) {
|
|
1366
|
-
if (VALID_SKIPS2.has(s)) skip.push(s);
|
|
1367
|
-
else if (!args.json) {
|
|
1368
|
-
console.error(pc5.yellow(`${project?.source}: unknown skip value "${s}", ignoring.`));
|
|
1369
|
-
}
|
|
1370
|
-
}
|
|
1371
|
-
}
|
|
1372
|
-
if (args.skip) {
|
|
1373
|
-
for (const s of args.skip.split(",").map((s2) => s2.trim()).filter(Boolean)) {
|
|
1374
|
-
if (!VALID_SKIPS2.has(s)) {
|
|
1375
|
-
throw new Error(`Unknown skip value "${s}". Valid: ${Array.from(VALID_SKIPS2).join(", ")}`);
|
|
1376
|
-
}
|
|
1377
|
-
skip.push(s);
|
|
1378
|
-
}
|
|
1379
|
-
}
|
|
1380
|
-
const maxWarningsRaw = args.maxWarnings !== void 0 ? parseInt(args.maxWarnings, 10) : void 0;
|
|
1381
|
-
if (maxWarningsRaw !== void 0 && isNaN(maxWarningsRaw)) {
|
|
1382
|
-
throw new Error(`--maxWarnings must be a number, got: ${args.maxWarnings}`);
|
|
1383
|
-
}
|
|
1384
|
-
const maxWarnings = maxWarningsRaw ?? Infinity;
|
|
1385
|
-
const files = await resolveGlob(args.input);
|
|
1386
|
-
if (files.length === 0) {
|
|
1387
|
-
if (args.json) {
|
|
1388
|
-
console.log(JSON.stringify({ files: [], totalErrors: 0, totalWarnings: 0 }));
|
|
1389
|
-
} else {
|
|
1390
|
-
console.error(pc5.red(`No files found matching: ${args.input}`));
|
|
1391
|
-
}
|
|
1392
|
-
process.exit(1);
|
|
1393
|
-
}
|
|
1394
|
-
const results = [];
|
|
1395
|
-
let totalErrors = 0;
|
|
1396
|
-
let totalWarnings = 0;
|
|
1397
|
-
for (const file of files) {
|
|
1398
|
-
const source = await readInput(file);
|
|
1399
|
-
const format = resolveFormat(args.format, file, source);
|
|
1400
|
-
const html = await compile6(source, format);
|
|
1401
|
-
const framework = toFramework(format);
|
|
1402
|
-
const positions = positionsApply(format);
|
|
1403
|
-
const targetingPolicy = parseTargetingPolicy(args.targetingPolicy);
|
|
1404
|
-
const report = auditEmail2(html, {
|
|
1405
|
-
framework,
|
|
1406
|
-
skip,
|
|
1407
|
-
positions,
|
|
1408
|
-
targetingPolicy
|
|
1409
|
-
});
|
|
1410
|
-
const issues = applySeverities(flattenToLintIssues(report, skip), project?.rules);
|
|
1411
|
-
const errors = issues.filter((i) => i.severity === "error").length;
|
|
1412
|
-
const warnings = issues.filter((i) => i.severity === "warning").length;
|
|
1413
|
-
results.push({ file: relative(process.cwd(), file), issues, errors, warnings });
|
|
1414
|
-
totalErrors += errors;
|
|
1415
|
-
totalWarnings += warnings;
|
|
1416
|
-
}
|
|
1417
|
-
if (args.json) {
|
|
1418
|
-
console.log(JSON.stringify({ files: results, totalErrors, totalWarnings }));
|
|
1419
|
-
} else {
|
|
1420
|
-
for (const result of results) {
|
|
1421
|
-
console.log(pc5.underline(result.file));
|
|
1422
|
-
const shown = args.info ? result.issues : result.issues.filter((i) => i.severity !== "info");
|
|
1423
|
-
const hidden = result.issues.length - shown.length;
|
|
1424
|
-
if (shown.length === 0) {
|
|
1425
|
-
console.log(` ${pc5.green("pass")} No issues found`);
|
|
1426
|
-
} else {
|
|
1427
|
-
const width = shown.reduce(
|
|
1428
|
-
(w, i) => i.loc ? Math.max(w, `${i.loc.line}:${i.loc.column}`.length) : w,
|
|
1429
|
-
0
|
|
1430
|
-
);
|
|
1431
|
-
for (const issue of shown) {
|
|
1432
|
-
const sev = issue.severity === "error" ? pc5.red("error") : issue.severity === "warning" ? pc5.yellow("warn ") : pc5.blue("info ");
|
|
1433
|
-
const pos = width > 0 ? `${pc5.dim((issue.loc ? `${issue.loc.line}:${issue.loc.column}` : "").padStart(width))} ` : "";
|
|
1434
|
-
console.log(` ${sev} ${pos}${pc5.dim(issue.category.padEnd(18))} ${pc5.bold(issue.rule.padEnd(22))} ${issue.message}`);
|
|
1435
|
-
}
|
|
1436
|
-
}
|
|
1437
|
-
if (hidden > 0) {
|
|
1438
|
-
console.log(pc5.dim(` ${hidden} info: safe fallbacks, not problems. --info lists them.`));
|
|
1439
|
-
}
|
|
1440
|
-
console.log();
|
|
1441
|
-
}
|
|
1442
|
-
const summary = [
|
|
1443
|
-
`${files.length} file${files.length === 1 ? "" : "s"}`,
|
|
1444
|
-
totalErrors > 0 ? pc5.red(`${totalErrors} error${totalErrors === 1 ? "" : "s"}`) : null,
|
|
1445
|
-
totalWarnings > 0 ? pc5.yellow(`${totalWarnings} warning${totalWarnings === 1 ? "" : "s"}`) : null,
|
|
1446
|
-
totalErrors === 0 && totalWarnings === 0 ? pc5.green("all clean") : null
|
|
1447
|
-
].filter(Boolean).join(" | ");
|
|
1448
|
-
console.log(summary);
|
|
1449
|
-
}
|
|
1450
|
-
let exitCode = 0;
|
|
1451
|
-
let reason = null;
|
|
1452
|
-
if (totalErrors > 0) {
|
|
1453
|
-
exitCode = 1;
|
|
1454
|
-
} else if (args.failOnWarning && totalWarnings > 0) {
|
|
1455
|
-
exitCode = 2;
|
|
1456
|
-
reason = pc5.yellow(`
|
|
1457
|
-
Failed: ${totalWarnings} warning${totalWarnings === 1 ? "" : "s"} found (--failOnWarning)`);
|
|
1458
|
-
} else if (Number.isFinite(maxWarnings) && totalWarnings > maxWarnings) {
|
|
1459
|
-
exitCode = 2;
|
|
1460
|
-
reason = pc5.red(`
|
|
1461
|
-
Exceeded max warnings: ${totalWarnings} > ${maxWarnings}`);
|
|
1462
|
-
}
|
|
1463
|
-
if (!args.json) {
|
|
1464
|
-
if (reason) console.error(reason);
|
|
1465
|
-
const hint = failureHint(exitCode, { quiet: args.quiet });
|
|
1466
|
-
if (hint) console.log(pc5.dim(hint));
|
|
1467
|
-
}
|
|
1468
|
-
if (exitCode !== 0) process.exit(exitCode);
|
|
1469
|
-
} catch (err) {
|
|
1470
|
-
if (err instanceof CompileError6) {
|
|
1471
|
-
console.error(pc5.red(`Compilation failed (${err.phase}): ${err.message}`));
|
|
1472
|
-
} else {
|
|
1473
|
-
console.error(pc5.red(err.message));
|
|
1474
|
-
}
|
|
1475
|
-
process.exit(1);
|
|
1476
|
-
}
|
|
1477
|
-
}
|
|
1478
|
-
});
|
|
1479
|
-
var HOSTED_HINT = "See it rendered in Gmail, Outlook and Apple Mail, no signup: https://app.emailens.dev/try?utm_source=cli&utm_medium=lint";
|
|
1480
|
-
function failureHint(exitCode, options = {}) {
|
|
1481
|
-
if (exitCode === 0 || options.quiet) return null;
|
|
1482
|
-
return HOSTED_HINT;
|
|
1483
|
-
}
|
|
1484
|
-
async function resolveGlob(pattern) {
|
|
1485
|
-
if (!pattern.includes("*")) {
|
|
1486
|
-
return [resolve2(pattern)];
|
|
1487
|
-
}
|
|
1488
|
-
if (pattern.includes("**")) {
|
|
1489
|
-
throw new Error("Recursive glob (**) is not supported. Use a single-level wildcard (e.g., src/*.html) or list files explicitly.");
|
|
1490
|
-
}
|
|
1491
|
-
const lastSep = Math.max(pattern.lastIndexOf("/"), pattern.lastIndexOf("\\"));
|
|
1492
|
-
const dir = lastSep >= 0 ? pattern.slice(0, lastSep) : ".";
|
|
1493
|
-
const glob = lastSep >= 0 ? pattern.slice(lastSep + 1) : pattern;
|
|
1494
|
-
const regex = new RegExp("^" + glob.replace(/\*/g, ".*") + "$");
|
|
1495
|
-
const entries = await readdir(resolve2(dir), { withFileTypes: true });
|
|
1496
|
-
return entries.filter((e) => e.isFile() && regex.test(e.name)).map((e) => resolve2(dir, e.name)).sort();
|
|
1497
|
-
}
|
|
1498
|
-
function mergeLocs(into, from) {
|
|
1499
|
-
if (!from) return false;
|
|
1500
|
-
let truncated = false;
|
|
1501
|
-
for (const loc of from) {
|
|
1502
|
-
if (into.some((l) => l.offset === loc.offset)) continue;
|
|
1503
|
-
if (into.length >= MAX_WARNING_LOCATIONS) {
|
|
1504
|
-
truncated = true;
|
|
1505
|
-
break;
|
|
1506
|
-
}
|
|
1507
|
-
into.push(loc);
|
|
1508
|
-
}
|
|
1509
|
-
into.sort((a, b) => a.offset - b.offset);
|
|
1510
|
-
return truncated;
|
|
1511
|
-
}
|
|
1512
|
-
function flattenToLintIssues(report, skip) {
|
|
1513
|
-
const issues = [];
|
|
1514
|
-
if (!skip.includes("compatibility")) {
|
|
1515
|
-
const seenProps = /* @__PURE__ */ new Map();
|
|
1516
|
-
for (const w of report.compatibility.warnings) {
|
|
1517
|
-
const key = `${w.property}\0${w.severity}`;
|
|
1518
|
-
const existing = seenProps.get(key);
|
|
1519
|
-
if (existing) {
|
|
1520
|
-
existing.clients.push(w.client);
|
|
1521
|
-
existing.loc ??= w.loc;
|
|
1522
|
-
if (mergeLocs(existing.locs, w.locs)) existing.locsTruncated = true;
|
|
1523
|
-
if (w.locsTruncated) existing.locsTruncated = true;
|
|
1524
|
-
} else {
|
|
1525
|
-
seenProps.set(key, {
|
|
1526
|
-
severity: w.severity,
|
|
1527
|
-
clients: [w.client],
|
|
1528
|
-
message: w.message,
|
|
1529
|
-
loc: w.loc,
|
|
1530
|
-
locs: (w.locs ?? []).slice(0, MAX_WARNING_LOCATIONS),
|
|
1531
|
-
...w.locsTruncated ? { locsTruncated: true } : {}
|
|
1532
|
-
});
|
|
1533
|
-
}
|
|
1534
|
-
}
|
|
1535
|
-
for (const [key, val] of seenProps) {
|
|
1536
|
-
const property = key.split("\0")[0];
|
|
1537
|
-
issues.push({
|
|
1538
|
-
severity: val.severity,
|
|
1539
|
-
category: val.clients.slice(0, 3).join(",") + (val.clients.length > 3 ? `+${val.clients.length - 3}` : ""),
|
|
1540
|
-
rule: property,
|
|
1541
|
-
message: val.message,
|
|
1542
|
-
...val.loc ? { loc: val.loc } : {},
|
|
1543
|
-
...val.locs.length ? { locs: val.locs } : {},
|
|
1544
|
-
...val.locsTruncated ? { locsTruncated: true } : {}
|
|
1545
|
-
});
|
|
1546
|
-
}
|
|
1547
|
-
}
|
|
1548
|
-
if (!skip.includes("spam")) {
|
|
1549
|
-
for (const issue of report.spam.issues) {
|
|
1550
|
-
issues.push({
|
|
1551
|
-
severity: issue.severity,
|
|
1552
|
-
category: "spam",
|
|
1553
|
-
rule: issue.rule,
|
|
1554
|
-
message: issue.message,
|
|
1555
|
-
detail: issue.detail,
|
|
1556
|
-
...issue.loc ? { loc: issue.loc } : {}
|
|
1557
|
-
});
|
|
1558
|
-
}
|
|
1559
|
-
}
|
|
1560
|
-
if (!skip.includes("links")) {
|
|
1561
|
-
for (const issue of report.links.issues) {
|
|
1562
|
-
issues.push({
|
|
1563
|
-
severity: issue.severity,
|
|
1564
|
-
category: "links",
|
|
1565
|
-
rule: issue.rule,
|
|
1566
|
-
message: issue.message,
|
|
1567
|
-
...issue.loc ? { loc: issue.loc } : {}
|
|
1568
|
-
});
|
|
1569
|
-
}
|
|
1570
|
-
}
|
|
1571
|
-
if (!skip.includes("accessibility")) {
|
|
1572
|
-
for (const issue of report.accessibility.issues) {
|
|
1573
|
-
issues.push({
|
|
1574
|
-
severity: issue.severity,
|
|
1575
|
-
category: "accessibility",
|
|
1576
|
-
rule: issue.rule,
|
|
1577
|
-
message: issue.message,
|
|
1578
|
-
...issue.loc ? { loc: issue.loc } : {}
|
|
1579
|
-
});
|
|
1580
|
-
}
|
|
1581
|
-
}
|
|
1582
|
-
if (!skip.includes("images")) {
|
|
1583
|
-
for (const issue of report.images.issues) {
|
|
1584
|
-
issues.push({
|
|
1585
|
-
severity: issue.severity,
|
|
1586
|
-
category: "images",
|
|
1587
|
-
rule: issue.rule,
|
|
1588
|
-
message: issue.message,
|
|
1589
|
-
...issue.loc ? { loc: issue.loc } : {}
|
|
1590
|
-
});
|
|
1591
|
-
}
|
|
1592
|
-
}
|
|
1593
|
-
if (!skip.includes("inboxPreview")) {
|
|
1594
|
-
for (const issue of report.inboxPreview.issues) {
|
|
1595
|
-
issues.push({
|
|
1596
|
-
severity: issue.severity,
|
|
1597
|
-
category: "inboxPreview",
|
|
1598
|
-
rule: issue.rule,
|
|
1599
|
-
message: issue.message,
|
|
1600
|
-
...issue.loc ? { loc: issue.loc } : {}
|
|
1601
|
-
});
|
|
1602
|
-
}
|
|
1603
|
-
}
|
|
1604
|
-
if (!skip.includes("size")) {
|
|
1605
|
-
for (const issue of report.size.issues) {
|
|
1606
|
-
issues.push({
|
|
1607
|
-
severity: issue.severity,
|
|
1608
|
-
category: "size",
|
|
1609
|
-
rule: issue.rule,
|
|
1610
|
-
message: issue.message,
|
|
1611
|
-
...issue.loc ? { loc: issue.loc } : {}
|
|
1612
|
-
});
|
|
1613
|
-
}
|
|
1614
|
-
}
|
|
1615
|
-
if (!skip.includes("templateVariables")) {
|
|
1616
|
-
for (const issue of report.templateVariables.issues) {
|
|
1617
|
-
issues.push({
|
|
1618
|
-
severity: issue.severity,
|
|
1619
|
-
category: "templateVars",
|
|
1620
|
-
rule: issue.rule,
|
|
1621
|
-
message: issue.message,
|
|
1622
|
-
...issue.loc ? { loc: issue.loc } : {}
|
|
1623
|
-
});
|
|
1624
|
-
}
|
|
1625
|
-
}
|
|
1626
|
-
if (!skip.includes("overflow")) {
|
|
1627
|
-
for (const issue of report.overflow.issues) {
|
|
1628
|
-
issues.push({
|
|
1629
|
-
severity: issue.severity,
|
|
1630
|
-
category: "overflow",
|
|
1631
|
-
rule: issue.rule,
|
|
1632
|
-
message: issue.message,
|
|
1633
|
-
...issue.loc ? { loc: issue.loc } : {}
|
|
1634
|
-
});
|
|
1635
|
-
}
|
|
1636
|
-
}
|
|
1637
|
-
if (!skip.includes("visual")) {
|
|
1638
|
-
for (const issue of report.visual.issues) {
|
|
1639
|
-
issues.push({
|
|
1640
|
-
severity: issue.severity,
|
|
1641
|
-
category: "visual",
|
|
1642
|
-
rule: issue.rule,
|
|
1643
|
-
message: issue.message,
|
|
1644
|
-
...issue.loc ? { loc: issue.loc } : {}
|
|
1645
|
-
});
|
|
1646
|
-
}
|
|
1647
|
-
}
|
|
1648
|
-
if (!skip.includes("darkContrast")) {
|
|
1649
|
-
for (const issue of report.darkContrast) {
|
|
1650
|
-
issues.push({
|
|
1651
|
-
severity: issue.severity,
|
|
1652
|
-
category: "darkContrast",
|
|
1653
|
-
rule: issue.rule,
|
|
1654
|
-
message: issue.message.replace(/^Dark mode: /, ""),
|
|
1655
|
-
...issue.loc ? { loc: issue.loc } : {}
|
|
1656
|
-
});
|
|
1657
|
-
}
|
|
1658
|
-
}
|
|
1659
|
-
if (!skip.includes("mobileContrast")) {
|
|
1660
|
-
for (const issue of report.mobileContrast) {
|
|
1661
|
-
issues.push({
|
|
1662
|
-
severity: issue.severity,
|
|
1663
|
-
category: "mobileContrast",
|
|
1664
|
-
rule: issue.rule,
|
|
1665
|
-
message: issue.message.replace(/^At mobile width: /, ""),
|
|
1666
|
-
...issue.loc ? { loc: issue.loc } : {}
|
|
1667
|
-
});
|
|
1668
|
-
}
|
|
1669
|
-
}
|
|
1670
|
-
if (!skip.includes("vml")) {
|
|
1671
|
-
for (const issue of report.vml.issues) {
|
|
1672
|
-
issues.push({
|
|
1673
|
-
severity: issue.severity,
|
|
1674
|
-
category: "vml",
|
|
1675
|
-
rule: issue.rule,
|
|
1676
|
-
message: issue.message,
|
|
1677
|
-
detail: issue.detail,
|
|
1678
|
-
...issue.loc ? { loc: issue.loc } : {}
|
|
1679
|
-
});
|
|
1680
|
-
}
|
|
1681
|
-
}
|
|
1682
|
-
if (!skip.includes("styleSurvival")) {
|
|
1683
|
-
for (const issue of report.styleSurvival.issues) {
|
|
1684
|
-
const clients = issue.clients.length ? ` (${issue.clients.join(", ")})` : "";
|
|
1685
|
-
issues.push({
|
|
1686
|
-
severity: issue.severity,
|
|
1687
|
-
category: "styleSurvival",
|
|
1688
|
-
rule: issue.rule,
|
|
1689
|
-
message: `${issue.message}${clients}`,
|
|
1690
|
-
detail: issue.frameworkNote ?? issue.detail,
|
|
1691
|
-
...issue.loc ? { loc: issue.loc } : {}
|
|
1692
|
-
});
|
|
1693
|
-
}
|
|
1694
|
-
}
|
|
1695
|
-
if (!skip.includes("targeting")) {
|
|
1696
|
-
for (const issue of report.targeting.warnings) {
|
|
1697
|
-
issues.push({
|
|
1698
|
-
severity: issue.severity,
|
|
1699
|
-
category: "targeting",
|
|
1700
|
-
rule: issue.property,
|
|
1701
|
-
message: issue.message,
|
|
1702
|
-
detail: issue.suggestion,
|
|
1703
|
-
...issue.loc ? { loc: issue.loc } : {},
|
|
1704
|
-
...issue.locs?.length ? { locs: issue.locs } : {},
|
|
1705
|
-
...issue.locsTruncated ? { locsTruncated: true } : {}
|
|
1706
|
-
});
|
|
1707
|
-
}
|
|
1708
|
-
}
|
|
1709
|
-
if (!skip.includes("design")) {
|
|
1710
|
-
for (const issue of report.design.issues) {
|
|
1711
|
-
issues.push({
|
|
1712
|
-
severity: issue.severity,
|
|
1713
|
-
category: "design",
|
|
1714
|
-
rule: issue.rule,
|
|
1715
|
-
message: issue.message,
|
|
1716
|
-
detail: issue.detail
|
|
1717
|
-
});
|
|
1718
|
-
}
|
|
1719
|
-
}
|
|
1720
|
-
const order = { error: 0, warning: 1, info: 2 };
|
|
1721
|
-
issues.sort((a, b) => order[a.severity] - order[b.severity]);
|
|
1722
|
-
return issues;
|
|
1723
|
-
}
|
|
1724
|
-
|
|
1725
|
-
// src/commands/inbox.ts
|
|
1726
|
-
import { defineCommand as defineCommand8 } from "citty";
|
|
1727
|
-
import pc6 from "picocolors";
|
|
1728
1141
|
var API_URL = () => process.env.EMAILENS_API_URL ?? "https://app.emailens.dev";
|
|
1729
1142
|
function parseSince(value, now = Date.now()) {
|
|
1730
1143
|
if (!value) return now - 2 * 6e4;
|
|
@@ -1768,7 +1181,7 @@ async function waitForEmail(o, fetchImpl = fetch) {
|
|
|
1768
1181
|
}
|
|
1769
1182
|
return { code: 2, error: `No matching email arrived within ${o.timeout}s.`, failures: [] };
|
|
1770
1183
|
}
|
|
1771
|
-
var wait =
|
|
1184
|
+
var wait = defineCommand7({
|
|
1772
1185
|
meta: {
|
|
1773
1186
|
name: "wait",
|
|
1774
1187
|
description: "Wait for an email your app sent to your test inbox; fail if it is no longer the email you checked, or changed since it last arrived"
|
|
@@ -1794,18 +1207,18 @@ var wait = defineCommand8({
|
|
|
1794
1207
|
const apiKey = args["api-key"] ?? process.env.EMAILENS_API_KEY;
|
|
1795
1208
|
const failOn = String(args["fail-on"]);
|
|
1796
1209
|
if (!apiKey) {
|
|
1797
|
-
console.error(
|
|
1210
|
+
console.error(pc5.red(" Set EMAILENS_API_KEY (or pass --api-key). Keys are at app.emailens.dev/dashboard/api."));
|
|
1798
1211
|
process.exit(2);
|
|
1799
1212
|
}
|
|
1800
1213
|
if (!["all", "check", "drift", "none"].includes(failOn)) {
|
|
1801
|
-
console.error(
|
|
1214
|
+
console.error(pc5.red(` --fail-on: all, check, drift or none, not ${failOn}.`));
|
|
1802
1215
|
process.exit(2);
|
|
1803
1216
|
}
|
|
1804
1217
|
let since;
|
|
1805
1218
|
try {
|
|
1806
1219
|
since = parseSince(args.since);
|
|
1807
1220
|
} catch (e) {
|
|
1808
|
-
console.error(
|
|
1221
|
+
console.error(pc5.red(` ${e.message}`));
|
|
1809
1222
|
process.exit(2);
|
|
1810
1223
|
}
|
|
1811
1224
|
const result = await waitForEmail({
|
|
@@ -1842,30 +1255,30 @@ var wait = defineCommand8({
|
|
|
1842
1255
|
}
|
|
1843
1256
|
console.log();
|
|
1844
1257
|
if (result.error) {
|
|
1845
|
-
console.log(` ${
|
|
1258
|
+
console.log(` ${pc5.red("\u2717")} ${result.error}`);
|
|
1846
1259
|
console.log();
|
|
1847
1260
|
process.exitCode = result.code;
|
|
1848
1261
|
return;
|
|
1849
1262
|
}
|
|
1850
1263
|
const m = result.response?.message;
|
|
1851
1264
|
const v = result.response?.verdict;
|
|
1852
|
-
console.log(` ${
|
|
1265
|
+
console.log(` ${pc5.bold(m?.subject ?? "")} ${pc5.dim(`from ${m?.sender ?? ""}`)}`);
|
|
1853
1266
|
console.log();
|
|
1854
|
-
console.log(` ${
|
|
1855
|
-
console.log(` ${
|
|
1267
|
+
console.log(` ${pc5.dim("Your check")} ${v?.checked ?? ""}`);
|
|
1268
|
+
console.log(` ${pc5.dim("Since last time")} ${v?.sinceLast ?? ""}`);
|
|
1856
1269
|
if (result.failures.length) {
|
|
1857
1270
|
console.log();
|
|
1858
|
-
for (const f of result.failures) console.log(` ${
|
|
1271
|
+
for (const f of result.failures) console.log(` ${pc5.red("\u2717")} ${f}`);
|
|
1859
1272
|
}
|
|
1860
1273
|
console.log();
|
|
1861
1274
|
console.log(
|
|
1862
|
-
result.code === 0 ? ` ${
|
|
1275
|
+
result.code === 0 ? ` ${pc5.green("\u2713 Pass")}` : ` ${pc5.red(`\u2717 Fail: ${result.failures.length} change${result.failures.length === 1 ? "" : "s"}`)}`
|
|
1863
1276
|
);
|
|
1864
1277
|
console.log();
|
|
1865
1278
|
process.exitCode = result.code;
|
|
1866
1279
|
}
|
|
1867
1280
|
});
|
|
1868
|
-
var inbox_default =
|
|
1281
|
+
var inbox_default = defineCommand7({
|
|
1869
1282
|
meta: {
|
|
1870
1283
|
name: "inbox",
|
|
1871
1284
|
description: "Your Emailens test inbox, from CI"
|
|
@@ -1874,7 +1287,7 @@ var inbox_default = defineCommand8({
|
|
|
1874
1287
|
});
|
|
1875
1288
|
|
|
1876
1289
|
// src/index.ts
|
|
1877
|
-
var main =
|
|
1290
|
+
var main = defineCommand8({
|
|
1878
1291
|
meta,
|
|
1879
1292
|
subCommands: {
|
|
1880
1293
|
analyze: analyze_default,
|