2022-01-04 23:12:52 +03:00
|
|
|
#!/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 )
|
|
|
|
|
2022-01-10 10:59:21 +03:00
|
|
|
echo "Reducing $1"
|
|
|
|
ls -al $1
|
|
|
|
|
2022-01-04 23:12:52 +03:00
|
|
|
# Build swc minifier
|
2022-04-17 13:53:47 +03:00
|
|
|
export MINIFY=$(cargo profile bin-path --release --example compress)
|
2022-01-10 10:59:21 +03:00
|
|
|
|
|
|
|
wd="$(mktemp -d)"
|
|
|
|
echo "Using $MINIFY; dir = $wd"
|
2022-01-04 23:12:52 +03:00
|
|
|
|
2022-01-10 10:59:21 +03:00
|
|
|
cp $1 "$wd/input.js"
|
|
|
|
dir="$(dirname $1)"
|
2022-01-04 23:12:52 +03:00
|
|
|
|
|
|
|
# Verify that we can run `creduce`
|
2022-04-17 13:53:47 +03:00
|
|
|
(cd $wd && "$SCRIPT_DIR/../_/reduce/compare.sh")
|
2022-01-04 23:12:52 +03:00
|
|
|
|
2022-04-17 13:53:47 +03:00
|
|
|
(cd $wd && creduce "$SCRIPT_DIR/../_/reduce/compare.sh" "$wd/input.js")
|
2022-01-04 23:12:52 +03:00
|
|
|
|
2022-01-10 10:59:21 +03:00
|
|
|
REDUCED_SIZE=$(wc -c <"$wd/input.js")
|
|
|
|
hash=$(sha1sum < "$wd/input.js")
|
|
|
|
echo "Hash is $hash"
|
|
|
|
|
2022-01-04 23:12:52 +03:00
|
|
|
echo "Reduced size is $REDUCED_SIZE bytes"
|
|
|
|
|
2022-01-10 10:59:21 +03:00
|
|
|
if [[ $REDUCED_SIZE -le 3 ]]; then
|
2022-01-04 23:12:52 +03:00
|
|
|
echo "Removing $1"
|
2022-01-10 10:59:21 +03:00
|
|
|
rm -rf $1
|
2022-01-04 23:12:52 +03:00
|
|
|
./scripts/_/notify.sh "Removed $1"
|
2022-01-10 10:59:21 +03:00
|
|
|
(cd $dir && git commit -m "Remove a file as it didn't break anything" $1)
|
2022-01-04 23:12:52 +03:00
|
|
|
else
|
2022-01-12 10:57:54 +03:00
|
|
|
cat $wd/input.js
|
2022-04-20 09:52:03 +03:00
|
|
|
# mkdir -p "$SCRIPT_DIR/../tests/fixture/reduced/$hash"
|
|
|
|
# cp "$wd/input.js" "$SCRIPT_DIR/../tests/fixture/reduced/$hash/input.js"
|
2022-01-04 23:12:52 +03:00
|
|
|
./scripts/_/notify.sh "Found errornous input"
|
|
|
|
fi
|