mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-11-29 00:20:51 +00:00
76 lines
1.2 KiB
Plaintext
76 lines
1.2 KiB
Plaintext
|
#!/usr/bin/env bash
|
||
|
# Enable this pre-commit hook by running 'make installhooks'
|
||
|
set -euo pipefail
|
||
|
|
||
|
git-staged-files() {
|
||
|
git diff --cached -C -C -z --name-only --diff-filter=ACMRTUXB "$@"
|
||
|
}
|
||
|
|
||
|
git-is-staged() {
|
||
|
local diff=0
|
||
|
git-staged-files --quiet "$@" 2> /dev/null || diff=$?
|
||
|
[[ diff -eq 1 ]] || return 1
|
||
|
}
|
||
|
|
||
|
map() { IFS= read -rd $'\0' "$@"; }
|
||
|
|
||
|
compress-png() {
|
||
|
git-staged-files \*.png|while map file; do
|
||
|
echo "Compressing $file"
|
||
|
optipng -q -o7 "$file" && advpng -z -4 "$file" && advdef -z -4 "$file" | grep Output
|
||
|
git add "$file"
|
||
|
done
|
||
|
}
|
||
|
|
||
|
compress-svg() {
|
||
|
git-staged-files \*.svg|while map file; do
|
||
|
make nodecheck
|
||
|
echo "Compressing $file"
|
||
|
node_modules/.bin/svgo --config=.svgo.yml "$file"
|
||
|
git add "$file"
|
||
|
done
|
||
|
}
|
||
|
|
||
|
test-whitespace() { git diff --cached --check; }
|
||
|
|
||
|
test-js() {
|
||
|
local err=0
|
||
|
|
||
|
make eslint || err+=1
|
||
|
|
||
|
if git-is-staged \*.js; then
|
||
|
make qunit || err+=1
|
||
|
fi
|
||
|
|
||
|
return $err
|
||
|
}
|
||
|
|
||
|
test-php() {
|
||
|
local err=0
|
||
|
if git-is-staged \*.php; then
|
||
|
make phplint || err+=1
|
||
|
fi
|
||
|
|
||
|
# todo: where is result set?
|
||
|
if git-is-staged 'includes/skins/*.php'; then
|
||
|
make validatehtml > $result || err+=1
|
||
|
fi
|
||
|
|
||
|
return $err
|
||
|
}
|
||
|
|
||
|
main() {
|
||
|
local err=0
|
||
|
|
||
|
compress-png
|
||
|
compress-svg
|
||
|
|
||
|
test-whitespace || err+=1
|
||
|
test-js || err+=1
|
||
|
test-php || err+=1
|
||
|
|
||
|
return $err
|
||
|
}
|
||
|
|
||
|
main "$@"
|