/
collect-metrics.sh
executable file
·61 lines (45 loc) · 1.52 KB
/
collect-metrics.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
#!/bin/sh
# Script to collect build size information
export PATH=$PATH:node_modules/.bin
# Get name from package.json
module=$(jq '.name' ./package.json)
# Get version from packag.json and remove quotes
version=$(jq '.version' ./package.json | awk '{ gsub(/"/,"",$1); printf "%-14s", $1 }')
# Helper functions
print_size_header() {
echo "| Version | Dist | Bundle Size | Compressed |"
echo "| --- | --- | --- | --- |"
}
print_size() {
DIST=$1
# Size it
size=$(wc -c /tmp/bundle.js | awk '{ print int($1 / 1024) "KB (" $1 ")" }')
# Zip it
gzip -9f /tmp/bundle.js
# Size it again
zipsize=$(wc -c /tmp/bundle.js.gz | awk '{ print int($1 / 1024) "KB (" $1 ")" }') # Size it
# Remove our copy
rm /tmp/bundle.js.gz
# Print version, size, compressed size with markdown
echo "| $version | $DIST | $size KB | $zipsize KB |"
}
build_bundle() {
ENV=$1
NODE_ENV=production webpack --config test/webpack.config.js --hide-modules --env.import-nothing --env.bundle --env.$ENV > /dev/null
}
# Main Script
echo
echo "\033[1mAutomatically collecting metrics for $module"
echo
print_size_header
build_bundle es6
print_size ES6
build_bundle esm
print_size ESM
build_bundle es5
print_size ES5
# Disable bold terminal font
echo "\033[0m"
(echo \"source size\" ; find src/ -name '*.js' | xargs cat | wc -c)
(echo \"dist esm size\" ; find dist/esm -name '*.js' | xargs cat | wc -c)
(echo \"dist/es6 size\" ; find dist/es6 -name '*.js' | xargs cat | wc -c)