@getcoherent/cli 0.3.8 → 0.3.10
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/dist/index.js +63 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6633,6 +6633,27 @@ ${fixed}`;
|
|
|
6633
6633
|
const cleaned = inner.replace(/\s{2,}/g, " ").trim();
|
|
6634
6634
|
return `className="${cleaned}"`;
|
|
6635
6635
|
});
|
|
6636
|
+
let imgCounter = 1;
|
|
6637
|
+
const beforeImgFix = fixed;
|
|
6638
|
+
fixed = fixed.replace(/["']\/api\/placeholder\/(\d+)\/(\d+)["']/g, (_m, w, h) => {
|
|
6639
|
+
return `"https://picsum.photos/${w}/${h}?random=${imgCounter++}"`;
|
|
6640
|
+
});
|
|
6641
|
+
fixed = fixed.replace(/["']\/placeholder-avatar[^"']*["']/g, () => {
|
|
6642
|
+
return `"https://i.pravatar.cc/150?u=user${imgCounter++}"`;
|
|
6643
|
+
});
|
|
6644
|
+
fixed = fixed.replace(/["']https?:\/\/via\.placeholder\.com\/(\d+)x?(\d*)(?:\/[^"']*)?\/?["']/g, (_m, w, h) => {
|
|
6645
|
+
const height = h || w;
|
|
6646
|
+
return `"https://picsum.photos/${w}/${height}?random=${imgCounter++}"`;
|
|
6647
|
+
});
|
|
6648
|
+
fixed = fixed.replace(/["']\/images\/[^"']+\.(?:jpg|jpeg|png|webp|gif)["']/g, () => {
|
|
6649
|
+
return `"https://picsum.photos/800/400?random=${imgCounter++}"`;
|
|
6650
|
+
});
|
|
6651
|
+
fixed = fixed.replace(/["']\/placeholder[^"']*\.(?:jpg|jpeg|png|webp)["']/g, () => {
|
|
6652
|
+
return `"https://picsum.photos/800/400?random=${imgCounter++}"`;
|
|
6653
|
+
});
|
|
6654
|
+
if (fixed !== beforeImgFix) {
|
|
6655
|
+
fixes.push("placeholder images \u2192 working URLs (picsum/pravatar)");
|
|
6656
|
+
}
|
|
6636
6657
|
return { code: fixed, fixes };
|
|
6637
6658
|
}
|
|
6638
6659
|
function formatIssues(issues) {
|
|
@@ -7117,6 +7138,42 @@ function stripInlineLayoutElements(code) {
|
|
|
7117
7138
|
}
|
|
7118
7139
|
return { code: result, stripped };
|
|
7119
7140
|
}
|
|
7141
|
+
function enforceWidthWrapper(code, route) {
|
|
7142
|
+
if (route === "/" || route === "/home") return { code, fixed: false };
|
|
7143
|
+
if (/<section[\s>]/i.test(code) && (/<section[\s>]/gi.exec(code) || []).length >= 2) {
|
|
7144
|
+
return { code, fixed: false };
|
|
7145
|
+
}
|
|
7146
|
+
const narrowWidths = /max-w-(xs|sm|md|lg|xl|2xl|3xl|4xl|5xl|6xl)\b/;
|
|
7147
|
+
const hasMax7xl = /max-w-7xl/.test(code);
|
|
7148
|
+
if (hasMax7xl) return { code, fixed: false };
|
|
7149
|
+
const mainMatch = code.match(/<main\s+className="([^"]*)"/);
|
|
7150
|
+
if (mainMatch) {
|
|
7151
|
+
const currentClasses = mainMatch[1];
|
|
7152
|
+
if (narrowWidths.test(currentClasses)) {
|
|
7153
|
+
const fixed = currentClasses.replace(narrowWidths, "max-w-7xl");
|
|
7154
|
+
return { code: code.replace(mainMatch[0], `<main className="${fixed}"`), fixed: true };
|
|
7155
|
+
}
|
|
7156
|
+
if (!currentClasses.includes("max-w-")) {
|
|
7157
|
+
const newClasses = `mx-auto max-w-7xl ${currentClasses}`;
|
|
7158
|
+
return { code: code.replace(mainMatch[0], `<main className="${newClasses}"`), fixed: true };
|
|
7159
|
+
}
|
|
7160
|
+
}
|
|
7161
|
+
const returnMatch = code.match(/return\s*\(\s*\n?\s*<(div|main)\s+className="([^"]*)"/);
|
|
7162
|
+
if (returnMatch) {
|
|
7163
|
+
const [fullMatch, tag, currentClasses] = returnMatch;
|
|
7164
|
+
if (narrowWidths.test(currentClasses)) {
|
|
7165
|
+
const fixed = currentClasses.replace(narrowWidths, "max-w-7xl");
|
|
7166
|
+
return { code: code.replace(fullMatch, `return (
|
|
7167
|
+
<${tag} className="${fixed}"`), fixed: true };
|
|
7168
|
+
}
|
|
7169
|
+
if (!currentClasses.includes("max-w-")) {
|
|
7170
|
+
const newClasses = `mx-auto max-w-7xl px-4 sm:px-6 lg:px-8 ${currentClasses}`;
|
|
7171
|
+
return { code: code.replace(fullMatch, `return (
|
|
7172
|
+
<${tag} className="${newClasses}"`), fixed: true };
|
|
7173
|
+
}
|
|
7174
|
+
}
|
|
7175
|
+
return { code, fixed: false };
|
|
7176
|
+
}
|
|
7120
7177
|
async function applyModification(request, dsm, cm, pm, projectRoot, aiProvider, originalMessage) {
|
|
7121
7178
|
switch (request.type) {
|
|
7122
7179
|
case "modify-layout-block": {
|
|
@@ -7491,8 +7548,11 @@ async function applyModification(request, dsm, cm, pm, projectRoot, aiProvider,
|
|
|
7491
7548
|
codeToWrite = autoFixed;
|
|
7492
7549
|
const { code: layoutStripped, stripped } = stripInlineLayoutElements(codeToWrite);
|
|
7493
7550
|
codeToWrite = layoutStripped;
|
|
7551
|
+
const { code: widthFixed, fixed: widthWasFixed } = enforceWidthWrapper(codeToWrite, route);
|
|
7552
|
+
codeToWrite = widthFixed;
|
|
7494
7553
|
const allFixes = [...postFixes, ...autoFixes];
|
|
7495
7554
|
if (stripped.length > 0) allFixes.push(`stripped inline ${stripped.join(", ")} (layout owns these)`);
|
|
7555
|
+
if (widthWasFixed) allFixes.push("enforced max-w-7xl width consistency");
|
|
7496
7556
|
if (allFixes.length > 0) {
|
|
7497
7557
|
console.log(chalk11.dim(" \u{1F527} Post-generation fixes:"));
|
|
7498
7558
|
allFixes.forEach((f) => console.log(chalk11.dim(` ${f}`)));
|
|
@@ -7658,8 +7718,11 @@ ${pagesCtx}`
|
|
|
7658
7718
|
codeToWrite = autoFixed;
|
|
7659
7719
|
const { code: layoutStripped, stripped } = stripInlineLayoutElements(codeToWrite);
|
|
7660
7720
|
codeToWrite = layoutStripped;
|
|
7721
|
+
const { code: widthFixed2, fixed: widthWasFixed2 } = enforceWidthWrapper(codeToWrite, route);
|
|
7722
|
+
codeToWrite = widthFixed2;
|
|
7661
7723
|
const allFixes = [...postFixes, ...autoFixes];
|
|
7662
7724
|
if (stripped.length > 0) allFixes.push(`stripped inline ${stripped.join(", ")} (layout owns these)`);
|
|
7725
|
+
if (widthWasFixed2) allFixes.push("enforced max-w-7xl width consistency");
|
|
7663
7726
|
if (allFixes.length > 0) {
|
|
7664
7727
|
console.log(chalk11.dim(" \u{1F527} Post-generation fixes:"));
|
|
7665
7728
|
allFixes.forEach((f) => console.log(chalk11.dim(` ${f}`)));
|