-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnpm.sh
executable file
·67 lines (53 loc) · 1.3 KB
/
npm.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
#!/bin/sh
# https://blog.uirig.com/finding-outdated-npm
usage() {
cat << EOF >&2
Usage: $0 {i|o|ob|og}
i Runs "npm install" on all projects
o Checks outdated NPMs on all projects
ob Same as "o" but opens the repos in a browser
og Checks outdated NPMs globally
EOF
exit 1
}
REPO=~/work/myrepo
apps="
project-a
project-b
"
npmi() { # Runs `npm install` on all the projects
local pids=""
for app in $apps; do
echo "Installing NPMs on $app..."
cd $REPO/$app
npm install &
pids="$pids $!"
done
wait $pids
}
# Checks for outdated NPMs on all the projects and prints a pasteable line for updating
# the dependency, along with a comment of the currently installed version, for example:
# cd $REPO/project-a && npm i foo@2.0.0 ;# foo@1.0.0
npmo() {
local pids=""
for app in $apps; do
cd $REPO/$app
npm outdated --parseable |\
awk -v app="$app" -F: \
'{ printf "cd $REPO/%-11s && npm i %-29s ;# %s\n", app, $4, $2 }' &
pids="$pids $!"
done
wait $pids
}
npmog() { # Checks for outdated global NPMs
npm outdated -g --parseable |\
awk -F: \
'{ printf "npm i -g %-18s ;# %s\n", $4, $3 }'
}
case $1 in
i) npmi ;;
o) npmo | sort -k6 ;;
ob) npmo | sort -k6 | tee /dev/tty | awk '{print $6}' | uniq | xargs npm repo ;;
og) npmog ;;
*) usage ;;
esac