docs(variants): define the build process (new variant) and rebuild process (build_all.sh)
- New variants/build_all.sh: rebuilds ALL variants from their json definitions in one go (loops over <definitions-dir>/*.json, calls build.php per variant, aggregates failures, exits non-zero on any failure) and prints the owner follow-up actions (reset each variant theme in the LS admin, flushassets, Ctrl+F5). Generic tooling — no client names — so it ships in the public repo. - README.md: the variants workflow is now split into a 'Build process' (defining a NEW variant: json + assets in the private definitions repo, build.php, deploy + theme reset + flushassets) and a 'Rebuild process' (build_all.sh after a mother config.xml change or a definitions change). The preview section now documents the standing rules: variant preview must differ from the mother's, preview.svg is committed + synced publicly, added only at first creation and never overwritten. - AGENTS.md propagation rule now points at build_all.sh. Verified: bash -n clean; PHP_BIN=/usr/bin/php bash variants/build_all.sh variants -> '2 built, 0 failed', rc=0, both variants' preview.svg untouched (md5 before = after); export_public.sh exit 0 with build_all.sh in the zip. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
parent
d288ac8197
commit
9cb0eb0723
2 changed files with 125 additions and 34 deletions
82
README.md
82
README.md
|
|
@ -351,28 +351,33 @@ its own font files and css:
|
|||
House-style-specific values are ONLY: colors, fonts, and font
|
||||
sizes/colors/weights (plus logo files). Everything else lives once, here.
|
||||
|
||||
### Theme preview image per variant (`files/preview.png`)
|
||||
### Theme preview image per variant (`files/preview.png` + `files/preview.svg`)
|
||||
|
||||
The theme list shows `files/preview.png` of each theme (hard-coded in core,
|
||||
`TemplateConfiguration::getPreview()` — `preview.svg` is NOT picked up; a feature
|
||||
request for SVG support and starter-theme fallback has been prepared for the
|
||||
LimeSurvey developers). The preview is read
|
||||
from the theme's OWN files folder — there is no starter-theme fallback — so every
|
||||
variant should ship its own `files/preview.png`: put it in
|
||||
`<client>/files/preview.png` in the private variants repo; `build.php` copies
|
||||
the whole `<client>/` asset folder into the generated variant automatically.
|
||||
A variant without its own preview shows "No preview available" in the theme
|
||||
list.
|
||||
`TemplateConfiguration::getPreview()` — `preview.svg` is NOT picked up by core;
|
||||
a feature request for SVG support has been prepared for the LimeSurvey
|
||||
developers). The preview is read from the theme's OWN files folder — there is no
|
||||
starter-theme fallback — so every variant must ship its own
|
||||
`files/preview.png`. Standing rule: **a variant's preview must differ from the
|
||||
mother theme's** — when defining a variant, create a variant-specific
|
||||
`files/preview.svg` (the editable source, committed and synced publicly) and
|
||||
export `files/preview.png` from it (Inkscape → PNG export). `build.php` adds
|
||||
`files/preview.svg` to a variant only ONCE, at first creation (seeded from the
|
||||
mother if the definitions dir has none), and NEVER overwrites it afterwards —
|
||||
after that you edit it in the variant folder. `build.php` prints a WARNING when
|
||||
the variant's `preview.png` is identical to the mother's.
|
||||
|
||||
Workflow:
|
||||
### Build process (defining a NEW variant)
|
||||
|
||||
1. In `config.xml`, the house-style options are marked with `HOUSE-STYLE`
|
||||
comments (colors, fonts, font sizes/weights, logo files, logo top margin,
|
||||
background image/color). Only those values belong in a variant json —
|
||||
never hardcode house-style values in shared files (`views/`, `css/`,
|
||||
`scripts/`), because those are inherited by all variants.
|
||||
2. Create `variants/<client>.json` with the variant name/title/description and
|
||||
only the house-style option keys with the client values:
|
||||
2. In the private variants repo, create `variants/<client>.json` with the
|
||||
variant name/title/description and only the house-style option keys with the
|
||||
client values, plus a `<client>/` asset folder (logos, `files/fonts/`,
|
||||
`css/variant.css`, `files/preview.svg`/`preview.png`):
|
||||
```json
|
||||
{
|
||||
"name": "respondage_client",
|
||||
|
|
@ -380,7 +385,7 @@ Workflow:
|
|||
"options": { "primarycolor": "#123456", "fontsize": "18px" }
|
||||
}
|
||||
```
|
||||
2. Run `php variants/build.php <client>`. This generates
|
||||
3. Run `php variants/build.php <client> <definitions-dir>`. 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
|
||||
|
|
@ -388,25 +393,36 @@ Workflow:
|
|||
kept: LimeSurvey resolves each listed file in the variant first and then in
|
||||
the starter theme, so the starter theme's css/js keep loading until a
|
||||
variant ships its own file with the same name. Unknown option keys make the build fail
|
||||
loudly, so drift is caught at build time.
|
||||
3. The `<client>/` assets (logos, `files/fonts/`, `css/variant.css`,
|
||||
`files/preview.png`) from the definitions dir are copied into `../<client>/`
|
||||
automatically — every build OVERWRITES existing files there, so never edit the
|
||||
generated folder by hand. Upload the folder to `upload/themes/survey/` and
|
||||
install/reset the theme in LimeSurvey, then FLUSH the LimeSurvey asset cache and
|
||||
hard-refresh the browser (Ctrl+F5) — after a rebuild the asset hash changes, and a
|
||||
stale cached css is exactly how an old placeholder font keeps showing.
|
||||
REBUILD RULE: after every change to `<client>.json` or `<client>/` in the
|
||||
private definitions repo, re-run `php variants/build.php <client>` and reset
|
||||
the variant theme in LimeSurvey — a variant folder that is not rebuilt after
|
||||
a definitions change is stale (fonts/logo/css then don't match, e.g. an old
|
||||
placeholder `css/variant.css` keeps loading instead of the client font).
|
||||
IMPORTANT: a variant only works when the starter theme `vanilla_respondage`
|
||||
is also present in `upload/themes/survey/` on the server — the variant
|
||||
extends it and inherits all views/css/js/options from it. The core theme
|
||||
`vanilla` (which this starter theme extends) ships with LimeSurvey itself,
|
||||
so that one is always there. So deploy: `vanilla_respondage` + each
|
||||
`respondage_<client>` you use.
|
||||
loudly, so drift is caught at build time. The whole `<client>/` asset folder
|
||||
is copied into `../<client>/` automatically.
|
||||
4. Deploy and activate: upload `../<client>/` to `upload/themes/survey/` (the
|
||||
mother theme `vanilla_respondage` must be present there too — the variant
|
||||
extends it; the core theme `vanilla` ships with LimeSurvey itself), then
|
||||
install/reset the variant theme in the LimeSurvey admin (Theme options →
|
||||
`<client>` → Reset, which imports the new config.xml into the DB), FLUSH the
|
||||
asset cache (`php application/commands/console.php flushassets`) and
|
||||
hard-refresh the browser (Ctrl+F5) — a stale cached css is exactly how an
|
||||
old placeholder font keeps showing.
|
||||
|
||||
### Rebuild process (after a change in THIS mother theme or in a definitions file)
|
||||
|
||||
- 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:
|
||||
```
|
||||
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, and fails
|
||||
non-zero if any variant fails. Then, per rebuilt variant: reset the theme in
|
||||
the LimeSurvey admin (Theme options → Reset), flush assets, Ctrl+F5.
|
||||
Never edit the generated `../<client>/` folder by hand — every build
|
||||
OVERWRITES its files from the definitions dir, EXCEPT `files/preview.svg`
|
||||
(first-creation-only, see above). A variant folder that is not rebuilt after
|
||||
a definitions change is stale (fonts/logo/css then don't match).
|
||||
|
||||
Because of the native `<extends>` mechanism:
|
||||
- changes to any file (twig/css/js) in this starter theme apply to all
|
||||
|
|
|
|||
75
variants/build_all.sh
Normal file
75
variants/build_all.sh
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
#!/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)").
|
||||
#
|
||||
# Usage:
|
||||
# bash variants/build_all.sh [definitions-dir]
|
||||
#
|
||||
# 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>.
|
||||
#
|
||||
# Environment:
|
||||
# PHP_BIN php binary to use (default: "php"; e.g. PHP_BIN=/usr/bin/php)
|
||||
#
|
||||
# Per-variant rules enforced by build.php itself:
|
||||
# - unknown option keys fail the build loudly (drift check);
|
||||
# - files/preview.svg is added only at FIRST creation and never overwritten
|
||||
# (row 235) — edit it in the variant, not here;
|
||||
# - a WARNING is printed when the variant's preview.png is identical to the
|
||||
# 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),
|
||||
# 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);
|
||||
# 3. hard-refresh the browser (Ctrl+F5).
|
||||
# ---------------------------------------------------------------------------
|
||||
set -u
|
||||
|
||||
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||
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
|
||||
exit 1
|
||||
fi
|
||||
|
||||
shopt -s nullglob
|
||||
jsons=("$DEFS"/*.json)
|
||||
if [ ${#jsons[@]} -eq 0 ]; then
|
||||
echo "ERROR: no *.json variant definitions found in $DEFS" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
built=0
|
||||
failed=0
|
||||
for json in "${jsons[@]}"; do
|
||||
name="$(basename "$json" .json)"
|
||||
echo "=================================================================="
|
||||
echo "=== building variant: $name (from $json)"
|
||||
echo "=================================================================="
|
||||
if "$PHP_BIN" "$HERE/build.php" "$name" "$DEFS"; then
|
||||
built=$((built + 1))
|
||||
else
|
||||
failed=$((failed + 1))
|
||||
echo "!!! BUILD FAILED: $name (see output above)" >&2
|
||||
fi
|
||||
done
|
||||
|
||||
echo "=================================================================="
|
||||
echo "Rebuild summary: $built built, $failed failed (definitions dir: $DEFS)"
|
||||
if [ "$failed" -gt 0 ]; then
|
||||
echo "Fix the failing definitions and re-run this script." >&2
|
||||
exit 1
|
||||
fi
|
||||
echo
|
||||
echo "Next — owner actions in the LimeSurvey admin UI:"
|
||||
echo " 1. reset every rebuilt 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)"
|
||||
Loading…
Reference in a new issue