chore(variants): standing rule row 235 — variant preview must differ from mother's; preview.svg not gitignored, added once at first creation

- .gitignore: /files/*.svg reverted to /files/logos.svg — files/preview.svg is
  deliberately NOT ignored anymore (it is the editable source of preview.png
  and lives committed in the private variants repo). The public export still
  excludes files/*.svg (LimeSurvey's image validator rejects SVG for images).
- variants/build.php: copyDirRecursive() gained a $neverOverwrite list;
  files/preview.svg is copied into a variant only at FIRST creation (seeded
  from the mother when the definitions dir has none) and never overwritten on
  later builds. The build prints a WARNING when the variant's preview.png is
  md5-identical to the mother's, enforcing the standing rule that every
  variant has its own preview.
- Standing rule recorded in AGENTS.md (project) and ~/.vibe/AGENTS.md.

Verified in a /tmp sandbox build: first build copies/seeds preview.svg; a
user-edited preview.svg survives rebuilds (also when the definitions copy
changes); all other assets are still overwritten; identical-preview.png
warning fires; php -l clean; export_public.sh exit 0 with no .svg in the zip.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
Tammo ter Hark 2026-11-30 12:08:06 +01:00
commit 52fc90b062
2 changed files with 66 additions and 9 deletions

13
.gitignore vendored
View file

@ -32,10 +32,15 @@
# Export zips, if an output dir inside the theme is ever used. # Export zips, if an output dir inside the theme is ever used.
/dist/ /dist/
# Work-in-progress artwork sources (logo/preview SVGs) — local only, never # Work-in-progress logo artwork — local only, never commit/publish.
# commit/publish. LimeSurvey's image validator rejects SVG for theme images /files/logos.svg
# anyway, so only the exported PNG is ever committed (e.g. files/preview.png).
/files/*.svg # NOTE: files/preview.svg is deliberately NOT ignored (standing rule, row 235):
# it is the editable source of files/preview.png and is meant to be committed —
# in a variant (private variants repo) build.php adds it only once, at first
# creation, and never overwrites it afterwards. The public export still excludes
# all files/*.svg (see variants/export_public.sh): LimeSurvey's image validator
# rejects SVG for theme images, so only the exported PNG ships.
# Session prompt log (prompts used + results). Internal working notes — never # Session prompt log (prompts used + results). Internal working notes — never
# commit, never publish. # commit, never publish.

View file

@ -39,6 +39,14 @@
* <variantName>/css/... client css (e.g. css/variant.css with @font-face) * <variantName>/css/... client css (e.g. css/variant.css with @font-face)
* The <variantName>/ folder is copied into the generated theme automatically. * The <variantName>/ folder is copied into the generated theme automatically.
* *
* PREVIEW RULE (standing rule, row 235): every variant must have a preview that
* DIFFERS from the mother's (files/preview.png). files/preview.svg is the
* editable source of that png: it is NOT gitignored, it is added to the variant
* only ONCE at first creation (seeded from the mother if the definitions dir has
* none) and is NEVER overwritten on later builds — the user may edit it. After
* editing preview.svg, export files/preview.png from it (Inkscape: PNG export).
* The build warns when the variant's preview.png is identical to the mother's.
*
* Example: * Example:
* php variants/build.php <client> /path/to/private-variants * php variants/build.php <client> /path/to/private-variants
* *
@ -114,8 +122,15 @@ function setMetadata(DOMXPath $xpath, DOMDocument $doc, string $tag, string $val
$node->textContent = $value; $node->textContent = $value;
} }
/** Recursively copy a directory (used for the variant's own assets). */ /**
function copyDirRecursive(string $src, string $dst): void * Recursively copy a directory (used for the variant's own assets).
*
* $neverOverwrite lists destination-relative paths (with '/' separators) that
* are copied ONLY when they do not exist yet in $dst — used for
* files/preview.svg: added to a variant once, at first creation, and never
* overwritten afterwards, because the user may have edited it (row 235).
*/
function copyDirRecursive(string $src, string $dst, array $neverOverwrite = [], string $prefix = ''): void
{ {
if (!is_dir($dst)) { if (!is_dir($dst)) {
mkdir($dst, 0775, true); mkdir($dst, 0775, true);
@ -128,8 +143,12 @@ function copyDirRecursive(string $src, string $dst): void
$s = $src . DIRECTORY_SEPARATOR . $entry; $s = $src . DIRECTORY_SEPARATOR . $entry;
$d = $dst . DIRECTORY_SEPARATOR . $entry; $d = $dst . DIRECTORY_SEPARATOR . $entry;
if (is_dir($s)) { if (is_dir($s)) {
copyDirRecursive($s, $d); copyDirRecursive($s, $d, $neverOverwrite, $prefix . $entry . '/');
} else { } else {
$rel = $prefix . $entry; // relative to the top-level $src, '/' separators
if (in_array($rel, $neverOverwrite, true) && file_exists($d)) {
continue; // first-creation-only file already present: never overwrite
}
copy($s, $d); copy($s, $d);
} }
} }
@ -352,11 +371,43 @@ $doc->save($out);
// folder is copied into the generated theme, so a client-specific font or css is // folder is copied into the generated theme, so a client-specific font or css is
// part of the variant by default (no manual copying needed). // part of the variant by default (no manual copying needed).
$variantAssets = rtrim($definitionsDir, '/\\') . DIRECTORY_SEPARATOR . $variantName; $variantAssets = rtrim($definitionsDir, '/\\') . DIRECTORY_SEPARATOR . $variantName;
// Row 235: files/preview.svg is added to a variant only at FIRST creation and is
// never overwritten afterwards (the user may have edited it in the variant), so
// it is passed in $neverOverwrite. Everything else is overwritten as before.
$neverOverwrite = ['files/preview.svg'];
if (is_dir($variantAssets)) { if (is_dir($variantAssets)) {
copyDirRecursive($variantAssets, $variantDir); copyDirRecursive($variantAssets, $variantDir, $neverOverwrite);
echo "Copied variant assets: $variantAssets -> $variantDir\n"; echo "Copied variant assets: $variantAssets -> $variantDir\n";
} }
// --- row 235: seed files/preview.svg at first creation only ---
// The variant's preview must DIFFER from the mother's (standing rule), so the
// developer defines a variant-specific preview.svg (editable source of
// files/preview.png) in <definitionsDir>/<variantName>/files/. If neither the
// definitions dir nor the variant itself has one yet (first creation), seed it
// from the mother's files/preview.svg as a starting point to edit.
$variantPreviewSvg = $variantDir . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . 'preview.svg';
if (!is_file($variantPreviewSvg)) {
$motherPreviewSvg = $motherDir . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . 'preview.svg';
if (is_file($motherPreviewSvg)) {
if (!is_dir(dirname($variantPreviewSvg))) {
mkdir(dirname($variantPreviewSvg), 0775, true);
}
copy($motherPreviewSvg, $variantPreviewSvg);
echo "Seeded files/preview.svg from the mother (first creation) — EDIT IT so the variant preview differs from vanilla_respondage, then export files/preview.png\n";
} else {
fwrite(STDERR, "NOTE: no files/preview.svg found for this variant (neither in $variantAssets nor in the mother). Create one and export files/preview.png — the variant preview must differ from the mother's (row 235).\n");
}
}
// --- row 235 standing rule: a variant preview must differ from the mother's ---
$variantPreviewPng = $variantDir . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . 'preview.png';
$motherPreviewPng = $motherDir . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . 'preview.png';
if (is_file($variantPreviewPng) && is_file($motherPreviewPng)
&& md5_file($variantPreviewPng) === md5_file($motherPreviewPng)) {
fwrite(STDERR, "WARNING: $variantName files/preview.png is IDENTICAL to the mother's — standing rule (row 235): each variant must have its own preview. Define files/preview.svg in the definitions dir, edit it, export files/preview.png.\n");
}
// --- footer override: variants show NO Respondage theme footer to respondents --- // --- footer override: variants show NO Respondage theme footer to respondents ---
// The mother's views/subviews/footer/footer.twig renders a "proudly developed by // The mother's views/subviews/footer/footer.twig renders a "proudly developed by
// Respondage" credit; in a variant that must not appear (the Respondage footer on // Respondage" credit; in a variant that must not appear (the Respondage footer on
@ -376,7 +427,8 @@ if (!is_file($variantFooterFile)) {
echo "Variant '$variantName' built: $out\n"; echo "Variant '$variantName' built: $out\n";
echo 'Options overridden: ' . (empty($definition['options']) ? '(none)' : implode(', ', array_keys($definition['options']))) . "\n"; echo 'Options overridden: ' . (empty($definition['options']) ? '(none)' : implode(', ', array_keys($definition['options']))) . "\n";
echo "Note: existing files in $variantDir were OVERWRITTEN from the definitions dir.\n"; echo "Note: existing files in $variantDir were OVERWRITTEN from the definitions dir,\n";
echo " EXCEPT files/preview.svg: added only at first creation, never overwritten (row 235).\n";
echo "REBUILD RULE: re-run this build after EVERY change to $variantName.json or to the\n"; echo "REBUILD RULE: re-run this build after EVERY change to $variantName.json or to the\n";
echo " <definitionsDir>/$variantName/ assets — a variant folder that is not rebuilt after\n"; echo " <definitionsDir>/$variantName/ assets — a variant folder that is not rebuilt after\n";
echo " a definitions change is stale (fonts/logo/css then don't match the definitions).\n"; echo " a definitions change is stale (fonts/logo/css then don't match the definitions).\n";