#!/usr/bin/env bash # --------------------------------------------------------------------------- # Build/rebuild ALL variants of this theme from their json definitions # (see README.md, "Client variants (house styles)"). # # Usage: # bash variants/build_all.sh [--rebuild] [definitions-dir] # # Modes: # (default) BUILD — picks up only the *.json files for which NO variant # exists yet (no ..// 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 .json files and / asset folders). Every picked-up # .json is built with variants/build.php . # # 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 (re)built variant theme (Theme options -> -> 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 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 [--rebuild] [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 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 "=== [$MODE] 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 "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 (re)built variant theme (Theme options -> -> Reset)" echo " 2. flush the asset cache (php application/commands/console.php flushassets)" echo " 3. hard-refresh the browser (Ctrl+F5)"