-
Notifications
You must be signed in to change notification settings - Fork 0
/
unused.sh
executable file
·68 lines (56 loc) · 1.77 KB
/
unused.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
60
61
62
63
64
65
66
67
68
#!/usr/bin/bash
# File: /unused.sh
# Description:
# Date By Comments
# ---------- ----- ------------------------------
# 2023-12-31 C2RLO Initial
v_date=$(date +"%Y-%m-%d")
export TERM=xterm-color
export GREP_OPTIONS='--color=auto' GREP_COLOR='1;32'
export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad
export COLOR_NC='\e[0m' # No Color
export COLOR_BLACK='\e[0;30m'
export COLOR_GRAY='\e[1;30m'
export COLOR_RED='\e[0;31m'
export COLOR_LIGHT_RED='\e[1;31m'
export COLOR_GREEN='\e[0;32m'
export COLOR_LIGHT_GREEN='\e[1;32m'
export COLOR_BROWN='\e[0;33m'
export COLOR_YELLOW='\e[1;33m'
export COLOR_BLUE='\e[0;34m'
export COLOR_LIGHT_BLUE='\e[1;34m'
export COLOR_PURPLE='\e[0;35m'
export COLOR_LIGHT_PURPLE='\e[1;35m'
export COLOR_CYAN='\e[0;36m'
export COLOR_LIGHT_CYAN='\e[1;36m'
export COLOR_LIGHT_GRAY='\e[0;37m'
export COLOR_WHITE='\e[1;37m'
DIRNAME=${1:-.}
cd $DIRNAME
FILES=$(mktemp)
PACKAGES=$(mktemp)
# use fd
# https://github.com/sharkdp/fd
function check {
cat package.json | jq "{} + .$1 | keys" | sed -n 's/.*"\(.*\)".*/\1/p' >$PACKAGES
echo ""
echo "Checking $1..."
echo "--------------------------"
fd -t f '(js|mjs|ts|json|eslintrc)$' >$FILES
# cat $FILE >all-files.csv
while read PACKAGE; do
if [ -d "node_modules/${PACKAGE}" ]; then
fd -t f '(js|mjs|ts|json)$' node_modules/${PACKAGE} >>$FILES
fi
RES=$(cat $FILES | xargs -I {} egrep -i -w "(import|require|loader|plugins|${PACKAGE}).*[\'\"](${PACKAGE}|.?\d+)[\"\']" '{}' | wc -l)
if [ $RES = 0 ]; then
printf "${COLOR_RED}UNUSED${COLOR_NC}\t\t %-20s npm remove %-20s\n" $PACKAGE $PACKAGE
else
printf "${COLOR_GREEN}USED${COLOR_NC} (%3s) %-20s\n" $RES $PACKAGE
fi
done <$PACKAGES
}
check "dependencies"
check "devDependencies"
check "peerDependencies"