-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
reduce.sh
executable file
·49 lines (37 loc) · 1.24 KB
/
reduce.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
#!/usr/bin/env bash
set -eu
if ! command -v creduce &> /dev/null
then
echo "creduce not found. Installing"
brew install creduce
exit
fi
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
TARGET_DIR="$(cargo metadata --format-version 1 --no-deps | jq -r '.target_directory')"
echo "Reducing $1"
ls -al $1
# Build swc minifier
cargo build --release --example compress
export MINIFY="$TARGET_DIR/release/examples/compress"
wd="$(mktemp -d)"
echo "Using $MINIFY; dir = $wd"
cp $1 "$wd/input.js"
dir="$(dirname $1)"
# Verify that we can run `creduce`
(cd $wd && "$SCRIPT_DIR/../_/reduce/compare.sh")
(cd $wd && creduce "$SCRIPT_DIR/../_/reduce/compare.sh" "$wd/input.js")
REDUCED_SIZE=$(wc -c <"$wd/input.js")
hash=$(sha1sum < "$wd/input.js")
echo "Hash is $hash"
echo "Reduced size is $REDUCED_SIZE bytes"
if [[ $REDUCED_SIZE -le 3 ]]; then
echo "Removing $1"
rm -rf $1
./scripts/_/notify.sh "Removed $1"
(cd $dir && git commit -m "Remove a file as it didn't break anything" $1)
else
cat $wd/input.js
# mkdir -p "$SCRIPT_DIR/../tests/fixture/reduced/$hash"
# cp "$wd/input.js" "$SCRIPT_DIR/../tests/fixture/reduced/$hash/input.js"
./scripts/_/notify.sh "Found errornous input"
fi