refactor(css): row 216 — sass is leading for ALL css files, not just plain.css

Previously only css/plain.css was compiled from sass/plain.sass; css/custom.css
and css/fonts.css were hand-written. Now every theme stylesheet has a leading
sass source: sass/plain.sass, sass/custom.sass, sass/fonts.sass (partials _*),
compiled with 'sass --watch sass:css' (dart-sass 1.83.4 added as local
devDependency; node_modules/package.json stay gitignored). css/*.css are build
artifacts and remain the committed runtime files; sass/ stays developer-local.
Recompiled output is semantically identical to the previous hand-written files
(dart-sass normalization only: 2-space indent, double quotes, @charset).
variants/export_public.sh step 0 now checks BOTH directions for every pair:
stale css/<name>.css vs sass/<name>.sass aborts, and a css file without a sass
source aborts; compiler resolved from PATH or node_modules/.bin/sass.
.gitignore/README document the workflow.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
Tammo ter Hark 2026-11-30 09:11:39 +01:00
commit 756c0ec2d1

View file

@ -36,30 +36,66 @@ STAGE="$OUT_DIR/$MOTHER_NAME"
VERSION="$(sed -n 's:.*<version>\([^<]*\)</version>.*:\1:p' "$THEME_DIR/config.xml" | head -1)"
ZIP_NAME="${MOTHER_NAME}-${VERSION}-public.zip"
# 0. optional guard: css/plain.css must be in sync with sass/plain.sass.
# LimeSurvey serves the committed css/plain.css and NEVER compiles sass
# 0. optional guard: SASS IS LEADING — every sass/*.sass must be compiled to
# its css/<name>.css counterpart and every css/*.css must have a sass source.
# LimeSurvey serves the committed css/ files and NEVER compiles sass
# itself, so a stale compiled file would be shipped/served. If a sass
# compiler is on PATH AND the developer-local sass/ sources are present
# (sass/ is gitignored and NOT part of this repo), recompile to a temp
# file and compare; abort on drift.
if command -v sass >/dev/null 2>&1 && [ -f "$THEME_DIR/sass/plain.sass" ]; then
TMP_CSS="$(mktemp --suffix=.css)"
if sass --no-source-map "$THEME_DIR/sass/plain.sass" "$TMP_CSS" 2>/dev/null; then
# compiler is available (on PATH, or the local devDependency
# node_modules/.bin/sass) AND the developer-local sass/ sources are present
# (sass/ is gitignored and NOT part of this repo), recompile each top-level
# sass source to a temp file and compare; abort on drift.
run_sass() {
if command -v sass >/dev/null 2>&1; then
sass "$@"
elif [ -x "$THEME_DIR/node_modules/.bin/sass" ]; then
# env -u LD_LIBRARY_PATH: harmless normally, works around a broken
# LD_LIBRARY_PATH that makes the shebang's `node` crash (glibc)
env -u LD_LIBRARY_PATH "$THEME_DIR/node_modules/.bin/sass" "$@"
else
return 1
fi
}
if [ -d "$THEME_DIR/sass" ] && run_sass --version >/dev/null 2>&1; then
STALE=0
for SRC in "$THEME_DIR"/sass/*.sass; do
[ -e "$SRC" ] || continue
BASE="$(basename "$SRC" .sass)"
case "$BASE" in _*) continue ;; esac # partials are not compiled standalone
CSS="$THEME_DIR/css/$BASE.css"
if [ ! -f "$CSS" ]; then
echo "ERROR: sass/$BASE.sass has no compiled counterpart css/$BASE.css - aborting." >&2
STALE=1; continue
fi
TMP_CSS="$(mktemp --suffix=.css)"
if ! run_sass --no-source-map "$SRC" "$TMP_CSS" 2>/dev/null; then
echo "ERROR: sass/$BASE.sass does not compile - aborting." >&2
rm -f "$TMP_CSS"; STALE=1; continue
fi
# -B ignores blank-line-only changes (dart-sass adds one before the
# sourceMappingURL comment); strip that comment line: it contains the
# output file name and differs between the real and the temp output
if ! diff -qB <(sed '/sourceMappingURL/d' "$THEME_DIR/css/plain.css") <(sed '/sourceMappingURL/d' "$TMP_CSS") >/dev/null 2>&1; then
echo "ERROR: css/plain.css is stale relative to sass/plain.sass - aborting." >&2
echo " Recompile in the theme dir, e.g.: sass sass/plain.sass css/plain.css" >&2
echo " (a watcher like 'sass --watch sass/plain.sass css/plain.css' prevents this)" >&2
echo " Commit the recompiled css/plain.css (the .map stays local, gitignored); sass/ is developer-local and not committed." >&2
rm -f "$TMP_CSS"
exit 1
if ! diff -qB <(sed '/sourceMappingURL/d' "$CSS") <(sed '/sourceMappingURL/d' "$TMP_CSS") >/dev/null 2>&1; then
echo "ERROR: css/$BASE.css is stale relative to sass/$BASE.sass - aborting." >&2
echo " Recompile in the theme dir, e.g.: sass --watch sass:css (all sass/*.sass -> css/*.css)" >&2
echo " or per file: sass sass/$BASE.sass css/$BASE.css" >&2
echo " Commit the recompiled css/$BASE.css (the .map stays local, gitignored); sass/ is developer-local and not committed." >&2
STALE=1
fi
fi
rm -f "$TMP_CSS"
rm -f "$TMP_CSS"
done
# reverse direction: css is a build artifact, every css/*.css needs a sass source
for CSS in "$THEME_DIR"/css/*.css; do
[ -e "$CSS" ] || continue
BASE="$(basename "$CSS" .css)"
if [ ! -f "$THEME_DIR/sass/$BASE.sass" ]; then
echo "ERROR: css/$BASE.css has no leading sass source sass/$BASE.sass - aborting." >&2
echo " Create sass/$BASE.sass, compile it (sass --watch sass:css) and commit the result; sass is leading." >&2
STALE=1
fi
done
[ "$STALE" = "1" ] && exit 1
else
echo "NOTE: 'sass' binary or local sass/ sources not present - skipped the css/plain.css sync check (sass/ is developer-local, gitignored)." >&2
echo "NOTE: 'sass' binary or local sass/ sources not present - skipped the sass->css sync check (sass/ is developer-local, gitignored)." >&2
fi
rm -rf "$STAGE"