-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathnpmprune.sh
executable file
·123 lines (110 loc) · 1.69 KB
/
npmprune.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
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
#!/bin/sh
TARGET_DIR=node_modules
if [ ! -d $TARGET_DIR ]; then
echo "$TARGET_DIR" does not exist
exit 1
fi
PATTERNS="
__tests__
_config.yml
.*ignore
.babel*
.circle*
.documentup*
.ds_store
.editorconfig
.env*
.git*
.idea
.lint*
.npm*
.nyc*
.prettier*
.tern-project
.yarn-integrity
.yarn-metadata.json
.yarnclean
.yo-*
*.coffee
*.flow*
*.jst
*.markdown
*.md
*.mkd
*.swp
*.tgz
*appveyor*
*coveralls*
*eslint*
*htmllint*
*jshint*
*readme*
*stylelint*
*travis*
*tslint*
*vscode*
*wallaby*
authors
changelog
changes
circle.yml
component.json
contributors
coverage
doc
docs
example
examples
grunt*
gulp*
jenkins*
jest.config.*
jsconfig.json
karma.conf*
licence
licence.txt
license
license.txt
makefile
npm-debug.log
powered-test
prettier.*
test
tests
tsconfig.json
"
PROD_PATTERNS="
*.map
*.mts
*.ts
"
# Add patterns from command-line arguments
[ "$#" -gt 0 ] && PATTERNS="$PATTERNS $(printf '\n%s' "$@")"
if [ "$NODE_ENV" = "production" ]; then
PATTERNS="$PATTERNS $PROD_PATTERNS"
fi
if [ ! "$NODE_ENV" = "production" ]; then
echo "$TARGET_DIR size before: $(du -sh $TARGET_DIR | awk '{print $1}')"
fi
find_cmd="find $TARGET_DIR \("
first_pattern=true
printf '%s\n' "$PATTERNS" | (
while IFS= read -r line; do
line=$(echo "$line" | xargs)
# skip empty lines
if [ -z "$line" ]; then
continue
fi
# add -o if not the first pattern
if [ "$first_pattern" = false ]; then
find_cmd="$find_cmd -o"
else
first_pattern=false
fi
find_cmd="$find_cmd -iname '$line'"
done
eval "$find_cmd \) -exec rm -rf {} +"
)
if [ ! "$NODE_ENV" = "production" ]; then
echo "$TARGET_DIR size after: $(du -sh $TARGET_DIR | awk '{print $1}')"
fi