@getcoherent/cli 0.3.8 → 0.3.9

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.
Files changed (2) hide show
  1. package/dist/index.js +42 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -7117,6 +7117,42 @@ function stripInlineLayoutElements(code) {
7117
7117
  }
7118
7118
  return { code: result, stripped };
7119
7119
  }
7120
+ function enforceWidthWrapper(code, route) {
7121
+ if (route === "/" || route === "/home") return { code, fixed: false };
7122
+ if (/<section[\s>]/i.test(code) && (/<section[\s>]/gi.exec(code) || []).length >= 2) {
7123
+ return { code, fixed: false };
7124
+ }
7125
+ const narrowWidths = /max-w-(xs|sm|md|lg|xl|2xl|3xl|4xl|5xl|6xl)\b/;
7126
+ const hasMax7xl = /max-w-7xl/.test(code);
7127
+ if (hasMax7xl) return { code, fixed: false };
7128
+ const mainMatch = code.match(/<main\s+className="([^"]*)"/);
7129
+ if (mainMatch) {
7130
+ const currentClasses = mainMatch[1];
7131
+ if (narrowWidths.test(currentClasses)) {
7132
+ const fixed = currentClasses.replace(narrowWidths, "max-w-7xl");
7133
+ return { code: code.replace(mainMatch[0], `<main className="${fixed}"`), fixed: true };
7134
+ }
7135
+ if (!currentClasses.includes("max-w-")) {
7136
+ const newClasses = `mx-auto max-w-7xl ${currentClasses}`;
7137
+ return { code: code.replace(mainMatch[0], `<main className="${newClasses}"`), fixed: true };
7138
+ }
7139
+ }
7140
+ const returnMatch = code.match(/return\s*\(\s*\n?\s*<(div|main)\s+className="([^"]*)"/);
7141
+ if (returnMatch) {
7142
+ const [fullMatch, tag, currentClasses] = returnMatch;
7143
+ if (narrowWidths.test(currentClasses)) {
7144
+ const fixed = currentClasses.replace(narrowWidths, "max-w-7xl");
7145
+ return { code: code.replace(fullMatch, `return (
7146
+ <${tag} className="${fixed}"`), fixed: true };
7147
+ }
7148
+ if (!currentClasses.includes("max-w-")) {
7149
+ const newClasses = `mx-auto max-w-7xl px-4 sm:px-6 lg:px-8 ${currentClasses}`;
7150
+ return { code: code.replace(fullMatch, `return (
7151
+ <${tag} className="${newClasses}"`), fixed: true };
7152
+ }
7153
+ }
7154
+ return { code, fixed: false };
7155
+ }
7120
7156
  async function applyModification(request, dsm, cm, pm, projectRoot, aiProvider, originalMessage) {
7121
7157
  switch (request.type) {
7122
7158
  case "modify-layout-block": {
@@ -7491,8 +7527,11 @@ async function applyModification(request, dsm, cm, pm, projectRoot, aiProvider,
7491
7527
  codeToWrite = autoFixed;
7492
7528
  const { code: layoutStripped, stripped } = stripInlineLayoutElements(codeToWrite);
7493
7529
  codeToWrite = layoutStripped;
7530
+ const { code: widthFixed, fixed: widthWasFixed } = enforceWidthWrapper(codeToWrite, route);
7531
+ codeToWrite = widthFixed;
7494
7532
  const allFixes = [...postFixes, ...autoFixes];
7495
7533
  if (stripped.length > 0) allFixes.push(`stripped inline ${stripped.join(", ")} (layout owns these)`);
7534
+ if (widthWasFixed) allFixes.push("enforced max-w-7xl width consistency");
7496
7535
  if (allFixes.length > 0) {
7497
7536
  console.log(chalk11.dim(" \u{1F527} Post-generation fixes:"));
7498
7537
  allFixes.forEach((f) => console.log(chalk11.dim(` ${f}`)));
@@ -7658,8 +7697,11 @@ ${pagesCtx}`
7658
7697
  codeToWrite = autoFixed;
7659
7698
  const { code: layoutStripped, stripped } = stripInlineLayoutElements(codeToWrite);
7660
7699
  codeToWrite = layoutStripped;
7700
+ const { code: widthFixed2, fixed: widthWasFixed2 } = enforceWidthWrapper(codeToWrite, route);
7701
+ codeToWrite = widthFixed2;
7661
7702
  const allFixes = [...postFixes, ...autoFixes];
7662
7703
  if (stripped.length > 0) allFixes.push(`stripped inline ${stripped.join(", ")} (layout owns these)`);
7704
+ if (widthWasFixed2) allFixes.push("enforced max-w-7xl width consistency");
7663
7705
  if (allFixes.length > 0) {
7664
7706
  console.log(chalk11.dim(" \u{1F527} Post-generation fixes:"));
7665
7707
  allFixes.forEach((f) => console.log(chalk11.dim(` ${f}`)));
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.3.8",
6
+ "version": "0.3.9",
7
7
  "description": "CLI interface for Coherent Design Method",
8
8
  "type": "module",
9
9
  "main": "./dist/index.js",