-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathnodeula-rasa
More file actions
executable file
·89 lines (73 loc) · 2.45 KB
/
Copy pathnodeula-rasa
File metadata and controls
executable file
·89 lines (73 loc) · 2.45 KB
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
#!/bin/bash -e
# Gives you a total clean slate in your node project.
usage() {
echo "usage: ${0##*/} [options]" 1>&2
echo "" 1>&2
echo "Gives you a total clean slate in your node project." 1>&2
echo ""
echo "options:"
echo " -h or --help shows usage help" 1>&2
exit 1
}
if echo "$*" | grep -Eq -- '--help\b|-h\b'; then
usage
fi
show() {
if [[ $1 == "-r" ]]; then
shift
echo -n $'\e[38;5;40m$\e[38;5;63m '
else
echo -n $'\e[1;34m>\e[0m\e[31m '
fi
echo -n "$@"
echo -n $'\e[0m'
echo
}
run() {
show -r "$@"
eval "$@"
return $?
}
clean_test_cache() {
# Not all test scripts accept a "--clearCache" option, so we can't
# assume that this will even work, though it may for your project.
# if npm run | grep -qE "^\s*test$"; then
# run "npm run test -- --clearCache"
# fi
if ! command -v jq >/dev/null 2>&1 && command -v jest >/dev/null 2>&1; then
show "warning: you must install jq if you want this script to clear your test cache"
elif command -v jq >/dev/null 2>&1 && command -v jest >/dev/null 2>&1; then
run "jest --showConfig | jq '.configs[].cacheDirectory' | sort -u | xargs -n 1 -P 8 rm -rf"
fi
}
# make sure the user doesn't accidently blow away their changes
echo -n "Blow away $(tput setaf 7)$(tput setab 1)$(tput bold)$(tput smul)all untracked files and local changes in your repository$(tput sgr0) and all node related caches?"
read -rp "$1 (y/n) [n] ... "
if [[ $REPLY != "y" ]]; then
exit 1
fi
# clear node's require cache
run "node -e 'Object.keys(require.cache).forEach(function(k) { delete require.cache[k]; })'"
if command -v npm >/dev/null 2>&1; then
# attempt to find and clean any test caches
clean_test_cache
# clean global and local npm caches
export npm_config_loglevel=silent
run "npm -g cache clean --force"
run "npm cache clean --force"
unset npm_config_loglevel
fi
# bable cache
test -e "$HOME/.babel.json" && run "rm -f '$_'"
# node-gyp cache
test -d "$HOME/.node-gyp" && run "rm -rf '$_'"
# project node_modules
test -d node_modules && run "rm -rf '$_'"
# blow away any untracked files or local changes
command -v git >/dev/null 2>&1 && run "git clean -dfx"
if echo "$*" | grep -Eq -- '\b--install\b|\b-i\b'; then
NPM_VERSION="$(npm --version)"
NODE_VERSION="$(node --version)"
show "running \`npm install\` using node: $NODE_VERSION, npm: $NPM_VERSION ..."
npm install
fi