-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreinstall_npm_packages.sh
executable file
·55 lines (46 loc) · 1.16 KB
/
reinstall_npm_packages.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
#!/bin/bash
set -euo pipefail
log() {
local status="$1"
local message="$2"
local timestamp=$(date +"%Y-%m-%d %H:%M:%S")
echo "[$timestamp] $status: $message"
}
cleanup() {
log "INFO" "Starting cleanup"
if rm -f package-lock.json; then
log "SUCCESS" "package-lock.json removed"
else
log "ERROR" "Failed to remove package-lock.json"
fi
if rm -rf node_modules; then
log "SUCCESS" "node_modules removed"
else
log "ERROR" "Failed to remove node_modules"
fi
}
npm_clean_install_update() {
log "INFO" "Cleaning npm cache"
if npm cache clean --force; then
log "SUCCESS" "npm cache cleaned"
else
log "ERROR" "Failed to clean npm cache"
fi
log "INFO" "Installing npm packages"
if npm install --legacy-peer-deps; then
log "SUCCESS" "npm install successful"
else
log "ERROR" "npm install failed"
fi
log "INFO" "Updating npm packages"
if npm update --legacy-peer-deps; then
log "SUCCESS" "npm update successful"
else
log "ERROR" "npm update failed"
fi
}
main() {
cleanup
npm_clean_install_update
}
main "$@"