-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_unused_files
executable file
·213 lines (193 loc) · 6.21 KB
/
find_unused_files
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/bin/bash
#
# @author Zeus Intuivo <[email protected]>
#
#
set -Eu
function main() {
local red="\\033[38;5;1m"
local reset="\\033[0m"
function msg_error() {
echo -e "${red} ERROR ! ${*-} ${reset}"
}
local PACKAGE_JSON=""
if [ ! -f package.json ] ; then
{
msg_error "package.json file not found ! Stopping."
exit 69
} else {
PACKAGE_JSON=$(<package.json)
}
fi
local -i JQ_INSTALLED=0
# check operation systems
if [[ "$(uname)" == "Darwin" ]] ; then
# Do something under Mac OS X platform
# if value is not set -- exit silent it
if command -v jq >/dev/null 2>&1; then
{
JQ_INSTALLED=1
}
else
{
msg_error "jq dependency missing ! Attempting to install."
brew install jq
wait
if command -v jq >/dev/null 2>&1; then
{
JQ_INSTALLED=1
}
else
{
msg_error "jq dependency missing ! Attempt to install seem to have failed ! Stopping."
exit 69
}
fi
}
fi
elif [[ "$(expr substr "$(uname -s)" 1 5)" == "Linux" ]] ; then
# Do something under GNU/Linux platform
if command -v jq >/dev/null 2>&1; then
{
JQ_INSTALLED=1
}
else
{
msg_error "jq dependency missing ! Attempting to install."
(( command -v dnf >/dev/null 2>&1; )) && sudo dnf install jq
(( command -v brew >/dev/null 2>&1; )) && brew install jq
(( command -v apt >/dev/null 2>&1; )) && sudo apt install jq
wait
if command -v jq >/dev/null 2>&1; then
{
JQ_INSTALLED=1
}
else
{
msg_error "jq dependency missing ! Attempt to install seem to have failed ! Stopping."
msg_error "jq dependency missing ! I don't know how to attemp to install in this Linux $(expr substr "$(uname -s)" 1 5)"
exit 69
}
fi
}
fi
elif [[ "$(expr substr "$(uname -s)" 1 10)" == "MINGW32_NT" ]] || [[ "$(expr substr "$(uname -s)" 1 10)" == "MINGW64_NT" ]] ; then
# Do something under Windows NT platform
msg_error "jq dependency missing ! I don't know how to attemp to install in this Windows $(expr substr "$(uname -s)" 1 10)"
exit 69
# nothing here
fi
# if everything else --
# check operation systems
if [[ "$(uname)" == "Darwin" ]] ; then
# Do something under Mac OS X platform
local DEPS=""
DEPS=$(echo """${PACKAGE_JSON}""" | jq -r '.dependencies | keys | .[]' 2> /dev/null ) # capture all stout sderr ignored
local DEVDEPS=""
DEVDEPS=$(echo """${PACKAGE_JSON}""" | jq -r '.devDependencies | keys | .[]' 2> /dev/null ) # capture all stout sderr ignored
local OPTDEPS=""
OPTDEPS=$(echo """${PACKAGE_JSON}""" | jq -r '.optionalDependencies | keys | .[]' 2> /dev/null) # capture all stout sderr ignored
local ALLDEPS=""
ALLDEPS=$(echo -e "${DEPS}\n${DEVDEPS}\n${OPTDEPS}" 2> /dev/null ) # capture all stout sderr ignored
local USED=""
local NOTUSED=""
local TESTREQUIRE=""
local TESTIMPORT=""
local dep=""
for dep in ${ALLDEPS}; do
if [[ -n "${dep}" ]] ; then
{
echo -e "require(*$dep*)"
TESTREQUIRE=""
TESTREQUIRE=$(grep "require\(.*$dep.*\)" -Rl . )
if [[ -n "${TEST}" ]] ; then
{
USED=$(echo -e "${USED}\n${TESTREQUIRE}")
}
fi
TESTREQUIRE=$(grep "require\(.*$dep.*\)" -Rl . )
if [[ -n "${TEST}" ]] ; then
{
USED=$(echo -e "${USED}\n${TESTREQUIRE}")
}
fi
if [[ -z "${TESTREQUIRE}" ]] && [[ -z "${TESTIMPORT}" ]] ; then
{
NOTUSED=$(echo -e "${NOTUSED}\n${dep}")
}
fi
echo 'import { colorConvert } from "./utils/color-convert"' | grep -E "from.*$dep.*"
#grep "*$dep*" -Rq --exclude-dir="node_modules" .
# ü "$dep"
# if ( ; then
#{
# echo "Found as require ${dep}"
#}
#fi
#if ( grep "from \.*$dep.*" -Rq --exclude-dir="node_modules" . ) ; then
#{
# echo "Found as import ${dep}"
#}
#fi
}
fi
done
elif [[ "$(expr substr "$(uname -s)" 1 5)" == "Linux" ]] ; then
# Do something under GNU/Linux platform
local DEPS=""
DEPS=$(echo """${PACKAGE_JSON}""" | jq -r '.dependencies | keys | .[]' 2> /dev/null ) # capture all stout sderr ignored
local DEVDEPS=""
DEVDEPS=$(echo """${PACKAGE_JSON}""" | jq -r '.devDependencies | keys | .[]' 2> /dev/null ) # capture all stout sderr ignored
local OPTDEPS=""
OPTDEPS=$(echo """${PACKAGE_JSON}""" | jq -r '.optionalDependencies | keys | .[]' 2> /dev/null) # capture all stout sderr ignored
local ALLDEPS=""
ALLDEPS=$(echo -e "${DEPS}\n${DEVDEPS}\n${OPTDEPS}" 2> /dev/null ) # capture all stout sderr ignored
local USED=""
local NOTUSED=""
local TESTREQUIRE=""
local TESTIMPORT=""
local dep=""
for dep in ${ALLDEPS}; do
if [[ -n "${dep}" ]] ; then
{
echo -e "checking require(*$dep*)"
echo 'import { colorConvert } from "./utils/color-convert"' | grep -E "from.*$dep.*"
TESTREQUIRE=$(grep "require\(.*$dep.*\)" -Rl . )
if [[ -n "${TESTREQUIRE}" ]] ; then
{
USED=$(echo -e " \\____ ${USED}\n${TESTREQUIRE}")
}
fi
TESTREQUIRE=$(grep "require\(.*$dep.*\)" -Rl . )
if [[ -n "${TESTREQUIRE}" ]] ; then
{
USED=$(echo -e " \\____ ${USED}\n${TESTREQUIRE}")
}
fi
if [[ -z "${TESTREQUIRE}" ]] && [[ -z "${TESTIMPORT}" ]] ; then
{
NOTUSED=$(echo -e " -________ ${NOTUSED}\n${dep}")
}
fi
#grep "*$dep*" -Rq --exclude-dir="node_modules" .
# ü "$dep"
# if ( ; then
#{
# echo "Found as require ${dep}"
#}
#fi
#if ( grep "from \.*$dep.*" -Rq --exclude-dir="node_modules" . ) ; then
#{
# echo "Found as import ${dep}"
#}
#fi
}
fi
done
elif [[ "$(expr substr "$(uname -s)" 1 10)" == "MINGW32_NT" ]] || [[ "$(expr substr "$(uname -s)" 1 10)" == "MINGW64_NT" ]] ; then
# Do something under Windows NT platform
echo "nothing to do sed 's/'"""${SEEKING-}"""'//g' ;"
# nothing here
fi
} # end main
main "${*-}"