Enforce style module import rule in skill and sync guard
This commit is contained in:
@@ -90,8 +90,36 @@ flatten_css() {
|
||||
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"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user