chore(es/minifier): Add scripts to extract tests automatically (#3212)

This commit is contained in:
Donny/강동윤 2022-01-10 16:59:21 +09:00 committed by GitHub
parent db71f7a42d
commit 057fca4196
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 110 additions and 19 deletions

View File

@ -6,4 +6,7 @@ private/
# Used for reducing
/input.js
/output.js
*.orig
*.orig
creduce_bug_*

View File

@ -8,7 +8,7 @@ let [ast1, ast2] =
process.argv.slice(2) // skip node executable and script filename
.map(file => readFileSync(file, 'utf-8')) // read given files as strings
.map(code => {
console.log(code);
// console.log(code);
return parseModule(code)
}); // parse into ASTs

View File

@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -eu
# Work in .data directory
cd .data
git clone https://github.com/cdnjs/cdnjs.git --depth 1 || true
cd cdnjs

View File

@ -0,0 +1,56 @@
#!/usr/bin/env bash
set -eu
dir="${1-"./inputs/"}"
echo "Removing useless files in $dir"
find $dir -type f \( \
-name "*.html" -o \
-name "*.xml" -o \
-name "*.aac" -o \
-name "*.avif" -o \
-name "*.ogg" -o \
-name "*.mp3" -o \
-name "*.mp4" -o \
-name "*.wav" -o \
-name "*.bat" -o \
-name "*.cur" -o \
-name "*.db" -o \
-name "*.diff" -o \
-name "*.donotoptimizepng" -o \
-name "*.gif" -o \
-name "*.svg" -o \
-name "*.css" -o \
-name "*.png" -o \
-name "*.json" -o \
-name "*.woff" -o \
-name "*.woff2" -o \
-name "*.otf" -o \
-name "*.ttf" -o \
-name "*.eot" -o \
-name "*.flow" -o \
-name "*.md" -o \
-name "*.less" -o \
-name "*.sass" -o \
-name "*.scss" -o \
-name "*.ico" -o \
-name "*.sh" -o \
-name "*.jpg" -o \
-name "*.webp" -o \
-name "*.jpeg" -o \
-name "*.gz" -o \
-name "*.gzip" -o \
-name "*.zip" -o \
-name "*.woff" -o \
-name "*.wasm" -o \
-name "*.wast" -o \
-name "*.tsbuildinfo" \
\) \
-delete
echo "Removing empty directories in $dir"
find $dir -type d -empty -delete
echo "Reducing js files in $dir"

View File

@ -1,7 +1,20 @@
#!/usr/bin/env bash
#
# Usage: ./scrtips/reduce-all.sh path/to/minifier-tasklist
#
# e.g:
# - ./scrtips/reduce-all.sh ~/projects/minifier-tasklist
# - ./scrtips/reduce-all.sh ~/projects/minifier-tasklist/react
#
#
set -eu
dir="$1"
find ./inputs/ -type f -name '*.js' -print0 | xargs -0 -I {} sh -c '\
echo "Processing {}"
./scripts/reduce.sh {}'
echo "Reducing javascript files in $dir"
find $dir -type f -name '*.js' -print0 | xargs -0 -P 4 -I {} sh -c './scripts/reduce.sh {}' || true
echo "Removing empty directories in $dir"
find $dir -type d -empty -delete

View File

@ -8,32 +8,38 @@ then
exit
fi
cp $1 input.js
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
# Build swc minifier
export MINIFY=$(cargo profile bin-path --example minifier)
echo "Reducing $1"
ls -al $1
echo "Using $MINIFY"
# Build swc minifier
export MINIFY=$(cargo profile bin-path --release --example minifier)
wd="$(mktemp -d)"
echo "Using $MINIFY; dir = $wd"
cp $1 "$wd/input.js"
dir="$(dirname $1)"
# Verify that we can run `creduce`
$SCRIPT_DIR/_/reduce/compare.sh
creduce "$SCRIPT_DIR/_/reduce/compare.sh" input.js
REDUCED_SIZE=$(wc -c <"input.js")
(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 [[ "$1" == *"inputs"* && $REDUCED_SIZE -le 3 ]]; then
if [[ $REDUCED_SIZE -le 3 ]]; then
echo "Removing $1"
git rm --force $1
git commit -m 'Remove useless input'
find ./inputs -type d -empty -delete
rm -rf $1
./scripts/_/notify.sh "Removed $1"
(cd $dir && git commit -m "Remove a file as it didn't break anything" $1)
else
# mkdir -p "$SCRIPT_DIR/../tests/compress/fixture/reduced/$hash"
# cp "$wd/input.js" "$SCRIPT_DIR/../tests/compress/fixture/reduced/$hash/input.js"
./scripts/_/notify.sh "Found errornous input"
fi

View File

@ -0,0 +1,4 @@
{
"defaults": true,
"toplevel": false
}