[Scripts] Fix some issues and upgrade to external changes

This commit is contained in:
Ton Huisman
2024-09-20 21:38:03 +02:00
parent fbe91b25fe
commit c92aadcc50
4 changed files with 31 additions and 13 deletions
+26 -10
View File
@@ -15,17 +15,17 @@ rm $outputfile
function minify_html {
file=$1
post_To https://www.toptal.com/developers/html-minifier/raw $file
post_To https://www.toptal.com/developers/html-minifier/api/raw $file
}
function minify_css {
file=$1
post_To https://www.toptal.com/developers/cssminifier/raw $file
post_To https://www.toptal.com/developers/cssminifier/api/raw $file
}
function minify_js {
file=$1
post_To https://www.toptal.com/developers/javascript-minifier/raw $file
post_To https://www.toptal.com/developers/javascript-minifier/api/raw $file
}
function post_To {
@@ -34,7 +34,7 @@ function post_To {
RESPONSE=/tmp/response.txt
HEADERS=/tmp/headers.txt
curl -X POST -s --data-urlencode "input@$file" $url -D $HEADERS -o $RESPONSE
status=$(cat $HEADERS | grep '^HTTP/1' | tail -1 | awk '{print $2}')
status=$(cat $HEADERS | grep '^HTTP/2' | tail -1 | awk '{print $2}')
if [[ "$status" == "200" ]]; then
cat $RESPONSE > /tmp/converter.temp
rm $RESPONSE
@@ -50,18 +50,34 @@ function minify_svg {
svgo -i /Users/User/Desktop/icons/tools.svg -o - > /tmp/converter.temp
}
function ascii2hexCstyle {
function ascii2hexCstyle { # fold at column 135 so VSCode can 'color-highlight' the array
file_name=$(constFileName $1)
result=$(cat /tmp/converter.temp | hexdump -ve '1/1 "0x%.2x,"')
result=$(echo $result | sed 's/,$//')
echo "static const char DATA_${file_name}[] PROGMEM = {$result,0};"
result=$(echo $result | sed 's/,$//' | fold -w 135)
echo "static const char DATA_${file_name}[] PROGMEM = {"
echo "$result,0"
echo "};"
echo
echo
}
# split text in 132 character chunks, replace \ by \\, replace " by ', replace temp linebreak by real linebreak, wrap in quoted PROGMEM char array
function ascii2stringCstyle {
file_name=$(constFileName $1)
result=$(cat /tmp/converter.temp)
# s/\"/\\\"/g # double-quote " to escaped double-quote \", can use for .js but increases byte count
# s/\"/'"'"'/g # replace double-quote by single-quote, in a single-quoted string, can not be used for js
result=$(echo $result | sed -r 's/(.{132})/\1\x02/g; s/\\/\\\\/g; s/\"/'"'"'/g; s/\x02/\"\n\"/g')
echo "static const char DATA_${file_name}[] PROGMEM = {"
echo "\"$result\""
echo "};"
echo
echo
}
function constFileName {
extension=$(echo $1 | egrep -io "(json|svg|css|js|html)$" | tr "[:lower:]" "[:upper:]")
file=$(echo $1 | sed 's/\.json//' | sed 's/\.svg//' | sed 's/\.css//' | sed 's/\.html//' | sed 's/\.js//' | sed 's/\.\///' | tr '/' '_' | tr '.' '_' | tr '-' '_' | tr "[:lower:]" "[:upper:]")
file=$(echo $1 | sed 's/\.json//; s/\.svg//; s/\.css//; s/\.html//; s/\.js//; s/\.\///' | tr '/' '_' | tr '.' '_' | tr '-' '_' | tr "[:lower:]" "[:upper:]")
underscore="_"
echo $file$underscore$extension
}
@@ -91,12 +107,12 @@ for file in $file_list; do
elif [[ "$file" == *.min.css ]]; then
echo " CSS already minified"
cat $file > /tmp/converter.temp
ascii2hexCstyle $file >> $outputfile
ascii2stringCstyle $file >> $outputfile
elif [[ "$file" == *.css ]]; then
echo " CSS minify"
minify_css $file
keepMinifiedFile $file
ascii2hexCstyle $file >> $outputfile
ascii2stringCstyle $file >> $outputfile
elif [[ "$file" == *.html ]]; then
echo " HTML minify"
minify_html $file
+2 -1
View File
@@ -678,7 +678,8 @@ static const char jsSaveRules[] PROGMEM = {
"else{"
"fetch('/upload',{"
"method:'POST',"
"body:a"
"body:a,"
"mode:'no-cors'"
"}).then(e=>e.text()).then(l=>{"
"let a='/rules'+n+'.txt?callback='+Date.now();"
"fetch(a).then(e=>e.text()).then(n=>{"
+1 -1
View File
File diff suppressed because one or more lines are too long
+2 -1
View File
@@ -17,7 +17,8 @@ function saveRulesFile() {
} else {
fetch("/upload", {
method: "POST",
body: formData
body: formData,
mode: "no-cors"
}).then(response => response.text()).then(l => {
let url = "/rules" + ruleNumber + ".txt?callback=" + Date.now();
fetch(url).then(res => res.text()).then(ruleTextNewCheck => {