-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnpm-uncache
executable file
·56 lines (43 loc) · 880 Bytes
/
npm-uncache
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
#!/usr/bin/env bash
set -o errexit
set -o pipefail
set -o nounset
# set -o xtrace
main() {
verify_installed
uncache
}
verify_installed() {
msg1 'Verifying that npm is installed'
is_installed 'npm' || fail 1 'npm is not installed'
}
is_installed() {
local -r cmd="$1"
command -v "${cmd}" &>/dev/null
}
uncache() {
msg1 'Running: "npm cache clear --force"'
npm cache clear --force || fail $? 'Failed to run "npm cache clear --force"'
msg1 'Running: "npm rebuild"'
npm rebuild || fail $? 'Failed to run "npm rebuild"'
}
fail() {
local -r scode="$1"
local -r msg="$2"
err "${msg}"
exit "${scode}"
}
msg1() {
local -r msg="$1"
echo "[$(timestamp)]: ${msg}"
}
err() {
local -r msg="$1"
echo "[$(timestamp)]: ${msg}" >&2
}
timestamp() {
date +'%Y-%m-%d %H:%M:%S'
# date +'%Y-%m-%dT%H:%M:%S%z'
# date -u +'%Y-%m-%dT%H:%M:%SZ'
}
main