@decocms/parity 0.19.0 → 0.21.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/CHANGELOG.md +25 -0
- package/dist/cli.js +392 -77
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.21.0] — 2026-08-17
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
* **`parity migrate` now covers the whole store, not just the home page.** It samples extra pages per kind from the classified sitemap (`--sample`, default `plp=2,pdp=2,other=3,search=1`, capped at 15) — including **institutional** pages (`other`, which prefers real about/contact/policy URLs over deep categories) — and reads the **VTEX block tree + content on every captured page**, merged by treePath. On Electrolux this took the captured content from home-only to home + PLP + PDP + institutional (`store.home`/`store.product`/`store.search`). (#214)
|
|
15
|
+
* **Report organized per page.** `index.md` / `index.html` / `report.html` show a "Global components" section (captured once) plus one section per captured page — a single report separated by page. (#214)
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
* **Exact-duplicate VTEX blocks are collapsed** (a `product-summary` per product, repeated layout wrappers) into one representative with a `repeated` count, keeping distinct-content blocks — `blocks.json` went from 5242 to 883 on Electrolux without losing content. (#215)
|
|
20
|
+
* **`category-auto` no longer lands on an institutional page** (institutional keywords filtered from the PLP pick). (#214)
|
|
21
|
+
|
|
22
|
+
## [0.20.0] — 2026-08-17
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
|
|
26
|
+
* **`parity migrate` now captures the VTEX CMS content + all its images.** Each block's `props` (the merchant's registered content — banner images, texts, links, shelf config) is kept in `blocks.json`; content-image references (site-relative `/arquivos/ids/…`, `/img/…`) are resolved to absolute URLs, and the images — from block props **and** the Apollo `__STATE__` (product/catalog imagery) — are downloaded to `assets/content/` with a `content-assets.json` url→file map (up to 150/run). (#209, #211)
|
|
27
|
+
* **Quality pass:** robust logo capture (screenshots the element, so sprite `<use>` logos aren't blank), web-font download from `@font-face` (`assets/fonts/`), scroll-before-screenshot (lazy footers render), and a self-contained **`report.html`** (every image inlined) to share as a single link. (#209)
|
|
28
|
+
|
|
29
|
+
### Fixed
|
|
30
|
+
|
|
31
|
+
* **Header/footer are now detected on sites without semantic tags** (e.g. VTEX IO, which renders both as plain `<div>`s) via a geometry/anchor fallback that only fires when no `<header>`/`<footer>` matched. Shared by `extract` + `migrate`. (#212)
|
|
32
|
+
* **Theme election cleanups:** primary skips translucent overlays and considers opaque colors across all usages; breakpoints kept by frequency (real tiers, not 100+ media-query one-offs); background falls back to the most frequent opaque color; implausible motion durations dropped. (#209)
|
|
33
|
+
* Ignore `parity-migrate/` / `parity-extract/` output dirs so scraped store data can't be committed. (#210)
|
|
34
|
+
|
|
10
35
|
## [0.19.0] — 2026-08-17
|
|
11
36
|
|
|
12
37
|
### Added
|
package/dist/cli.js
CHANGED
|
@@ -44445,7 +44445,9 @@ function pickPlpFromHomeHtml(html3, homeUrl) {
|
|
|
44445
44445
|
continue;
|
|
44446
44446
|
candidates.add(href.split("?")[0]);
|
|
44447
44447
|
}
|
|
44448
|
-
const
|
|
44448
|
+
const INSTITUTIONAL = /(sobre|about|institucional|contato|contact|ajuda|help|faq|blog|trabalhe|careers|carreiras|politica|policy|privacidade|privacy|termos|terms|troca|devolu|garantia|warranty|lojas|stores|imprensa|press|sustentab|newsletter)/i;
|
|
44449
|
+
const filtered = Array.from(candidates).filter((c) => !INSTITUTIONAL.test(c));
|
|
44450
|
+
const sorted = (filtered.length ? filtered : Array.from(candidates)).sort((a, b) => a.length - b.length);
|
|
44449
44451
|
const pick = sorted[0];
|
|
44450
44452
|
if (!pick)
|
|
44451
44453
|
return null;
|
|
@@ -56006,6 +56008,48 @@ function collectCandidatesInPage() {
|
|
|
56006
56008
|
}
|
|
56007
56009
|
}
|
|
56008
56010
|
}
|
|
56011
|
+
const docHeight = Math.max(document.documentElement.scrollHeight, document.body?.scrollHeight ?? 0);
|
|
56012
|
+
function widest(els) {
|
|
56013
|
+
let best = null;
|
|
56014
|
+
let bestArea = 0;
|
|
56015
|
+
for (const el of els) {
|
|
56016
|
+
const r = rectOf(el);
|
|
56017
|
+
if (r.width < viewportWidth * 0.85)
|
|
56018
|
+
continue;
|
|
56019
|
+
const area = r.width * r.height;
|
|
56020
|
+
if (area > bestArea && area > 0) {
|
|
56021
|
+
best = el;
|
|
56022
|
+
bestArea = area;
|
|
56023
|
+
}
|
|
56024
|
+
}
|
|
56025
|
+
return best;
|
|
56026
|
+
}
|
|
56027
|
+
if (!out.some((c) => c.role === "header")) {
|
|
56028
|
+
let header = null;
|
|
56029
|
+
const anchor = document.querySelector("nav, [class*='logo' i], [class*='search' i]");
|
|
56030
|
+
let el = anchor;
|
|
56031
|
+
while (el?.parentElement) {
|
|
56032
|
+
const r = rectOf(el.parentElement);
|
|
56033
|
+
if (r.y <= 5 && r.width >= viewportWidth * 0.85 && r.height < window.innerHeight * 1.5) {
|
|
56034
|
+
header = el.parentElement;
|
|
56035
|
+
}
|
|
56036
|
+
el = el.parentElement;
|
|
56037
|
+
}
|
|
56038
|
+
header ??= widest(Array.from(document.querySelectorAll("[class*='header' i]")).filter((e) => rectOf(e).y < 200));
|
|
56039
|
+
if (header)
|
|
56040
|
+
push("header", header);
|
|
56041
|
+
}
|
|
56042
|
+
if (!out.some((c) => c.role === "footer")) {
|
|
56043
|
+
const footer = widest(Array.from(document.querySelectorAll("[class*='footer' i]")).filter((e) => {
|
|
56044
|
+
const r = rectOf(e);
|
|
56045
|
+
return r.y + r.height > docHeight - window.innerHeight && e.querySelectorAll("a").length >= 4;
|
|
56046
|
+
})) ?? widest(Array.from(document.querySelectorAll("div, section")).filter((e) => {
|
|
56047
|
+
const r = rectOf(e);
|
|
56048
|
+
return r.y + r.height > docHeight - window.innerHeight * 0.6 && r.y > docHeight * 0.5 && e.querySelectorAll("a").length >= 6;
|
|
56049
|
+
}));
|
|
56050
|
+
if (footer)
|
|
56051
|
+
push("footer", footer);
|
|
56052
|
+
}
|
|
56009
56053
|
return out;
|
|
56010
56054
|
}
|
|
56011
56055
|
|
|
@@ -58417,7 +58461,7 @@ function listCommand(output) {
|
|
|
58417
58461
|
}
|
|
58418
58462
|
|
|
58419
58463
|
// src/commands/migrate.ts
|
|
58420
|
-
import { existsSync as existsSync11, mkdirSync as
|
|
58464
|
+
import { existsSync as existsSync11, mkdirSync as mkdirSync15, readFileSync as readFileSync14, writeFileSync as writeFileSync21 } from "node:fs";
|
|
58421
58465
|
import { resolve as resolve3 } from "node:path";
|
|
58422
58466
|
import chalk16 from "chalk";
|
|
58423
58467
|
import open from "open";
|
|
@@ -59086,8 +59130,138 @@ var jsonExporter2 = {
|
|
|
59086
59130
|
};
|
|
59087
59131
|
|
|
59088
59132
|
// src/migrate/exporters/markdown.ts
|
|
59133
|
+
import { mkdirSync as mkdirSync14, writeFileSync as writeFileSync19 } from "node:fs";
|
|
59134
|
+
import { join as join20 } from "node:path";
|
|
59135
|
+
|
|
59136
|
+
// src/migrate/vtex/content-assets.ts
|
|
59089
59137
|
import { mkdirSync as mkdirSync13, writeFileSync as writeFileSync18 } from "node:fs";
|
|
59090
59138
|
import { join as join19 } from "node:path";
|
|
59139
|
+
var MAX_IMAGES = 150;
|
|
59140
|
+
var IMG_EXT = /\.(jpe?g|png|webp|gif|svg|avif)(\?|#|$)/i;
|
|
59141
|
+
var VTEX_ASSET = /vtexassets\.com|vteximg\.com\.br|\/arquivos\/(ids|assets)\//i;
|
|
59142
|
+
function isImageUrl(s) {
|
|
59143
|
+
if (typeof s !== "string")
|
|
59144
|
+
return false;
|
|
59145
|
+
const v = s.trim();
|
|
59146
|
+
if (!/^(https?:)?\/\//i.test(v))
|
|
59147
|
+
return false;
|
|
59148
|
+
return IMG_EXT.test(v) || VTEX_ASSET.test(v);
|
|
59149
|
+
}
|
|
59150
|
+
function isImageRef(s) {
|
|
59151
|
+
if (typeof s !== "string")
|
|
59152
|
+
return false;
|
|
59153
|
+
const v = s.trim();
|
|
59154
|
+
if (isImageUrl(v))
|
|
59155
|
+
return true;
|
|
59156
|
+
return v.startsWith("/") && !v.startsWith("//") && (IMG_EXT.test(v) || VTEX_ASSET.test(v) || v.startsWith("/img/"));
|
|
59157
|
+
}
|
|
59158
|
+
function resolveRef(ref, baseUrl) {
|
|
59159
|
+
const v = ref.trim();
|
|
59160
|
+
try {
|
|
59161
|
+
if (v.startsWith("//"))
|
|
59162
|
+
return `https:${v}`;
|
|
59163
|
+
return new URL(v, baseUrl).toString();
|
|
59164
|
+
} catch {
|
|
59165
|
+
return null;
|
|
59166
|
+
}
|
|
59167
|
+
}
|
|
59168
|
+
function collectImageRefs(blocks, baseUrl) {
|
|
59169
|
+
const out = {};
|
|
59170
|
+
const walk = (v) => {
|
|
59171
|
+
if (typeof v === "string") {
|
|
59172
|
+
const s = v.trim();
|
|
59173
|
+
if (isImageRef(s) && !(s in out)) {
|
|
59174
|
+
const abs = resolveRef(s, baseUrl);
|
|
59175
|
+
if (abs)
|
|
59176
|
+
out[s] = abs;
|
|
59177
|
+
}
|
|
59178
|
+
} else if (Array.isArray(v)) {
|
|
59179
|
+
for (const x of v)
|
|
59180
|
+
walk(x);
|
|
59181
|
+
} else if (v && typeof v === "object") {
|
|
59182
|
+
for (const x of Object.values(v))
|
|
59183
|
+
walk(x);
|
|
59184
|
+
}
|
|
59185
|
+
};
|
|
59186
|
+
for (const b of blocks)
|
|
59187
|
+
if (b.props)
|
|
59188
|
+
walk(b.props);
|
|
59189
|
+
return out;
|
|
59190
|
+
}
|
|
59191
|
+
function countContentImages(blocks) {
|
|
59192
|
+
const urls = new Set;
|
|
59193
|
+
const walk = (v) => {
|
|
59194
|
+
if (typeof v === "string") {
|
|
59195
|
+
if (isImageUrl(v.trim()))
|
|
59196
|
+
urls.add(v.trim());
|
|
59197
|
+
} else if (Array.isArray(v)) {
|
|
59198
|
+
for (const x of v)
|
|
59199
|
+
walk(x);
|
|
59200
|
+
} else if (v && typeof v === "object") {
|
|
59201
|
+
for (const x of Object.values(v))
|
|
59202
|
+
walk(x);
|
|
59203
|
+
}
|
|
59204
|
+
};
|
|
59205
|
+
for (const b of blocks)
|
|
59206
|
+
if (b.props)
|
|
59207
|
+
walk(b.props);
|
|
59208
|
+
return urls.size;
|
|
59209
|
+
}
|
|
59210
|
+
function rewriteBlockUrls(blocks, urlToPath) {
|
|
59211
|
+
const replace = (v) => {
|
|
59212
|
+
if (typeof v === "string")
|
|
59213
|
+
return urlToPath[v.trim()] ?? v;
|
|
59214
|
+
if (Array.isArray(v))
|
|
59215
|
+
return v.map(replace);
|
|
59216
|
+
if (v && typeof v === "object") {
|
|
59217
|
+
const out = {};
|
|
59218
|
+
for (const [k, val2] of Object.entries(v))
|
|
59219
|
+
out[k] = replace(val2);
|
|
59220
|
+
return out;
|
|
59221
|
+
}
|
|
59222
|
+
return v;
|
|
59223
|
+
};
|
|
59224
|
+
return blocks.map((b) => ({
|
|
59225
|
+
...b,
|
|
59226
|
+
props: b.props ? replace(b.props) : b.props
|
|
59227
|
+
}));
|
|
59228
|
+
}
|
|
59229
|
+
function contentImageName(url, index2, used) {
|
|
59230
|
+
let base = "img";
|
|
59231
|
+
try {
|
|
59232
|
+
base = new URL(url, "https://x").pathname.split("/").filter(Boolean).pop() ?? "img";
|
|
59233
|
+
} catch {}
|
|
59234
|
+
base = base.split("?")[0].replace(/[^\w.-]/g, "_").slice(-60) || "img";
|
|
59235
|
+
if (!/\.(jpe?g|png|webp|gif|svg|avif)$/i.test(base))
|
|
59236
|
+
base += ".img";
|
|
59237
|
+
let name = base;
|
|
59238
|
+
if (used.has(name))
|
|
59239
|
+
name = `${index2}-${base}`;
|
|
59240
|
+
used.add(name);
|
|
59241
|
+
return name;
|
|
59242
|
+
}
|
|
59243
|
+
async function downloadContentImages(urls, runDir, fetchBytes) {
|
|
59244
|
+
const map2 = {};
|
|
59245
|
+
if (urls.length === 0)
|
|
59246
|
+
return { map: map2, downloaded: 0, skipped: 0 };
|
|
59247
|
+
const dir = join19(runDir, "assets", "content");
|
|
59248
|
+
mkdirSync13(dir, { recursive: true });
|
|
59249
|
+
const used = new Set;
|
|
59250
|
+
const take = urls.slice(0, MAX_IMAGES);
|
|
59251
|
+
let downloaded = 0;
|
|
59252
|
+
for (const [i, url] of take.entries()) {
|
|
59253
|
+
const got = await fetchBytes(url.startsWith("//") ? `https:${url}` : url);
|
|
59254
|
+
if (!got)
|
|
59255
|
+
continue;
|
|
59256
|
+
const name = contentImageName(url, i, used);
|
|
59257
|
+
writeFileSync18(join19(dir, name), got.buf);
|
|
59258
|
+
map2[url] = `assets/content/${name}`;
|
|
59259
|
+
downloaded++;
|
|
59260
|
+
}
|
|
59261
|
+
return { map: map2, downloaded, skipped: Math.max(0, urls.length - take.length) };
|
|
59262
|
+
}
|
|
59263
|
+
|
|
59264
|
+
// src/migrate/exporters/markdown.ts
|
|
59091
59265
|
var markdownExporter2 = {
|
|
59092
59266
|
name: "markdown",
|
|
59093
59267
|
async export(bundle, outDir) {
|
|
@@ -59095,19 +59269,19 @@ var markdownExporter2 = {
|
|
|
59095
59269
|
const notes = [];
|
|
59096
59270
|
bundle.components.forEach((component, i) => {
|
|
59097
59271
|
const dirName = dirNames[i];
|
|
59098
|
-
const componentDir =
|
|
59099
|
-
|
|
59272
|
+
const componentDir = join20(outDir, "components", dirName);
|
|
59273
|
+
mkdirSync14(componentDir, { recursive: true });
|
|
59100
59274
|
const compact = compactComponentHtml(component.html);
|
|
59101
59275
|
if (compact.collapsed > 0)
|
|
59102
59276
|
notes.push(`\`${dirName}\`: collapsed ${compact.collapsed} repeated child element(s)`);
|
|
59103
59277
|
if (compact.truncated)
|
|
59104
59278
|
notes.push(`\`${dirName}\`: HTML truncated to fit the per-component token ceiling`);
|
|
59105
|
-
|
|
59279
|
+
writeFileSync19(join20(componentDir, "README.md"), renderComponentReadme2(bundle.url, component, compact.html), "utf8");
|
|
59106
59280
|
});
|
|
59107
|
-
|
|
59281
|
+
writeFileSync19(join20(outDir, "index.md"), renderIndex2(bundle, notes), "utf8");
|
|
59108
59282
|
}
|
|
59109
59283
|
};
|
|
59110
|
-
function renderIndex2(bundle,
|
|
59284
|
+
function renderIndex2(bundle, notes) {
|
|
59111
59285
|
const lines = [];
|
|
59112
59286
|
const md = lines.push.bind(lines);
|
|
59113
59287
|
md(`# Migration snapshot: ${bundle.url}`);
|
|
@@ -59137,7 +59311,7 @@ function renderIndex2(bundle, dirNames, notes) {
|
|
|
59137
59311
|
if (bundle.vtex) {
|
|
59138
59312
|
md("## VTEX IO → FastStore blocks");
|
|
59139
59313
|
md("");
|
|
59140
|
-
md(`_${bundle.vtex.blocks.length} block instances
|
|
59314
|
+
md(`_${bundle.vtex.blocks.length} block instances · ${bundle.vtex.blocks.filter((x) => x.props).length} carry CMS content (props), ${countContentImages(bundle.vtex.blocks)} content images downloaded to \`assets/content/\` (URLs rewritten in \`blocks.json\`). \`confidence\` (0–1) = mapper certainty; \`custom-component\` = build from captured DOM/CSS._`);
|
|
59141
59315
|
md("");
|
|
59142
59316
|
md("| VTEX block | → FastStore | confidence | count |");
|
|
59143
59317
|
md("|---|---|---|---|");
|
|
@@ -59146,17 +59320,37 @@ function renderIndex2(bundle, dirNames, notes) {
|
|
|
59146
59320
|
}
|
|
59147
59321
|
md("");
|
|
59148
59322
|
}
|
|
59149
|
-
|
|
59150
|
-
|
|
59151
|
-
|
|
59152
|
-
|
|
59153
|
-
|
|
59154
|
-
const keys = c.interactions.map((x) => x.e2eKey).filter((k) => Boolean(k));
|
|
59155
|
-
const uniqueKeys = [...new Set(keys)];
|
|
59323
|
+
const compIndex = new Map;
|
|
59324
|
+
bundle.components.forEach((c, i) => compIndex.set(`${c.role}::${c.selector}`, i + 1));
|
|
59325
|
+
const rowFor = (c) => {
|
|
59326
|
+
const keys = [...new Set(c.interactions.map((x) => x.e2eKey).filter((k) => Boolean(k)))];
|
|
59327
|
+
const dir = componentDirName(c.role, compIndex.get(`${c.role}::${c.selector}`) ?? 1);
|
|
59156
59328
|
const roleCell = c.repeated && c.repeated > 1 ? `\`${c.role}\` ×${c.repeated}` : `\`${c.role}\``;
|
|
59157
|
-
|
|
59158
|
-
}
|
|
59329
|
+
return `| ${roleCell} | ${keys.length ? keys.map((k) => `\`${k}\``).join(", ") : "—"} | [${dir}](./components/${dir}/README.md) |`;
|
|
59330
|
+
};
|
|
59331
|
+
const globalComps = bundle.components.filter((c) => c.scope === "global");
|
|
59332
|
+
md("## Components — by page");
|
|
59159
59333
|
md("");
|
|
59334
|
+
md(`### Global (${globalComps.length}) — on every page`);
|
|
59335
|
+
md("");
|
|
59336
|
+
md("| Role | e2e keys | Folder |");
|
|
59337
|
+
md("|---|---|---|");
|
|
59338
|
+
for (const c of globalComps)
|
|
59339
|
+
md(rowFor(c));
|
|
59340
|
+
md("");
|
|
59341
|
+
for (const pg of bundle.pages) {
|
|
59342
|
+
md(`### Page: ${pg.kind} \`${pg.path}\``);
|
|
59343
|
+
md("");
|
|
59344
|
+
if (pg.components.length) {
|
|
59345
|
+
md("| Role | e2e keys | Folder |");
|
|
59346
|
+
md("|---|---|---|");
|
|
59347
|
+
for (const c of pg.components)
|
|
59348
|
+
md(rowFor(c));
|
|
59349
|
+
} else {
|
|
59350
|
+
md("_no page-specific components_");
|
|
59351
|
+
}
|
|
59352
|
+
md("");
|
|
59353
|
+
}
|
|
59160
59354
|
if (notes.length) {
|
|
59161
59355
|
md("## Compaction notes");
|
|
59162
59356
|
md("");
|
|
@@ -59275,14 +59469,14 @@ function escapePipes2(s) {
|
|
|
59275
59469
|
}
|
|
59276
59470
|
|
|
59277
59471
|
// src/migrate/exporters/html.ts
|
|
59278
|
-
import { readFileSync as readFileSync13, writeFileSync as
|
|
59279
|
-
import { join as
|
|
59472
|
+
import { readFileSync as readFileSync13, writeFileSync as writeFileSync20 } from "node:fs";
|
|
59473
|
+
import { join as join21 } from "node:path";
|
|
59280
59474
|
var htmlExporter = {
|
|
59281
59475
|
name: "html",
|
|
59282
59476
|
async export(bundle, outDir) {
|
|
59283
|
-
|
|
59284
|
-
const inline = (p) => p ? dataUri(
|
|
59285
|
-
|
|
59477
|
+
writeFileSync20(join21(outDir, "index.html"), renderHtml(bundle, (p) => p ?? null), "utf8");
|
|
59478
|
+
const inline = (p) => p ? dataUri(join21(outDir, p)) ?? p : null;
|
|
59479
|
+
writeFileSync20(join21(outDir, "report.html"), renderHtml(bundle, inline), "utf8");
|
|
59286
59480
|
}
|
|
59287
59481
|
};
|
|
59288
59482
|
var MIME = {
|
|
@@ -59322,11 +59516,19 @@ function renderHtml(b, embed) {
|
|
|
59322
59516
|
const src = embed(s.path);
|
|
59323
59517
|
return src ? `<figure><figcaption>${esc(s.viewport)}</figcaption><img src="${esc(src)}" alt="${esc(s.viewport)}"></figure>` : "";
|
|
59324
59518
|
}).join("");
|
|
59325
|
-
const
|
|
59519
|
+
const compIndex = new Map;
|
|
59520
|
+
b.components.forEach((c, i) => compIndex.set(`${c.role}::${c.selector}`, i + 1));
|
|
59521
|
+
const compHead = "<tr><th>role</th><th>tw</th><th>interactions</th><th>e2e keys</th><th>folder</th></tr>";
|
|
59522
|
+
const rowFor = (c) => {
|
|
59326
59523
|
const keys = [...new Set(c.interactions.map((x) => x.e2eKey).filter(Boolean))];
|
|
59327
|
-
const folder = componentDirName(c.role,
|
|
59328
|
-
return `<tr><td
|
|
59329
|
-
}
|
|
59524
|
+
const folder = componentDirName(c.role, compIndex.get(`${c.role}::${c.selector}`) ?? 1);
|
|
59525
|
+
return `<tr><td><code>${esc(c.role)}</code>${c.repeated && c.repeated > 1 ? ` <span class="badge">×${c.repeated}</span>` : ""}</td><td>${c.tailwind.length}</td><td>${c.interactions.length}</td><td>${keys.length ? keys.map((k) => `<code>${esc(String(k))}</code>`).join(" ") : "—"}</td><td><a href="components/${esc(folder)}/README.md">${esc(folder)}</a></td></tr>`;
|
|
59526
|
+
};
|
|
59527
|
+
const globalComps = b.components.filter((c) => c.scope === "global");
|
|
59528
|
+
const componentsByPage = [
|
|
59529
|
+
`<section class="card"><h2>Global components (${globalComps.length})</h2><p class="dim">Captured once — shown on every page (header, footer, minicart…).</p><table>${compHead}${globalComps.map(rowFor).join("")}</table></section>`,
|
|
59530
|
+
...b.pages.map((pg) => `<section class="card"><h2>Page: ${esc(pg.kind)} <code>${esc(pg.path)}</code></h2>${pg.components.length ? `<table>${compHead}${pg.components.map(rowFor).join("")}</table>` : '<p class="dim">no page-specific components</p>'}</section>`)
|
|
59531
|
+
].join("");
|
|
59330
59532
|
const vtexRows = b.vtex ? b.vtex.map.slice(0, 80).map((m) => `<tr><td><code>${esc(m.vtex)}</code></td><td>${m.faststore ? `<code>${esc(m.faststore)}</code>` : "<em>custom-component</em>"}</td><td>${m.confidence || "—"}</td><td>${m.count}</td></tr>`).join("") : "";
|
|
59331
59533
|
const iconRows = t && b.assets.icons.length ? b.assets.icons.slice(0, 40).map((ic) => `<tr><td>${esc(ic.kind)}</td><td><code>${esc(ic.id)}</code></td><td>${ic.count}</td></tr>`).join("") : "";
|
|
59332
59534
|
return `<!doctype html>
|
|
@@ -59411,15 +59613,10 @@ function renderHtml(b, embed) {
|
|
|
59411
59613
|
${iconRows ? `<table style="margin-top:16px"><tr><th>kind</th><th>id</th><th>count</th></tr>${iconRows}</table>` : ""}
|
|
59412
59614
|
</section>
|
|
59413
59615
|
|
|
59414
|
-
${b.vtex ? `<section class="card"><h2>VTEX IO → FastStore blocks</h2><p class="dim">${b.vtex.blocks.length} block instances from the store runtime · ${b.vtex.blocks.filter((x) => x.props).length} carry CMS content (props)
|
|
59616
|
+
${b.vtex ? `<section class="card"><h2>VTEX IO → FastStore blocks</h2><p class="dim">${b.vtex.blocks.length} block instances from the store runtime · ${b.vtex.blocks.filter((x) => x.props).length} carry CMS content (props), ${countContentImages(b.vtex.blocks)} content images downloaded to <code>assets/content/</code> (URLs rewritten in <code>blocks.json</code>). <b>confidence</b> = how sure the deterministic mapper is (0–1).</p><table><tr><th>VTEX block</th><th>→ FastStore</th><th>confidence</th><th>count</th></tr>${vtexRows}</table></section>` : ""}
|
|
59415
59617
|
|
|
59416
|
-
<section class="card">
|
|
59417
|
-
|
|
59418
|
-
<table>
|
|
59419
|
-
<tr><th>scope</th><th>role</th><th>tw</th><th>interactions</th><th>e2e keys</th><th>folder</th></tr>
|
|
59420
|
-
${componentRows}
|
|
59421
|
-
</table>
|
|
59422
|
-
</section>
|
|
59618
|
+
<section class="card"><h2>Components (${b.components.length}) — by page</h2></section>
|
|
59619
|
+
${componentsByPage}
|
|
59423
59620
|
|
|
59424
59621
|
<section class="card links">
|
|
59425
59622
|
<h2>Files</h2>
|
|
@@ -59862,7 +60059,7 @@ function lookup(blockName) {
|
|
|
59862
60059
|
function mapVtexBlocksToFastStore(blocks) {
|
|
59863
60060
|
const counts = new Map;
|
|
59864
60061
|
for (const b of blocks)
|
|
59865
|
-
counts.set(b.blockName, (counts.get(b.blockName) ?? 0) + 1);
|
|
60062
|
+
counts.set(b.blockName, (counts.get(b.blockName) ?? 0) + (b.repeated ?? 1));
|
|
59866
60063
|
const out = [];
|
|
59867
60064
|
for (const [vtex, count] of counts) {
|
|
59868
60065
|
const entry = lookup(vtex);
|
|
@@ -59876,6 +60073,18 @@ function mapVtexBlocksToFastStore(blocks) {
|
|
|
59876
60073
|
}
|
|
59877
60074
|
|
|
59878
60075
|
// src/migrate/vtex/runtime.ts
|
|
60076
|
+
function dedupeVtexBlocks(blocks) {
|
|
60077
|
+
const groups = new Map;
|
|
60078
|
+
for (const b of blocks) {
|
|
60079
|
+
const key = `${b.blockName}\x00${JSON.stringify(b.props ?? null)}`;
|
|
60080
|
+
const existing = groups.get(key);
|
|
60081
|
+
if (existing)
|
|
60082
|
+
existing.repeated = (existing.repeated ?? 1) + 1;
|
|
60083
|
+
else
|
|
60084
|
+
groups.set(key, { ...b });
|
|
60085
|
+
}
|
|
60086
|
+
return [...groups.values()];
|
|
60087
|
+
}
|
|
59879
60088
|
function blockNameFromTreePath(treePath) {
|
|
59880
60089
|
const leaf = treePath.split("/").pop() ?? treePath;
|
|
59881
60090
|
const noInstance = leaf.split("#")[0] ?? leaf;
|
|
@@ -59885,6 +60094,26 @@ function parentTreePath(treePath) {
|
|
|
59885
60094
|
const i = treePath.lastIndexOf("/");
|
|
59886
60095
|
return i > 0 ? treePath.slice(0, i) : null;
|
|
59887
60096
|
}
|
|
60097
|
+
async function readVtexStateImages(page) {
|
|
60098
|
+
try {
|
|
60099
|
+
return await page.evaluate(() => {
|
|
60100
|
+
const w = window;
|
|
60101
|
+
const st = w.__STATE__ ?? w.__APOLLO_STATE__;
|
|
60102
|
+
if (!st)
|
|
60103
|
+
return [];
|
|
60104
|
+
let s;
|
|
60105
|
+
try {
|
|
60106
|
+
s = JSON.stringify(st);
|
|
60107
|
+
} catch {
|
|
60108
|
+
return [];
|
|
60109
|
+
}
|
|
60110
|
+
const re = /https?:\/\/[^"'\\ ]*(?:vtexassets\.com|vteximg\.com\.br)[^"'\\ ]*\.(?:jpe?g|png|webp|gif|avif)/gi;
|
|
60111
|
+
return [...new Set(s.match(re) ?? [])].slice(0, 300);
|
|
60112
|
+
});
|
|
60113
|
+
} catch {
|
|
60114
|
+
return [];
|
|
60115
|
+
}
|
|
60116
|
+
}
|
|
59888
60117
|
async function readVtexBlockTree(page) {
|
|
59889
60118
|
let paths;
|
|
59890
60119
|
try {
|
|
@@ -60091,7 +60320,7 @@ async function migrateCommand(opts) {
|
|
|
60091
60320
|
const allowlist = parseAllowlist2(opts.components);
|
|
60092
60321
|
const host = safeHost5(opts.url);
|
|
60093
60322
|
const runDir = resolve3(opts.outDir, host);
|
|
60094
|
-
|
|
60323
|
+
mkdirSync15(runDir, { recursive: true });
|
|
60095
60324
|
const browser = await launchBrowser({ headless: true });
|
|
60096
60325
|
try {
|
|
60097
60326
|
const themePath = resolve3(runDir, "theme.json");
|
|
@@ -60102,18 +60331,17 @@ async function migrateCommand(opts) {
|
|
|
60102
60331
|
let assets;
|
|
60103
60332
|
let screenshots;
|
|
60104
60333
|
let vtexBlocks = null;
|
|
60334
|
+
let contentMap = {};
|
|
60105
60335
|
if (!opts.refresh && existsSync11(themePath) && existsSync11(assetsPath)) {
|
|
60106
60336
|
theme = readJson(themePath);
|
|
60107
60337
|
const meta = readJson(assetsPath);
|
|
60108
60338
|
platform = meta.platform;
|
|
60109
60339
|
assets = meta.assets;
|
|
60110
60340
|
screenshots = meta.screenshots ?? [];
|
|
60111
|
-
if (existsSync11(blocksPath))
|
|
60112
|
-
vtexBlocks = readJson(blocksPath);
|
|
60113
60341
|
console.log(chalk16.dim(" phase 1 theme+assets: cached"));
|
|
60114
60342
|
} else {
|
|
60115
60343
|
console.log(chalk16.dim(` phase 1 theme+assets: scraping (${viewports.join(", ")})…`));
|
|
60116
|
-
|
|
60344
|
+
mkdirSync15(resolve3(runDir, "screenshots"), { recursive: true });
|
|
60117
60345
|
const samples = [];
|
|
60118
60346
|
screenshots = [];
|
|
60119
60347
|
let platformSeen = null;
|
|
@@ -60156,7 +60384,6 @@ async function migrateCommand(opts) {
|
|
|
60156
60384
|
assetsResolved.logoSource = assetsResolved.logoSource ?? "screenshot";
|
|
60157
60385
|
}
|
|
60158
60386
|
}
|
|
60159
|
-
vtexBlocks = await readVtexBlockTree(page);
|
|
60160
60387
|
}
|
|
60161
60388
|
} finally {
|
|
60162
60389
|
await page.close().catch(() => {
|
|
@@ -60170,15 +60397,10 @@ async function migrateCommand(opts) {
|
|
|
60170
60397
|
theme = aggregateTheme(mergeRawThemeSamples(samples));
|
|
60171
60398
|
platform = platformSeen ?? "custom";
|
|
60172
60399
|
assets = assetsResolved;
|
|
60173
|
-
|
|
60400
|
+
writeFileSync21(themePath, `${JSON.stringify(theme, null, 2)}
|
|
60174
60401
|
`, "utf8");
|
|
60175
|
-
|
|
60402
|
+
writeFileSync21(assetsPath, `${JSON.stringify({ platform, assets, screenshots }, null, 2)}
|
|
60176
60403
|
`, "utf8");
|
|
60177
|
-
if (vtexBlocks) {
|
|
60178
|
-
writeFileSync20(blocksPath, `${JSON.stringify(vtexBlocks, null, 2)}
|
|
60179
|
-
`, "utf8");
|
|
60180
|
-
console.log(chalk16.dim(` vtex io: ${vtexBlocks.length} blocks read from runtime`));
|
|
60181
|
-
}
|
|
60182
60404
|
}
|
|
60183
60405
|
const sitemapPath = resolve3(runDir, "sitemap.json");
|
|
60184
60406
|
let resolvedPages;
|
|
@@ -60207,7 +60429,16 @@ async function migrateCommand(opts) {
|
|
|
60207
60429
|
});
|
|
60208
60430
|
}
|
|
60209
60431
|
const classified = sitemapUrls.slice(0, 500).map((u) => ({ url: u, kind: kindOf(u) }));
|
|
60210
|
-
|
|
60432
|
+
const sampled = sampleFromSitemap(classified, parseSample(opts.sample), resolvedPages);
|
|
60433
|
+
resolvedPages = [...resolvedPages, ...sampled].slice(0, MAX_PAGES);
|
|
60434
|
+
if (sampled.length) {
|
|
60435
|
+
const byKind = sampled.reduce((a, p) => {
|
|
60436
|
+
a[p.kind] = (a[p.kind] ?? 0) + 1;
|
|
60437
|
+
return a;
|
|
60438
|
+
}, {});
|
|
60439
|
+
console.log(chalk16.dim(` phase 2 sitemap: +${sampled.length} sampled (${Object.entries(byKind).map(([k, n]) => `${n} ${k}`).join(", ")})`));
|
|
60440
|
+
}
|
|
60441
|
+
writeFileSync21(sitemapPath, `${JSON.stringify({ pages: resolvedPages, sitemapUrls: classified }, null, 2)}
|
|
60211
60442
|
`, "utf8");
|
|
60212
60443
|
}
|
|
60213
60444
|
if (resolvedPages.length === 0) {
|
|
@@ -60221,17 +60452,21 @@ async function migrateCommand(opts) {
|
|
|
60221
60452
|
const cached = readJson(capturePath);
|
|
60222
60453
|
pages = cached.pages;
|
|
60223
60454
|
components = cached.components;
|
|
60455
|
+
vtexBlocks = cached.vtexBlocks ?? null;
|
|
60456
|
+
contentMap = cached.contentMap ?? {};
|
|
60224
60457
|
console.log(chalk16.dim(` phase 3 components: cached (${components.length})`));
|
|
60225
60458
|
} else {
|
|
60226
60459
|
console.log(chalk16.dim(" phase 3 components: capturing…"));
|
|
60227
|
-
({ pages, components } = await capturePages(browser, primaryViewport, resolvedPages, theme, {
|
|
60228
|
-
|
|
60229
|
-
llm: !opts.noLlm,
|
|
60230
|
-
runDir
|
|
60231
|
-
}));
|
|
60232
|
-
writeFileSync20(capturePath, `${JSON.stringify({ pages, components }, null, 2)}
|
|
60460
|
+
({ pages, components, vtexBlocks, contentMap } = await capturePages(browser, primaryViewport, resolvedPages, theme, { allowlist, llm: !opts.noLlm, runDir, baseUrl: opts.url }));
|
|
60461
|
+
writeFileSync21(capturePath, `${JSON.stringify({ pages, components, vtexBlocks, contentMap }, null, 2)}
|
|
60233
60462
|
`, "utf8");
|
|
60234
60463
|
}
|
|
60464
|
+
if (vtexBlocks)
|
|
60465
|
+
writeFileSync21(blocksPath, `${JSON.stringify(vtexBlocks, null, 2)}
|
|
60466
|
+
`, "utf8");
|
|
60467
|
+
if (Object.keys(contentMap).length)
|
|
60468
|
+
writeFileSync21(resolve3(runDir, "content-assets.json"), `${JSON.stringify(contentMap, null, 2)}
|
|
60469
|
+
`, "utf8");
|
|
60235
60470
|
const bundle = {
|
|
60236
60471
|
url: opts.url,
|
|
60237
60472
|
timestamp: new Date().toISOString(),
|
|
@@ -60251,13 +60486,13 @@ async function migrateCommand(opts) {
|
|
|
60251
60486
|
if (format === "md" || format === "both") {
|
|
60252
60487
|
await markdownExporter2.export(bundle, runDir);
|
|
60253
60488
|
await htmlExporter.export(bundle, runDir);
|
|
60254
|
-
|
|
60489
|
+
writeFileSync21(resolve3(runDir, "MIGRATION_PROMPT.md"), buildMigrationPrompt(bundle, playbook), "utf8");
|
|
60255
60490
|
}
|
|
60256
60491
|
if (opts.target === "faststore") {
|
|
60257
|
-
|
|
60492
|
+
writeFileSync21(resolve3(runDir, "custom-theme.scss"), buildFastStoreTheme(theme), "utf8");
|
|
60258
60493
|
}
|
|
60259
60494
|
if (bundle.vtex) {
|
|
60260
|
-
|
|
60495
|
+
writeFileSync21(resolve3(runDir, "component-map.json"), `${JSON.stringify(bundle.vtex.map, null, 2)}
|
|
60261
60496
|
`, "utf8");
|
|
60262
60497
|
}
|
|
60263
60498
|
if (opts.json) {
|
|
@@ -60277,10 +60512,13 @@ async function migrateCommand(opts) {
|
|
|
60277
60512
|
});
|
|
60278
60513
|
}
|
|
60279
60514
|
}
|
|
60515
|
+
var CONTENT_IMAGE_BUDGET = 200;
|
|
60280
60516
|
async function capturePages(browser, viewport, resolvedPages, theme, cfg) {
|
|
60281
60517
|
const pages = [];
|
|
60282
60518
|
const components = [];
|
|
60283
60519
|
const seenGlobalRoles = new Set;
|
|
60520
|
+
const blocksByPath = new Map;
|
|
60521
|
+
const contentMap = {};
|
|
60284
60522
|
for (const target of resolvedPages) {
|
|
60285
60523
|
const ctx = await newContext(browser, { viewport });
|
|
60286
60524
|
const page = await ctx.newPage();
|
|
@@ -60331,6 +60569,22 @@ async function capturePages(browser, viewport, resolvedPages, theme, cfg) {
|
|
|
60331
60569
|
pageComponents.push(migrated);
|
|
60332
60570
|
}
|
|
60333
60571
|
pages.push({ url: target.url, path: target.path, kind: target.kind, components: pageComponents });
|
|
60572
|
+
const pageBlocks = await readVtexBlockTree(page);
|
|
60573
|
+
if (pageBlocks) {
|
|
60574
|
+
const refMap = collectImageRefs(pageBlocks, cfg.baseUrl);
|
|
60575
|
+
for (const b of rewriteBlockUrls(pageBlocks, refMap)) {
|
|
60576
|
+
if (!blocksByPath.has(b.treePath))
|
|
60577
|
+
blocksByPath.set(b.treePath, b);
|
|
60578
|
+
}
|
|
60579
|
+
if (Object.keys(contentMap).length < CONTENT_IMAGE_BUDGET) {
|
|
60580
|
+
const stateImages = await readVtexStateImages(page);
|
|
60581
|
+
const fetchBytes = async (url) => await browserFetchBytes(page, url) ?? await nodeFetchBytes(url);
|
|
60582
|
+
const remaining = CONTENT_IMAGE_BUDGET - Object.keys(contentMap).length;
|
|
60583
|
+
const absUrls = [...new Set([...Object.values(refMap), ...stateImages])].filter((u) => !(u in contentMap)).slice(0, remaining);
|
|
60584
|
+
const { map: map2 } = await downloadContentImages(absUrls, cfg.runDir, fetchBytes);
|
|
60585
|
+
Object.assign(contentMap, map2);
|
|
60586
|
+
}
|
|
60587
|
+
}
|
|
60334
60588
|
} finally {
|
|
60335
60589
|
await page.close().catch(() => {
|
|
60336
60590
|
return;
|
|
@@ -60340,7 +60594,12 @@ async function capturePages(browser, viewport, resolvedPages, theme, cfg) {
|
|
|
60340
60594
|
});
|
|
60341
60595
|
}
|
|
60342
60596
|
}
|
|
60343
|
-
return {
|
|
60597
|
+
return {
|
|
60598
|
+
pages,
|
|
60599
|
+
components,
|
|
60600
|
+
vtexBlocks: blocksByPath.size ? dedupeVtexBlocks([...blocksByPath.values()]) : null,
|
|
60601
|
+
contentMap
|
|
60602
|
+
};
|
|
60344
60603
|
}
|
|
60345
60604
|
async function resolvePages2(page, baseUrl, pagesSpec, homeHtml, platform) {
|
|
60346
60605
|
const tokens = (pagesSpec ?? "/,category-auto,pdp-auto").split(",").map((s) => s.trim()).filter(Boolean);
|
|
@@ -60425,6 +60684,60 @@ async function structuralSignatures(page, selectors) {
|
|
|
60425
60684
|
return selectors.map(() => "");
|
|
60426
60685
|
}
|
|
60427
60686
|
}
|
|
60687
|
+
var DEFAULT_SAMPLE = "plp=2,pdp=2,other=3,search=1";
|
|
60688
|
+
var MAX_PAGES = 15;
|
|
60689
|
+
var INSTITUTIONAL_URL = /(sobre|about|institucional|quem-somos|contato|contact|ajuda|help|faq|blog|trabalhe|careers|carreiras|politica|policy|privacidade|privacy|termos|terms|troca|devolu|garantia|warranty|lojas|stores|imprensa|press|sustentab|acessibilidade|cookies)/i;
|
|
60690
|
+
function parseSample(spec) {
|
|
60691
|
+
const out = {};
|
|
60692
|
+
for (const part of (spec ?? DEFAULT_SAMPLE).split(",")) {
|
|
60693
|
+
const [k, n] = part.split("=").map((s) => s.trim());
|
|
60694
|
+
const count = Number.parseInt(n ?? "", 10);
|
|
60695
|
+
if (k && Number.isFinite(count) && count > 0)
|
|
60696
|
+
out[k] = count;
|
|
60697
|
+
}
|
|
60698
|
+
return out;
|
|
60699
|
+
}
|
|
60700
|
+
function pickSpread(items, count) {
|
|
60701
|
+
if (items.length <= count)
|
|
60702
|
+
return items;
|
|
60703
|
+
const step = items.length / count;
|
|
60704
|
+
const out = [];
|
|
60705
|
+
for (let i = 0;i < count; i++)
|
|
60706
|
+
out.push(items[Math.floor(i * step)]);
|
|
60707
|
+
return out;
|
|
60708
|
+
}
|
|
60709
|
+
function sampleFromSitemap(classified, spec, existing) {
|
|
60710
|
+
const seen = new Set(existing.map((p) => p.url));
|
|
60711
|
+
const byKind = new Map;
|
|
60712
|
+
for (const c of classified) {
|
|
60713
|
+
if (c.kind === "home" || seen.has(c.url))
|
|
60714
|
+
continue;
|
|
60715
|
+
const list = byKind.get(c.kind) ?? [];
|
|
60716
|
+
list.push(c.url);
|
|
60717
|
+
byKind.set(c.kind, list);
|
|
60718
|
+
}
|
|
60719
|
+
const other = byKind.get("other");
|
|
60720
|
+
if (other) {
|
|
60721
|
+
const inst = other.filter((u) => INSTITUTIONAL_URL.test(u));
|
|
60722
|
+
byKind.set("other", [...inst, ...other.filter((u) => !INSTITUTIONAL_URL.test(u))]);
|
|
60723
|
+
}
|
|
60724
|
+
const out = [];
|
|
60725
|
+
for (const [kind, count] of Object.entries(spec)) {
|
|
60726
|
+
const source = byKind.get(kind) ?? [];
|
|
60727
|
+
const chosen = kind === "other" ? source.slice(0, count) : pickSpread(source, count);
|
|
60728
|
+
for (const url of chosen) {
|
|
60729
|
+
if (seen.has(url))
|
|
60730
|
+
continue;
|
|
60731
|
+
seen.add(url);
|
|
60732
|
+
let path = url;
|
|
60733
|
+
try {
|
|
60734
|
+
path = new URL(url).pathname;
|
|
60735
|
+
} catch {}
|
|
60736
|
+
out.push({ path, url, kind });
|
|
60737
|
+
}
|
|
60738
|
+
}
|
|
60739
|
+
return out;
|
|
60740
|
+
}
|
|
60428
60741
|
function kindOf(url) {
|
|
60429
60742
|
try {
|
|
60430
60743
|
return classifyPath2(new URL(url).pathname);
|
|
@@ -60443,7 +60756,8 @@ function printResults4(runDir, bundle) {
|
|
|
60443
60756
|
if (bundle.vtex) {
|
|
60444
60757
|
const mapped = bundle.vtex.map.filter((m) => m.strategy === "mapped").length;
|
|
60445
60758
|
const withContent = bundle.vtex.blocks.filter((x) => x.props).length;
|
|
60446
|
-
|
|
60759
|
+
const contentImgs = countContentImages(bundle.vtex.blocks);
|
|
60760
|
+
console.log(chalk16.dim(` vtex io: ${bundle.vtex.blocks.length} blocks (${withContent} with CMS content, ${contentImgs} content images local) · ${mapped}/${bundle.vtex.map.length} mapped`));
|
|
60447
60761
|
}
|
|
60448
60762
|
console.log(chalk16.dim(` pages: ${bundle.pages.map((p) => p.kind).join(", ") || "—"}`));
|
|
60449
60763
|
console.log(chalk16.dim(` out: ${runDir}`));
|
|
@@ -60502,13 +60816,13 @@ function sleep2(ms) {
|
|
|
60502
60816
|
}
|
|
60503
60817
|
|
|
60504
60818
|
// src/commands/pr.ts
|
|
60505
|
-
import { existsSync as existsSync15, readFileSync as readFileSync17, writeFileSync as
|
|
60506
|
-
import { join as
|
|
60819
|
+
import { existsSync as existsSync15, readFileSync as readFileSync17, writeFileSync as writeFileSync22 } from "node:fs";
|
|
60820
|
+
import { join as join24 } from "node:path";
|
|
60507
60821
|
import chalk19 from "chalk";
|
|
60508
60822
|
|
|
60509
60823
|
// src/commands/run.ts
|
|
60510
60824
|
import { existsSync as existsSync14, readFileSync as readFileSync16, unlinkSync as unlinkSync3 } from "node:fs";
|
|
60511
|
-
import { join as
|
|
60825
|
+
import { join as join23 } from "node:path";
|
|
60512
60826
|
import chalk18 from "chalk";
|
|
60513
60827
|
import ora6 from "ora";
|
|
60514
60828
|
|
|
@@ -60990,7 +61304,7 @@ import chalk17 from "chalk";
|
|
|
60990
61304
|
// src/server/proxy-server.ts
|
|
60991
61305
|
import { existsSync as existsSync12, readFileSync as readFileSync15, statSync } from "node:fs";
|
|
60992
61306
|
import { createServer } from "node:http";
|
|
60993
|
-
import { extname, join as
|
|
61307
|
+
import { extname, join as join22, normalize as normalize3, resolve as resolve4, sep } from "node:path";
|
|
60994
61308
|
var MIME2 = {
|
|
60995
61309
|
".html": "text/html; charset=utf-8",
|
|
60996
61310
|
".css": "text/css; charset=utf-8",
|
|
@@ -61084,7 +61398,7 @@ async function handleRequest(req, res, runDir) {
|
|
|
61084
61398
|
return serveStatic(res, runDir, path);
|
|
61085
61399
|
}
|
|
61086
61400
|
function serveReportHtml(res, runDir) {
|
|
61087
|
-
const filePath =
|
|
61401
|
+
const filePath = join22(runDir, "report.html");
|
|
61088
61402
|
if (!existsSync12(filePath)) {
|
|
61089
61403
|
res.statusCode = 404;
|
|
61090
61404
|
res.end("report.html not found");
|
|
@@ -61481,7 +61795,7 @@ async function runCommand(rawOpts) {
|
|
|
61481
61795
|
}
|
|
61482
61796
|
const ignore = loadParityIgnore();
|
|
61483
61797
|
if (opts.clearCache) {
|
|
61484
|
-
const cacheFile =
|
|
61798
|
+
const cacheFile = join23(opts.output, "cache", "verdicts.json");
|
|
61485
61799
|
if (existsSync14(cacheFile)) {
|
|
61486
61800
|
try {
|
|
61487
61801
|
unlinkSync3(cacheFile);
|
|
@@ -61678,8 +61992,8 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
61678
61992
|
const traceEnabled = process.env.PARITY_TRACE === "1";
|
|
61679
61993
|
const runOneSide = async (viewport, side) => {
|
|
61680
61994
|
const baseUrl = side === "prod" ? opts.prod : opts.cand;
|
|
61681
|
-
const harPath =
|
|
61682
|
-
const tracePath = traceEnabled ?
|
|
61995
|
+
const harPath = join23(paths.harDir, `${viewport}-${side}.har`);
|
|
61996
|
+
const tracePath = traceEnabled ? join23(paths.tracesDir, `${viewport}-${side}.zip`) : null;
|
|
61683
61997
|
const ctx = await newContext(browser, {
|
|
61684
61998
|
viewport,
|
|
61685
61999
|
harPath,
|
|
@@ -61995,7 +62309,7 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
61995
62309
|
setSpinnerLabel("Rodando checks…");
|
|
61996
62310
|
spinner.start();
|
|
61997
62311
|
const checksHb = attachSpinnerHeartbeat(spinner, { baseText: "Rodando checks…" });
|
|
61998
|
-
const cacheDir =
|
|
62312
|
+
const cacheDir = join23(opts.output, "cache");
|
|
61999
62313
|
const checkCtx = {
|
|
62000
62314
|
prodPages: allPageCaptures.filter((p) => p.side === "prod"),
|
|
62001
62315
|
candPages: allPageCaptures.filter((p) => p.side === "cand"),
|
|
@@ -62402,7 +62716,7 @@ async function prCommand(opts) {
|
|
|
62402
62716
|
return runCode || 1;
|
|
62403
62717
|
}
|
|
62404
62718
|
const latest = runs[0];
|
|
62405
|
-
const reportJsonPath =
|
|
62719
|
+
const reportJsonPath = join24(opts.output, "runs", latest.id, "report.json");
|
|
62406
62720
|
if (!existsSync15(reportJsonPath)) {
|
|
62407
62721
|
console.error(chalk19.red(`report.json not found at ${reportJsonPath}`));
|
|
62408
62722
|
return runCode || 1;
|
|
@@ -62410,7 +62724,7 @@ async function prCommand(opts) {
|
|
|
62410
62724
|
const run = JSON.parse(readFileSync17(reportJsonPath, "utf8"));
|
|
62411
62725
|
const markdown = buildPrComment(run, opts);
|
|
62412
62726
|
if (opts.out) {
|
|
62413
|
-
|
|
62727
|
+
writeFileSync22(opts.out, markdown, "utf8");
|
|
62414
62728
|
console.log(chalk19.dim(` wrote PR comment: ${opts.out}`));
|
|
62415
62729
|
} else {
|
|
62416
62730
|
process.stdout.write(`
|
|
@@ -62419,7 +62733,7 @@ ${markdown}
|
|
|
62419
62733
|
}
|
|
62420
62734
|
if (opts.github && process.env.GITHUB_STEP_SUMMARY) {
|
|
62421
62735
|
try {
|
|
62422
|
-
|
|
62736
|
+
writeFileSync22(process.env.GITHUB_STEP_SUMMARY, markdown, { flag: "a" });
|
|
62423
62737
|
} catch (err) {
|
|
62424
62738
|
console.error(chalk19.yellow(`failed to write GITHUB_STEP_SUMMARY: ${err.message}`));
|
|
62425
62739
|
}
|
|
@@ -62480,7 +62794,7 @@ function buildPrComment(run, opts) {
|
|
|
62480
62794
|
}
|
|
62481
62795
|
|
|
62482
62796
|
// src/commands/prompt.ts
|
|
62483
|
-
import { existsSync as existsSync16, writeFileSync as
|
|
62797
|
+
import { existsSync as existsSync16, writeFileSync as writeFileSync23 } from "node:fs";
|
|
62484
62798
|
import chalk20 from "chalk";
|
|
62485
62799
|
function promptCommand(runId, opts) {
|
|
62486
62800
|
let run;
|
|
@@ -62495,7 +62809,7 @@ function promptCommand(runId, opts) {
|
|
|
62495
62809
|
limit: opts.limit
|
|
62496
62810
|
});
|
|
62497
62811
|
if (opts.out) {
|
|
62498
|
-
|
|
62812
|
+
writeFileSync23(opts.out, md, "utf8");
|
|
62499
62813
|
console.log(chalk20.green(`✔ prompt salvo em ${opts.out}`));
|
|
62500
62814
|
if (existsSync16(opts.out)) {
|
|
62501
62815
|
const sizeKb = (md.length / 1024).toFixed(1);
|
|
@@ -62690,8 +63004,8 @@ async function reportCommand(runId, opts) {
|
|
|
62690
63004
|
}
|
|
62691
63005
|
|
|
62692
63006
|
// src/commands/vitals.ts
|
|
62693
|
-
import { existsSync as existsSync18, readFileSync as readFileSync19, writeFileSync as
|
|
62694
|
-
import { join as
|
|
63007
|
+
import { existsSync as existsSync18, readFileSync as readFileSync19, writeFileSync as writeFileSync24 } from "node:fs";
|
|
63008
|
+
import { join as join25 } from "node:path";
|
|
62695
63009
|
import chalk22 from "chalk";
|
|
62696
63010
|
import ora7 from "ora";
|
|
62697
63011
|
async function vitalsCommand(opts) {
|
|
@@ -62799,7 +63113,7 @@ async function vitalsCommand(opts) {
|
|
|
62799
63113
|
writeRunReportJson(paths.runDir, run);
|
|
62800
63114
|
const html3 = renderHtmlReport(run, paths.runDir);
|
|
62801
63115
|
writeRunReportHtml(paths.runDir, html3);
|
|
62802
|
-
|
|
63116
|
+
writeFileSync24(join25(paths.runDir, "vitals.json"), `${JSON.stringify({
|
|
62803
63117
|
schemaVersion: "0.1",
|
|
62804
63118
|
prodUrl: opts.prod,
|
|
62805
63119
|
candUrl: opts.cand,
|
|
@@ -63117,7 +63431,7 @@ program.command("extract").description("Single-site AI-ready component extractio
|
|
|
63117
63431
|
json: opts.json
|
|
63118
63432
|
}));
|
|
63119
63433
|
});
|
|
63120
|
-
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("--open", "Open the generated index.html visual report in the browser", 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) => {
|
|
63434
|
+
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("--sample <spec>", "Extra pages to sample from the sitemap by kind, e.g. 'plp=2,pdp=2,other=3,search=1' (other = institutional). Default samples a few of each incl. institutional pages.").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("--open", "Open the generated index.html visual report in the browser", 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) => {
|
|
63121
63435
|
process.exit(await migrateCommand({
|
|
63122
63436
|
url: opts.url,
|
|
63123
63437
|
pages: opts.pages,
|
|
@@ -63125,6 +63439,7 @@ program.command("migrate").description("Single-site, phased migration capture (t
|
|
|
63125
63439
|
target: opts.target,
|
|
63126
63440
|
viewport: opts.viewport,
|
|
63127
63441
|
viewports: opts.viewports,
|
|
63442
|
+
sample: opts.sample,
|
|
63128
63443
|
format: opts.format,
|
|
63129
63444
|
outDir: opts.out,
|
|
63130
63445
|
refresh: opts.refresh,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/parity",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "E2E parity validator for site migrations. Compares prod vs cand and reports UI, functional, SEO, visual, and Web Vitals deltas with an LLM-ranked HTML report.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|