ampache_react/hooks/pre-commit

58 lines
1.1 KiB
Plaintext
Raw Normal View History

2016-07-07 23:23:18 +02:00
#!/bin/sh
# TODO: Rebuild only if needed
# Get against which ref to diff
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
js_files=""
for file in $(git diff-index --name-only $against); do
if [[ $file == "*.js" ]] || [[ $file == "*.jsx" ]]
then
js_files="$js_files $file"
fi
done
# Nothing more to do if no JS files was committed
if [ -z "$js_files" ]
then
exit 0
fi
# ESLint modified files
if [ -e "./node_modules/eslint/bin/eslint.js" ]
then
ESLINT="node ./node_modules/eslint/bin/eslint.js"
elif hash eslint
then
ESLINT="eslint"
else
exit "You should install ESLint."
fi
echo "Running ESLint on your code…"
$ESLINT $js_files
# Run webpack
if [ -e "./node_modules/webpack/bin/webpack.js" ]
then
WEBPACK="node ./node_modules/webpack/bin/webpack.js"
elif hash webpack
then
WEBPACK="webpack"
else
exit "You should install webpack."
fi
echo "Rebuilding dist JavaScript files…"
NODE_ENV=production $WEBPACK
git add app/dist