Fix CSS var sync: preserve starter file variable order
Some checks failed
Repo Health / Access control (push) Successful in 1s
Repo Health / Release configuration (push) Failing after 5s
Repo Health / Scripts governance (push) Successful in 4s
Repo Health / Repository health (push) Failing after 4s

groupBySection now walks the starter file top-to-bottom instead of
iterating the missing array by name. Injected variables match the
same order as the standard theme file.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jonathan Miller
2026-04-18 17:09:30 -05:00
parent 4cf2b0c7bb
commit 751cffbfbf

View File

@@ -181,29 +181,25 @@ final class MokoCssVarSync
{
$lines = file($starterPath, FILE_IGNORE_NEW_LINES);
$section = 'Uncategorised';
$map = []; // variable name => section
// Walk the starter file in order — this preserves the original
// variable ordering so injected variables match the standard theme layout.
$sections = [];
foreach ($lines as $line) {
// Detect section comment headers like /* ===== HERO VARIANTS ===== */
if (preg_match('/\/\*\s*=+\s*(.+?)\s*=+\s*\*\//', $line, $m)) {
$section = trim($m[1]);
}
// Detect variable declaration
// Detect variable declaration — only include if it's missing from user file
if (preg_match('/^\s*(--[\w-]+)\s*:/', $line, $m)) {
$name = trim($m[1]);
if (isset($missing[$name])) {
$map[$name] = $section;
$sections[$section][] = $missing[$name];
}
}
}
// Group by section
$sections = [];
foreach ($missing as $name => $declaration) {
$sec = $map[$name] ?? 'Uncategorised';
$sections[$sec][] = $declaration;
}
return $sections;
}