feat(variants): build_all.sh modes — build only new variants, --rebuild only existing ones

- Default (build) mode picks up only *.json files for which NO variant folder
  (../<name>/) exists yet, so an existing variant is never clobbered by a
  build run (e.g. by a just-copied, not-yet-adjusted json). At the end it lists
  the jsons that were NOT picked up and advises that they possibly need to be
  re-built via 'build_all.sh --rebuild'.
- '--rebuild' mode picks up only *.json files whose variant folder already
  exists, and advises about the jsons without a variant yet (build them with
  the default mode).
- Both modes print a 'N built, M failed, K not picked up' summary, exit non-zero
  on any build failure, and keep the owner follow-up actions (reset themes in
  the LS admin, flushassets, Ctrl+F5).
- README build/rebuild sections and AGENTS.md updated to the two modes.

Verified in a /tmp sandbox: build mode built only the json without a variant
folder and listed the existing ones with the --rebuild advice; --rebuild built
only existing variants and listed the new json with the build advice; on the
real definitions dir the default mode built 0 and skipped all 3 (variants
exist) without touching ../respondage_respondage/config.xml (md5 unchanged).
export_public.sh exit 0.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
Tammo ter Hark 2026-11-30 12:38:05 +01:00
commit 92cc6443ac
2 changed files with 79 additions and 23 deletions

View file

