Skip to content

Commit

Permalink
Reduce extension size by using Google Closure Compiler
Browse files Browse the repository at this point in the history
It's not much, but it's not nothing either.
Also dropped README.md from zip-file
  • Loading branch information
MrMinemeet committed Nov 20, 2024
1 parent 3dfff69 commit aa2a2bc
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 7 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
*.zip
*.zip

*.min.js

closure-compiler.jar
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ Furthermore, not every site has it's own translation for the warning message.
- amazon.sa
- amazon.eg
- amazon.sg
- amazon.com.tr
- amazon.com.tr

## External Dependencies
The extension is minified using the [Google Closure Compiler](https://github.com/google/closure-compiler).
3 changes: 2 additions & 1 deletion amznshipwarn.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ function getWarning() {
return "Ce produit n'est pas expédié par Amazon";
case "it":
return "Questo prodotto non è spedito da Amazon";
case "es", "com.mx":
case "es":
case "com.mx":
return "Este producto no es enviado por Amazon";
// TODO: Add more countries based on the Amazon TLD
default:
Expand Down
20 changes: 20 additions & 0 deletions fetchClosureCompiler.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

# Remove the old version of the closure compiler
rm -f ./closure-compiler.jar

# Fetch the latest version of the closure compiler
latest_version=$(curl -s https://repo1.maven.org/maven2/com/google/javascript/closure-compiler/ | grep -oP '(?<=href=")[^"]*(?=/)' | sort -V | tail -n 1)
# Download and rename the closure compiler
wget https://repo1.maven.org/maven2/com/google/javascript/closure-compiler/$latest_version/closure-compiler-$latest_version.jar -O ./closure-compiler.jar

# Verify the checksum of closure compiler with the checksum file
expected_sha512=$(curl -s https://repo1.maven.org/maven2/com/google/javascript/closure-compiler/$latest_version/closure-compiler-$latest_version.jar.sha512)
computed_sha512=$(sha512sum ./closure-compiler.jar | cut -d ' ' -f 1)

if [ "$computed_sha512" != "$expected_sha512" ]; then
echo "Checksum verification failed!"
exit 1
else
echo "Checksum verification passed!"
fi
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "AmznShipWarn",
"version": "1.0.1",
"version": "1.0.2",
"description": "Adds a warning to the Amazon page if the item is not shipped by Amazon.",
"homepage_url": "https://github.com/MrMinemeet/AmznShipWarn",

Expand All @@ -28,7 +28,7 @@
"https://*.amazon.com.tr/*"
],
"js": [
"amznshipwarn.js"
"amznshipwarn.min.js"
]
}
]
Expand Down
6 changes: 4 additions & 2 deletions pack.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/sh
# This script packs up necessary files into a .zip for publishing

zip AmznShipWarn.zip amznshipwarn.js LICENSE README.md manifest.json
# This script minifies and then packs up necessary files into a .zip for publishing
java -jar ./closure-compiler.jar -O ADVANCED --js amznshipwarn.js --js_output_file amznshipwarn.min.js --language_out=ECMASCRIPT_2019

zip AmznShipWarn.zip amznshipwarn.min.js LICENSE manifest.json

0 comments on commit aa2a2bc

Please sign in to comment.