-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_js.sh
executable file
·59 lines (53 loc) · 1.32 KB
/
check_js.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env bash
# Colors
GREEN="\033[1;32m"
NC="\033[0m"
YELLOW="\033[1;33m"
MAGENTA="\033[1;35m"
RED="\033[0;31m"
# Check if JSHint & Node Available
JSHint="$(command -v jshint)"
NODE="$(command -v node)"
if [[ -z "${JSHint}" ]]; then
echo -e "${YELLOW}JSHint not available, kindly run ${NC}${MAGENTA}'npm install -g jshint'${NC}"
echo ""
echo -e "${RED}Exiting...${NC}"
exit 1
fi
if [[ -z "${NODE}" ]]; then
echo -e "${YELLOW}Node not available, kindly install ${NC}${MAGENTA}'nodejs'${NC} (See: https://nodejs.org/en/)"
echo ""
echo -e "${RED}Exiting...${NC}"
exit 1
fi
# List all the .js file(s)
echo -e "${GREEN}" "Available files -${NC}"
FILES=0
LIST_FILES="$(find . -path ./.git -prune -o -name '*.js' -print | sed 's|^./||')"
for file in ${LIST_FILES}; do
echo "$file"
((FILES = FILES + 1))
done
# Check file(s) with JSHint
echo ""
ERROR_FILES=0
for file in ${LIST_FILES}; do
echo "Checking '${file}'"
jshint --verbose "${file}" 1>/dev/null
ERROR_CODE="${?}"
if [[ "${ERROR_CODE}" -ne "0" ]]; then
echo ""
echo -e "${RED}$(jshint --verbose "${file}")${NC}"
echo ""
((ERROR_FILES = ERROR_FILES + 1))
else
echo "OK"
fi
done
echo ""
if [[ "${ERROR_FILES}" -eq "0" ]]; then
echo -e "Number of file(s) checked: ${GREEN}${FILES}${NC}"
else
echo -e "Number of file(s) checked: ${RED}${FILES}${NC}"
exit 1
fi