@ -391,10 +391,14 @@ the variant's `preview.png` is identical to the mother's.
"options": { "primarycolor": "#123456", "fontsize": "18px" }
}
```
CAUTION: `build_all.sh` (step below) builds EVERY `*.json` in the
definitions dir — do not run it while a just-copied json is still
unadjusted, it would rebuild that variant with the copied values.
3. Run `php variants/build.php <client> <definitions-dir>`. This generates
3. Run `php variants/build.php <client> <definitions-dir>` — or, to build ALL
new variants in one go, `bash variants/build_all.sh <definitions-dir>`:
the default (build) mode picks up ONLY the `*.json` files for which NO
variant exists yet (no `../<client>/` folder), so an existing variant is
never clobbered by a build run — even by a just-copied, not-yet-adjusted
json. The json files that were NOT picked up are listed at the end with the
advice that they possibly need to be re-built (see the rebuild process).
This generates
`../<client>/config.xml`: a copy of this theme's config.xml with only those
option values replaced, `<extends>` set to this theme, and the `<engine>`
section emptied except `<optionspage>` (same as LimeSurvey's own "extend
@ -418,18 +422,22 @@ the variant's `preview.png` is identical to the mother's.
- Views/css/js changes in this theme apply to all variants immediately via
`<extends>` — no rebuild needed (but do flush assets + Ctrl+F5 on the server).
- After a `config.xml` change (new/renamed options) or a change to a
`<client>.json` / `<client>/` in the definitions repo, rebuild ALL variants
in one go:
`<client>.json` / `<client>/` in the definitions repo, rebuild ALL existing
variants in one go:
```
bash variants/build_all.sh <definitions-dir>
bash variants/build_all.sh --rebuild <definitions-dir>
```
The `--rebuild` mode picks up ONLY the `*.json` files for which a variant
folder ALREADY exists (`../<client>/`); the json files that were NOT picked
up (no variant yet) are listed at the end with the advice to build them with
the default mode (`bash variants/build_all.sh <definitions-dir>`).
(`<definitions-dir>` defaults to `variants/` or `$RESPONDAGE_VARIANTS_DIR`;
set `PHP_BIN=/path/to/php` if `php` is not on PATH.) It loops over every
`*.json` in the definitions dir, calls `build.php` per variant, prints a
summary (`N built, M failed`) and exits non-zero if any variant fails
(unknown option keys fail loudly — the drift check). Then, per rebuilt
variant: reset the theme in the LimeSurvey admin (Theme options → Reset),
flush assets, Ctrl+F5. `build.php` enforces the per-variant rules itself:
set `PHP_BIN=/path/to/php` if `php` is not on PATH.) Both modes call
`build.php` per picked-up variant, print a summary
(`N built, M failed, K not picked up`) and exit non-zero if any variant
fails (unknown option keys fail loudly — the drift check). Then, per
(re)built variant: reset the theme in the LimeSurvey admin (Theme options →
Reset), flush assets, Ctrl+F5. `build.php` enforces the per-variant rules itself:
`files/preview.svg` is only added at first creation and never overwritten,
and it warns when a variant's `preview.png` is identical to the mother's.
Never edit the generated `../<client>/` folder by hand — every build

View file

@ -1,15 +1,28 @@
#!/usr/bin/env bash
# ---------------------------------------------------------------------------
# REBUILD process: rebuild ALL variants of this theme from their json
# definitions in one go (see README.md, "Client variants (house styles)").
# Build/rebuild ALL variants of this theme from their json definitions
# (see README.md, "Client variants (house styles)").
#
# Usage:
# bash variants/build_all.sh [definitions-dir]
# bash variants/build_all.sh [--rebuild] [definitions-dir]
#
# Modes:
# (default) BUILD — picks up only the *.json files for which NO variant
# exists yet (no ../<name>/ folder next to this theme),
# so existing variants are never clobbered by accident.
# --rebuild REBUILD — picks up only the *.json files for which a variant
# folder ALREADY exists (rebuild after a change in this
# mother theme or in the definitions).
#
# In both modes the *.json files that were NOT picked up are listed at the end
# with advice: in build mode, existing variants possibly need a re-build
# (`--rebuild`); in rebuild mode, json files without a variant yet still need
# to be built (default mode).
#
# definitions-dir defaults to the variants/ folder next to this script, or to
# $RESPONDAGE_VARIANTS_DIR (the private variants repository, which holds the
# confidential <client>.json files and <client>/ asset folders). Every
# <name>.json in that dir is built with variants/build.php <name> <dir>.
# confidential <client>.json files and <client>/ asset folders). Every picked-up
# <name>.json is built with variants/build.php <name> <dir>.
#
# Environment:
# PHP_BIN php binary to use (default: "php"; e.g. PHP_BIN=/usr/bin/php)
@ -22,7 +35,7 @@
# mother's (standing rule: each variant has its own preview).
#
# After a successful run, the OWNER actions in the LimeSurvey admin UI are:
# 1. reset every rebuilt variant theme (Theme options -> <variant> -> Reset),
# 1. reset every (re)built variant theme (Theme options -> <variant> -> Reset),
# so the new config.xml is imported into lime_template_configuration;
# 2. flush the asset cache: php application/commands/console.php flushassets
# (or the button in the admin UI);
@ -30,13 +43,21 @@
# ---------------------------------------------------------------------------
set -u
MODE="build"
if [ "${1:-}" = "--rebuild" ]; then
MODE="rebuild"
shift
fi
HERE="$(cd "$(dirname "$0")" && pwd)"
MOTHER_DIR="$(dirname "$HERE")" # .../themes/survey/vanilla_respondage
THEMES_DIR="$(dirname "$MOTHER_DIR")" # .../themes/survey
DEFS="${1:-${RESPONDAGE_VARIANTS_DIR:-$HERE}}"
PHP_BIN="${PHP_BIN:-php}"
if [ ! -d "$DEFS" ]; then
echo "ERROR: definitions dir not found: $DEFS" >&2
echo "Usage: bash variants/build_all.sh [definitions-dir]" >&2
echo "Usage: bash variants/build_all.sh [--rebuild] [definitions-dir]" >&2
exit 1
fi
@ -49,10 +70,20 @@ fi
built=0
failed=0
skipped=()
for json in "${jsons[@]}"; do
name="$(basename "$json" .json)"
variant_dir="$THEMES_DIR/$name"
if [ "$MODE" = "build" ] && [ -d "$variant_dir" ]; then
skipped+=("$name (variant already exists)")
continue
fi
if [ "$MODE" = "rebuild" ] && [ ! -d "$variant_dir" ]; then
skipped+=("$name (no variant folder yet)")
continue
fi
echo "=================================================================="
echo "=== building variant: $name (from $json)"
echo "=== [$MODE] building variant: $name (from $json)"
echo "=================================================================="
if "$PHP_BIN" "$HERE/build.php" "$name" "$DEFS"; then
built=$((built + 1))
@ -63,13 +94,30 @@ for json in "${jsons[@]}"; do
done
echo "=================================================================="
echo "Rebuild summary: $built built, $failed failed (definitions dir: $DEFS)"
echo "Summary [$MODE]: $built built, $failed failed, ${#skipped[@]} not picked up (definitions dir: $DEFS)"
if [ ${#skipped[@]} -gt 0 ]; then
echo "Not picked up:"
for s in "${skipped[@]}"; do echo " - $s"; done
fi
if [ "$failed" -gt 0 ]; then
echo "Fix the failing definitions and re-run this script." >&2
exit 1
fi
if [ "$MODE" = "build" ] && [ ${#skipped[@]} -gt 0 ]; then
echo
echo "NOTE: the .json files above were NOT picked up because their variant already"
echo "exists — existing variants are never clobbered by a build run. They POSSIBLY"
echo "NEED TO BE RE-BUILT (after a change in this mother theme or in their definitions):"
echo " bash variants/build_all.sh --rebuild $DEFS"
fi
if [ "$MODE" = "rebuild" ] && [ ${#skipped[@]} -gt 0 ]; then
echo
echo "NOTE: the .json files above were NOT picked up because no variant exists for them"
echo "yet — build them with the default (build) mode:"
echo " bash variants/build_all.sh $DEFS"
fi
echo
echo "Next — owner actions in the LimeSurvey admin UI:"
echo " 1. reset every rebuilt variant theme (Theme options -> <variant> -> Reset)"
echo " 1. reset every (re)built variant theme (Theme options -> <variant> -> Reset)"
echo " 2. flush the asset cache (php application/commands/console.php flushassets)"
echo " 3. hard-refresh the browser (Ctrl+F5)"