Skip to content

Commit

Permalink
[mate-scripts] add git-hooks folders for vue projects
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrinko committed Aug 15, 2024
1 parent 35f078b commit 021cd06
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
42 changes: 42 additions & 0 deletions mate-scripts/configs/git-hooks/vue/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

function join_by { local IFS="$1"; shift; echo "$*"; }

PASS=true

# ESLint
STAGED_JS_FILES=$(git diff --cached --name-only --diff-filter=ACM ./src | grep ".\(j\|t\)sx\{0,1\}$")

if [[ "$STAGED_JS_FILES" != "" ]]; then
echo "Linting javascript files"

npx mate-scripts lint --javascript $(join_by " " ${STAGED_JS_FILES})

if [[ "$?" == 0 ]]; then
printf "\033[32mESLint Passed\033[0m\n\n"
else
printf "\033[031mESLint Failed\033[0m\n\n"
PASS=false
fi
fi

# StyleLint
STAGED_CSS_FILES=$(git diff --cached --name-only --diff-filter=ACM ./src | grep ".s\?css$")

if [[ "$STAGED_CSS_FILES" != "" ]]; then
echo "Linting CSS files"

npx mate-scripts lint --styles $(join_by " " ${STAGED_CSS_FILES})

if [[ "$?" == 0 ]]; then
printf "\033[32mStyleLint Passed\033[0m\n\n"
else
printf "\033[031mStyleLint Failed\033[0m\n\n"
PASS=false
fi
fi

if ! ${PASS}; then
printf "Pre-commits check failed. Fix problems above before commit.\n\n"
exit 1
fi
42 changes: 42 additions & 0 deletions mate-scripts/configs/git-hooks/vueTypescript/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

function join_by { local IFS="$1"; shift; echo "$*"; }

PASS=true

# ESLint
STAGED_JS_FILES=$(git diff --cached --name-only --diff-filter=ACM ./src | grep ".\(j\|t\)sx\{0,1\}$")

if [[ "$STAGED_JS_FILES" != "" ]]; then
echo "Linting javascript files"

npx mate-scripts lint --javascript $(join_by " " ${STAGED_JS_FILES})

if [[ "$?" == 0 ]]; then
printf "\033[32mESLint Passed\033[0m\n\n"
else
printf "\033[031mESLint Failed\033[0m\n\n"
PASS=false
fi
fi

# StyleLint
STAGED_CSS_FILES=$(git diff --cached --name-only --diff-filter=ACM ./src | grep ".s\?css$")

if [[ "$STAGED_CSS_FILES" != "" ]]; then
echo "Linting CSS files"

npx mate-scripts lint --styles $(join_by " " ${STAGED_CSS_FILES})

if [[ "$?" == 0 ]]; then
printf "\033[32mStyleLint Passed\033[0m\n\n"
else
printf "\033[031mStyleLint Failed\033[0m\n\n"
PASS=false
fi
fi

if ! ${PASS}; then
printf "Pre-commits check failed. Fix problems above before commit.\n\n"
exit 1
fi
2 changes: 1 addition & 1 deletion mate-scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mate-academy/scripts",
"version": "1.9.2",
"version": "1.9.3",
"description": "Scripts to init, run, test, deploy Mate academy homework projects",
"main": "bin/mateScripts.js",
"scripts": {
Expand Down

0 comments on commit 021cd06

Please sign in to comment.