#!/usr/bin/env bash set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" STYLEGUIDE_REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" SOURCE_CSS="$STYLEGUIDE_REPO_ROOT/styleguide.css" VERSION_FILE="$STYLEGUIDE_REPO_ROOT/VERSION" PORTAL_REPO_PATH="/Users/mathias/Documents/Dokumente Chouchou/Codebases/WebApp_Aktienberater" PORTAL_CSS_REL="public/assets/styleguide.upstream.css" PORTAL_META_REL="public/assets/styleguide.upstream.meta.json" PORTAL_STYLEGUIDE_DOCS_REL="docs/styleguide" COMMIT_IN_PORTAL="false" usage() { cat <] [--commit-portal] Options: --portal-repo Optional override for portal repository root. --commit-portal Create commit in portal repo after sync. -h, --help Show this help. USAGE } while [[ $# -gt 0 ]]; do case "$1" in --portal-repo) PORTAL_REPO_PATH="${2:-}" shift 2 ;; --commit-portal) COMMIT_IN_PORTAL="true" shift ;; -h|--help) usage exit 0 ;; *) echo "Unknown argument: $1" >&2 usage exit 1 ;; esac done if [[ ! -f "$SOURCE_CSS" ]]; then echo "Source CSS not found: $SOURCE_CSS" >&2 exit 1 fi if [[ ! -f "$VERSION_FILE" ]]; then echo "Version file not found: $VERSION_FILE" >&2 exit 1 fi if [[ ! -d "$PORTAL_REPO_PATH/.git" ]]; then echo "Portal repo is not a git repository: $PORTAL_REPO_PATH" >&2 exit 1 fi PORTAL_CSS_PATH="$PORTAL_REPO_PATH/$PORTAL_CSS_REL" PORTAL_META_PATH="$PORTAL_REPO_PATH/$PORTAL_META_REL" PORTAL_STYLEGUIDE_DOCS_PATH="$PORTAL_REPO_PATH/$PORTAL_STYLEGUIDE_DOCS_REL" mkdir -p "$(dirname "$PORTAL_CSS_PATH")" mkdir -p "$PORTAL_STYLEGUIDE_DOCS_PATH" flatten_css() { local source_file="$1" local source_root="$2" local output_file="$3" : > "$output_file" while IFS= read -r line; do if [[ "$line" =~ ^[[:space:]]*@import[[:space:]]+\"([^\"]+)\"[[:space:]]*\;[[:space:]]*$ ]]; then local import_path="${BASH_REMATCH[1]}" local import_abs="$source_root/$import_path" if [[ ! -f "$import_abs" ]]; then echo "Imported CSS not found: $import_abs" >&2 exit 1 fi cat "$import_abs" >> "$output_file" printf "\n" >> "$output_file" else printf "%s\n" "$line" >> "$output_file" fi done < "$source_file" } assert_no_unimported_styles() { local source_file="$1" local source_root="$2" local styles_dir="$source_root/styles" local missing_imports=() if [[ ! -d "$styles_dir" ]]; then return 0 fi while IFS= read -r css_file; do local rel_path="./styles/$(basename "$css_file")" if ! grep -Eq "^[[:space:]]*@import[[:space:]]+\"$rel_path\"[[:space:]]*;" "$source_file"; then missing_imports+=("$rel_path") fi done < <(find "$styles_dir" -maxdepth 1 -type f -name '*.css' | sort) if [[ ${#missing_imports[@]} -gt 0 ]]; then echo "Unimported CSS module files detected in styles/:" >&2 for file in "${missing_imports[@]}"; do echo " - $file" >&2 done echo "Add missing @import lines in $source_file before syncing." >&2 exit 1 fi } TMP_UPSTREAM_CSS="$(mktemp)" trap 'rm -f "$TMP_UPSTREAM_CSS"' EXIT assert_no_unimported_styles "$SOURCE_CSS" "$STYLEGUIDE_REPO_ROOT" flatten_css "$SOURCE_CSS" "$STYLEGUIDE_REPO_ROOT" "$TMP_UPSTREAM_CSS" cp "$TMP_UPSTREAM_CSS" "$PORTAL_CSS_PATH" rsync -a --delete \ --exclude ".git/" \ --exclude ".codex/" \ --exclude ".DS_Store" \ --exclude "AGENTS.md" \ --exclude "scripts/" \ "$STYLEGUIDE_REPO_ROOT/" \ "$PORTAL_STYLEGUIDE_DOCS_PATH/" STYLEGUIDE_VERSION="$(tr -d '[:space:]' < "$VERSION_FILE")" STYLEGUIDE_COMMIT="$(git -C "$STYLEGUIDE_REPO_ROOT" rev-parse --short HEAD)" SYNCED_AT="$(date -u +"%Y-%m-%dT%H:%M:%SZ")" cat > "$PORTAL_META_PATH" < $PORTAL_CSS_PATH" echo "Metadata written: $PORTAL_META_PATH" echo "Mirrored styleguide docs: $PORTAL_STYLEGUIDE_DOCS_PATH"