@decocms/parity 0.17.9 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +1 -0
- package/CHANGELOG.md +12 -0
- package/dist/cli.js +2029 -260
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -7549,14 +7549,14 @@ class Tokenizer2 {
|
|
|
7549
7549
|
}
|
|
7550
7550
|
}
|
|
7551
7551
|
_emitEOFToken() {
|
|
7552
|
-
const
|
|
7553
|
-
if (
|
|
7554
|
-
|
|
7555
|
-
|
|
7556
|
-
|
|
7557
|
-
}
|
|
7558
|
-
this._emitCurrentCharacterToken(
|
|
7559
|
-
this.handler.onEof({ type: TokenType.EOF, location });
|
|
7552
|
+
const location2 = this.getCurrentLocation(0);
|
|
7553
|
+
if (location2) {
|
|
7554
|
+
location2.endLine = location2.startLine;
|
|
7555
|
+
location2.endCol = location2.startCol;
|
|
7556
|
+
location2.endOffset = location2.startOffset;
|
|
7557
|
+
}
|
|
7558
|
+
this._emitCurrentCharacterToken(location2);
|
|
7559
|
+
this.handler.onEof({ type: TokenType.EOF, location: location2 });
|
|
7560
7560
|
this.active = false;
|
|
7561
7561
|
}
|
|
7562
7562
|
_appendCharToCurrentCharacterToken(type, ch) {
|
|
@@ -10278,8 +10278,8 @@ var init_default = __esm(() => {
|
|
|
10278
10278
|
isElementNode(node2) {
|
|
10279
10279
|
return Object.prototype.hasOwnProperty.call(node2, "tagName");
|
|
10280
10280
|
},
|
|
10281
|
-
setNodeSourceCodeLocation(node2,
|
|
10282
|
-
node2.sourceCodeLocation =
|
|
10281
|
+
setNodeSourceCodeLocation(node2, location2) {
|
|
10282
|
+
node2.sourceCodeLocation = location2;
|
|
10283
10283
|
},
|
|
10284
10284
|
getNodeSourceCodeLocation(node2) {
|
|
10285
10285
|
return node2.sourceCodeLocation;
|
|
@@ -10796,11 +10796,11 @@ class Parser2 {
|
|
|
10796
10796
|
}
|
|
10797
10797
|
}
|
|
10798
10798
|
}
|
|
10799
|
-
_attachElementToTree(element,
|
|
10799
|
+
_attachElementToTree(element, location2) {
|
|
10800
10800
|
if (this.options.sourceCodeLocationInfo) {
|
|
10801
|
-
const loc =
|
|
10802
|
-
...
|
|
10803
|
-
startTag:
|
|
10801
|
+
const loc = location2 && {
|
|
10802
|
+
...location2,
|
|
10803
|
+
startTag: location2
|
|
10804
10804
|
};
|
|
10805
10805
|
this.treeAdapter.setNodeSourceCodeLocation(element, loc);
|
|
10806
10806
|
}
|
|
@@ -11084,11 +11084,11 @@ class Parser2 {
|
|
|
11084
11084
|
return { parent: this.openElements.items[0], beforeElement: null };
|
|
11085
11085
|
}
|
|
11086
11086
|
_fosterParentElement(element) {
|
|
11087
|
-
const
|
|
11088
|
-
if (
|
|
11089
|
-
this.treeAdapter.insertBefore(
|
|
11087
|
+
const location2 = this._findFosterParentingLocation();
|
|
11088
|
+
if (location2.beforeElement) {
|
|
11089
|
+
this.treeAdapter.insertBefore(location2.parent, element, location2.beforeElement);
|
|
11090
11090
|
} else {
|
|
11091
|
-
this.treeAdapter.appendChild(
|
|
11091
|
+
this.treeAdapter.appendChild(location2.parent, element);
|
|
11092
11092
|
}
|
|
11093
11093
|
}
|
|
11094
11094
|
_isSpecialElement(element, id) {
|
|
@@ -13940,12 +13940,12 @@ var init_dist2 = __esm(() => {
|
|
|
13940
13940
|
isDocumentTypeNode(node2) {
|
|
13941
13941
|
return isDirective(node2) && node2.name === "!doctype";
|
|
13942
13942
|
},
|
|
13943
|
-
setNodeSourceCodeLocation(node2,
|
|
13944
|
-
if (
|
|
13945
|
-
node2.startIndex =
|
|
13946
|
-
node2.endIndex =
|
|
13943
|
+
setNodeSourceCodeLocation(node2, location2) {
|
|
13944
|
+
if (location2) {
|
|
13945
|
+
node2.startIndex = location2.startOffset;
|
|
13946
|
+
node2.endIndex = location2.endOffset;
|
|
13947
13947
|
}
|
|
13948
|
-
node2.sourceCodeLocation =
|
|
13948
|
+
node2.sourceCodeLocation = location2;
|
|
13949
13949
|
},
|
|
13950
13950
|
getNodeSourceCodeLocation(node2) {
|
|
13951
13951
|
return node2.sourceCodeLocation;
|
|
@@ -18479,17 +18479,17 @@ var require_util2 = __commonJS((exports, module) => {
|
|
|
18479
18479
|
if (!redirectStatusSet.has(response.status)) {
|
|
18480
18480
|
return null;
|
|
18481
18481
|
}
|
|
18482
|
-
let
|
|
18483
|
-
if (
|
|
18484
|
-
if (!isValidEncodedURL(
|
|
18485
|
-
|
|
18482
|
+
let location2 = response.headersList.get("location", true);
|
|
18483
|
+
if (location2 !== null && isValidHeaderValue(location2)) {
|
|
18484
|
+
if (!isValidEncodedURL(location2)) {
|
|
18485
|
+
location2 = normalizeBinaryStringToUtf8(location2);
|
|
18486
18486
|
}
|
|
18487
|
-
|
|
18487
|
+
location2 = new URL(location2, responseURL(response));
|
|
18488
18488
|
}
|
|
18489
|
-
if (
|
|
18490
|
-
|
|
18489
|
+
if (location2 && !location2.hash) {
|
|
18490
|
+
location2.hash = requestFragment;
|
|
18491
18491
|
}
|
|
18492
|
-
return
|
|
18492
|
+
return location2;
|
|
18493
18493
|
}
|
|
18494
18494
|
function isValidEncodedURL(url) {
|
|
18495
18495
|
for (let i = 0;i < url.length; ++i) {
|
|
@@ -32547,9 +32547,9 @@ var require_fetch = __commonJS((exports, module) => {
|
|
|
32547
32547
|
headersList.append(nameStr, value.toString("latin1"), true);
|
|
32548
32548
|
}
|
|
32549
32549
|
}
|
|
32550
|
-
const
|
|
32550
|
+
const location2 = headersList.get("location", true);
|
|
32551
32551
|
this.body = new Readable({ read: resume });
|
|
32552
|
-
const willFollow =
|
|
32552
|
+
const willFollow = location2 && request.redirect === "follow" && redirectStatusSet.has(status);
|
|
32553
32553
|
const decoders = [];
|
|
32554
32554
|
if (request.method !== "HEAD" && request.method !== "CONNECT" && !nullBodyStatus.includes(status) && !willFollow) {
|
|
32555
32555
|
const contentEncoding = headersList.get("content-encoding", true);
|
|
@@ -44427,6 +44427,34 @@ function withPage(url, n) {
|
|
|
44427
44427
|
return `${url}${sep}page=${n}`;
|
|
44428
44428
|
}
|
|
44429
44429
|
}
|
|
44430
|
+
function pickPlpFromHomeHtml(html3, homeUrl) {
|
|
44431
|
+
const candidates = new Set;
|
|
44432
|
+
const re = /href="([^"]+)"/gi;
|
|
44433
|
+
for (;; ) {
|
|
44434
|
+
const m = re.exec(html3);
|
|
44435
|
+
if (!m)
|
|
44436
|
+
break;
|
|
44437
|
+
const href = m[1];
|
|
44438
|
+
if (!href)
|
|
44439
|
+
continue;
|
|
44440
|
+
if (/^https?:\/\//.test(href) || href.startsWith("#") || href === "/" || /\/(p|cart|carrinho|checkout|account|conta|login|wishlist|favoritos)(\/|$|\?)/i.test(href) || /\.(jpg|png|webp|css|js|svg|ico|woff)/i.test(href)) {
|
|
44441
|
+
continue;
|
|
44442
|
+
}
|
|
44443
|
+
const segments = href.split("?")[0].split("/").filter(Boolean);
|
|
44444
|
+
if (segments.length === 0 || segments.length > 3)
|
|
44445
|
+
continue;
|
|
44446
|
+
candidates.add(href.split("?")[0]);
|
|
44447
|
+
}
|
|
44448
|
+
const sorted = Array.from(candidates).sort((a, b) => a.length - b.length);
|
|
44449
|
+
const pick = sorted[0];
|
|
44450
|
+
if (!pick)
|
|
44451
|
+
return null;
|
|
44452
|
+
try {
|
|
44453
|
+
return new URL(pick, new URL(homeUrl)).toString();
|
|
44454
|
+
} catch {
|
|
44455
|
+
return null;
|
|
44456
|
+
}
|
|
44457
|
+
}
|
|
44430
44458
|
async function discoverPlpFromHome(homeUrl) {
|
|
44431
44459
|
try {
|
|
44432
44460
|
const res = await fetch(homeUrl, {
|
|
@@ -44437,30 +44465,7 @@ async function discoverPlpFromHome(homeUrl) {
|
|
|
44437
44465
|
});
|
|
44438
44466
|
if (!res.ok)
|
|
44439
44467
|
return null;
|
|
44440
|
-
|
|
44441
|
-
const candidates = new Set;
|
|
44442
|
-
const re = /href="([^"]+)"/gi;
|
|
44443
|
-
for (;; ) {
|
|
44444
|
-
const m = re.exec(html3);
|
|
44445
|
-
if (!m)
|
|
44446
|
-
break;
|
|
44447
|
-
const href = m[1];
|
|
44448
|
-
if (!href)
|
|
44449
|
-
continue;
|
|
44450
|
-
if (/^https?:\/\//.test(href) || href.startsWith("#") || href === "/" || /\/(p|cart|carrinho|checkout|account|conta|login|wishlist|favoritos)(\/|$|\?)/i.test(href) || /\.(jpg|png|webp|css|js|svg|ico|woff)/i.test(href)) {
|
|
44451
|
-
continue;
|
|
44452
|
-
}
|
|
44453
|
-
const segments = href.split("?")[0].split("/").filter(Boolean);
|
|
44454
|
-
if (segments.length === 0 || segments.length > 3)
|
|
44455
|
-
continue;
|
|
44456
|
-
candidates.add(href.split("?")[0]);
|
|
44457
|
-
}
|
|
44458
|
-
const sorted = Array.from(candidates).sort((a, b) => a.length - b.length);
|
|
44459
|
-
const home = new URL(homeUrl);
|
|
44460
|
-
const pick = sorted[0];
|
|
44461
|
-
if (!pick)
|
|
44462
|
-
return null;
|
|
44463
|
-
return new URL(pick, home).toString();
|
|
44468
|
+
return pickPlpFromHomeHtml(await res.text(), homeUrl);
|
|
44464
44469
|
} catch {
|
|
44465
44470
|
return null;
|
|
44466
44471
|
}
|
|
@@ -55271,6 +55276,9 @@ function detectFromHeaders(headers) {
|
|
|
55271
55276
|
}
|
|
55272
55277
|
function detectFromHtml(html3) {
|
|
55273
55278
|
try {
|
|
55279
|
+
if (html3.includes("demandware.static") || html3.includes("/on/demandware.store/")) {
|
|
55280
|
+
return "salesforce-commerce";
|
|
55281
|
+
}
|
|
55274
55282
|
const $2 = load(html3);
|
|
55275
55283
|
const fsClasses = $2('[class*="fs-"], [data-fs-]').length;
|
|
55276
55284
|
if (fsClasses > 5)
|
|
@@ -55295,6 +55303,8 @@ function detectFromHtml(html3) {
|
|
|
55295
55303
|
return "vtex";
|
|
55296
55304
|
if (generator.includes("shopify"))
|
|
55297
55305
|
return "shopify";
|
|
55306
|
+
if (generator.includes("demandware") || generator.includes("salesforce"))
|
|
55307
|
+
return "salesforce-commerce";
|
|
55298
55308
|
if (generator.includes("deco"))
|
|
55299
55309
|
return "deco";
|
|
55300
55310
|
} catch {}
|
|
@@ -56193,9 +56203,14 @@ var SECTION_STYLE_KEYS = [
|
|
|
56193
56203
|
"border",
|
|
56194
56204
|
"font-size",
|
|
56195
56205
|
"font-weight",
|
|
56206
|
+
"line-height",
|
|
56207
|
+
"letter-spacing",
|
|
56208
|
+
"text-transform",
|
|
56196
56209
|
"color",
|
|
56197
56210
|
"background-color",
|
|
56198
56211
|
"background-image",
|
|
56212
|
+
"border-radius",
|
|
56213
|
+
"box-shadow",
|
|
56199
56214
|
"flex-direction",
|
|
56200
56215
|
"justify-content",
|
|
56201
56216
|
"align-items",
|
|
@@ -58401,74 +58416,42 @@ function listCommand(output) {
|
|
|
58401
58416
|
return 0;
|
|
58402
58417
|
}
|
|
58403
58418
|
|
|
58404
|
-
// src/commands/
|
|
58405
|
-
import { existsSync as
|
|
58406
|
-
import {
|
|
58407
|
-
import
|
|
58408
|
-
|
|
58409
|
-
// src/commands/run.ts
|
|
58410
|
-
import { existsSync as existsSync13, readFileSync as readFileSync14, unlinkSync as unlinkSync3 } from "node:fs";
|
|
58411
|
-
import { join as join18 } from "node:path";
|
|
58412
|
-
import chalk17 from "chalk";
|
|
58413
|
-
import ora6 from "ora";
|
|
58419
|
+
// src/commands/migrate.ts
|
|
58420
|
+
import { existsSync as existsSync11, mkdirSync as mkdirSync14, readFileSync as readFileSync13, writeFileSync as writeFileSync19 } from "node:fs";
|
|
58421
|
+
import { resolve as resolve3 } from "node:path";
|
|
58422
|
+
import chalk16 from "chalk";
|
|
58414
58423
|
|
|
58415
|
-
// src/
|
|
58416
|
-
|
|
58417
|
-
|
|
58418
|
-
|
|
58419
|
-
|
|
58420
|
-
|
|
58421
|
-
|
|
58422
|
-
|
|
58423
|
-
|
|
58424
|
-
|
|
58425
|
-
|
|
58426
|
-
|
|
58427
|
-
|
|
58428
|
-
|
|
58429
|
-
|
|
58430
|
-
return
|
|
58431
|
-
}
|
|
58432
|
-
|
|
58433
|
-
if (!trimmed)
|
|
58434
|
-
return ALL_MODULE_NAMES2;
|
|
58435
|
-
const uncheckIdx = new Set(trimmed.split(",").map((s) => Number.parseInt(s.trim(), 10)).filter((n) => Number.isInteger(n) && n >= 1 && n <= ALL_MODULE_NAMES2.length));
|
|
58436
|
-
const selected = ALL_MODULE_NAMES2.filter((_name, i) => !uncheckIdx.has(i + 1));
|
|
58437
|
-
if (selected.length === 0) {
|
|
58438
|
-
console.log(" (everything unchecked — running all modules instead)");
|
|
58439
|
-
return ALL_MODULE_NAMES2;
|
|
58424
|
+
// src/migrate/pdp-discovery.ts
|
|
58425
|
+
var PLATFORM_PATTERNS = {
|
|
58426
|
+
"salesforce-commerce": [
|
|
58427
|
+
/href="([^"]*-[A-Za-z]?\d{3,}\.html)"/gi,
|
|
58428
|
+
/href="([^"]*Product-(?:Show|Detail)[^"]*[?&]pid=[^"&]+[^"]*)"/gi
|
|
58429
|
+
],
|
|
58430
|
+
shopify: [/href="([^"]*\/products\/[^"]+)"/gi],
|
|
58431
|
+
vtex: [/href="([^"]*\/p(?:\?[^"]*|\/[^"]+|))"/gi],
|
|
58432
|
+
"vtex-fs": [/href="([^"]*\/p(?:\?[^"]*|\/[^"]+|))"/gi]
|
|
58433
|
+
};
|
|
58434
|
+
var ACTION_URL = /(Wishlist|Cart|MiniCart|Login|Account|Address|Order|Compare)-|add-?to-?/i;
|
|
58435
|
+
function acceptProductUrl(href, baseUrl) {
|
|
58436
|
+
if (ACTION_URL.test(href))
|
|
58437
|
+
return null;
|
|
58438
|
+
try {
|
|
58439
|
+
return new URL(href, baseUrl).toString();
|
|
58440
|
+
} catch {
|
|
58441
|
+
return null;
|
|
58440
58442
|
}
|
|
58441
|
-
console.log(` running: ${selected.join(", ")}`);
|
|
58442
|
-
return selected;
|
|
58443
|
-
}
|
|
58444
|
-
function readLine(prompt) {
|
|
58445
|
-
return new Promise((resolveLine) => {
|
|
58446
|
-
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
58447
|
-
rl.question(prompt, (ans) => {
|
|
58448
|
-
rl.close();
|
|
58449
|
-
resolveLine(ans);
|
|
58450
|
-
});
|
|
58451
|
-
rl.on("SIGINT", () => {
|
|
58452
|
-
rl.close();
|
|
58453
|
-
resolveLine(null);
|
|
58454
|
-
});
|
|
58455
|
-
});
|
|
58456
58443
|
}
|
|
58457
|
-
|
|
58458
|
-
|
|
58459
|
-
|
|
58460
|
-
|
|
58461
|
-
|
|
58462
|
-
|
|
58463
|
-
|
|
58464
|
-
|
|
58465
|
-
|
|
58466
|
-
|
|
58467
|
-
|
|
58468
|
-
return false;
|
|
58469
|
-
if (isLlmAvailable())
|
|
58470
|
-
return false;
|
|
58471
|
-
return true;
|
|
58444
|
+
function firstProductHref(html3, baseUrl, platform) {
|
|
58445
|
+
const patterns = platform ? PLATFORM_PATTERNS[platform] ?? [] : [];
|
|
58446
|
+
for (const re of patterns) {
|
|
58447
|
+
re.lastIndex = 0;
|
|
58448
|
+
for (let m = re.exec(html3);m; m = re.exec(html3)) {
|
|
58449
|
+
const url = m[1] ? acceptProductUrl(m[1], baseUrl) : null;
|
|
58450
|
+
if (url)
|
|
58451
|
+
return url;
|
|
58452
|
+
}
|
|
58453
|
+
}
|
|
58454
|
+
return firstProductHrefFromPlpHtml(html3, baseUrl);
|
|
58472
58455
|
}
|
|
58473
58456
|
|
|
58474
58457
|
// src/engine/sitemap-discover.ts
|
|
@@ -58550,6 +58533,1777 @@ async function discoverPagesFromSitemap(prodUrl, opts = {}) {
|
|
|
58550
58533
|
return result;
|
|
58551
58534
|
}
|
|
58552
58535
|
|
|
58536
|
+
// src/migrate/assets.ts
|
|
58537
|
+
import { mkdirSync as mkdirSync12, writeFileSync as writeFileSync16 } from "node:fs";
|
|
58538
|
+
import { join as join17 } from "node:path";
|
|
58539
|
+
function aggregateIcons(icons) {
|
|
58540
|
+
const byKey = new Map;
|
|
58541
|
+
for (const icon of icons) {
|
|
58542
|
+
const id = icon.id.trim();
|
|
58543
|
+
if (!id)
|
|
58544
|
+
continue;
|
|
58545
|
+
const key = `${icon.kind} ${id}`;
|
|
58546
|
+
const existing = byKey.get(key);
|
|
58547
|
+
if (existing)
|
|
58548
|
+
existing.count += icon.count;
|
|
58549
|
+
else
|
|
58550
|
+
byKey.set(key, { ...icon, id });
|
|
58551
|
+
}
|
|
58552
|
+
return [...byKey.values()].sort((a, b) => b.count - a.count);
|
|
58553
|
+
}
|
|
58554
|
+
async function collectSiteAssets(page) {
|
|
58555
|
+
const raw = await page.evaluate(() => {
|
|
58556
|
+
const abs = (href) => {
|
|
58557
|
+
if (!href)
|
|
58558
|
+
return null;
|
|
58559
|
+
try {
|
|
58560
|
+
return new URL(href, location.href).href;
|
|
58561
|
+
} catch {
|
|
58562
|
+
return null;
|
|
58563
|
+
}
|
|
58564
|
+
};
|
|
58565
|
+
const linkHref = (sel) => abs(document.querySelector(sel)?.getAttribute("href"));
|
|
58566
|
+
const favicon = linkHref("link[rel='icon']") || linkHref("link[rel='shortcut icon']") || abs("/favicon.ico");
|
|
58567
|
+
const appleTouchIcon = linkHref("link[rel='apple-touch-icon']");
|
|
58568
|
+
const manifest = linkHref("link[rel='manifest']");
|
|
58569
|
+
const ogImage = abs(document.querySelector("meta[property='og:image']")?.getAttribute("content"));
|
|
58570
|
+
const fonts = Array.from(document.querySelectorAll("link[rel='preload'][as='font']")).map((l) => abs(l.getAttribute("href"))).filter((u) => Boolean(u));
|
|
58571
|
+
const header = document.querySelector("header, [role='banner']") || document.body;
|
|
58572
|
+
let logo = null;
|
|
58573
|
+
if (header) {
|
|
58574
|
+
const hinted = Array.from(header.querySelectorAll("img, svg")).find((el2) => {
|
|
58575
|
+
const bag = `${el2.getAttribute("alt") ?? ""} ${el2.getAttribute("class") ?? ""} ${el2.getAttribute("aria-label") ?? ""} ${el2.closest("a")?.getAttribute("href") ?? ""}`.toLowerCase();
|
|
58576
|
+
return bag.includes("logo") || bag.includes("brand");
|
|
58577
|
+
});
|
|
58578
|
+
const el = hinted ?? header.querySelector("a[href='/'] img, a[href='/'] svg") ?? header.querySelector("img, svg");
|
|
58579
|
+
if (el) {
|
|
58580
|
+
if (el.tagName.toLowerCase() === "img") {
|
|
58581
|
+
const url = abs(el.getAttribute("src"));
|
|
58582
|
+
if (url)
|
|
58583
|
+
logo = { type: "img", url };
|
|
58584
|
+
} else {
|
|
58585
|
+
logo = { type: "svg", markup: el.outerHTML.slice(0, 20000) };
|
|
58586
|
+
}
|
|
58587
|
+
}
|
|
58588
|
+
}
|
|
58589
|
+
const icons = [];
|
|
58590
|
+
for (const use of Array.from(document.querySelectorAll("use"))) {
|
|
58591
|
+
const href = use.getAttribute("href") || use.getAttribute("xlink:href") || "";
|
|
58592
|
+
const id = href.startsWith("#") ? href.slice(1) : href.split("#")[1] || "";
|
|
58593
|
+
if (id)
|
|
58594
|
+
icons.push({ kind: "svg-use", id, count: 1 });
|
|
58595
|
+
}
|
|
58596
|
+
for (const svg of Array.from(document.querySelectorAll("svg"))) {
|
|
58597
|
+
if (svg.querySelector("use"))
|
|
58598
|
+
continue;
|
|
58599
|
+
const label = svg.getAttribute("aria-label") || svg.querySelector("title")?.textContent?.trim() || svg.getAttribute("class") || "unnamed";
|
|
58600
|
+
icons.push({ kind: "inline-svg", id: label.slice(0, 40), count: 1 });
|
|
58601
|
+
}
|
|
58602
|
+
const iconClassRe = /\b(icon(?![a-z])|fa-[a-z0-9-]+|material-icons|ph-[a-z0-9-]+|glyphicon-[a-z0-9-]+)\b/i;
|
|
58603
|
+
for (const el of Array.from(document.querySelectorAll("i, span"))) {
|
|
58604
|
+
const cls = el.getAttribute("class") ?? "";
|
|
58605
|
+
const m = cls.match(iconClassRe);
|
|
58606
|
+
if (m?.[1])
|
|
58607
|
+
icons.push({ kind: "icon-font", id: m[1], count: 1 });
|
|
58608
|
+
}
|
|
58609
|
+
return { favicon, appleTouchIcon, manifest, ogImage, fonts, logo, icons };
|
|
58610
|
+
});
|
|
58611
|
+
return { ...raw, icons: aggregateIcons(raw.icons) };
|
|
58612
|
+
}
|
|
58613
|
+
async function browserFetchBytes(page, url) {
|
|
58614
|
+
try {
|
|
58615
|
+
const r = await page.evaluate(async (u) => {
|
|
58616
|
+
const res = await fetch(u);
|
|
58617
|
+
if (!res.ok)
|
|
58618
|
+
return null;
|
|
58619
|
+
const bytes = new Uint8Array(await res.arrayBuffer());
|
|
58620
|
+
let binary = "";
|
|
58621
|
+
for (let i = 0;i < bytes.length; i++)
|
|
58622
|
+
binary += String.fromCharCode(bytes[i]);
|
|
58623
|
+
return { b64: btoa(binary), ct: res.headers.get("content-type") };
|
|
58624
|
+
}, url);
|
|
58625
|
+
if (!r)
|
|
58626
|
+
return null;
|
|
58627
|
+
return { buf: Buffer.from(r.b64, "base64"), contentType: r.ct };
|
|
58628
|
+
} catch {
|
|
58629
|
+
return null;
|
|
58630
|
+
}
|
|
58631
|
+
}
|
|
58632
|
+
async function nodeFetchBytes(url) {
|
|
58633
|
+
try {
|
|
58634
|
+
const res = await fetch(url, { signal: AbortSignal.timeout(15000) });
|
|
58635
|
+
if (!res.ok)
|
|
58636
|
+
return null;
|
|
58637
|
+
return { buf: Buffer.from(await res.arrayBuffer()), contentType: res.headers.get("content-type") };
|
|
58638
|
+
} catch {
|
|
58639
|
+
return null;
|
|
58640
|
+
}
|
|
58641
|
+
}
|
|
58642
|
+
async function downloadTo(url, dir, name, fetchBytes) {
|
|
58643
|
+
const got = await fetchBytes(url);
|
|
58644
|
+
if (!got)
|
|
58645
|
+
return null;
|
|
58646
|
+
const ext = extFromUrlOrType(url, got.contentType);
|
|
58647
|
+
const file = `${name}${ext}`;
|
|
58648
|
+
writeFileSync16(join17(dir, file), got.buf);
|
|
58649
|
+
return `assets/${file}`;
|
|
58650
|
+
}
|
|
58651
|
+
function extFromUrlOrType(url, contentType) {
|
|
58652
|
+
try {
|
|
58653
|
+
const m = new URL(url).pathname.match(/\.[a-z0-9]{2,5}$/i);
|
|
58654
|
+
if (m)
|
|
58655
|
+
return m[0];
|
|
58656
|
+
} catch {}
|
|
58657
|
+
if (contentType?.includes("svg"))
|
|
58658
|
+
return ".svg";
|
|
58659
|
+
if (contentType?.includes("png"))
|
|
58660
|
+
return ".png";
|
|
58661
|
+
if (contentType?.includes("jpeg"))
|
|
58662
|
+
return ".jpg";
|
|
58663
|
+
if (contentType?.includes("webp"))
|
|
58664
|
+
return ".webp";
|
|
58665
|
+
if (contentType?.includes("json"))
|
|
58666
|
+
return ".json";
|
|
58667
|
+
return "";
|
|
58668
|
+
}
|
|
58669
|
+
async function downloadSiteAssets(raw, runDir, fetchBytes) {
|
|
58670
|
+
const dir = join17(runDir, "assets");
|
|
58671
|
+
mkdirSync12(dir, { recursive: true });
|
|
58672
|
+
let logo = null;
|
|
58673
|
+
let logoSource = null;
|
|
58674
|
+
if (raw.logo?.type === "img") {
|
|
58675
|
+
logoSource = raw.logo.url;
|
|
58676
|
+
logo = await downloadTo(raw.logo.url, dir, "logo", fetchBytes);
|
|
58677
|
+
} else if (raw.logo?.type === "svg") {
|
|
58678
|
+
writeFileSync16(join17(dir, "logo.svg"), raw.logo.markup, "utf8");
|
|
58679
|
+
logo = "assets/logo.svg";
|
|
58680
|
+
logoSource = "inline-svg";
|
|
58681
|
+
}
|
|
58682
|
+
const [favicon, appleTouchIcon, ogImage] = await Promise.all([
|
|
58683
|
+
raw.favicon ? downloadTo(raw.favicon, dir, "favicon", fetchBytes) : Promise.resolve(null),
|
|
58684
|
+
raw.appleTouchIcon ? downloadTo(raw.appleTouchIcon, dir, "apple-touch-icon", fetchBytes) : Promise.resolve(null),
|
|
58685
|
+
raw.ogImage ? downloadTo(raw.ogImage, dir, "og-image", fetchBytes) : Promise.resolve(null)
|
|
58686
|
+
]);
|
|
58687
|
+
return {
|
|
58688
|
+
logo,
|
|
58689
|
+
logoSource,
|
|
58690
|
+
favicon,
|
|
58691
|
+
faviconSource: raw.favicon,
|
|
58692
|
+
appleTouchIcon,
|
|
58693
|
+
ogImage,
|
|
58694
|
+
manifest: raw.manifest,
|
|
58695
|
+
fonts: raw.fonts,
|
|
58696
|
+
icons: raw.icons
|
|
58697
|
+
};
|
|
58698
|
+
}
|
|
58699
|
+
|
|
58700
|
+
// src/migrate/browser-fetch.ts
|
|
58701
|
+
async function browserFetchText(page, url) {
|
|
58702
|
+
try {
|
|
58703
|
+
const text3 = await page.evaluate(async (u) => {
|
|
58704
|
+
const res = await fetch(u);
|
|
58705
|
+
if (!res.ok)
|
|
58706
|
+
return null;
|
|
58707
|
+
return res.text();
|
|
58708
|
+
}, url);
|
|
58709
|
+
if (text3 != null)
|
|
58710
|
+
return text3;
|
|
58711
|
+
} catch {}
|
|
58712
|
+
return nodeFetchText(url);
|
|
58713
|
+
}
|
|
58714
|
+
async function nodeFetchText(url) {
|
|
58715
|
+
try {
|
|
58716
|
+
const res = await fetch(url, {
|
|
58717
|
+
headers: {
|
|
58718
|
+
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1"
|
|
58719
|
+
},
|
|
58720
|
+
signal: AbortSignal.timeout(15000)
|
|
58721
|
+
});
|
|
58722
|
+
if (!res.ok)
|
|
58723
|
+
return null;
|
|
58724
|
+
return await res.text();
|
|
58725
|
+
} catch {
|
|
58726
|
+
return null;
|
|
58727
|
+
}
|
|
58728
|
+
}
|
|
58729
|
+
|
|
58730
|
+
// src/migrate/bundle.ts
|
|
58731
|
+
init_esm10();
|
|
58732
|
+
init_html_compact();
|
|
58733
|
+
|
|
58734
|
+
// src/migrate/tailwind.ts
|
|
58735
|
+
var SPACING = {
|
|
58736
|
+
"0px": "0",
|
|
58737
|
+
"2px": "0.5",
|
|
58738
|
+
"4px": "1",
|
|
58739
|
+
"6px": "1.5",
|
|
58740
|
+
"8px": "2",
|
|
58741
|
+
"10px": "2.5",
|
|
58742
|
+
"12px": "3",
|
|
58743
|
+
"14px": "3.5",
|
|
58744
|
+
"16px": "4",
|
|
58745
|
+
"20px": "5",
|
|
58746
|
+
"24px": "6",
|
|
58747
|
+
"28px": "7",
|
|
58748
|
+
"32px": "8",
|
|
58749
|
+
"36px": "9",
|
|
58750
|
+
"40px": "10",
|
|
58751
|
+
"44px": "11",
|
|
58752
|
+
"48px": "12",
|
|
58753
|
+
"56px": "14",
|
|
58754
|
+
"64px": "16",
|
|
58755
|
+
"80px": "20",
|
|
58756
|
+
"96px": "24"
|
|
58757
|
+
};
|
|
58758
|
+
var FONT_SIZE = {
|
|
58759
|
+
"12px": "text-xs",
|
|
58760
|
+
"14px": "text-sm",
|
|
58761
|
+
"16px": "text-base",
|
|
58762
|
+
"18px": "text-lg",
|
|
58763
|
+
"20px": "text-xl",
|
|
58764
|
+
"24px": "text-2xl",
|
|
58765
|
+
"30px": "text-3xl",
|
|
58766
|
+
"36px": "text-4xl",
|
|
58767
|
+
"48px": "text-5xl",
|
|
58768
|
+
"60px": "text-6xl",
|
|
58769
|
+
"72px": "text-7xl",
|
|
58770
|
+
"96px": "text-8xl",
|
|
58771
|
+
"128px": "text-9xl"
|
|
58772
|
+
};
|
|
58773
|
+
var FONT_WEIGHT = {
|
|
58774
|
+
"100": "font-thin",
|
|
58775
|
+
"200": "font-extralight",
|
|
58776
|
+
"300": "font-light",
|
|
58777
|
+
"400": "font-normal",
|
|
58778
|
+
"500": "font-medium",
|
|
58779
|
+
"600": "font-semibold",
|
|
58780
|
+
"700": "font-bold",
|
|
58781
|
+
"800": "font-extrabold",
|
|
58782
|
+
"900": "font-black"
|
|
58783
|
+
};
|
|
58784
|
+
var RADIUS = {
|
|
58785
|
+
"0px": "rounded-none",
|
|
58786
|
+
"2px": "rounded-sm",
|
|
58787
|
+
"4px": "rounded",
|
|
58788
|
+
"6px": "rounded-md",
|
|
58789
|
+
"8px": "rounded-lg",
|
|
58790
|
+
"12px": "rounded-xl",
|
|
58791
|
+
"16px": "rounded-2xl",
|
|
58792
|
+
"24px": "rounded-3xl",
|
|
58793
|
+
"9999px": "rounded-full"
|
|
58794
|
+
};
|
|
58795
|
+
var DISPLAY = {
|
|
58796
|
+
flex: "flex",
|
|
58797
|
+
"inline-flex": "inline-flex",
|
|
58798
|
+
grid: "grid",
|
|
58799
|
+
"inline-grid": "inline-grid",
|
|
58800
|
+
block: "block",
|
|
58801
|
+
"inline-block": "inline-block",
|
|
58802
|
+
inline: "inline",
|
|
58803
|
+
none: "hidden"
|
|
58804
|
+
};
|
|
58805
|
+
var FLEX_DIR = {
|
|
58806
|
+
row: "flex-row",
|
|
58807
|
+
"row-reverse": "flex-row-reverse",
|
|
58808
|
+
column: "flex-col",
|
|
58809
|
+
"column-reverse": "flex-col-reverse"
|
|
58810
|
+
};
|
|
58811
|
+
var JUSTIFY = {
|
|
58812
|
+
"flex-start": "justify-start",
|
|
58813
|
+
"flex-end": "justify-end",
|
|
58814
|
+
center: "justify-center",
|
|
58815
|
+
"space-between": "justify-between",
|
|
58816
|
+
"space-around": "justify-around",
|
|
58817
|
+
"space-evenly": "justify-evenly"
|
|
58818
|
+
};
|
|
58819
|
+
var ALIGN = {
|
|
58820
|
+
"flex-start": "items-start",
|
|
58821
|
+
"flex-end": "items-end",
|
|
58822
|
+
center: "items-center",
|
|
58823
|
+
baseline: "items-baseline",
|
|
58824
|
+
stretch: "items-stretch"
|
|
58825
|
+
};
|
|
58826
|
+
var TEXT_TRANSFORM = {
|
|
58827
|
+
uppercase: "uppercase",
|
|
58828
|
+
lowercase: "lowercase",
|
|
58829
|
+
capitalize: "capitalize"
|
|
58830
|
+
};
|
|
58831
|
+
var POSITION = {
|
|
58832
|
+
relative: "relative",
|
|
58833
|
+
absolute: "absolute",
|
|
58834
|
+
fixed: "fixed",
|
|
58835
|
+
sticky: "sticky"
|
|
58836
|
+
};
|
|
58837
|
+
var OVERFLOW = {
|
|
58838
|
+
hidden: "overflow-hidden",
|
|
58839
|
+
auto: "overflow-auto",
|
|
58840
|
+
scroll: "overflow-scroll"
|
|
58841
|
+
};
|
|
58842
|
+
function normalizeColor(value) {
|
|
58843
|
+
return value.trim().replace(/\s+/g, "");
|
|
58844
|
+
}
|
|
58845
|
+
function spacingClass(prefix, value) {
|
|
58846
|
+
const step = SPACING[value.trim()];
|
|
58847
|
+
return step !== undefined ? `${prefix}-${step}` : `${prefix}-[${value.trim()}]`;
|
|
58848
|
+
}
|
|
58849
|
+
function boxSpacing(prop2, value) {
|
|
58850
|
+
const parts = value.trim().split(/\s+/);
|
|
58851
|
+
if (parts.length === 1 && parts[0])
|
|
58852
|
+
return [spacingClass(prop2, parts[0])];
|
|
58853
|
+
if (parts.length === 2 && parts[0] && parts[1]) {
|
|
58854
|
+
return [spacingClass(`${prop2}y`, parts[0]), spacingClass(`${prop2}x`, parts[1])];
|
|
58855
|
+
}
|
|
58856
|
+
return [];
|
|
58857
|
+
}
|
|
58858
|
+
function sizeClass(prefix, value) {
|
|
58859
|
+
const v = value.trim();
|
|
58860
|
+
if (v === "auto" || v === "")
|
|
58861
|
+
return null;
|
|
58862
|
+
if (v === "100%")
|
|
58863
|
+
return `${prefix}-full`;
|
|
58864
|
+
if (prefix === "w" && v === "100vw")
|
|
58865
|
+
return "w-screen";
|
|
58866
|
+
if (prefix === "h" && v === "100vh")
|
|
58867
|
+
return "h-screen";
|
|
58868
|
+
const step = SPACING[v];
|
|
58869
|
+
return step !== undefined ? `${prefix}-${step}` : `${prefix}-[${v}]`;
|
|
58870
|
+
}
|
|
58871
|
+
function colorClass(prefix, value, tokenByValue) {
|
|
58872
|
+
const v = value.trim();
|
|
58873
|
+
if (!v || v === "transparent" || v === "rgba(0, 0, 0, 0)" || v === "currentcolor")
|
|
58874
|
+
return null;
|
|
58875
|
+
const token = tokenByValue.get(v);
|
|
58876
|
+
if (token)
|
|
58877
|
+
return `${prefix}-${token}`;
|
|
58878
|
+
return `${prefix}-[${normalizeColor(v)}]`;
|
|
58879
|
+
}
|
|
58880
|
+
function stylesToTailwind(styles, themeTokens) {
|
|
58881
|
+
const tokenByValue = new Map;
|
|
58882
|
+
if (themeTokens) {
|
|
58883
|
+
for (const [token, value] of Object.entries(themeTokens)) {
|
|
58884
|
+
tokenByValue.set(value.trim(), token);
|
|
58885
|
+
}
|
|
58886
|
+
}
|
|
58887
|
+
const out = [];
|
|
58888
|
+
const push = (c) => {
|
|
58889
|
+
if (c && !out.includes(c))
|
|
58890
|
+
out.push(c);
|
|
58891
|
+
};
|
|
58892
|
+
const g = (k) => (styles[k] ?? "").trim();
|
|
58893
|
+
const display = g("display");
|
|
58894
|
+
push(DISPLAY[display]);
|
|
58895
|
+
if (display === "flex" || display === "inline-flex") {
|
|
58896
|
+
push(FLEX_DIR[g("flex-direction")]);
|
|
58897
|
+
}
|
|
58898
|
+
push(JUSTIFY[g("justify-content")]);
|
|
58899
|
+
push(ALIGN[g("align-items")]);
|
|
58900
|
+
const gap = g("gap");
|
|
58901
|
+
if (gap && gap !== "normal")
|
|
58902
|
+
push(spacingClass("gap", gap.split(/\s+/)[0] ?? gap));
|
|
58903
|
+
for (const c of boxSpacing("p", g("padding")))
|
|
58904
|
+
push(c);
|
|
58905
|
+
for (const c of boxSpacing("m", g("margin")))
|
|
58906
|
+
push(c);
|
|
58907
|
+
push(sizeClass("w", g("width")));
|
|
58908
|
+
push(sizeClass("h", g("height")));
|
|
58909
|
+
push(FONT_SIZE[g("font-size")] ?? (g("font-size") ? `text-[${g("font-size")}]` : null));
|
|
58910
|
+
push(FONT_WEIGHT[g("font-weight")]);
|
|
58911
|
+
push(TEXT_TRANSFORM[g("text-transform")]);
|
|
58912
|
+
push(colorClass("text", g("color"), tokenByValue));
|
|
58913
|
+
push(colorClass("bg", g("background-color"), tokenByValue));
|
|
58914
|
+
const radius = g("border-radius");
|
|
58915
|
+
if (radius)
|
|
58916
|
+
push(RADIUS[radius] ?? `rounded-[${radius}]`);
|
|
58917
|
+
const shadow = g("box-shadow");
|
|
58918
|
+
if (shadow && shadow !== "none")
|
|
58919
|
+
push("shadow");
|
|
58920
|
+
push(POSITION[g("position")]);
|
|
58921
|
+
push(OVERFLOW[g("overflow")]);
|
|
58922
|
+
return out;
|
|
58923
|
+
}
|
|
58924
|
+
|
|
58925
|
+
// src/migrate/bundle.ts
|
|
58926
|
+
var GLOBAL_ROLE_PREFIXES = ["header", "footer", "nav", "minicart"];
|
|
58927
|
+
function isGlobalRole(role) {
|
|
58928
|
+
const r = role.toLowerCase();
|
|
58929
|
+
return GLOBAL_ROLE_PREFIXES.some((p) => r === p || r.startsWith(`${p}-`));
|
|
58930
|
+
}
|
|
58931
|
+
function toMigratedComponent(c, interactions, scope, themeTokens, repeated) {
|
|
58932
|
+
return {
|
|
58933
|
+
...c,
|
|
58934
|
+
tailwind: stylesToTailwind(c.computedStyles ?? {}, themeTokens),
|
|
58935
|
+
interactions,
|
|
58936
|
+
scope,
|
|
58937
|
+
...repeated && repeated > 1 ? { repeated } : {}
|
|
58938
|
+
};
|
|
58939
|
+
}
|
|
58940
|
+
function planComponentDedup(items) {
|
|
58941
|
+
const firstAt = new Map;
|
|
58942
|
+
const plan = [];
|
|
58943
|
+
items.forEach((item, index2) => {
|
|
58944
|
+
const key = `${item.role}\x00${item.signature}`;
|
|
58945
|
+
const existing = firstAt.get(key);
|
|
58946
|
+
if (existing === undefined) {
|
|
58947
|
+
firstAt.set(key, plan.length);
|
|
58948
|
+
plan.push({ index: index2, repeated: 1 });
|
|
58949
|
+
} else {
|
|
58950
|
+
plan[existing].repeated += 1;
|
|
58951
|
+
}
|
|
58952
|
+
});
|
|
58953
|
+
return plan;
|
|
58954
|
+
}
|
|
58955
|
+
var COLLAPSE_THRESHOLD = 3;
|
|
58956
|
+
function dedupeRepeatedChildren(html3) {
|
|
58957
|
+
let collapsed = 0;
|
|
58958
|
+
try {
|
|
58959
|
+
const $2 = load(html3, null, false);
|
|
58960
|
+
$2("*").each((_, parent2) => {
|
|
58961
|
+
const children2 = $2(parent2).children().toArray();
|
|
58962
|
+
if (children2.length < COLLAPSE_THRESHOLD)
|
|
58963
|
+
return;
|
|
58964
|
+
const groups = new Map;
|
|
58965
|
+
for (const child of children2) {
|
|
58966
|
+
const fp = computeHtmlFingerprint($2.html(child) ?? "");
|
|
58967
|
+
const list = groups.get(fp) ?? [];
|
|
58968
|
+
list.push(child);
|
|
58969
|
+
groups.set(fp, list);
|
|
58970
|
+
}
|
|
58971
|
+
for (const list of groups.values()) {
|
|
58972
|
+
if (list.length < COLLAPSE_THRESHOLD)
|
|
58973
|
+
continue;
|
|
58974
|
+
const [first2, ...rest] = list;
|
|
58975
|
+
for (const el of rest)
|
|
58976
|
+
$2(el).remove();
|
|
58977
|
+
collapsed += rest.length;
|
|
58978
|
+
$2(first2).after(`<!-- ×${list.length} itens idênticos omitidos -->`);
|
|
58979
|
+
}
|
|
58980
|
+
});
|
|
58981
|
+
return { html: $2.html() ?? html3, collapsed };
|
|
58982
|
+
} catch {
|
|
58983
|
+
return { html: html3, collapsed: 0 };
|
|
58984
|
+
}
|
|
58985
|
+
}
|
|
58986
|
+
var COMPONENT_HTML_MAX_CHARS = 6000;
|
|
58987
|
+
function compactComponentHtml(html3, maxChars = COMPONENT_HTML_MAX_CHARS) {
|
|
58988
|
+
let stripped = html3;
|
|
58989
|
+
try {
|
|
58990
|
+
const $2 = load(html3);
|
|
58991
|
+
$2("script, style, noscript, svg, template, link[rel='stylesheet']").remove();
|
|
58992
|
+
$2("*").each((_, node2) => {
|
|
58993
|
+
const attrs = node2.attribs;
|
|
58994
|
+
if (!attrs)
|
|
58995
|
+
return;
|
|
58996
|
+
for (const name of Object.keys(attrs)) {
|
|
58997
|
+
if (name === "style") {
|
|
58998
|
+
delete attrs[name];
|
|
58999
|
+
continue;
|
|
59000
|
+
}
|
|
59001
|
+
if (/^data-(event|track|analytics)/.test(name) && (attrs[name]?.length ?? 0) > 100) {
|
|
59002
|
+
attrs[name] = "[…]";
|
|
59003
|
+
}
|
|
59004
|
+
if ((name === "src" || name === "srcset") && attrs[name]?.startsWith("data:")) {
|
|
59005
|
+
attrs[name] = "[data-uri]";
|
|
59006
|
+
}
|
|
59007
|
+
}
|
|
59008
|
+
if (attrs.class) {
|
|
59009
|
+
const kept = attrs.class.split(/\s+/).filter((t) => t && isSemanticClassToken(t));
|
|
59010
|
+
if (kept.length)
|
|
59011
|
+
attrs.class = kept.join(" ");
|
|
59012
|
+
else
|
|
59013
|
+
delete attrs.class;
|
|
59014
|
+
}
|
|
59015
|
+
});
|
|
59016
|
+
stripped = $2.html() ?? html3;
|
|
59017
|
+
} catch {}
|
|
59018
|
+
const { html: deduped, collapsed } = dedupeRepeatedChildren(stripped);
|
|
59019
|
+
const truncated = deduped.length > maxChars;
|
|
59020
|
+
return {
|
|
59021
|
+
html: truncated ? `${deduped.slice(0, maxChars)}
|
|
59022
|
+
<!-- TRUNCATED -->` : deduped,
|
|
59023
|
+
collapsed,
|
|
59024
|
+
truncated
|
|
59025
|
+
};
|
|
59026
|
+
}
|
|
59027
|
+
|
|
59028
|
+
// src/migrate/exporters/json.ts
|
|
59029
|
+
import { writeFileSync as writeFileSync17 } from "node:fs";
|
|
59030
|
+
import { join as join18 } from "node:path";
|
|
59031
|
+
var jsonExporter2 = {
|
|
59032
|
+
name: "json",
|
|
59033
|
+
async export(bundle, outDir) {
|
|
59034
|
+
writeFileSync17(join18(outDir, "manifest.json"), `${JSON.stringify(bundle, null, 2)}
|
|
59035
|
+
`, "utf8");
|
|
59036
|
+
}
|
|
59037
|
+
};
|
|
59038
|
+
|
|
59039
|
+
// src/migrate/exporters/markdown.ts
|
|
59040
|
+
import { mkdirSync as mkdirSync13, writeFileSync as writeFileSync18 } from "node:fs";
|
|
59041
|
+
import { join as join19 } from "node:path";
|
|
59042
|
+
var markdownExporter2 = {
|
|
59043
|
+
name: "markdown",
|
|
59044
|
+
async export(bundle, outDir) {
|
|
59045
|
+
const dirNames = bundle.components.map((c, i) => componentDirName(c.role, i + 1));
|
|
59046
|
+
const notes = [];
|
|
59047
|
+
bundle.components.forEach((component, i) => {
|
|
59048
|
+
const dirName = dirNames[i];
|
|
59049
|
+
const componentDir = join19(outDir, "components", dirName);
|
|
59050
|
+
mkdirSync13(componentDir, { recursive: true });
|
|
59051
|
+
const compact = compactComponentHtml(component.html);
|
|
59052
|
+
if (compact.collapsed > 0)
|
|
59053
|
+
notes.push(`\`${dirName}\`: collapsed ${compact.collapsed} repeated child element(s)`);
|
|
59054
|
+
if (compact.truncated)
|
|
59055
|
+
notes.push(`\`${dirName}\`: HTML truncated to fit the per-component token ceiling`);
|
|
59056
|
+
writeFileSync18(join19(componentDir, "README.md"), renderComponentReadme2(bundle.url, component, compact.html), "utf8");
|
|
59057
|
+
});
|
|
59058
|
+
writeFileSync18(join19(outDir, "index.md"), renderIndex2(bundle, dirNames, notes), "utf8");
|
|
59059
|
+
}
|
|
59060
|
+
};
|
|
59061
|
+
function renderIndex2(bundle, dirNames, notes) {
|
|
59062
|
+
const lines = [];
|
|
59063
|
+
const md = lines.push.bind(lines);
|
|
59064
|
+
md(`# Migration snapshot: ${bundle.url}`);
|
|
59065
|
+
md("");
|
|
59066
|
+
md("AI-ready, token-lean snapshot for migrating this storefront. Theme + component");
|
|
59067
|
+
md("map below; per-component detail (Tailwind, interactions, e2e selectors) lives in");
|
|
59068
|
+
md("each `components/<folder>/README.md`. Full raw HTML/CSS is in `manifest.json`.");
|
|
59069
|
+
md("");
|
|
59070
|
+
md("## Site");
|
|
59071
|
+
md("");
|
|
59072
|
+
md(`- **URL**: ${bundle.url}`);
|
|
59073
|
+
md(`- **Source platform**: ${bundle.platform}`);
|
|
59074
|
+
if (bundle.target)
|
|
59075
|
+
md(`- **Target**: ${bundle.target} (see MIGRATION_PROMPT.md)`);
|
|
59076
|
+
md(`- **Captured**: ${bundle.timestamp} (${bundle.viewport})`);
|
|
59077
|
+
md(`- **Pages**: ${bundle.pages.map((p) => `${p.kind} \`${p.path}\``).join(", ") || "—"}`);
|
|
59078
|
+
md("");
|
|
59079
|
+
if (bundle.screenshots?.length) {
|
|
59080
|
+
md("## Screenshots by viewport");
|
|
59081
|
+
md("");
|
|
59082
|
+
for (const s of bundle.screenshots)
|
|
59083
|
+
md(`- **${s.viewport}**: `);
|
|
59084
|
+
md("");
|
|
59085
|
+
}
|
|
59086
|
+
renderTheme(md, bundle.theme);
|
|
59087
|
+
renderAssets(md, bundle.assets);
|
|
59088
|
+
if (bundle.vtex) {
|
|
59089
|
+
md("## VTEX IO → FastStore blocks");
|
|
59090
|
+
md("");
|
|
59091
|
+
md(`_${bundle.vtex.blocks.length} block instances from the store runtime. \`custom-component\` = build from captured DOM/CSS; see component-map.json._`);
|
|
59092
|
+
md("");
|
|
59093
|
+
md("| VTEX block | → FastStore | confidence | count |");
|
|
59094
|
+
md("|---|---|---|---|");
|
|
59095
|
+
for (const m of bundle.vtex.map.slice(0, 40)) {
|
|
59096
|
+
md(`| \`${m.vtex}\` | ${m.faststore ? `\`${m.faststore}\`` : "_custom-component_"} | ${m.confidence || "—"} | ${m.count} |`);
|
|
59097
|
+
}
|
|
59098
|
+
md("");
|
|
59099
|
+
}
|
|
59100
|
+
md("## Components");
|
|
59101
|
+
md("");
|
|
59102
|
+
md("| Scope | Role | e2e keys | Folder |");
|
|
59103
|
+
md("|---|---|---|---|");
|
|
59104
|
+
bundle.components.forEach((c, i) => {
|
|
59105
|
+
const keys = c.interactions.map((x) => x.e2eKey).filter((k) => Boolean(k));
|
|
59106
|
+
const uniqueKeys = [...new Set(keys)];
|
|
59107
|
+
const roleCell = c.repeated && c.repeated > 1 ? `\`${c.role}\` ×${c.repeated}` : `\`${c.role}\``;
|
|
59108
|
+
md(`| ${c.scope} | ${roleCell} | ${uniqueKeys.length ? uniqueKeys.map((k) => `\`${k}\``).join(", ") : "—"} | [${dirNames[i]}](./components/${dirNames[i]}/README.md) |`);
|
|
59109
|
+
});
|
|
59110
|
+
md("");
|
|
59111
|
+
if (notes.length) {
|
|
59112
|
+
md("## Compaction notes");
|
|
59113
|
+
md("");
|
|
59114
|
+
md("_The lean artifact shrank these components; the full data is in `manifest.json`._");
|
|
59115
|
+
md("");
|
|
59116
|
+
for (const n of notes)
|
|
59117
|
+
md(`- ${n}`);
|
|
59118
|
+
md("");
|
|
59119
|
+
}
|
|
59120
|
+
return lines.join(`
|
|
59121
|
+
`);
|
|
59122
|
+
}
|
|
59123
|
+
function renderTheme(md, theme) {
|
|
59124
|
+
md("## Theme");
|
|
59125
|
+
md("");
|
|
59126
|
+
md("| Token | Value |");
|
|
59127
|
+
md("|---|---|");
|
|
59128
|
+
for (const [token, value] of Object.entries(theme.tokens)) {
|
|
59129
|
+
md(`| \`${token}\` | \`${value}\` |`);
|
|
59130
|
+
}
|
|
59131
|
+
md("");
|
|
59132
|
+
md(`- **Fonts**: ${listOrNone2(theme.typography.fontFamilies)}`);
|
|
59133
|
+
md(`- **Font sizes**: ${listOrNone2(theme.typography.sizeScale)}`);
|
|
59134
|
+
md(`- **Spacing scale**: ${listOrNone2(theme.spacingScale)}`);
|
|
59135
|
+
md(`- **Radii**: ${listOrNone2(theme.radii)}`);
|
|
59136
|
+
md(`- **Breakpoints**: ${listOrNone2(theme.breakpoints)}`);
|
|
59137
|
+
md(`- **Motion**: durations ${listOrNone2(theme.motion.durations)} · easings ${listOrNone2(theme.motion.easings)}`);
|
|
59138
|
+
md(`- **Shadows**: ${theme.shadows.length}`);
|
|
59139
|
+
md("");
|
|
59140
|
+
}
|
|
59141
|
+
function renderAssets(md, assets) {
|
|
59142
|
+
md("## Brand assets");
|
|
59143
|
+
md("");
|
|
59144
|
+
md(`- **Logo**: ${assets.logo ? `\`${assets.logo}\`${assets.logoSource ? ` (from ${assets.logoSource})` : ""}` : "_not found_"}`);
|
|
59145
|
+
md(`- **Favicon**: ${assets.favicon ? `\`${assets.favicon}\`` : "_not found_"}`);
|
|
59146
|
+
md(`- **Apple touch icon**: ${assets.appleTouchIcon ? `\`${assets.appleTouchIcon}\`` : "—"}`);
|
|
59147
|
+
md(`- **OG image**: ${assets.ogImage ? `\`${assets.ogImage}\`` : "—"}`);
|
|
59148
|
+
md(`- **Web app manifest**: ${assets.manifest ? assets.manifest : "—"}`);
|
|
59149
|
+
md(`- **Web fonts**: ${listOrNone2(assets.fonts)}`);
|
|
59150
|
+
md("");
|
|
59151
|
+
if (assets.icons.length) {
|
|
59152
|
+
md(`## Icons (${assets.icons.length})`);
|
|
59153
|
+
md("");
|
|
59154
|
+
md("_Map these to the target's icon set (e.g. FastStore uses Phosphor `<Icon>`)._");
|
|
59155
|
+
md("");
|
|
59156
|
+
md("| Kind | Id | Count |");
|
|
59157
|
+
md("|---|---|---|");
|
|
59158
|
+
for (const icon of assets.icons.slice(0, 60)) {
|
|
59159
|
+
md(`| ${icon.kind} | \`${escapePipes2(icon.id)}\` | ${icon.count} |`);
|
|
59160
|
+
}
|
|
59161
|
+
md("");
|
|
59162
|
+
}
|
|
59163
|
+
}
|
|
59164
|
+
function renderComponentReadme2(url, c, compactHtml) {
|
|
59165
|
+
const lines = [];
|
|
59166
|
+
const md = lines.push.bind(lines);
|
|
59167
|
+
md(`# Component: \`${c.role}\` (${c.scope})`);
|
|
59168
|
+
md("");
|
|
59169
|
+
if (c.repeated && c.repeated > 1) {
|
|
59170
|
+
md(`> ${c.repeated} structurally-identical instances on the page — one shown here.`);
|
|
59171
|
+
md("");
|
|
59172
|
+
}
|
|
59173
|
+
md(`- **Site**: ${url}`);
|
|
59174
|
+
md(`- **Selector**: \`${c.selector}\``);
|
|
59175
|
+
md(`- **Screenshot**: `);
|
|
59176
|
+
md("");
|
|
59177
|
+
md("## Tailwind (suggested)");
|
|
59178
|
+
md("");
|
|
59179
|
+
md(c.tailwind.length ? `\`\`\`
|
|
59180
|
+
${c.tailwind.join(" ")}
|
|
59181
|
+
\`\`\`` : "_none inferred_");
|
|
59182
|
+
md("");
|
|
59183
|
+
if (c.interactions.length) {
|
|
59184
|
+
md("## Interactions & e2e selectors");
|
|
59185
|
+
md("");
|
|
59186
|
+
md("| Selector | Kind | Label | e2e key | States |");
|
|
59187
|
+
md("|---|---|---|---|---|");
|
|
59188
|
+
for (const it of c.interactions) {
|
|
59189
|
+
const states = [
|
|
59190
|
+
it.hasHoverRule ? "hover" : "",
|
|
59191
|
+
it.hasFocusRule ? "focus" : "",
|
|
59192
|
+
it.animation ? "anim" : ""
|
|
59193
|
+
].filter(Boolean).join(", ");
|
|
59194
|
+
md(`| \`${escapePipes2(it.selector)}\` | ${it.kind} | ${escapePipes2(it.label) || "—"} | ${it.e2eKey ? `\`${it.e2eKey}\`` : "—"} | ${states || "—"} |`);
|
|
59195
|
+
}
|
|
59196
|
+
md("");
|
|
59197
|
+
}
|
|
59198
|
+
md("## Assets");
|
|
59199
|
+
md("");
|
|
59200
|
+
md(`- **Images** (${c.assets.images.length}): ${listOrNone2(c.assets.images)}`);
|
|
59201
|
+
md(`- **Fonts**: ${listOrNone2(c.assets.fonts)}`);
|
|
59202
|
+
md("");
|
|
59203
|
+
if (c.textContent.length) {
|
|
59204
|
+
md("## Notable text");
|
|
59205
|
+
md("");
|
|
59206
|
+
for (const t of c.textContent.slice(0, 15))
|
|
59207
|
+
md(`- ${t}`);
|
|
59208
|
+
md("");
|
|
59209
|
+
}
|
|
59210
|
+
md("## HTML (compacted)");
|
|
59211
|
+
md("");
|
|
59212
|
+
md("```html");
|
|
59213
|
+
md(compactHtml);
|
|
59214
|
+
md("```");
|
|
59215
|
+
md("");
|
|
59216
|
+
return lines.join(`
|
|
59217
|
+
`);
|
|
59218
|
+
}
|
|
59219
|
+
function listOrNone2(items) {
|
|
59220
|
+
if (items.length === 0)
|
|
59221
|
+
return "_none_";
|
|
59222
|
+
return items.slice(0, 10).map((i) => `\`${i}\``).join(", ");
|
|
59223
|
+
}
|
|
59224
|
+
function escapePipes2(s) {
|
|
59225
|
+
return s.replace(/\|/g, "\\|");
|
|
59226
|
+
}
|
|
59227
|
+
|
|
59228
|
+
// src/migrate/prompt.ts
|
|
59229
|
+
function buildMigrationPrompt(bundle, playbook) {
|
|
59230
|
+
const lines = [];
|
|
59231
|
+
const md = lines.push.bind(lines);
|
|
59232
|
+
md(`# Migration prompt: ${bundle.url}`);
|
|
59233
|
+
md("");
|
|
59234
|
+
md("You are migrating this storefront to a new framework. This folder is an");
|
|
59235
|
+
md("AI-ready snapshot of the live site — theme, page structure, and per-component");
|
|
59236
|
+
md("detail (suggested Tailwind classes, interaction hints, e2e selectors).");
|
|
59237
|
+
md("");
|
|
59238
|
+
md(`- **Source platform**: ${bundle.platform}`);
|
|
59239
|
+
md(`- **Captured**: ${bundle.timestamp} (${bundle.viewport})`);
|
|
59240
|
+
md(`- **Pages**: ${bundle.pages.map((p) => `${p.kind} (${p.path})`).join(", ") || "—"}`);
|
|
59241
|
+
md("");
|
|
59242
|
+
md("## How to work");
|
|
59243
|
+
md("");
|
|
59244
|
+
md("1. Read `index.md` for the theme tokens and the component map.");
|
|
59245
|
+
md("2. Start with **global** components (header/footer/minicart) — they appear on");
|
|
59246
|
+
md(" every page — then do page components per page kind (home → PLP → PDP).");
|
|
59247
|
+
md("3. For each component, open its `components/<folder>/README.md`: use the");
|
|
59248
|
+
md(" suggested Tailwind classes as the styling source of truth, keep the raw HTML");
|
|
59249
|
+
md(" only as a structure reference, and wire the listed e2e selectors.");
|
|
59250
|
+
md("4. Apply the theme tokens once, globally, then reference them (`bg-primary`).");
|
|
59251
|
+
md("");
|
|
59252
|
+
const globals = bundle.components.filter((c) => c.scope === "global");
|
|
59253
|
+
const pageComps = bundle.components.filter((c) => c.scope === "page");
|
|
59254
|
+
const row = (role, i) => `- \`${role}\` → components/${componentDirName(role, i + 1)}/README.md`;
|
|
59255
|
+
if (globals.length) {
|
|
59256
|
+
md("### Global components");
|
|
59257
|
+
bundle.components.forEach((c, i) => c.scope === "global" && md(row(c.role, i)));
|
|
59258
|
+
md("");
|
|
59259
|
+
}
|
|
59260
|
+
if (pageComps.length) {
|
|
59261
|
+
md("### Page components");
|
|
59262
|
+
bundle.components.forEach((c, i) => c.scope === "page" && md(row(c.role, i)));
|
|
59263
|
+
md("");
|
|
59264
|
+
}
|
|
59265
|
+
if (playbook) {
|
|
59266
|
+
md("---");
|
|
59267
|
+
md("");
|
|
59268
|
+
md(playbook);
|
|
59269
|
+
md("");
|
|
59270
|
+
}
|
|
59271
|
+
return lines.join(`
|
|
59272
|
+
`);
|
|
59273
|
+
}
|
|
59274
|
+
|
|
59275
|
+
// src/migrate/targets/faststore.ts
|
|
59276
|
+
function pickBreakpointTiers(breakpoints) {
|
|
59277
|
+
const px = breakpoints.map((b) => ({ raw: b, n: Number.parseFloat(b) })).filter((b) => Number.isFinite(b.n));
|
|
59278
|
+
const used = new Set;
|
|
59279
|
+
const nearest = (target) => {
|
|
59280
|
+
let best = null;
|
|
59281
|
+
for (const b of px) {
|
|
59282
|
+
if (used.has(b.raw))
|
|
59283
|
+
continue;
|
|
59284
|
+
const d = Math.abs(b.n - target);
|
|
59285
|
+
if (!best || d < best.d)
|
|
59286
|
+
best = { raw: b.raw, d };
|
|
59287
|
+
}
|
|
59288
|
+
if (best)
|
|
59289
|
+
used.add(best.raw);
|
|
59290
|
+
return best?.raw ?? null;
|
|
59291
|
+
};
|
|
59292
|
+
return {
|
|
59293
|
+
phone: nearest(480),
|
|
59294
|
+
tablet: nearest(768),
|
|
59295
|
+
notebook: nearest(1024),
|
|
59296
|
+
desktop: nearest(1280)
|
|
59297
|
+
};
|
|
59298
|
+
}
|
|
59299
|
+
function buildFastStoreTheme(theme) {
|
|
59300
|
+
const lines = [];
|
|
59301
|
+
const put = (token, value) => {
|
|
59302
|
+
if (value)
|
|
59303
|
+
lines.push(` ${token}: ${value};`);
|
|
59304
|
+
};
|
|
59305
|
+
const fonts = theme.typography.fontFamilies;
|
|
59306
|
+
const radii = theme.radii;
|
|
59307
|
+
const bp = theme.breakpoints;
|
|
59308
|
+
put("--fs-color-primary-bkg", theme.colors.primary);
|
|
59309
|
+
put("--fs-color-accent-0", theme.colors.secondary);
|
|
59310
|
+
put("--fs-color-text", theme.colors.text);
|
|
59311
|
+
put("--fs-color-body-bkg", theme.colors.background);
|
|
59312
|
+
put("--fs-text-face-body", fonts[0]);
|
|
59313
|
+
put("--fs-text-face-title", fonts[1] ?? fonts[0]);
|
|
59314
|
+
put("--fs-border-radius-medium", radii[Math.floor(radii.length / 2)]);
|
|
59315
|
+
put("--fs-shadow", theme.shadows[0]);
|
|
59316
|
+
const tiers = pickBreakpointTiers(bp);
|
|
59317
|
+
put("--fs-grid-breakpoint-phone", tiers.phone);
|
|
59318
|
+
put("--fs-grid-breakpoint-tablet", tiers.tablet);
|
|
59319
|
+
put("--fs-grid-breakpoint-notebook", tiers.notebook);
|
|
59320
|
+
put("--fs-grid-breakpoint-desktop", tiers.desktop);
|
|
59321
|
+
return [
|
|
59322
|
+
"// custom-theme.scss — starter generated by `parity migrate --target faststore`.",
|
|
59323
|
+
"// Brand tokens only; adjust and extend against @faststore/ui global tokens.",
|
|
59324
|
+
".theme {",
|
|
59325
|
+
...lines,
|
|
59326
|
+
"}",
|
|
59327
|
+
""
|
|
59328
|
+
].join(`
|
|
59329
|
+
`);
|
|
59330
|
+
}
|
|
59331
|
+
var faststore = `## Target: VTEX FastStore (v4)
|
|
59332
|
+
|
|
59333
|
+
Generate the migrated storefront as a FastStore v4 project. Do NOT hand-roll the
|
|
59334
|
+
scaffold — use the official CLI, then fill in sections from the components below.
|
|
59335
|
+
|
|
59336
|
+
### Setup (once)
|
|
59337
|
+
- Requirements + project setup: https://developers.vtex.com/docs/guides/faststore/getting-started-requirements
|
|
59338
|
+
- Project structure overview: https://developers.vtex.com/docs/guides/faststore/project-structure-overview
|
|
59339
|
+
- \`yarn install\` then \`yarn dev\` → dev store at http://localhost:3000
|
|
59340
|
+
|
|
59341
|
+
### CLI (@faststore/cli)
|
|
59342
|
+
- \`faststore dev\` — local dev server (localhost:3000)
|
|
59343
|
+
- \`faststore build\` — production build
|
|
59344
|
+
- \`faststore generate\` — regenerate schema + TS types after changes
|
|
59345
|
+
- \`faststore cms-sync\` — sync the \`cms/\` folder with the Headless CMS
|
|
59346
|
+
|
|
59347
|
+
### Styling — IMPORTANT: FastStore does NOT use Tailwind
|
|
59348
|
+
FastStore v4 styles with **SCSS design tokens + \`data-fs-*\` attributes**, not
|
|
59349
|
+
utility classes. The Tailwind classes in each component README are a convenience
|
|
59350
|
+
approximation — treat the **raw computed styles in manifest.json as the source
|
|
59351
|
+
of truth** for exact values. Package split: \`@faststore/components\` (structure/
|
|
59352
|
+
behavior, unstyled) · \`@faststore/ui\` (styles + design tokens) · \`@faststore/core\`
|
|
59353
|
+
(sections/pages).
|
|
59354
|
+
|
|
59355
|
+
- **Theme** → a starter \`custom-theme.scss\` was generated in this snapshot from
|
|
59356
|
+
the extracted brand tokens. Drop it in \`src/themes/\` and refine. Token map used:
|
|
59357
|
+
|
|
59358
|
+
| Extracted | FastStore global token |
|
|
59359
|
+
| --- | --- |
|
|
59360
|
+
| primary | \`--fs-color-primary-bkg\` |
|
|
59361
|
+
| secondary | \`--fs-color-accent-0\` |
|
|
59362
|
+
| text | \`--fs-color-text\` |
|
|
59363
|
+
| background | \`--fs-color-body-bkg\` |
|
|
59364
|
+
| font (body/title) | \`--fs-text-face-body\` / \`--fs-text-face-title\` |
|
|
59365
|
+
| radius | \`--fs-border-radius-medium\` |
|
|
59366
|
+
| shadow | \`--fs-shadow\` |
|
|
59367
|
+
| breakpoints | \`--fs-grid-breakpoint-phone|tablet|notebook|desktop\` |
|
|
59368
|
+
|
|
59369
|
+
Do NOT override \`--fs-spacing-*\`/\`--fs-text-size-*\` (structural scale).
|
|
59370
|
+
Global tokens: https://developers.vtex.com/docs/guides/faststore/global-tokens-overview
|
|
59371
|
+
- **Per-component styling** → override via each component's \`data-fs-*\` attribute
|
|
59372
|
+
in SCSS (e.g. \`[data-fs-product-shelf]\`), not utility classes.
|
|
59373
|
+
Styling a component: https://developers.vtex.com/docs/guides/faststore/using-themes-components
|
|
59374
|
+
|
|
59375
|
+
### Icons — Phosphor
|
|
59376
|
+
FastStore ships Phosphor icons via the \`<Icon>\` component (\`data-fs-icon\`, \`weight\`
|
|
59377
|
+
prop: thin|light|regular|bold). Map each entry in this snapshot's **icon inventory**
|
|
59378
|
+
to a Phosphor icon id; add any missing ones as custom icons.
|
|
59379
|
+
- Iconography: https://developers.vtex.com/docs/guides/faststore/reference-icons
|
|
59380
|
+
- Adding custom icons: https://developers.vtex.com/docs/guides/faststore/atoms-icon
|
|
59381
|
+
|
|
59382
|
+
### Brand assets
|
|
59383
|
+
- Logo + favicon (and apple-touch-icon / OG image) were downloaded to \`assets/\`
|
|
59384
|
+
in this snapshot — drop them into the FastStore project's \`public/\` and wire the
|
|
59385
|
+
logo into the Navbar/Header section.
|
|
59386
|
+
|
|
59387
|
+
### Where components go — section structure
|
|
59388
|
+
Each detected component → a FastStore section:
|
|
59389
|
+
- \`src/components/<SectionName>.tsx\` (the React section)
|
|
59390
|
+
- register it in \`src/components/index.tsx\` (the components entry)
|
|
59391
|
+
- add its schema to \`cms/faststore/sections.json\` (form editors use in the CMS)
|
|
59392
|
+
- **Global components** (header/footer/minicart) render on every page;
|
|
59393
|
+
**page components** (home/PLP/PDP) go into the matching page content type.
|
|
59394
|
+
- After adding/editing sections: \`faststore generate\` then \`faststore cms-sync\`.
|
|
59395
|
+
- Splitting a legacy CMS structure into components/content-types is supported by
|
|
59396
|
+
\`vtex content split-components\` and \`vtex content split-content-types\`.
|
|
59397
|
+
- Creating a section: https://developers.vtex.com/docs/guides/faststore/building-sections-creating-a-new-section
|
|
59398
|
+
- Headless CMS model: https://developers.vtex.com/docs/guides/faststore/headless-cms-overview
|
|
59399
|
+
- Creating sections: https://developers.vtex.com/docs/guides/faststore/creating-a-new-section-and-content-type
|
|
59400
|
+
|
|
59401
|
+
### e2e
|
|
59402
|
+
Use the suggested selectors (per component, mapped to known commerce keys) to
|
|
59403
|
+
seed Playwright/Cypress smoke tests on the migrated store.`;
|
|
59404
|
+
|
|
59405
|
+
// src/migrate/targets/index.ts
|
|
59406
|
+
var TARGETS = {
|
|
59407
|
+
faststore
|
|
59408
|
+
};
|
|
59409
|
+
function getTargetPlaybook(name) {
|
|
59410
|
+
return Object.hasOwn(TARGETS, name) ? TARGETS[name] : undefined;
|
|
59411
|
+
}
|
|
59412
|
+
var TARGET_NAMES = Object.keys(TARGETS);
|
|
59413
|
+
|
|
59414
|
+
// src/migrate/theme.ts
|
|
59415
|
+
var TRANSPARENT = new Set(["transparent", "rgba(0, 0, 0, 0)", "rgba(0,0,0,0)"]);
|
|
59416
|
+
function parseRgb(color) {
|
|
59417
|
+
const m = color.trim().match(/rgba?\(([^)]+)\)/i);
|
|
59418
|
+
if (!m || !m[1])
|
|
59419
|
+
return null;
|
|
59420
|
+
const parts = m[1].split(",").map((p) => Number.parseFloat(p.trim()));
|
|
59421
|
+
if (parts.length < 3 || parts.some((n) => Number.isNaN(n)))
|
|
59422
|
+
return null;
|
|
59423
|
+
return { r: parts[0], g: parts[1], b: parts[2], a: parts[3] ?? 1 };
|
|
59424
|
+
}
|
|
59425
|
+
function isNeutral(color) {
|
|
59426
|
+
const c = parseRgb(color);
|
|
59427
|
+
if (!c)
|
|
59428
|
+
return false;
|
|
59429
|
+
if (c.a < 0.1)
|
|
59430
|
+
return true;
|
|
59431
|
+
const max = Math.max(c.r, c.g, c.b);
|
|
59432
|
+
const min = Math.min(c.r, c.g, c.b);
|
|
59433
|
+
return max - min < 18;
|
|
59434
|
+
}
|
|
59435
|
+
function rank(values) {
|
|
59436
|
+
const counts = new Map;
|
|
59437
|
+
for (const v of values) {
|
|
59438
|
+
const key = v.trim();
|
|
59439
|
+
if (!key || TRANSPARENT.has(key))
|
|
59440
|
+
continue;
|
|
59441
|
+
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
59442
|
+
}
|
|
59443
|
+
return new Map([...counts.entries()].sort((a, b) => b[1] - a[1]));
|
|
59444
|
+
}
|
|
59445
|
+
function isPlausibleFontFamily(f) {
|
|
59446
|
+
const v = f.trim();
|
|
59447
|
+
return v.length > 0 && v.length < 120 && !v.includes("=") && !v.includes("&");
|
|
59448
|
+
}
|
|
59449
|
+
function sortByPx(values) {
|
|
59450
|
+
const uniq = [...new Set(values.map((v) => v.trim()).filter(Boolean))];
|
|
59451
|
+
return uniq.sort((a, b) => (Number.parseFloat(a) || 0) - (Number.parseFloat(b) || 0));
|
|
59452
|
+
}
|
|
59453
|
+
function mergeRawThemeSamples(list) {
|
|
59454
|
+
const first2 = list[0];
|
|
59455
|
+
const concat = (key) => list.flatMap((s) => s[key]);
|
|
59456
|
+
return {
|
|
59457
|
+
bodyBackground: first2.bodyBackground,
|
|
59458
|
+
bodyText: first2.bodyText,
|
|
59459
|
+
bodyFontFamily: first2.bodyFontFamily,
|
|
59460
|
+
colors: concat("colors"),
|
|
59461
|
+
backgrounds: concat("backgrounds"),
|
|
59462
|
+
interactiveBackgrounds: concat("interactiveBackgrounds"),
|
|
59463
|
+
fontFamilies: concat("fontFamilies"),
|
|
59464
|
+
fontSizes: concat("fontSizes"),
|
|
59465
|
+
radii: concat("radii"),
|
|
59466
|
+
shadows: concat("shadows"),
|
|
59467
|
+
spacings: concat("spacings"),
|
|
59468
|
+
breakpoints: concat("breakpoints"),
|
|
59469
|
+
motionDurations: concat("motionDurations"),
|
|
59470
|
+
motionEasings: concat("motionEasings")
|
|
59471
|
+
};
|
|
59472
|
+
}
|
|
59473
|
+
function aggregateTheme(raw) {
|
|
59474
|
+
const paletteRanked = rank([...raw.colors, ...raw.backgrounds]);
|
|
59475
|
+
const interactiveRanked = rank(raw.interactiveBackgrounds);
|
|
59476
|
+
const chromatic = [...interactiveRanked.keys()].filter((c) => !isNeutral(c));
|
|
59477
|
+
const primary = chromatic[0] ?? null;
|
|
59478
|
+
const secondary = chromatic.find((c) => c !== primary) ?? null;
|
|
59479
|
+
const tokens = {};
|
|
59480
|
+
if (primary)
|
|
59481
|
+
tokens.primary = primary;
|
|
59482
|
+
if (secondary)
|
|
59483
|
+
tokens.secondary = secondary;
|
|
59484
|
+
if (raw.bodyBackground && !TRANSPARENT.has(raw.bodyBackground.trim()))
|
|
59485
|
+
tokens.background = raw.bodyBackground.trim();
|
|
59486
|
+
if (raw.bodyText)
|
|
59487
|
+
tokens.text = raw.bodyText.trim();
|
|
59488
|
+
const palette = [...paletteRanked.entries()].map(([value, count]) => ({
|
|
59489
|
+
value,
|
|
59490
|
+
count,
|
|
59491
|
+
token: Object.entries(tokens).find(([, v]) => v === value)?.[0] ?? (isNeutral(value) ? "neutral" : "accent")
|
|
59492
|
+
}));
|
|
59493
|
+
return {
|
|
59494
|
+
colors: {
|
|
59495
|
+
primary,
|
|
59496
|
+
secondary,
|
|
59497
|
+
background: tokens.background ?? null,
|
|
59498
|
+
text: tokens.text ?? null,
|
|
59499
|
+
palette
|
|
59500
|
+
},
|
|
59501
|
+
typography: {
|
|
59502
|
+
fontFamilies: [...rank(raw.fontFamilies).keys()].filter(isPlausibleFontFamily),
|
|
59503
|
+
sizeScale: sortByPx(raw.fontSizes)
|
|
59504
|
+
},
|
|
59505
|
+
spacingScale: sortByPx(raw.spacings),
|
|
59506
|
+
radii: sortByPx(raw.radii).filter((r) => r !== "0px"),
|
|
59507
|
+
shadows: [...new Set(raw.shadows.map((s) => s.trim()))].filter((s) => s && s !== "none"),
|
|
59508
|
+
breakpoints: sortByPx(raw.breakpoints),
|
|
59509
|
+
motion: {
|
|
59510
|
+
durations: [...new Set(raw.motionDurations.map((d) => d.trim()))].filter((d) => d && d !== "0s" && d !== "0ms"),
|
|
59511
|
+
easings: [...new Set(raw.motionEasings.map((e) => e.trim()))].filter((e) => e && e !== "ease" && e !== "linear")
|
|
59512
|
+
},
|
|
59513
|
+
tokens
|
|
59514
|
+
};
|
|
59515
|
+
}
|
|
59516
|
+
async function scrapeThemeSamples(page) {
|
|
59517
|
+
return page.evaluate(() => {
|
|
59518
|
+
const cap = 2000;
|
|
59519
|
+
const els = Array.from(document.querySelectorAll("*")).slice(0, cap);
|
|
59520
|
+
const colors = [];
|
|
59521
|
+
const backgrounds = [];
|
|
59522
|
+
const interactiveBackgrounds = [];
|
|
59523
|
+
const fontFamilies = [];
|
|
59524
|
+
const fontSizes = [];
|
|
59525
|
+
const radii = [];
|
|
59526
|
+
const shadows = [];
|
|
59527
|
+
const spacings = [];
|
|
59528
|
+
const motionDurations = [];
|
|
59529
|
+
const motionEasings = [];
|
|
59530
|
+
const transparent = new Set(["transparent", "rgba(0, 0, 0, 0)"]);
|
|
59531
|
+
for (const el of els) {
|
|
59532
|
+
const cs = getComputedStyle(el);
|
|
59533
|
+
colors.push(cs.color);
|
|
59534
|
+
const bg = cs.backgroundColor;
|
|
59535
|
+
if (!transparent.has(bg))
|
|
59536
|
+
backgrounds.push(bg);
|
|
59537
|
+
fontFamilies.push(cs.fontFamily);
|
|
59538
|
+
fontSizes.push(cs.fontSize);
|
|
59539
|
+
if (cs.borderRadius)
|
|
59540
|
+
radii.push(cs.borderRadius);
|
|
59541
|
+
if (cs.boxShadow && cs.boxShadow !== "none")
|
|
59542
|
+
shadows.push(cs.boxShadow);
|
|
59543
|
+
if (cs.gap && cs.gap !== "normal")
|
|
59544
|
+
spacings.push(cs.gap.split(/\s+/)[0] ?? cs.gap);
|
|
59545
|
+
const pad = cs.padding.split(/\s+/);
|
|
59546
|
+
if (pad.length === 1 && pad[0] && pad[0] !== "0px")
|
|
59547
|
+
spacings.push(pad[0]);
|
|
59548
|
+
for (const d of cs.transitionDuration.split(","))
|
|
59549
|
+
if (d.trim())
|
|
59550
|
+
motionDurations.push(d.trim());
|
|
59551
|
+
for (const d of cs.animationDuration.split(","))
|
|
59552
|
+
if (d.trim())
|
|
59553
|
+
motionDurations.push(d.trim());
|
|
59554
|
+
for (const e of cs.transitionTimingFunction.split(","))
|
|
59555
|
+
if (e.trim())
|
|
59556
|
+
motionEasings.push(e.trim());
|
|
59557
|
+
const tag = el.tagName.toLowerCase();
|
|
59558
|
+
const role = el.getAttribute("role");
|
|
59559
|
+
const isInteractive = tag === "button" || tag === "a" || role === "button";
|
|
59560
|
+
if (isInteractive && !transparent.has(bg))
|
|
59561
|
+
interactiveBackgrounds.push(bg);
|
|
59562
|
+
}
|
|
59563
|
+
const breakpoints = [];
|
|
59564
|
+
for (const sheet of Array.from(document.styleSheets)) {
|
|
59565
|
+
let rules;
|
|
59566
|
+
try {
|
|
59567
|
+
rules = sheet.cssRules;
|
|
59568
|
+
} catch {
|
|
59569
|
+
continue;
|
|
59570
|
+
}
|
|
59571
|
+
for (const rule of Array.from(rules)) {
|
|
59572
|
+
const media = rule.media?.mediaText;
|
|
59573
|
+
if (!media)
|
|
59574
|
+
continue;
|
|
59575
|
+
const re = /(?:min|max)-width:\s*(\d+(?:\.\d+)?)px/g;
|
|
59576
|
+
let m;
|
|
59577
|
+
while ((m = re.exec(media)) !== null)
|
|
59578
|
+
breakpoints.push(`${m[1]}px`);
|
|
59579
|
+
}
|
|
59580
|
+
}
|
|
59581
|
+
const body = getComputedStyle(document.body);
|
|
59582
|
+
return {
|
|
59583
|
+
bodyBackground: getComputedStyle(document.documentElement).backgroundColor || body.backgroundColor,
|
|
59584
|
+
bodyText: body.color,
|
|
59585
|
+
bodyFontFamily: body.fontFamily,
|
|
59586
|
+
colors,
|
|
59587
|
+
backgrounds,
|
|
59588
|
+
interactiveBackgrounds,
|
|
59589
|
+
fontFamilies,
|
|
59590
|
+
fontSizes,
|
|
59591
|
+
radii,
|
|
59592
|
+
shadows,
|
|
59593
|
+
spacings,
|
|
59594
|
+
breakpoints,
|
|
59595
|
+
motionDurations,
|
|
59596
|
+
motionEasings
|
|
59597
|
+
};
|
|
59598
|
+
});
|
|
59599
|
+
}
|
|
59600
|
+
|
|
59601
|
+
// src/migrate/vtex/faststore-map.ts
|
|
59602
|
+
var TABLE = {
|
|
59603
|
+
"product-summary": { faststore: "ProductCard", confidence: 0.95 },
|
|
59604
|
+
shelf: { faststore: "ProductShelf", confidence: 0.9 },
|
|
59605
|
+
"product-shelf": { faststore: "ProductShelf", confidence: 0.92 },
|
|
59606
|
+
"flex-layout": { faststore: "FlexLayout", confidence: 0.9 },
|
|
59607
|
+
"rich-text": { faststore: "RichText", confidence: 0.97 },
|
|
59608
|
+
"responsive-layout": { faststore: "FlexLayout", confidence: 0.7 },
|
|
59609
|
+
image: { faststore: "Image", confidence: 0.9 },
|
|
59610
|
+
"list-context": { faststore: "ProductShelf", confidence: 0.6 },
|
|
59611
|
+
"slider-layout": { faststore: "Carousel", confidence: 0.85 },
|
|
59612
|
+
carousel: { faststore: "Carousel", confidence: 0.85 },
|
|
59613
|
+
"search-bar": { faststore: "SearchInput", confidence: 0.9 },
|
|
59614
|
+
"search-result": { faststore: "ProductGallery", confidence: 0.8 },
|
|
59615
|
+
minicart: { faststore: "Minicart", confidence: 0.9 },
|
|
59616
|
+
"add-to-cart-button": { faststore: "BuyButton", confidence: 0.9 },
|
|
59617
|
+
menu: { faststore: "Navbar", confidence: 0.7 },
|
|
59618
|
+
header: { faststore: "Navbar", confidence: 0.75 },
|
|
59619
|
+
footer: { faststore: "Footer", confidence: 0.9 },
|
|
59620
|
+
breadcrumb: { faststore: "Breadcrumb", confidence: 0.95 },
|
|
59621
|
+
"product-price": { faststore: "Price", confidence: 0.9 },
|
|
59622
|
+
"product-selling-price": { faststore: "Price", confidence: 0.85 },
|
|
59623
|
+
"product-list-price": { faststore: "Price", confidence: 0.85 },
|
|
59624
|
+
"product-images": { faststore: "ImageGallery", confidence: 0.85 },
|
|
59625
|
+
"sku-selector": { faststore: "SkuSelector", confidence: 0.85 },
|
|
59626
|
+
"product-name": { faststore: "ProductTitle", confidence: 0.85 }
|
|
59627
|
+
};
|
|
59628
|
+
function lookup(blockName) {
|
|
59629
|
+
if (TABLE[blockName])
|
|
59630
|
+
return TABLE[blockName];
|
|
59631
|
+
const head = blockName.split(".")[0];
|
|
59632
|
+
return TABLE[head] ?? null;
|
|
59633
|
+
}
|
|
59634
|
+
function mapVtexBlocksToFastStore(blocks) {
|
|
59635
|
+
const counts = new Map;
|
|
59636
|
+
for (const b of blocks)
|
|
59637
|
+
counts.set(b.blockName, (counts.get(b.blockName) ?? 0) + 1);
|
|
59638
|
+
const out = [];
|
|
59639
|
+
for (const [vtex, count] of counts) {
|
|
59640
|
+
const entry = lookup(vtex);
|
|
59641
|
+
if (entry) {
|
|
59642
|
+
out.push({ vtex, faststore: entry.faststore, confidence: entry.confidence, strategy: "mapped", count });
|
|
59643
|
+
} else {
|
|
59644
|
+
out.push({ vtex, faststore: null, confidence: 0, strategy: "custom-component", count });
|
|
59645
|
+
}
|
|
59646
|
+
}
|
|
59647
|
+
return out.sort((a, b) => b.count - a.count);
|
|
59648
|
+
}
|
|
59649
|
+
|
|
59650
|
+
// src/migrate/vtex/runtime.ts
|
|
59651
|
+
function blockNameFromTreePath(treePath) {
|
|
59652
|
+
const leaf = treePath.split("/").pop() ?? treePath;
|
|
59653
|
+
const noInstance = leaf.split("#")[0] ?? leaf;
|
|
59654
|
+
return noInstance.includes(":") ? noInstance.slice(noInstance.lastIndexOf(":") + 1) : noInstance;
|
|
59655
|
+
}
|
|
59656
|
+
function parentTreePath(treePath) {
|
|
59657
|
+
const i = treePath.lastIndexOf("/");
|
|
59658
|
+
return i > 0 ? treePath.slice(0, i) : null;
|
|
59659
|
+
}
|
|
59660
|
+
async function readVtexBlockTree(page) {
|
|
59661
|
+
let paths;
|
|
59662
|
+
try {
|
|
59663
|
+
paths = await page.evaluate(() => {
|
|
59664
|
+
const rt = window.__RUNTIME__;
|
|
59665
|
+
if (!rt || !rt.extensions || typeof rt.extensions !== "object")
|
|
59666
|
+
return null;
|
|
59667
|
+
return Object.entries(rt.extensions).map(([treePath, ext]) => ({
|
|
59668
|
+
treePath,
|
|
59669
|
+
component: ext && typeof ext === "object" && "component" in ext ? ext.component ?? null : null
|
|
59670
|
+
}));
|
|
59671
|
+
});
|
|
59672
|
+
} catch {
|
|
59673
|
+
return null;
|
|
59674
|
+
}
|
|
59675
|
+
if (!paths || paths.length === 0)
|
|
59676
|
+
return null;
|
|
59677
|
+
return paths.map((p) => ({
|
|
59678
|
+
treePath: p.treePath,
|
|
59679
|
+
blockName: blockNameFromTreePath(p.treePath),
|
|
59680
|
+
component: p.component,
|
|
59681
|
+
parent: parentTreePath(p.treePath)
|
|
59682
|
+
})).filter((b) => b.blockName.length > 0 && !b.blockName.startsWith("$"));
|
|
59683
|
+
}
|
|
59684
|
+
|
|
59685
|
+
// src/migrate/interactions.ts
|
|
59686
|
+
var MAX_INTERACTIONS = 40;
|
|
59687
|
+
function classifyE2eKey(hint, kind) {
|
|
59688
|
+
const h = hint.toLowerCase();
|
|
59689
|
+
const has2 = (...words) => words.some((w) => h.includes(w));
|
|
59690
|
+
if (has2("add to cart", "add-to-cart", "adicionar", "comprar", "buy"))
|
|
59691
|
+
return "buyButton";
|
|
59692
|
+
if (has2("checkout", "finalizar compra", "fechar pedido"))
|
|
59693
|
+
return "checkoutButton";
|
|
59694
|
+
if (kind === "input" && has2("search", "buscar", "pesquis", "q="))
|
|
59695
|
+
return "searchInput";
|
|
59696
|
+
if (has2("search", "buscar", "pesquis"))
|
|
59697
|
+
return "searchTrigger";
|
|
59698
|
+
if (has2("minicart", "mini-cart", "cart", "carrinho", "sacola", "bag", "basket"))
|
|
59699
|
+
return "minicartTrigger";
|
|
59700
|
+
if (kind === "input" && has2("email", "e-mail"))
|
|
59701
|
+
return "loginEmailInput";
|
|
59702
|
+
if (kind === "input" && has2("password", "senha"))
|
|
59703
|
+
return "loginPasswordInput";
|
|
59704
|
+
if (has2("login", "sign in", "entrar", "minha conta", "my account"))
|
|
59705
|
+
return "loginTrigger";
|
|
59706
|
+
if (has2("load more", "ver mais", "carregar mais", "show more"))
|
|
59707
|
+
return "loadMoreButton";
|
|
59708
|
+
if (has2("next", "próxima", "proxima", "próximo"))
|
|
59709
|
+
return "paginationNext";
|
|
59710
|
+
if (has2("increment", "increase", "aumentar", "qty-plus", "plus"))
|
|
59711
|
+
return "quantityIncrement";
|
|
59712
|
+
if (has2("remove", "remover", "excluir", "delete"))
|
|
59713
|
+
return "cartRemoveItem";
|
|
59714
|
+
if (has2("coupon", "cupom", "promo code"))
|
|
59715
|
+
return "cartCouponInput";
|
|
59716
|
+
return null;
|
|
59717
|
+
}
|
|
59718
|
+
async function captureInteractions(page, selector) {
|
|
59719
|
+
let raw;
|
|
59720
|
+
try {
|
|
59721
|
+
raw = await page.evaluate(({ sel, cap }) => {
|
|
59722
|
+
const root2 = document.querySelector(sel);
|
|
59723
|
+
if (!root2)
|
|
59724
|
+
return [];
|
|
59725
|
+
const hoverBases = [];
|
|
59726
|
+
const focusBases = [];
|
|
59727
|
+
const splitBases = (selectorText, pseudo, out) => {
|
|
59728
|
+
for (const part of selectorText.split(",")) {
|
|
59729
|
+
if (part.includes(pseudo)) {
|
|
59730
|
+
const base = part.split(pseudo)[0]?.trim();
|
|
59731
|
+
if (base)
|
|
59732
|
+
out.push(base);
|
|
59733
|
+
}
|
|
59734
|
+
}
|
|
59735
|
+
};
|
|
59736
|
+
for (const sheet of Array.from(document.styleSheets)) {
|
|
59737
|
+
let rules;
|
|
59738
|
+
try {
|
|
59739
|
+
rules = sheet.cssRules;
|
|
59740
|
+
} catch {
|
|
59741
|
+
continue;
|
|
59742
|
+
}
|
|
59743
|
+
for (const rule of Array.from(rules)) {
|
|
59744
|
+
const text3 = rule.selectorText;
|
|
59745
|
+
if (!text3)
|
|
59746
|
+
continue;
|
|
59747
|
+
if (text3.includes(":hover"))
|
|
59748
|
+
splitBases(text3, ":hover", hoverBases);
|
|
59749
|
+
if (text3.includes(":focus"))
|
|
59750
|
+
splitBases(text3, ":focus", focusBases);
|
|
59751
|
+
}
|
|
59752
|
+
}
|
|
59753
|
+
const matchesAny = (el, bases) => bases.some((b) => {
|
|
59754
|
+
try {
|
|
59755
|
+
return el.matches(b);
|
|
59756
|
+
} catch {
|
|
59757
|
+
return false;
|
|
59758
|
+
}
|
|
59759
|
+
});
|
|
59760
|
+
const cssEscape = (s) => window.CSS?.escape ? window.CSS.escape(s) : s.replace(/[^a-zA-Z0-9_-]/g, "\\$&");
|
|
59761
|
+
const suggestSelector = (el) => {
|
|
59762
|
+
const tag = el.tagName.toLowerCase();
|
|
59763
|
+
if (el.id)
|
|
59764
|
+
return `#${cssEscape(el.id)}`;
|
|
59765
|
+
const testid = el.getAttribute("data-testid");
|
|
59766
|
+
if (testid)
|
|
59767
|
+
return `[data-testid="${testid}"]`;
|
|
59768
|
+
for (const attr2 of Array.from(el.attributes)) {
|
|
59769
|
+
if (attr2.name.startsWith("data-") && attr2.value) {
|
|
59770
|
+
return `${tag}[${attr2.name}="${attr2.value}"]`;
|
|
59771
|
+
}
|
|
59772
|
+
}
|
|
59773
|
+
const aria = el.getAttribute("aria-label");
|
|
59774
|
+
if (aria)
|
|
59775
|
+
return `${tag}[aria-label="${aria}"]`;
|
|
59776
|
+
const semantic = Array.from(el.classList).find((c) => !/[:[\]/]/.test(c) && !/\d/.test(c) && c.length > 2);
|
|
59777
|
+
return semantic ? `${tag}.${cssEscape(semantic)}` : tag;
|
|
59778
|
+
};
|
|
59779
|
+
const nodes = Array.from(root2.querySelectorAll("a, button, input, select, [role='button'], [onclick]")).slice(0, cap);
|
|
59780
|
+
return nodes.map((el) => {
|
|
59781
|
+
const tag = el.tagName.toLowerCase();
|
|
59782
|
+
const role = el.getAttribute("role");
|
|
59783
|
+
const kind = tag === "input" ? "input" : tag === "select" ? "select" : tag === "a" ? "link" : tag === "button" || role === "button" ? "button" : "clickable";
|
|
59784
|
+
const cs = getComputedStyle(el);
|
|
59785
|
+
const transition = cs.transitionProperty && cs.transitionProperty !== "all" && cs.transitionProperty !== "none" ? `transition: ${cs.transitionProperty} ${cs.transitionDuration}` : cs.animationName && cs.animationName !== "none" ? `animation: ${cs.animationName} ${cs.animationDuration}` : null;
|
|
59786
|
+
const label = (el.getAttribute("aria-label") || (el.textContent ?? "").trim()).replace(/\s+/g, " ").slice(0, 80);
|
|
59787
|
+
const hint = [
|
|
59788
|
+
label,
|
|
59789
|
+
el.getAttribute("aria-label") ?? "",
|
|
59790
|
+
el.getAttribute("name") ?? "",
|
|
59791
|
+
el.getAttribute("placeholder") ?? "",
|
|
59792
|
+
el.getAttribute("type") ?? "",
|
|
59793
|
+
el.getAttribute("href") ?? "",
|
|
59794
|
+
el.className && typeof el.className === "string" ? el.className : ""
|
|
59795
|
+
].join(" ").toLowerCase();
|
|
59796
|
+
return {
|
|
59797
|
+
selector: suggestSelector(el),
|
|
59798
|
+
kind,
|
|
59799
|
+
label,
|
|
59800
|
+
animation: transition,
|
|
59801
|
+
hasHoverRule: matchesAny(el, hoverBases),
|
|
59802
|
+
hasFocusRule: matchesAny(el, focusBases),
|
|
59803
|
+
hint
|
|
59804
|
+
};
|
|
59805
|
+
});
|
|
59806
|
+
}, { sel: selector, cap: MAX_INTERACTIONS });
|
|
59807
|
+
} catch {
|
|
59808
|
+
return [];
|
|
59809
|
+
}
|
|
59810
|
+
return raw.map((r) => ({
|
|
59811
|
+
selector: r.selector,
|
|
59812
|
+
kind: r.kind,
|
|
59813
|
+
label: r.label,
|
|
59814
|
+
e2eKey: classifyE2eKey(r.hint, r.kind),
|
|
59815
|
+
animation: r.animation,
|
|
59816
|
+
hasHoverRule: r.hasHoverRule,
|
|
59817
|
+
hasFocusRule: r.hasFocusRule
|
|
59818
|
+
}));
|
|
59819
|
+
}
|
|
59820
|
+
|
|
59821
|
+
// src/commands/migrate.ts
|
|
59822
|
+
async function migrateCommand(opts) {
|
|
59823
|
+
const viewport = parseViewport3(opts.viewport);
|
|
59824
|
+
if (!viewport) {
|
|
59825
|
+
console.error(chalk16.red(`viewport inválido: ${opts.viewport} (use mobile|desktop|tablet)`));
|
|
59826
|
+
return 2;
|
|
59827
|
+
}
|
|
59828
|
+
const viewports = (opts.viewports ? opts.viewports.split(",") : [opts.viewport]).map((v) => parseViewport3(v.trim())).filter((v) => Boolean(v));
|
|
59829
|
+
if (viewports.length === 0) {
|
|
59830
|
+
console.error(chalk16.red(`--viewports inválido: ${opts.viewports}`));
|
|
59831
|
+
return 2;
|
|
59832
|
+
}
|
|
59833
|
+
const primaryViewport = viewports[0];
|
|
59834
|
+
if (!isValidUrl4(opts.url)) {
|
|
59835
|
+
console.error(chalk16.red(`--url inválido: ${opts.url}`));
|
|
59836
|
+
return 2;
|
|
59837
|
+
}
|
|
59838
|
+
const format = normalizeFormat2(opts.format);
|
|
59839
|
+
if (!format) {
|
|
59840
|
+
console.error(chalk16.red(`--format inválido: ${opts.format} (use md|json|both)`));
|
|
59841
|
+
return 2;
|
|
59842
|
+
}
|
|
59843
|
+
let playbook;
|
|
59844
|
+
if (opts.target) {
|
|
59845
|
+
playbook = getTargetPlaybook(opts.target);
|
|
59846
|
+
if (!playbook) {
|
|
59847
|
+
console.error(chalk16.red(`--target inválido: ${opts.target} (disponíveis: ${TARGET_NAMES.join(", ")})`));
|
|
59848
|
+
return 2;
|
|
59849
|
+
}
|
|
59850
|
+
}
|
|
59851
|
+
const allowlist = parseAllowlist2(opts.components);
|
|
59852
|
+
const host = safeHost5(opts.url);
|
|
59853
|
+
const runDir = resolve3(opts.outDir, host);
|
|
59854
|
+
mkdirSync14(runDir, { recursive: true });
|
|
59855
|
+
const browser = await launchBrowser({ headless: true });
|
|
59856
|
+
try {
|
|
59857
|
+
const themePath = resolve3(runDir, "theme.json");
|
|
59858
|
+
const assetsPath = resolve3(runDir, "assets.json");
|
|
59859
|
+
const blocksPath = resolve3(runDir, "blocks.json");
|
|
59860
|
+
let theme;
|
|
59861
|
+
let platform;
|
|
59862
|
+
let assets;
|
|
59863
|
+
let screenshots;
|
|
59864
|
+
let vtexBlocks = null;
|
|
59865
|
+
if (!opts.refresh && existsSync11(themePath) && existsSync11(assetsPath)) {
|
|
59866
|
+
theme = readJson(themePath);
|
|
59867
|
+
const meta = readJson(assetsPath);
|
|
59868
|
+
platform = meta.platform;
|
|
59869
|
+
assets = meta.assets;
|
|
59870
|
+
screenshots = meta.screenshots ?? [];
|
|
59871
|
+
if (existsSync11(blocksPath))
|
|
59872
|
+
vtexBlocks = readJson(blocksPath);
|
|
59873
|
+
console.log(chalk16.dim(" phase 1 theme+assets: cached"));
|
|
59874
|
+
} else {
|
|
59875
|
+
console.log(chalk16.dim(` phase 1 theme+assets: scraping (${viewports.join(", ")})…`));
|
|
59876
|
+
mkdirSync14(resolve3(runDir, "screenshots"), { recursive: true });
|
|
59877
|
+
const samples = [];
|
|
59878
|
+
screenshots = [];
|
|
59879
|
+
let platformSeen = null;
|
|
59880
|
+
let assetsResolved = null;
|
|
59881
|
+
for (const vp of viewports) {
|
|
59882
|
+
const ctx = await newContext(browser, { viewport: vp });
|
|
59883
|
+
const page = await ctx.newPage();
|
|
59884
|
+
try {
|
|
59885
|
+
await page.goto(opts.url, { waitUntil: "domcontentloaded", timeout: 30000 });
|
|
59886
|
+
await page.waitForLoadState("networkidle", { timeout: 8000 }).catch(() => {
|
|
59887
|
+
return;
|
|
59888
|
+
});
|
|
59889
|
+
samples.push(await scrapeThemeSamples(page));
|
|
59890
|
+
const shot = resolve3(runDir, "screenshots", `${vp}.png`);
|
|
59891
|
+
await page.screenshot({ path: shot, fullPage: true, animations: "disabled", timeout: 15000 }).then(() => screenshots.push({ viewport: vp, path: `screenshots/${vp}.png` })).catch(() => {
|
|
59892
|
+
return;
|
|
59893
|
+
});
|
|
59894
|
+
if (!assetsResolved) {
|
|
59895
|
+
platformSeen = detectPlatform({ url: opts.url, html: await page.content().catch(() => "") });
|
|
59896
|
+
const rawAssets = await collectSiteAssets(page);
|
|
59897
|
+
const fetchBytes = async (url) => await browserFetchBytes(page, url) ?? await nodeFetchBytes(url);
|
|
59898
|
+
assetsResolved = await downloadSiteAssets(rawAssets, runDir, fetchBytes);
|
|
59899
|
+
vtexBlocks = await readVtexBlockTree(page);
|
|
59900
|
+
}
|
|
59901
|
+
} finally {
|
|
59902
|
+
await page.close().catch(() => {
|
|
59903
|
+
return;
|
|
59904
|
+
});
|
|
59905
|
+
await ctx.close().catch(() => {
|
|
59906
|
+
return;
|
|
59907
|
+
});
|
|
59908
|
+
}
|
|
59909
|
+
}
|
|
59910
|
+
theme = aggregateTheme(mergeRawThemeSamples(samples));
|
|
59911
|
+
platform = platformSeen ?? "custom";
|
|
59912
|
+
assets = assetsResolved;
|
|
59913
|
+
writeFileSync19(themePath, `${JSON.stringify(theme, null, 2)}
|
|
59914
|
+
`, "utf8");
|
|
59915
|
+
writeFileSync19(assetsPath, `${JSON.stringify({ platform, assets, screenshots }, null, 2)}
|
|
59916
|
+
`, "utf8");
|
|
59917
|
+
if (vtexBlocks) {
|
|
59918
|
+
writeFileSync19(blocksPath, `${JSON.stringify(vtexBlocks, null, 2)}
|
|
59919
|
+
`, "utf8");
|
|
59920
|
+
console.log(chalk16.dim(` vtex io: ${vtexBlocks.length} blocks read from runtime`));
|
|
59921
|
+
}
|
|
59922
|
+
}
|
|
59923
|
+
const sitemapPath = resolve3(runDir, "sitemap.json");
|
|
59924
|
+
let resolvedPages;
|
|
59925
|
+
if (!opts.refresh && existsSync11(sitemapPath)) {
|
|
59926
|
+
resolvedPages = readJson(sitemapPath).pages;
|
|
59927
|
+
console.log(chalk16.dim(` phase 2 sitemap: cached (${resolvedPages.length} page(s))`));
|
|
59928
|
+
} else {
|
|
59929
|
+
console.log(chalk16.dim(" phase 2 sitemap: resolving pages…"));
|
|
59930
|
+
const ctx = await newContext(browser, { viewport: primaryViewport });
|
|
59931
|
+
const page = await ctx.newPage();
|
|
59932
|
+
let sitemapUrls = [];
|
|
59933
|
+
try {
|
|
59934
|
+
await page.goto(opts.url, { waitUntil: "domcontentloaded", timeout: 30000 });
|
|
59935
|
+
await page.waitForLoadState("networkidle", { timeout: 8000 }).catch(() => {
|
|
59936
|
+
return;
|
|
59937
|
+
});
|
|
59938
|
+
const homeHtml = await page.content().catch(() => "");
|
|
59939
|
+
resolvedPages = await resolvePages2(page, opts.url, opts.pages, homeHtml, platform);
|
|
59940
|
+
sitemapUrls = await discoverSitemapUrls(page, opts.url);
|
|
59941
|
+
} finally {
|
|
59942
|
+
await page.close().catch(() => {
|
|
59943
|
+
return;
|
|
59944
|
+
});
|
|
59945
|
+
await ctx.close().catch(() => {
|
|
59946
|
+
return;
|
|
59947
|
+
});
|
|
59948
|
+
}
|
|
59949
|
+
const classified = sitemapUrls.slice(0, 500).map((u) => ({ url: u, kind: kindOf(u) }));
|
|
59950
|
+
writeFileSync19(sitemapPath, `${JSON.stringify({ pages: resolvedPages, sitemapUrls: classified }, null, 2)}
|
|
59951
|
+
`, "utf8");
|
|
59952
|
+
}
|
|
59953
|
+
if (resolvedPages.length === 0) {
|
|
59954
|
+
console.error(chalk16.red("nenhuma página resolvida a partir de --pages"));
|
|
59955
|
+
return 1;
|
|
59956
|
+
}
|
|
59957
|
+
const capturePath = resolve3(runDir, "capture.json");
|
|
59958
|
+
let pages;
|
|
59959
|
+
let components;
|
|
59960
|
+
if (!opts.refresh && existsSync11(capturePath)) {
|
|
59961
|
+
const cached = readJson(capturePath);
|
|
59962
|
+
pages = cached.pages;
|
|
59963
|
+
components = cached.components;
|
|
59964
|
+
console.log(chalk16.dim(` phase 3 components: cached (${components.length})`));
|
|
59965
|
+
} else {
|
|
59966
|
+
console.log(chalk16.dim(" phase 3 components: capturing…"));
|
|
59967
|
+
({ pages, components } = await capturePages(browser, primaryViewport, resolvedPages, theme, {
|
|
59968
|
+
allowlist,
|
|
59969
|
+
llm: !opts.noLlm,
|
|
59970
|
+
runDir
|
|
59971
|
+
}));
|
|
59972
|
+
writeFileSync19(capturePath, `${JSON.stringify({ pages, components }, null, 2)}
|
|
59973
|
+
`, "utf8");
|
|
59974
|
+
}
|
|
59975
|
+
const bundle = {
|
|
59976
|
+
url: opts.url,
|
|
59977
|
+
timestamp: new Date().toISOString(),
|
|
59978
|
+
viewport: primaryViewport,
|
|
59979
|
+
viewports,
|
|
59980
|
+
screenshots,
|
|
59981
|
+
platform,
|
|
59982
|
+
target: opts.target,
|
|
59983
|
+
theme,
|
|
59984
|
+
assets,
|
|
59985
|
+
vtex: vtexBlocks ? { blocks: vtexBlocks, map: mapVtexBlocksToFastStore(vtexBlocks) } : undefined,
|
|
59986
|
+
pages,
|
|
59987
|
+
components
|
|
59988
|
+
};
|
|
59989
|
+
if (format === "json" || format === "both")
|
|
59990
|
+
await jsonExporter2.export(bundle, runDir);
|
|
59991
|
+
if (format === "md" || format === "both") {
|
|
59992
|
+
await markdownExporter2.export(bundle, runDir);
|
|
59993
|
+
writeFileSync19(resolve3(runDir, "MIGRATION_PROMPT.md"), buildMigrationPrompt(bundle, playbook), "utf8");
|
|
59994
|
+
}
|
|
59995
|
+
if (opts.target === "faststore") {
|
|
59996
|
+
writeFileSync19(resolve3(runDir, "custom-theme.scss"), buildFastStoreTheme(theme), "utf8");
|
|
59997
|
+
}
|
|
59998
|
+
if (bundle.vtex) {
|
|
59999
|
+
writeFileSync19(resolve3(runDir, "component-map.json"), `${JSON.stringify(bundle.vtex.map, null, 2)}
|
|
60000
|
+
`, "utf8");
|
|
60001
|
+
}
|
|
60002
|
+
if (opts.json) {
|
|
60003
|
+
console.log(JSON.stringify({ outDir: runDir, componentCount: components.length, bundle }));
|
|
60004
|
+
return 0;
|
|
60005
|
+
}
|
|
60006
|
+
printResults4(runDir, bundle);
|
|
60007
|
+
return 0;
|
|
60008
|
+
} finally {
|
|
60009
|
+
await browser.close().catch(() => {
|
|
60010
|
+
return;
|
|
60011
|
+
});
|
|
60012
|
+
}
|
|
60013
|
+
}
|
|
60014
|
+
async function capturePages(browser, viewport, resolvedPages, theme, cfg) {
|
|
60015
|
+
const pages = [];
|
|
60016
|
+
const components = [];
|
|
60017
|
+
const seenGlobalRoles = new Set;
|
|
60018
|
+
for (const target of resolvedPages) {
|
|
60019
|
+
const ctx = await newContext(browser, { viewport });
|
|
60020
|
+
const page = await ctx.newPage();
|
|
60021
|
+
const pageComponents = [];
|
|
60022
|
+
try {
|
|
60023
|
+
await page.goto(target.url, { waitUntil: "domcontentloaded", timeout: 30000 });
|
|
60024
|
+
await page.waitForLoadState("networkidle", { timeout: 8000 }).catch(() => {
|
|
60025
|
+
return;
|
|
60026
|
+
});
|
|
60027
|
+
await Promise.race([stabilizeCarousels(page).catch(() => {
|
|
60028
|
+
return;
|
|
60029
|
+
}), sleep2(3000)]);
|
|
60030
|
+
await Promise.race([scrollFullPage(page, 30000).catch(() => {
|
|
60031
|
+
return;
|
|
60032
|
+
}), sleep2(32000)]);
|
|
60033
|
+
await Promise.race([
|
|
60034
|
+
waitForSkeletonsToResolve(page, 5000).catch(() => {
|
|
60035
|
+
return;
|
|
60036
|
+
}),
|
|
60037
|
+
sleep2(5000)
|
|
60038
|
+
]);
|
|
60039
|
+
let detected = await detectComponents(page, { llm: cfg.llm });
|
|
60040
|
+
if (cfg.allowlist)
|
|
60041
|
+
detected = detected.filter((c) => matchesAllowlist2(c.role, cfg.allowlist));
|
|
60042
|
+
const signatures = await structuralSignatures(page, detected.map((d) => d.selector));
|
|
60043
|
+
const plan = planComponentDedup(detected.map((d, i) => ({ role: d.role, signature: signatures[i] ?? "" })));
|
|
60044
|
+
const pageScreenshot = await page.screenshot({ fullPage: true, animations: "disabled", timeout: 15000 }).catch(() => {
|
|
60045
|
+
return;
|
|
60046
|
+
});
|
|
60047
|
+
for (const { index: index2, repeated } of plan) {
|
|
60048
|
+
const component = detected[index2];
|
|
60049
|
+
const global = isGlobalRole(component.role);
|
|
60050
|
+
if (global && seenGlobalRoles.has(component.role))
|
|
60051
|
+
continue;
|
|
60052
|
+
if (global)
|
|
60053
|
+
seenGlobalRoles.add(component.role);
|
|
60054
|
+
const idx = components.length + 1;
|
|
60055
|
+
const componentDir = resolve3(cfg.runDir, "components", componentDirName(component.role, idx));
|
|
60056
|
+
const extracted = await extractComponent(page, component, {
|
|
60057
|
+
outDir: componentDir,
|
|
60058
|
+
index: idx,
|
|
60059
|
+
pageScreenshot
|
|
60060
|
+
});
|
|
60061
|
+
const interactions = await captureInteractions(page, component.selector);
|
|
60062
|
+
const migrated = toMigratedComponent(extracted, interactions, global ? "global" : "page", theme.tokens, repeated);
|
|
60063
|
+
components.push(migrated);
|
|
60064
|
+
if (!global)
|
|
60065
|
+
pageComponents.push(migrated);
|
|
60066
|
+
}
|
|
60067
|
+
pages.push({ url: target.url, path: target.path, kind: target.kind, components: pageComponents });
|
|
60068
|
+
} finally {
|
|
60069
|
+
await page.close().catch(() => {
|
|
60070
|
+
return;
|
|
60071
|
+
});
|
|
60072
|
+
await ctx.close().catch(() => {
|
|
60073
|
+
return;
|
|
60074
|
+
});
|
|
60075
|
+
}
|
|
60076
|
+
}
|
|
60077
|
+
return { pages, components };
|
|
60078
|
+
}
|
|
60079
|
+
async function resolvePages2(page, baseUrl, pagesSpec, homeHtml, platform) {
|
|
60080
|
+
const tokens = (pagesSpec ?? "/,category-auto,pdp-auto").split(",").map((s) => s.trim()).filter(Boolean);
|
|
60081
|
+
const out = [];
|
|
60082
|
+
const plp = pickPlpFromHomeHtml(homeHtml, baseUrl);
|
|
60083
|
+
for (const token of tokens) {
|
|
60084
|
+
if (token === "category-auto") {
|
|
60085
|
+
if (plp)
|
|
60086
|
+
out.push({ path: token, url: plp, kind: "plp" });
|
|
60087
|
+
else
|
|
60088
|
+
console.warn(chalk16.yellow(" ⚠ category-auto: nenhuma PLP descoberta na home"));
|
|
60089
|
+
continue;
|
|
60090
|
+
}
|
|
60091
|
+
if (token === "pdp-auto") {
|
|
60092
|
+
if (!plp) {
|
|
60093
|
+
console.warn(chalk16.yellow(" ⚠ pdp-auto: sem PLP pra derivar PDP"));
|
|
60094
|
+
continue;
|
|
60095
|
+
}
|
|
60096
|
+
let html3 = null;
|
|
60097
|
+
try {
|
|
60098
|
+
await page.goto(plp, { waitUntil: "domcontentloaded", timeout: 30000 });
|
|
60099
|
+
await page.waitForLoadState("networkidle", { timeout: 8000 }).catch(() => {
|
|
60100
|
+
return;
|
|
60101
|
+
});
|
|
60102
|
+
html3 = await page.content();
|
|
60103
|
+
} catch {
|
|
60104
|
+
html3 = await browserFetchText(page, plp);
|
|
60105
|
+
}
|
|
60106
|
+
const pdp = html3 ? firstProductHref(html3, plp, platform) : null;
|
|
60107
|
+
if (pdp)
|
|
60108
|
+
out.push({ path: token, url: pdp, kind: "pdp" });
|
|
60109
|
+
else
|
|
60110
|
+
console.warn(chalk16.yellow(" ⚠ pdp-auto: nenhum produto encontrado na PLP"));
|
|
60111
|
+
continue;
|
|
60112
|
+
}
|
|
60113
|
+
try {
|
|
60114
|
+
const url = new URL(token, baseUrl).toString();
|
|
60115
|
+
out.push({ path: token, url, kind: kindOf(url) });
|
|
60116
|
+
} catch {}
|
|
60117
|
+
}
|
|
60118
|
+
return out;
|
|
60119
|
+
}
|
|
60120
|
+
async function discoverSitemapUrls(page, baseUrl) {
|
|
60121
|
+
try {
|
|
60122
|
+
const origin = new URL(baseUrl).origin;
|
|
60123
|
+
const rootXml = await browserFetchText(page, `${origin}/sitemap.xml`);
|
|
60124
|
+
if (!rootXml)
|
|
60125
|
+
return [];
|
|
60126
|
+
const root2 = parseSitemap(rootXml);
|
|
60127
|
+
if (!root2.isIndex)
|
|
60128
|
+
return root2.urls;
|
|
60129
|
+
const urls = [];
|
|
60130
|
+
for (const child of root2.childSitemaps.slice(0, 5)) {
|
|
60131
|
+
const xml2 = await browserFetchText(page, child);
|
|
60132
|
+
if (xml2)
|
|
60133
|
+
urls.push(...parseSitemap(xml2).urls);
|
|
60134
|
+
if (urls.length >= 500)
|
|
60135
|
+
break;
|
|
60136
|
+
}
|
|
60137
|
+
return urls;
|
|
60138
|
+
} catch {
|
|
60139
|
+
return [];
|
|
60140
|
+
}
|
|
60141
|
+
}
|
|
60142
|
+
async function structuralSignatures(page, selectors) {
|
|
60143
|
+
try {
|
|
60144
|
+
return await page.evaluate((sels) => {
|
|
60145
|
+
return sels.map((s) => {
|
|
60146
|
+
let el = null;
|
|
60147
|
+
try {
|
|
60148
|
+
el = document.querySelector(s);
|
|
60149
|
+
} catch {
|
|
60150
|
+
return "";
|
|
60151
|
+
}
|
|
60152
|
+
if (!el)
|
|
60153
|
+
return "";
|
|
60154
|
+
const cls = Array.from(el.classList).filter((c) => !/\d/.test(c)).sort().join(".");
|
|
60155
|
+
return `${el.tagName}|${cls}|${el.children.length}`;
|
|
60156
|
+
});
|
|
60157
|
+
}, selectors);
|
|
60158
|
+
} catch {
|
|
60159
|
+
return selectors.map(() => "");
|
|
60160
|
+
}
|
|
60161
|
+
}
|
|
60162
|
+
function kindOf(url) {
|
|
60163
|
+
try {
|
|
60164
|
+
return classifyPath2(new URL(url).pathname);
|
|
60165
|
+
} catch {
|
|
60166
|
+
return "other";
|
|
60167
|
+
}
|
|
60168
|
+
}
|
|
60169
|
+
function printResults4(runDir, bundle) {
|
|
60170
|
+
console.log(chalk16.bold(`
|
|
60171
|
+
parity migrate`));
|
|
60172
|
+
console.log(chalk16.dim(` url: ${bundle.url}`));
|
|
60173
|
+
console.log(chalk16.dim(` platform: ${bundle.platform}${bundle.target ? ` → ${bundle.target}` : ""}`));
|
|
60174
|
+
console.log(chalk16.dim(` viewports:${(bundle.viewports ?? [bundle.viewport]).join(", ")}`));
|
|
60175
|
+
console.log(chalk16.dim(` theme: primary=${bundle.theme.colors.primary ?? "—"} text=${bundle.theme.colors.text ?? "—"}`));
|
|
60176
|
+
console.log(chalk16.dim(` assets: logo=${bundle.assets.logo ? "✓" : "✗"} favicon=${bundle.assets.favicon ? "✓" : "✗"} icons=${bundle.assets.icons.length}`));
|
|
60177
|
+
if (bundle.vtex) {
|
|
60178
|
+
const mapped = bundle.vtex.map.filter((m) => m.strategy === "mapped").length;
|
|
60179
|
+
console.log(chalk16.dim(` vtex io: ${bundle.vtex.blocks.length} blocks · ${mapped}/${bundle.vtex.map.length} block types mapped to FastStore`));
|
|
60180
|
+
}
|
|
60181
|
+
console.log(chalk16.dim(` pages: ${bundle.pages.map((p) => p.kind).join(", ") || "—"}`));
|
|
60182
|
+
console.log(chalk16.dim(` out: ${runDir}`));
|
|
60183
|
+
console.log("");
|
|
60184
|
+
console.log(chalk16.bold(` ${bundle.components.length} component(s):`));
|
|
60185
|
+
for (const c of bundle.components) {
|
|
60186
|
+
console.log(` ${chalk16.cyan(`${c.scope}/${c.role}`.padEnd(28))} ${chalk16.dim(`${c.tailwind.length} tw · ${c.interactions.length} interactions`)}`);
|
|
60187
|
+
}
|
|
60188
|
+
console.log("");
|
|
60189
|
+
}
|
|
60190
|
+
function readJson(path) {
|
|
60191
|
+
try {
|
|
60192
|
+
return JSON.parse(readFileSync13(path, "utf8"));
|
|
60193
|
+
} catch {
|
|
60194
|
+
return null;
|
|
60195
|
+
}
|
|
60196
|
+
}
|
|
60197
|
+
function parseAllowlist2(spec) {
|
|
60198
|
+
if (!spec || spec.trim().length === 0)
|
|
60199
|
+
return null;
|
|
60200
|
+
const set = new Set(spec.split(",").map((s) => s.trim().toLowerCase()).filter(Boolean));
|
|
60201
|
+
return set.size > 0 ? set : null;
|
|
60202
|
+
}
|
|
60203
|
+
function matchesAllowlist2(role, allowlist) {
|
|
60204
|
+
const lower = role.toLowerCase();
|
|
60205
|
+
if (allowlist.has(lower))
|
|
60206
|
+
return true;
|
|
60207
|
+
for (const name of allowlist) {
|
|
60208
|
+
if (lower.startsWith(`${name}-`))
|
|
60209
|
+
return true;
|
|
60210
|
+
}
|
|
60211
|
+
return false;
|
|
60212
|
+
}
|
|
60213
|
+
function normalizeFormat2(raw) {
|
|
60214
|
+
if (raw === "md" || raw === "json" || raw === "both")
|
|
60215
|
+
return raw;
|
|
60216
|
+
return null;
|
|
60217
|
+
}
|
|
60218
|
+
function safeHost5(url) {
|
|
60219
|
+
try {
|
|
60220
|
+
return new URL(url).host || "site";
|
|
60221
|
+
} catch {
|
|
60222
|
+
return "site";
|
|
60223
|
+
}
|
|
60224
|
+
}
|
|
60225
|
+
function isValidUrl4(s) {
|
|
60226
|
+
try {
|
|
60227
|
+
new URL(s);
|
|
60228
|
+
return true;
|
|
60229
|
+
} catch {
|
|
60230
|
+
return false;
|
|
60231
|
+
}
|
|
60232
|
+
}
|
|
60233
|
+
function sleep2(ms) {
|
|
60234
|
+
return new Promise((resolveTimeout) => setTimeout(resolveTimeout, ms));
|
|
60235
|
+
}
|
|
60236
|
+
|
|
60237
|
+
// src/commands/pr.ts
|
|
60238
|
+
import { existsSync as existsSync15, readFileSync as readFileSync16, writeFileSync as writeFileSync20 } from "node:fs";
|
|
60239
|
+
import { join as join22 } from "node:path";
|
|
60240
|
+
import chalk19 from "chalk";
|
|
60241
|
+
|
|
60242
|
+
// src/commands/run.ts
|
|
60243
|
+
import { existsSync as existsSync14, readFileSync as readFileSync15, unlinkSync as unlinkSync3 } from "node:fs";
|
|
60244
|
+
import { join as join21 } from "node:path";
|
|
60245
|
+
import chalk18 from "chalk";
|
|
60246
|
+
import ora6 from "ora";
|
|
60247
|
+
|
|
60248
|
+
// src/engine/interactive-module-prompt.ts
|
|
60249
|
+
import { createInterface } from "node:readline";
|
|
60250
|
+
var ALL_MODULE_NAMES2 = Object.keys(MODULES);
|
|
60251
|
+
async function promptForModuleSelection() {
|
|
60252
|
+
console.log("");
|
|
60253
|
+
console.log(" Select modules to run (all checked by default):");
|
|
60254
|
+
console.log("");
|
|
60255
|
+
ALL_MODULE_NAMES2.forEach((name, i) => {
|
|
60256
|
+
const def = MODULES[name];
|
|
60257
|
+
console.log(` [x] ${i + 1}. ${name.padEnd(8)} — ${def.description}`);
|
|
60258
|
+
});
|
|
60259
|
+
console.log("");
|
|
60260
|
+
const answer = await readLine(" Type numbers to UNCHECK (comma-separated), or press Enter to run all: ");
|
|
60261
|
+
if (answer === null) {
|
|
60262
|
+
console.log(" (aborted — running all modules)");
|
|
60263
|
+
return ALL_MODULE_NAMES2;
|
|
60264
|
+
}
|
|
60265
|
+
const trimmed = answer.trim();
|
|
60266
|
+
if (!trimmed)
|
|
60267
|
+
return ALL_MODULE_NAMES2;
|
|
60268
|
+
const uncheckIdx = new Set(trimmed.split(",").map((s) => Number.parseInt(s.trim(), 10)).filter((n) => Number.isInteger(n) && n >= 1 && n <= ALL_MODULE_NAMES2.length));
|
|
60269
|
+
const selected = ALL_MODULE_NAMES2.filter((_name, i) => !uncheckIdx.has(i + 1));
|
|
60270
|
+
if (selected.length === 0) {
|
|
60271
|
+
console.log(" (everything unchecked — running all modules instead)");
|
|
60272
|
+
return ALL_MODULE_NAMES2;
|
|
60273
|
+
}
|
|
60274
|
+
console.log(` running: ${selected.join(", ")}`);
|
|
60275
|
+
return selected;
|
|
60276
|
+
}
|
|
60277
|
+
function readLine(prompt) {
|
|
60278
|
+
return new Promise((resolveLine) => {
|
|
60279
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
60280
|
+
rl.question(prompt, (ans) => {
|
|
60281
|
+
rl.close();
|
|
60282
|
+
resolveLine(ans);
|
|
60283
|
+
});
|
|
60284
|
+
rl.on("SIGINT", () => {
|
|
60285
|
+
rl.close();
|
|
60286
|
+
resolveLine(null);
|
|
60287
|
+
});
|
|
60288
|
+
});
|
|
60289
|
+
}
|
|
60290
|
+
|
|
60291
|
+
// src/engine/interactive-selector-prompt.ts
|
|
60292
|
+
init_client();
|
|
60293
|
+
var forceDisabled = false;
|
|
60294
|
+
function disableInteractive() {
|
|
60295
|
+
forceDisabled = true;
|
|
60296
|
+
}
|
|
60297
|
+
function isInteractiveMode() {
|
|
60298
|
+
if (forceDisabled)
|
|
60299
|
+
return false;
|
|
60300
|
+
if (!process.stdout.isTTY || !process.stdin.isTTY)
|
|
60301
|
+
return false;
|
|
60302
|
+
if (isLlmAvailable())
|
|
60303
|
+
return false;
|
|
60304
|
+
return true;
|
|
60305
|
+
}
|
|
60306
|
+
|
|
58553
60307
|
// src/llm/aggregate-issues.ts
|
|
58554
60308
|
init_client();
|
|
58555
60309
|
var REPORT_ISSUES_TOOL = {
|
|
@@ -58963,13 +60717,13 @@ function formatMs(ms) {
|
|
|
58963
60717
|
}
|
|
58964
60718
|
|
|
58965
60719
|
// src/commands/serve.ts
|
|
58966
|
-
import { existsSync as
|
|
58967
|
-
import
|
|
60720
|
+
import { existsSync as existsSync13 } from "node:fs";
|
|
60721
|
+
import chalk17 from "chalk";
|
|
58968
60722
|
|
|
58969
60723
|
// src/server/proxy-server.ts
|
|
58970
|
-
import { existsSync as
|
|
60724
|
+
import { existsSync as existsSync12, readFileSync as readFileSync14, statSync } from "node:fs";
|
|
58971
60725
|
import { createServer } from "node:http";
|
|
58972
|
-
import { extname, join as
|
|
60726
|
+
import { extname, join as join20, normalize as normalize3, resolve as resolve4, sep } from "node:path";
|
|
58973
60727
|
var MIME = {
|
|
58974
60728
|
".html": "text/html; charset=utf-8",
|
|
58975
60729
|
".css": "text/css; charset=utf-8",
|
|
@@ -59005,8 +60759,8 @@ var STRIPPED_REQUEST_HEADERS = new Set([
|
|
|
59005
60759
|
"origin"
|
|
59006
60760
|
]);
|
|
59007
60761
|
async function startProxyServer(runDir, opts = {}) {
|
|
59008
|
-
const absRunDir =
|
|
59009
|
-
if (!
|
|
60762
|
+
const absRunDir = resolve4(runDir);
|
|
60763
|
+
if (!existsSync12(absRunDir)) {
|
|
59010
60764
|
throw new Error(`Run directory not found: ${runDir}`);
|
|
59011
60765
|
}
|
|
59012
60766
|
const server = createServer((req, res) => {
|
|
@@ -59017,9 +60771,9 @@ async function startProxyServer(runDir, opts = {}) {
|
|
|
59017
60771
|
} catch {}
|
|
59018
60772
|
});
|
|
59019
60773
|
});
|
|
59020
|
-
await new Promise((
|
|
60774
|
+
await new Promise((resolve5, reject) => {
|
|
59021
60775
|
server.once("error", reject);
|
|
59022
|
-
server.listen(opts.port ?? 0, opts.host ?? "127.0.0.1", () =>
|
|
60776
|
+
server.listen(opts.port ?? 0, opts.host ?? "127.0.0.1", () => resolve5());
|
|
59023
60777
|
});
|
|
59024
60778
|
const addr = server.address();
|
|
59025
60779
|
const port = typeof addr === "object" && addr ? addr.port : 0;
|
|
@@ -59027,13 +60781,13 @@ async function startProxyServer(runDir, opts = {}) {
|
|
|
59027
60781
|
return {
|
|
59028
60782
|
port,
|
|
59029
60783
|
url: `http://${host}:${port}/`,
|
|
59030
|
-
close: () => new Promise((
|
|
60784
|
+
close: () => new Promise((resolve5) => {
|
|
59031
60785
|
try {
|
|
59032
60786
|
server.closeAllConnections?.();
|
|
59033
60787
|
server.closeIdleConnections?.();
|
|
59034
60788
|
} catch {}
|
|
59035
|
-
server.close(() =>
|
|
59036
|
-
setTimeout(() =>
|
|
60789
|
+
server.close(() => resolve5());
|
|
60790
|
+
setTimeout(() => resolve5(), 1000);
|
|
59037
60791
|
})
|
|
59038
60792
|
};
|
|
59039
60793
|
}
|
|
@@ -59063,13 +60817,13 @@ async function handleRequest(req, res, runDir) {
|
|
|
59063
60817
|
return serveStatic(res, runDir, path);
|
|
59064
60818
|
}
|
|
59065
60819
|
function serveReportHtml(res, runDir) {
|
|
59066
|
-
const filePath =
|
|
59067
|
-
if (!
|
|
60820
|
+
const filePath = join20(runDir, "report.html");
|
|
60821
|
+
if (!existsSync12(filePath)) {
|
|
59068
60822
|
res.statusCode = 404;
|
|
59069
60823
|
res.end("report.html not found");
|
|
59070
60824
|
return;
|
|
59071
60825
|
}
|
|
59072
|
-
const html3 =
|
|
60826
|
+
const html3 = readFileSync14(filePath, "utf8");
|
|
59073
60827
|
const inject = `<script>window.__parity_proxy = "/proxy?url=";</script>`;
|
|
59074
60828
|
const out = html3.includes("</head>") ? html3.replace("</head>", `${inject}</head>`) : `${inject}${html3}`;
|
|
59075
60829
|
res.statusCode = 200;
|
|
@@ -59079,13 +60833,13 @@ function serveReportHtml(res, runDir) {
|
|
|
59079
60833
|
}
|
|
59080
60834
|
function serveStatic(res, runDir, path) {
|
|
59081
60835
|
const safePath2 = normalize3(path).replace(/^[/\\]+/, "");
|
|
59082
|
-
const filePath =
|
|
60836
|
+
const filePath = resolve4(runDir, safePath2);
|
|
59083
60837
|
if (!filePath.startsWith(runDir + sep) && filePath !== runDir) {
|
|
59084
60838
|
res.statusCode = 403;
|
|
59085
60839
|
res.end("forbidden");
|
|
59086
60840
|
return;
|
|
59087
60841
|
}
|
|
59088
|
-
if (!
|
|
60842
|
+
if (!existsSync12(filePath)) {
|
|
59089
60843
|
res.statusCode = 404;
|
|
59090
60844
|
res.end("not found");
|
|
59091
60845
|
return;
|
|
@@ -59100,7 +60854,7 @@ function serveStatic(res, runDir, path) {
|
|
|
59100
60854
|
res.statusCode = 200;
|
|
59101
60855
|
res.setHeader("content-type", MIME[ext] ?? "application/octet-stream");
|
|
59102
60856
|
res.setHeader("cache-control", "no-store");
|
|
59103
|
-
res.end(
|
|
60857
|
+
res.end(readFileSync14(filePath));
|
|
59104
60858
|
}
|
|
59105
60859
|
async function proxyRequest(req, res, targetUrl, opts = {}) {
|
|
59106
60860
|
let target;
|
|
@@ -59198,16 +60952,16 @@ async function serveRunAndBlock(runDir, opts = {}) {
|
|
|
59198
60952
|
try {
|
|
59199
60953
|
handle = await startProxyServer(runDir, { port: opts.port });
|
|
59200
60954
|
} catch (err) {
|
|
59201
|
-
console.error(
|
|
60955
|
+
console.error(chalk17.red(` ✖ Falha ao iniciar servidor: ${err.message}`));
|
|
59202
60956
|
return 2;
|
|
59203
60957
|
}
|
|
59204
60958
|
const label = opts.label ?? "parity serve";
|
|
59205
60959
|
console.log("");
|
|
59206
|
-
console.log(
|
|
59207
|
-
console.log(` ${
|
|
59208
|
-
console.log(
|
|
59209
|
-
console.log(
|
|
59210
|
-
console.log(
|
|
60960
|
+
console.log(chalk17.bold(` ${label}`));
|
|
60961
|
+
console.log(` ${chalk17.green("●")} ${handle.url}`);
|
|
60962
|
+
console.log(chalk17.dim(` Servindo: ${runDir}`));
|
|
60963
|
+
console.log(chalk17.dim(` Proxy de iframes: ${handle.url}proxy?url=<encoded>`));
|
|
60964
|
+
console.log(chalk17.dim(` Ctrl+C pra parar (2x pra forçar saída).
|
|
59211
60965
|
`));
|
|
59212
60966
|
if (opts.open !== false) {
|
|
59213
60967
|
const { default: open } = await import("open");
|
|
@@ -59239,12 +60993,12 @@ async function serveRunAndBlock(runDir, opts = {}) {
|
|
|
59239
60993
|
}
|
|
59240
60994
|
async function serveCommand(runId, opts) {
|
|
59241
60995
|
const paths = getRunPaths(opts.output, runId);
|
|
59242
|
-
if (!
|
|
59243
|
-
console.error(
|
|
60996
|
+
if (!existsSync13(paths.runDir)) {
|
|
60997
|
+
console.error(chalk17.red(`✖ Run não encontrado: ${runId} (em ${opts.output})`));
|
|
59244
60998
|
return 1;
|
|
59245
60999
|
}
|
|
59246
|
-
if (!
|
|
59247
|
-
console.error(
|
|
61000
|
+
if (!existsSync13(paths.reportHtml)) {
|
|
61001
|
+
console.error(chalk17.red(`✖ report.html não existe em ${paths.runDir}`));
|
|
59248
61002
|
return 1;
|
|
59249
61003
|
}
|
|
59250
61004
|
return serveRunAndBlock(paths.runDir, {
|
|
@@ -59375,14 +61129,14 @@ function evaluateFailOnGate(allIssues, failOn) {
|
|
|
59375
61129
|
async function runCommand(rawOpts) {
|
|
59376
61130
|
if (!rawOpts.prod) {
|
|
59377
61131
|
const target = rawOpts.cand ?? "<url>";
|
|
59378
|
-
console.error(`${
|
|
59379
|
-
For one site, use: ${
|
|
61132
|
+
console.error(`${chalk18.yellow("Single-site run?")} \`parity run\` compares two URLs (prod↔cand).
|
|
61133
|
+
For one site, use: ${chalk18.cyan(`parity e2e --url ${target}`)}
|
|
59380
61134
|
(runs the functional flows + all checks in single-site mode — no prod baseline needed).`);
|
|
59381
61135
|
return 2;
|
|
59382
61136
|
}
|
|
59383
61137
|
let opts = applyPreset(rawOpts);
|
|
59384
61138
|
if (rawOpts.preset) {
|
|
59385
|
-
console.log(
|
|
61139
|
+
console.log(chalk18.dim(` preset: ${rawOpts.preset}`));
|
|
59386
61140
|
}
|
|
59387
61141
|
if (opts.pt)
|
|
59388
61142
|
setLlmLanguage("pt");
|
|
@@ -59390,14 +61144,14 @@ async function runCommand(rawOpts) {
|
|
|
59390
61144
|
disableInteractive();
|
|
59391
61145
|
const llmCfgErr = applyLlmOptions(opts);
|
|
59392
61146
|
if (llmCfgErr) {
|
|
59393
|
-
console.error(
|
|
61147
|
+
console.error(chalk18.red(` ${llmCfgErr}`));
|
|
59394
61148
|
return 2;
|
|
59395
61149
|
}
|
|
59396
61150
|
const llmStillAvailable = isLlmAvailable();
|
|
59397
61151
|
const preSmart = opts;
|
|
59398
61152
|
opts = applySmartDefaults(opts, llmStillAvailable);
|
|
59399
61153
|
if (!llmStillAvailable && opts.visualPages !== preSmart.visualPages) {
|
|
59400
|
-
console.log(
|
|
61154
|
+
console.log(chalk18.dim(" visual-pages auto-set to 0 (no LLM available — analysis layer would be skipped; opt in with --visual-pages N)"));
|
|
59401
61155
|
}
|
|
59402
61156
|
let interactivePromptShown = false;
|
|
59403
61157
|
if (!opts.only && !opts.skip && !rawOpts.preset) {
|
|
@@ -59411,10 +61165,10 @@ async function runCommand(rawOpts) {
|
|
|
59411
61165
|
}
|
|
59412
61166
|
const selection = resolveSelection({ only: opts.only, skip: opts.skip });
|
|
59413
61167
|
if (selection.errors.length > 0) {
|
|
59414
|
-
console.error(
|
|
61168
|
+
console.error(chalk18.red(" --only/--skip: invalid value(s):"));
|
|
59415
61169
|
for (const e of selection.errors)
|
|
59416
|
-
console.error(
|
|
59417
|
-
console.error(
|
|
61170
|
+
console.error(chalk18.red(` - ${e}`));
|
|
61171
|
+
console.error(chalk18.dim(`
|
|
59418
61172
|
valid modules: ${Object.keys(MODULES).join(", ")}`));
|
|
59419
61173
|
return 2;
|
|
59420
61174
|
}
|
|
@@ -59425,16 +61179,16 @@ async function runCommand(rawOpts) {
|
|
|
59425
61179
|
if (hasSelection) {
|
|
59426
61180
|
const explicitFlows = userSetFlows ? opts.flows.split(",").map((s) => s.trim()).filter(Boolean) : [];
|
|
59427
61181
|
flows2 = Array.from(new Set([...explicitFlows, ...selection.flows]));
|
|
59428
|
-
console.log(
|
|
61182
|
+
console.log(chalk18.dim(` modules: ${selection.modules.join(", ") || "(none)"} → flows: ${flows2.join(",")}`));
|
|
59429
61183
|
} else {
|
|
59430
61184
|
flows2 = opts.flows.split(",").map((s) => s.trim());
|
|
59431
61185
|
if (!interactivePromptShown) {
|
|
59432
|
-
console.log(
|
|
61186
|
+
console.log(chalk18.dim(" no --only/--skip given — running ALL modules; pass --only to scope the run for a lighter/faster result"));
|
|
59433
61187
|
}
|
|
59434
61188
|
}
|
|
59435
61189
|
const pagesScopeWarning = pagesFlowsScopeWarning(opts, flows2);
|
|
59436
61190
|
if (pagesScopeWarning) {
|
|
59437
|
-
console.log(
|
|
61191
|
+
console.log(chalk18.dim(` ${pagesScopeWarning}`));
|
|
59438
61192
|
}
|
|
59439
61193
|
if (hasSelection) {
|
|
59440
61194
|
const needsSitemapPages = selection.modules.some((m) => MODULES[m].needsSitemapPages);
|
|
@@ -59443,12 +61197,12 @@ async function runCommand(rawOpts) {
|
|
|
59443
61197
|
const VISUAL_PAGES_DEFAULT = 5;
|
|
59444
61198
|
if (!needsSitemapPages && opts.vitalsPages === VITALS_PAGES_DEFAULT) {
|
|
59445
61199
|
opts.vitalsPages = 0;
|
|
59446
|
-
console.log(
|
|
61200
|
+
console.log(chalk18.dim(" vitals-pages auto-set to 0 (no selected module needs sitemap-page crawling)"));
|
|
59447
61201
|
}
|
|
59448
61202
|
if (!needsLlmPass && opts.visualPages === VISUAL_PAGES_DEFAULT) {
|
|
59449
61203
|
opts.visualPages = 0;
|
|
59450
61204
|
opts.noVisualDiff = true;
|
|
59451
|
-
console.log(
|
|
61205
|
+
console.log(chalk18.dim(" visual-pages auto-set to 0 (no selected module needs the visual-diff pass)"));
|
|
59452
61206
|
}
|
|
59453
61207
|
}
|
|
59454
61208
|
const viewports = opts.viewports.split(",").map((s) => s.trim());
|
|
@@ -59460,38 +61214,38 @@ async function runCommand(rawOpts) {
|
|
|
59460
61214
|
}
|
|
59461
61215
|
const ignore = loadParityIgnore();
|
|
59462
61216
|
if (opts.clearCache) {
|
|
59463
|
-
const cacheFile =
|
|
59464
|
-
if (
|
|
61217
|
+
const cacheFile = join21(opts.output, "cache", "verdicts.json");
|
|
61218
|
+
if (existsSync14(cacheFile)) {
|
|
59465
61219
|
try {
|
|
59466
61220
|
unlinkSync3(cacheFile);
|
|
59467
|
-
console.log(
|
|
61221
|
+
console.log(chalk18.dim(` cache wiped: ${cacheFile}`));
|
|
59468
61222
|
} catch (err) {
|
|
59469
|
-
console.log(
|
|
61223
|
+
console.log(chalk18.yellow(` cache wipe falhou: ${err.message}`));
|
|
59470
61224
|
}
|
|
59471
61225
|
}
|
|
59472
61226
|
}
|
|
59473
61227
|
const llmTimeoutRaw = opts.llmTimeout ?? 60;
|
|
59474
61228
|
if (!Number.isFinite(llmTimeoutRaw)) {
|
|
59475
|
-
console.error(
|
|
61229
|
+
console.error(chalk18.red(` --llm-timeout inválido: "${opts.llmTimeout}" não é um número`));
|
|
59476
61230
|
return 2;
|
|
59477
61231
|
}
|
|
59478
61232
|
const llmTimeoutSec = Math.max(5, Math.floor(llmTimeoutRaw));
|
|
59479
61233
|
if (isLlmAvailable()) {
|
|
59480
|
-
console.log(
|
|
61234
|
+
console.log(chalk18.dim(` llm: ${providerLabel()} (timeout=${llmTimeoutSec}s)`));
|
|
59481
61235
|
} else {
|
|
59482
|
-
console.log(
|
|
61236
|
+
console.log(chalk18.dim(" llm: offline (LLM keys ausentes — agregação heurística)"));
|
|
59483
61237
|
}
|
|
59484
61238
|
if (isInteractiveMode()) {
|
|
59485
|
-
console.log(
|
|
61239
|
+
console.log(chalk18.dim(" interactive: enabled — TTY + no LLM. Missing selectors will pause to prompt (disable with --no-interactive). Issue #72."));
|
|
59486
61240
|
}
|
|
59487
61241
|
const primaryViewport = viewports[0] ?? "mobile";
|
|
59488
61242
|
const preflight = await preflightCheck(opts.prod, opts.cand, primaryViewport);
|
|
59489
61243
|
if (!preflight.ok) {
|
|
59490
|
-
console.error(
|
|
61244
|
+
console.error(chalk18.red(`
|
|
59491
61245
|
✖ pre-flight falhou:`));
|
|
59492
61246
|
for (const err of preflight.errors)
|
|
59493
|
-
console.error(
|
|
59494
|
-
console.error(
|
|
61247
|
+
console.error(chalk18.red(` - ${err}`));
|
|
61248
|
+
console.error(chalk18.dim(`
|
|
59495
61249
|
dica: verifique se as URLs estão corretas e acessíveis`));
|
|
59496
61250
|
return 2;
|
|
59497
61251
|
}
|
|
@@ -59502,7 +61256,7 @@ async function runCommand(rawOpts) {
|
|
|
59502
61256
|
if (prodHomeHtml) {
|
|
59503
61257
|
platform = detectPlatform({ url: opts.prod, html: prodHomeHtml });
|
|
59504
61258
|
if (platform !== "custom") {
|
|
59505
|
-
console.log(
|
|
61259
|
+
console.log(chalk18.dim(` Detected platform: ${platform}`));
|
|
59506
61260
|
}
|
|
59507
61261
|
}
|
|
59508
61262
|
const prodHost = hostOf3(opts.prod);
|
|
@@ -59537,11 +61291,11 @@ async function runCommand(rawOpts) {
|
|
|
59537
61291
|
viewports,
|
|
59538
61292
|
timestamp
|
|
59539
61293
|
});
|
|
59540
|
-
console.log(
|
|
61294
|
+
console.log(chalk18.bold(`
|
|
59541
61295
|
parity run ${runId}`));
|
|
59542
|
-
console.log(
|
|
59543
|
-
console.log(
|
|
59544
|
-
console.log(
|
|
61296
|
+
console.log(chalk18.dim(` prod: ${opts.prod}`));
|
|
61297
|
+
console.log(chalk18.dim(` cand: ${opts.cand}`));
|
|
61298
|
+
console.log(chalk18.dim(` flows: ${flows2.join(", ")} · viewports: ${viewports.join(", ")} · CEP: ${rc.cep}
|
|
59545
61299
|
`));
|
|
59546
61300
|
const spinner = ora6("Launching browser…").start();
|
|
59547
61301
|
let browser = null;
|
|
@@ -59553,7 +61307,7 @@ async function runCommand(rawOpts) {
|
|
|
59553
61307
|
const min = Math.floor(elapsedSec / 60);
|
|
59554
61308
|
const sec = elapsedSec % 60;
|
|
59555
61309
|
const mmss = `${min.toString().padStart(2, "0")}:${sec.toString().padStart(2, "0")}`;
|
|
59556
|
-
spinner.text = `${
|
|
61310
|
+
spinner.text = `${chalk18.dim(`⏱ ${mmss} ·`)} ${currentSpinnerLabel}`;
|
|
59557
61311
|
};
|
|
59558
61312
|
const setSpinnerLabel = (label) => {
|
|
59559
61313
|
currentSpinnerLabel = label;
|
|
@@ -59578,7 +61332,7 @@ async function runCommand(rawOpts) {
|
|
|
59578
61332
|
b.close().catch(() => {
|
|
59579
61333
|
return;
|
|
59580
61334
|
}),
|
|
59581
|
-
new Promise((
|
|
61335
|
+
new Promise((resolve5) => setTimeout(resolve5, capMs))
|
|
59582
61336
|
]);
|
|
59583
61337
|
};
|
|
59584
61338
|
const shutdown = async (reason) => {
|
|
@@ -59657,8 +61411,8 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
59657
61411
|
const traceEnabled = process.env.PARITY_TRACE === "1";
|
|
59658
61412
|
const runOneSide = async (viewport, side) => {
|
|
59659
61413
|
const baseUrl = side === "prod" ? opts.prod : opts.cand;
|
|
59660
|
-
const harPath =
|
|
59661
|
-
const tracePath = traceEnabled ?
|
|
61414
|
+
const harPath = join21(paths.harDir, `${viewport}-${side}.har`);
|
|
61415
|
+
const tracePath = traceEnabled ? join21(paths.tracesDir, `${viewport}-${side}.zip`) : null;
|
|
59662
61416
|
const ctx = await newContext(browser, {
|
|
59663
61417
|
viewport,
|
|
59664
61418
|
harPath,
|
|
@@ -59673,8 +61427,8 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
59673
61427
|
for (const flow of flows2) {
|
|
59674
61428
|
const flowStart = Date.now();
|
|
59675
61429
|
let lastStepTotal = 0;
|
|
59676
|
-
const sideTag = side === "prod" ?
|
|
59677
|
-
const prefix = `${
|
|
61430
|
+
const sideTag = side === "prod" ? chalk18.cyan("prod") : chalk18.magenta("cand");
|
|
61431
|
+
const prefix = `${chalk18.dim(`[${viewport}/`)}${sideTag}${chalk18.dim("]")}`;
|
|
59678
61432
|
setSpinnerLabel(`${prefix} ${flow}: starting…`);
|
|
59679
61433
|
const cap = await runFlow(flow, {
|
|
59680
61434
|
baseUrl,
|
|
@@ -59691,7 +61445,7 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
59691
61445
|
onStep: (event) => {
|
|
59692
61446
|
if (event.phase === "start") {
|
|
59693
61447
|
lastStepTotal = event.total;
|
|
59694
|
-
setSpinnerLabel(`${prefix} ${flow} ${
|
|
61448
|
+
setSpinnerLabel(`${prefix} ${flow} ${chalk18.dim(`${event.index}/${event.total}`)} ${event.name}…`);
|
|
59695
61449
|
}
|
|
59696
61450
|
}
|
|
59697
61451
|
});
|
|
@@ -59700,18 +61454,18 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
59700
61454
|
const target = lastStepTotal || recorded;
|
|
59701
61455
|
const failed = cap.steps?.find((s) => s.status === "failed");
|
|
59702
61456
|
const lastStep = cap.steps?.[cap.steps.length - 1];
|
|
59703
|
-
const elapsedDim =
|
|
59704
|
-
const counts = target > 0 ?
|
|
61457
|
+
const elapsedDim = chalk18.dim(`${((Date.now() - flowStart) / 1000).toFixed(1)}s`);
|
|
61458
|
+
const counts = target > 0 ? chalk18.dim(`${okSteps}/${target}`) : "";
|
|
59705
61459
|
let glyph;
|
|
59706
61460
|
let detail;
|
|
59707
61461
|
if (failed) {
|
|
59708
|
-
glyph =
|
|
59709
|
-
detail = `stopped at ${
|
|
61462
|
+
glyph = chalk18.red("✗");
|
|
61463
|
+
detail = `stopped at ${chalk18.yellow(failed.name)}`;
|
|
59710
61464
|
} else if (target > 0 && okSteps < target) {
|
|
59711
|
-
glyph =
|
|
59712
|
-
detail = lastStep ? `ended at ${
|
|
61465
|
+
glyph = chalk18.yellow("▴");
|
|
61466
|
+
detail = lastStep ? `ended at ${chalk18.dim(lastStep.name)}` : "incomplete";
|
|
59713
61467
|
} else {
|
|
59714
|
-
glyph =
|
|
61468
|
+
glyph = chalk18.green("✓");
|
|
59715
61469
|
detail = "";
|
|
59716
61470
|
}
|
|
59717
61471
|
const summary = `${glyph} ${prefix} ${flow} ${counts} ${detail} ${elapsedDim}`.replace(/\s+/g, " ").trim();
|
|
@@ -59773,7 +61527,7 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
59773
61527
|
const vitalsPagesLimit = opts.vitalsPages ?? vitalsPagesDefault;
|
|
59774
61528
|
const vitalsRuns = Math.max(1, Number.parseInt(opts.runs, 10) || 1);
|
|
59775
61529
|
if (candIsDevServer && vitalsPagesLimit > 0) {
|
|
59776
|
-
console.log(
|
|
61530
|
+
console.log(chalk18.dim(` cand=localhost detectado — vitals-pages=${vitalsPagesLimit}, networkidle desabilitado (issue #55)`));
|
|
59777
61531
|
}
|
|
59778
61532
|
if (browser && vitalsPagesLimit > 0) {
|
|
59779
61533
|
currentPhase = "vitals-pages";
|
|
@@ -59854,8 +61608,8 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
59854
61608
|
noNetworkIdle: targetIsDevServer,
|
|
59855
61609
|
runs: vitalsRuns
|
|
59856
61610
|
}),
|
|
59857
|
-
new Promise((
|
|
59858
|
-
const t = setTimeout(() =>
|
|
61611
|
+
new Promise((resolve5) => {
|
|
61612
|
+
const t = setTimeout(() => resolve5(null), PER_TASK_WALLCLOCK_MS);
|
|
59859
61613
|
t.unref?.();
|
|
59860
61614
|
})
|
|
59861
61615
|
]);
|
|
@@ -59974,7 +61728,7 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
59974
61728
|
setSpinnerLabel("Rodando checks…");
|
|
59975
61729
|
spinner.start();
|
|
59976
61730
|
const checksHb = attachSpinnerHeartbeat(spinner, { baseText: "Rodando checks…" });
|
|
59977
|
-
const cacheDir =
|
|
61731
|
+
const cacheDir = join21(opts.output, "cache");
|
|
59978
61732
|
const checkCtx = {
|
|
59979
61733
|
prodPages: allPageCaptures.filter((p) => p.side === "prod"),
|
|
59980
61734
|
candPages: allPageCaptures.filter((p) => p.side === "cand"),
|
|
@@ -60096,7 +61850,7 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
60096
61850
|
${formatTimingsSummary(runTimings, buildFlowBreakdown(allFlowCaptures))}`);
|
|
60097
61851
|
const failOnGate = evaluateFailOnGate(allIssues, failOn);
|
|
60098
61852
|
if (failOnGate.exitCode === 1) {
|
|
60099
|
-
console.log(
|
|
61853
|
+
console.log(chalk18.red(failOnGate.message));
|
|
60100
61854
|
return 1;
|
|
60101
61855
|
}
|
|
60102
61856
|
if (opts.open) {
|
|
@@ -60156,10 +61910,10 @@ function buildPartialRun(args) {
|
|
|
60156
61910
|
}
|
|
60157
61911
|
function resolveExplicitPages(pagesFile, pagesList) {
|
|
60158
61912
|
if (pagesFile) {
|
|
60159
|
-
if (!
|
|
61913
|
+
if (!existsSync14(pagesFile)) {
|
|
60160
61914
|
throw new Error(`--pages-file não encontrado: ${pagesFile}`);
|
|
60161
61915
|
}
|
|
60162
|
-
const raw =
|
|
61916
|
+
const raw = readFileSync15(pagesFile, "utf-8");
|
|
60163
61917
|
const lines = raw.split(/\r?\n/).map((l) => l.trim()).filter((l) => l.length > 0 && !l.startsWith("#"));
|
|
60164
61918
|
return lines.map(normalizePath);
|
|
60165
61919
|
}
|
|
@@ -60310,44 +62064,44 @@ function hostOf3(url) {
|
|
|
60310
62064
|
}
|
|
60311
62065
|
function printSummary5(run, htmlPath, meta) {
|
|
60312
62066
|
const { verdict: verdict2 } = run;
|
|
60313
|
-
const emoji = verdict2.status === "pass" ?
|
|
60314
|
-
const score = verdict2.status === "pass" ?
|
|
62067
|
+
const emoji = verdict2.status === "pass" ? chalk18.green("✔") : verdict2.status === "warn" ? chalk18.yellow("⚠") : chalk18.red("✖");
|
|
62068
|
+
const score = verdict2.status === "pass" ? chalk18.green(verdict2.score) : verdict2.status === "warn" ? chalk18.yellow(verdict2.score) : chalk18.red(verdict2.score);
|
|
60315
62069
|
const prev2 = run.previousRun;
|
|
60316
|
-
const scoreDelta = !prev2 ?
|
|
62070
|
+
const scoreDelta = !prev2 ? chalk18.dim(" (sem run anterior comparável)") : prev2.scoreDelta > 0 ? chalk18.green(` (+${prev2.scoreDelta} vs run anterior: ${prev2.score})`) : prev2.scoreDelta < 0 ? chalk18.red(` (${prev2.scoreDelta} vs run anterior: ${prev2.score})`) : chalk18.dim(` (= run anterior: ${prev2.score})`);
|
|
60317
62071
|
console.log("");
|
|
60318
62072
|
console.log(` ${emoji} parity ${verdict2.status.toUpperCase()} · score ${score}/100${scoreDelta}`);
|
|
60319
|
-
console.log(` checks: ${
|
|
60320
|
-
console.log(` issues: ${
|
|
62073
|
+
console.log(` checks: ${chalk18.green(verdict2.checksPassed)} pass · ${chalk18.red(verdict2.checksFailed)} fail · ${chalk18.dim(`${verdict2.checksSkipped} skipped`)}`);
|
|
62074
|
+
console.log(` issues: ${chalk18.red(verdict2.critical)} critical · ${chalk18.yellow(verdict2.high)} high · ${verdict2.medium} medium · ${chalk18.dim(`${verdict2.low} low`)}`);
|
|
60321
62075
|
if (run.moduleVerdicts && run.moduleVerdicts.length > 0) {
|
|
60322
62076
|
const perModule = run.moduleVerdicts.map((mv) => {
|
|
60323
|
-
const colored = mv.status === "pass" ?
|
|
62077
|
+
const colored = mv.status === "pass" ? chalk18.green(mv.score) : mv.status === "warn" ? chalk18.yellow(mv.score) : chalk18.red(mv.score);
|
|
60324
62078
|
return `${mv.module} ${colored}`;
|
|
60325
62079
|
}).join(" · ");
|
|
60326
62080
|
console.log(` modules: ${perModule} → composite ${score}`);
|
|
60327
62081
|
}
|
|
60328
62082
|
if (run.visualDiff) {
|
|
60329
62083
|
const vd = run.visualDiff;
|
|
60330
|
-
const parityIcon = vd.parityOk ?
|
|
60331
|
-
const parityLabel = vd.parityOk ?
|
|
60332
|
-
const cacheNote = vd.pagesFromCache > 0 ?
|
|
60333
|
-
console.log(` visual: ${parityIcon} parityOk=${parityLabel} · ${vd.pagesChecked} pages · ${
|
|
62084
|
+
const parityIcon = vd.parityOk ? chalk18.green("✔") : chalk18.red("✖");
|
|
62085
|
+
const parityLabel = vd.parityOk ? chalk18.green("OK") : chalk18.red("DIFFS");
|
|
62086
|
+
const cacheNote = vd.pagesFromCache > 0 ? chalk18.dim(` · ${vd.pagesFromCache} cached`) : "";
|
|
62087
|
+
console.log(` visual: ${parityIcon} parityOk=${parityLabel} · ${vd.pagesChecked} pages · ${chalk18.red(vd.pagesWithDiffs)} diffs · ${chalk18.green(vd.pagesPassed)} pass${cacheNote}`);
|
|
60334
62088
|
}
|
|
60335
62089
|
if (run.topIssues.length > 0) {
|
|
60336
62090
|
console.log("");
|
|
60337
|
-
console.log(
|
|
62091
|
+
console.log(chalk18.bold(" Top issues:"));
|
|
60338
62092
|
for (const g of groupIssues(run.topIssues).slice(0, 5)) {
|
|
60339
62093
|
const i = g.sample;
|
|
60340
|
-
const sev = i.severity === "critical" ?
|
|
60341
|
-
const pagesNote = g.pages.length > 1 ?
|
|
62094
|
+
const sev = i.severity === "critical" ? chalk18.red(`[${i.severity}]`) : i.severity === "high" ? chalk18.yellow(`[${i.severity}]`) : chalk18.dim(`[${i.severity}]`);
|
|
62095
|
+
const pagesNote = g.pages.length > 1 ? chalk18.dim(` (${g.pages.length} páginas)`) : "";
|
|
60342
62096
|
console.log(` ${sev} ${i.summary}${pagesNote}`);
|
|
60343
62097
|
}
|
|
60344
62098
|
}
|
|
60345
62099
|
if (meta.promotedCount > 0 || meta.deprecatedCount > 0) {
|
|
60346
62100
|
console.log("");
|
|
60347
|
-
console.log(
|
|
62101
|
+
console.log(chalk18.dim(` \uD83D\uDCDA learned-selectors [${meta.platform}]: ${chalk18.green(`+${meta.promotedCount}`)} promoted · ${chalk18.yellow(meta.deprecatedCount)} deprecated`));
|
|
60348
62102
|
}
|
|
60349
62103
|
console.log("");
|
|
60350
|
-
console.log(
|
|
62104
|
+
console.log(chalk18.dim(` → ${htmlPath}`));
|
|
60351
62105
|
console.log("");
|
|
60352
62106
|
}
|
|
60353
62107
|
|
|
@@ -60371,26 +62125,26 @@ async function prCommand(opts) {
|
|
|
60371
62125
|
preset: opts.preset ?? "ci",
|
|
60372
62126
|
open: false
|
|
60373
62127
|
};
|
|
60374
|
-
console.log(
|
|
60375
|
-
console.log(
|
|
62128
|
+
console.log(chalk19.dim(` prod : ${opts.prod}`));
|
|
62129
|
+
console.log(chalk19.dim(` preview : ${opts.preview}`));
|
|
60376
62130
|
console.log("");
|
|
60377
62131
|
const runCode = await runCommand(runOpts);
|
|
60378
62132
|
const runs = listRuns(opts.output);
|
|
60379
62133
|
if (runs.length === 0) {
|
|
60380
|
-
console.error(
|
|
62134
|
+
console.error(chalk19.red("no run was produced — cannot build PR comment"));
|
|
60381
62135
|
return runCode || 1;
|
|
60382
62136
|
}
|
|
60383
62137
|
const latest = runs[0];
|
|
60384
|
-
const reportJsonPath =
|
|
60385
|
-
if (!
|
|
60386
|
-
console.error(
|
|
62138
|
+
const reportJsonPath = join22(opts.output, "runs", latest.id, "report.json");
|
|
62139
|
+
if (!existsSync15(reportJsonPath)) {
|
|
62140
|
+
console.error(chalk19.red(`report.json not found at ${reportJsonPath}`));
|
|
60387
62141
|
return runCode || 1;
|
|
60388
62142
|
}
|
|
60389
|
-
const run = JSON.parse(
|
|
62143
|
+
const run = JSON.parse(readFileSync16(reportJsonPath, "utf8"));
|
|
60390
62144
|
const markdown = buildPrComment(run, opts);
|
|
60391
62145
|
if (opts.out) {
|
|
60392
|
-
|
|
60393
|
-
console.log(
|
|
62146
|
+
writeFileSync20(opts.out, markdown, "utf8");
|
|
62147
|
+
console.log(chalk19.dim(` wrote PR comment: ${opts.out}`));
|
|
60394
62148
|
} else {
|
|
60395
62149
|
process.stdout.write(`
|
|
60396
62150
|
${markdown}
|
|
@@ -60398,9 +62152,9 @@ ${markdown}
|
|
|
60398
62152
|
}
|
|
60399
62153
|
if (opts.github && process.env.GITHUB_STEP_SUMMARY) {
|
|
60400
62154
|
try {
|
|
60401
|
-
|
|
62155
|
+
writeFileSync20(process.env.GITHUB_STEP_SUMMARY, markdown, { flag: "a" });
|
|
60402
62156
|
} catch (err) {
|
|
60403
|
-
console.error(
|
|
62157
|
+
console.error(chalk19.yellow(`failed to write GITHUB_STEP_SUMMARY: ${err.message}`));
|
|
60404
62158
|
}
|
|
60405
62159
|
}
|
|
60406
62160
|
return runCode;
|
|
@@ -60459,14 +62213,14 @@ function buildPrComment(run, opts) {
|
|
|
60459
62213
|
}
|
|
60460
62214
|
|
|
60461
62215
|
// src/commands/prompt.ts
|
|
60462
|
-
import { existsSync as
|
|
60463
|
-
import
|
|
62216
|
+
import { existsSync as existsSync16, writeFileSync as writeFileSync21 } from "node:fs";
|
|
62217
|
+
import chalk20 from "chalk";
|
|
60464
62218
|
function promptCommand(runId, opts) {
|
|
60465
62219
|
let run;
|
|
60466
62220
|
try {
|
|
60467
62221
|
run = loadRun(opts.output, runId);
|
|
60468
62222
|
} catch (err) {
|
|
60469
|
-
console.error(
|
|
62223
|
+
console.error(chalk20.red(`✖ ${err.message}`));
|
|
60470
62224
|
return 1;
|
|
60471
62225
|
}
|
|
60472
62226
|
const md = buildLlmPrompt(run, {
|
|
@@ -60474,11 +62228,11 @@ function promptCommand(runId, opts) {
|
|
|
60474
62228
|
limit: opts.limit
|
|
60475
62229
|
});
|
|
60476
62230
|
if (opts.out) {
|
|
60477
|
-
|
|
60478
|
-
console.log(
|
|
60479
|
-
if (
|
|
62231
|
+
writeFileSync21(opts.out, md, "utf8");
|
|
62232
|
+
console.log(chalk20.green(`✔ prompt salvo em ${opts.out}`));
|
|
62233
|
+
if (existsSync16(opts.out)) {
|
|
60480
62234
|
const sizeKb = (md.length / 1024).toFixed(1);
|
|
60481
|
-
console.log(
|
|
62235
|
+
console.log(chalk20.dim(` ${md.length} chars (${sizeKb} KB)`));
|
|
60482
62236
|
}
|
|
60483
62237
|
} else {
|
|
60484
62238
|
process.stdout.write(md);
|
|
@@ -60487,8 +62241,8 @@ function promptCommand(runId, opts) {
|
|
|
60487
62241
|
}
|
|
60488
62242
|
|
|
60489
62243
|
// src/commands/report.ts
|
|
60490
|
-
import { existsSync as
|
|
60491
|
-
import
|
|
62244
|
+
import { existsSync as existsSync17, readFileSync as readFileSync17 } from "node:fs";
|
|
62245
|
+
import chalk21 from "chalk";
|
|
60492
62246
|
import open from "open";
|
|
60493
62247
|
|
|
60494
62248
|
// src/report/extract-section.ts
|
|
@@ -60637,41 +62391,41 @@ async function reportCommand(runId, opts) {
|
|
|
60637
62391
|
const run = loadRun(opts.output, runId);
|
|
60638
62392
|
const payload = extractReportSection({ kind: "json", section: opts.section, run });
|
|
60639
62393
|
if (payload === null) {
|
|
60640
|
-
console.error(
|
|
62394
|
+
console.error(chalk21.red(`section "${opts.section}" not present in this run`));
|
|
60641
62395
|
return 1;
|
|
60642
62396
|
}
|
|
60643
62397
|
process.stdout.write(`${JSON.stringify(payload, null, 2)}
|
|
60644
62398
|
`);
|
|
60645
62399
|
return 0;
|
|
60646
62400
|
} catch (err) {
|
|
60647
|
-
console.error(
|
|
62401
|
+
console.error(chalk21.red(`failed to load run: ${err.message}`));
|
|
60648
62402
|
return 1;
|
|
60649
62403
|
}
|
|
60650
62404
|
}
|
|
60651
|
-
if (!
|
|
60652
|
-
console.error(
|
|
62405
|
+
if (!existsSync17(paths.reportHtml)) {
|
|
62406
|
+
console.error(chalk21.red(`report.html not found at ${paths.reportHtml}`));
|
|
60653
62407
|
return 1;
|
|
60654
62408
|
}
|
|
60655
|
-
const html3 =
|
|
62409
|
+
const html3 = readFileSync17(paths.reportHtml, "utf8");
|
|
60656
62410
|
const slice2 = extractReportSection({ kind: "html", section: opts.section, html: html3 });
|
|
60657
62411
|
if (slice2 === null) {
|
|
60658
|
-
console.error(
|
|
62412
|
+
console.error(chalk21.red(`section "${opts.section}" not present in this report`));
|
|
60659
62413
|
return 1;
|
|
60660
62414
|
}
|
|
60661
62415
|
process.stdout.write(slice2);
|
|
60662
62416
|
return 0;
|
|
60663
62417
|
}
|
|
60664
|
-
console.log(
|
|
62418
|
+
console.log(chalk21.dim(`opening ${paths.reportHtml}`));
|
|
60665
62419
|
await open(paths.reportHtml).catch((err) => {
|
|
60666
|
-
console.error(
|
|
62420
|
+
console.error(chalk21.red(`failed to open: ${err.message}`));
|
|
60667
62421
|
});
|
|
60668
62422
|
return 0;
|
|
60669
62423
|
}
|
|
60670
62424
|
|
|
60671
62425
|
// src/commands/vitals.ts
|
|
60672
|
-
import { existsSync as
|
|
60673
|
-
import { join as
|
|
60674
|
-
import
|
|
62426
|
+
import { existsSync as existsSync18, readFileSync as readFileSync18, writeFileSync as writeFileSync22 } from "node:fs";
|
|
62427
|
+
import { join as join23 } from "node:path";
|
|
62428
|
+
import chalk22 from "chalk";
|
|
60675
62429
|
import ora7 from "ora";
|
|
60676
62430
|
async function vitalsCommand(opts) {
|
|
60677
62431
|
const viewports = opts.viewports.split(",").map((s) => s.trim()).filter((s) => s === "mobile" || s === "desktop");
|
|
@@ -60679,10 +62433,10 @@ async function vitalsCommand(opts) {
|
|
|
60679
62433
|
const runId = newRunId();
|
|
60680
62434
|
const paths = createRunDir(opts.output, runId);
|
|
60681
62435
|
const t0 = Date.now();
|
|
60682
|
-
console.log(
|
|
62436
|
+
console.log(chalk22.bold(`
|
|
60683
62437
|
parity vitals ${runId}`));
|
|
60684
|
-
console.log(
|
|
60685
|
-
console.log(
|
|
62438
|
+
console.log(chalk22.dim(` prod: ${opts.prod}`));
|
|
62439
|
+
console.log(chalk22.dim(` cand: ${opts.cand}`));
|
|
60686
62440
|
const discoverSpinner = ora7("Descobrindo páginas…").start();
|
|
60687
62441
|
const pagePaths = await discoverPagePaths2(opts.prod, opts);
|
|
60688
62442
|
if (pagePaths.length === 0) {
|
|
@@ -60714,7 +62468,7 @@ async function vitalsCommand(opts) {
|
|
|
60714
62468
|
completed++;
|
|
60715
62469
|
const elapsed = ((Date.now() - t0) / 1000).toFixed(0);
|
|
60716
62470
|
const etaSec = completed > 0 ? Math.round((Date.now() - t0) / completed * (total - completed) / 1000) : 0;
|
|
60717
|
-
progress.text = `${completed}/${total} · ${elapsed}s · ETA ${etaSec}s · ${task.side === "prod" ?
|
|
62471
|
+
progress.text = `${completed}/${total} · ${elapsed}s · ETA ${etaSec}s · ${task.side === "prod" ? chalk22.cyan("prod") : chalk22.magenta("cand")} ${task.path} (${task.viewport})`;
|
|
60718
62472
|
}
|
|
60719
62473
|
});
|
|
60720
62474
|
progress.succeed(`${total} capture(s) em ${((Date.now() - t0) / 1000).toFixed(1)}s`);
|
|
@@ -60778,7 +62532,7 @@ async function vitalsCommand(opts) {
|
|
|
60778
62532
|
writeRunReportJson(paths.runDir, run);
|
|
60779
62533
|
const html3 = renderHtmlReport(run, paths.runDir);
|
|
60780
62534
|
writeRunReportHtml(paths.runDir, html3);
|
|
60781
|
-
|
|
62535
|
+
writeFileSync22(join23(paths.runDir, "vitals.json"), `${JSON.stringify({
|
|
60782
62536
|
schemaVersion: "0.1",
|
|
60783
62537
|
prodUrl: opts.prod,
|
|
60784
62538
|
candUrl: opts.cand,
|
|
@@ -60789,8 +62543,8 @@ async function vitalsCommand(opts) {
|
|
|
60789
62543
|
`, "utf8");
|
|
60790
62544
|
printSummary6(vitalsResult, cacheResult);
|
|
60791
62545
|
console.log("");
|
|
60792
|
-
console.log(
|
|
60793
|
-
console.log(
|
|
62546
|
+
console.log(chalk22.dim(` → ${paths.reportHtml}`));
|
|
62547
|
+
console.log(chalk22.dim(` \uD83D\uDCA1 use 'parity serve ${runId}' pra preview iframe`));
|
|
60794
62548
|
console.log("");
|
|
60795
62549
|
if (opts.open) {
|
|
60796
62550
|
const { default: open2 } = await import("open");
|
|
@@ -60877,8 +62631,8 @@ async function discoverPagePaths2(prodUrl, opts) {
|
|
|
60877
62631
|
function parseUrlList(input) {
|
|
60878
62632
|
if (input.startsWith("file:") || input.endsWith(".txt") || input.endsWith(".list")) {
|
|
60879
62633
|
const path = input.replace(/^file:\/\//, "");
|
|
60880
|
-
if (
|
|
60881
|
-
return
|
|
62634
|
+
if (existsSync18(path)) {
|
|
62635
|
+
return readFileSync18(path, "utf8").split(/\r?\n/).map((s) => s.trim()).filter((s) => s && !s.startsWith("#")).map((s) => s.startsWith("/") ? s : `/${s}`);
|
|
60882
62636
|
}
|
|
60883
62637
|
}
|
|
60884
62638
|
return input.split(",").map((s) => s.trim()).filter(Boolean).map((s) => s.startsWith("/") || s.startsWith("http") ? s : `/${s}`);
|
|
@@ -60896,22 +62650,22 @@ async function runWithConcurrency3(items, workers, fn) {
|
|
|
60896
62650
|
}
|
|
60897
62651
|
function printSummary6(vitals, cache) {
|
|
60898
62652
|
console.log("");
|
|
60899
|
-
console.log(
|
|
62653
|
+
console.log(chalk22.bold(" Summary:"));
|
|
60900
62654
|
console.log(` ${vitals.summary}`);
|
|
60901
62655
|
console.log(` ${cache.summary}`);
|
|
60902
62656
|
}
|
|
60903
62657
|
|
|
60904
62658
|
// src/util/version.ts
|
|
60905
|
-
import { readFileSync as
|
|
60906
|
-
import { dirname as dirname5, resolve as
|
|
62659
|
+
import { readFileSync as readFileSync19 } from "node:fs";
|
|
62660
|
+
import { dirname as dirname5, resolve as resolve5 } from "node:path";
|
|
60907
62661
|
import { fileURLToPath } from "node:url";
|
|
60908
62662
|
function getPackageVersion() {
|
|
60909
62663
|
try {
|
|
60910
62664
|
const here = dirname5(fileURLToPath(import.meta.url));
|
|
60911
62665
|
for (const up of ["..", "../..", "../../.."]) {
|
|
60912
62666
|
try {
|
|
60913
|
-
const pkgPath =
|
|
60914
|
-
const raw =
|
|
62667
|
+
const pkgPath = resolve5(here, up, "package.json");
|
|
62668
|
+
const raw = readFileSync19(pkgPath, "utf8");
|
|
60915
62669
|
const parsed = JSON.parse(raw);
|
|
60916
62670
|
if (parsed.name === "@decocms/parity" && typeof parsed.version === "string") {
|
|
60917
62671
|
return parsed.version;
|
|
@@ -60924,7 +62678,7 @@ function getPackageVersion() {
|
|
|
60924
62678
|
|
|
60925
62679
|
// src/cli.ts
|
|
60926
62680
|
var program = new Command;
|
|
60927
|
-
program.name("parity").description("E2E parity validator
|
|
62681
|
+
program.name("parity").description("E2E parity validator + migration capture for site migrations").version(getPackageVersion());
|
|
60928
62682
|
program.command("run").description([
|
|
60929
62683
|
"Compare two URLs and produce a parity report.",
|
|
60930
62684
|
"",
|
|
@@ -61096,6 +62850,21 @@ program.command("extract").description("Single-site AI-ready component extractio
|
|
|
61096
62850
|
json: opts.json
|
|
61097
62851
|
}));
|
|
61098
62852
|
});
|
|
62853
|
+
program.command("migrate").description("Single-site, phased migration capture (theme → sitemap → components). No prod×cand comparison — produces a target-agnostic, token-lean bundle + prompt for a migration agent: site theme (colors/typography/spacing as Tailwind tokens), classified pages, and per-component detail (suggested Tailwind classes, interaction hints, e2e selectors). Works whether or not the source code exists. Pass --target faststore to append a target playbook. Resumable: re-runs skip a completed phase unless --refresh.").requiredOption("--url <url>", "Site to migrate from").option("--pages <list>", 'Comma-separated pages: literal paths/URLs, and/or "category-auto"/"pdp-auto". Default: "/,category-auto,pdp-auto" (home + a PLP + a PDP).').option("--components <list>", "Comma-separated role allowlist, e.g. header,footer,nav,shelf,minicart. Default: all detected.").option("--target <name>", "Target playbook to append to the prompt (e.g. faststore)").option("--viewport <viewport>", "Primary viewport for component capture: mobile | desktop | tablet", "mobile").option("--viewports <list>", "Comma-separated viewports for theme + site screenshots (e.g. mobile,desktop). Default: --viewport only.").option("--format <fmt>", "md | json | both", "both").option("--out <dir>", "Output directory (stable per host, for resume)", "./parity-migrate").option("--refresh", "Re-run all phases even if cached artifacts exist", false).option("--no-llm", "Skip the optional LLM component-relabeling pass (heuristic detection always runs regardless).").option("--json", "Emit one-line JSON instead of pretty text", false).action(async (opts) => {
|
|
62854
|
+
process.exit(await migrateCommand({
|
|
62855
|
+
url: opts.url,
|
|
62856
|
+
pages: opts.pages,
|
|
62857
|
+
components: opts.components,
|
|
62858
|
+
target: opts.target,
|
|
62859
|
+
viewport: opts.viewport,
|
|
62860
|
+
viewports: opts.viewports,
|
|
62861
|
+
format: opts.format,
|
|
62862
|
+
outDir: opts.out,
|
|
62863
|
+
refresh: opts.refresh,
|
|
62864
|
+
noLlm: !opts.llm,
|
|
62865
|
+
json: opts.json
|
|
62866
|
+
}));
|
|
62867
|
+
});
|
|
61099
62868
|
program.command("learned").description("Inspect the learned-selectors library").addCommand(new Command("stats").description("Print learned-selectors stats per platform").action(() => {
|
|
61100
62869
|
process.exit(learnedStats());
|
|
61101
62870
|
})).addCommand(new Command("validate").description("Debug: run selector discovery + live-validation against a single URL and print a table (not part of `parity run`)").requiredOption("--url <url>", "URL to fetch + discover + validate").action(async (opts) => {
|