mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-07-27 19:57:38 +00:00
[Scripts] Fix some issues and upgrade to external changes
This commit is contained in:
+26
-10
@@ -15,17 +15,17 @@ rm $outputfile
|
|||||||
|
|
||||||
function minify_html {
|
function minify_html {
|
||||||
file=$1
|
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 {
|
function minify_css {
|
||||||
file=$1
|
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 {
|
function minify_js {
|
||||||
file=$1
|
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 {
|
function post_To {
|
||||||
@@ -34,7 +34,7 @@ function post_To {
|
|||||||
RESPONSE=/tmp/response.txt
|
RESPONSE=/tmp/response.txt
|
||||||
HEADERS=/tmp/headers.txt
|
HEADERS=/tmp/headers.txt
|
||||||
curl -X POST -s --data-urlencode "input@$file" $url -D $HEADERS -o $RESPONSE
|
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
|
if [[ "$status" == "200" ]]; then
|
||||||
cat $RESPONSE > /tmp/converter.temp
|
cat $RESPONSE > /tmp/converter.temp
|
||||||
rm $RESPONSE
|
rm $RESPONSE
|
||||||
@@ -50,18 +50,34 @@ function minify_svg {
|
|||||||
svgo -i /Users/User/Desktop/icons/tools.svg -o - > /tmp/converter.temp
|
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)
|
file_name=$(constFileName $1)
|
||||||
result=$(cat /tmp/converter.temp | hexdump -ve '1/1 "0x%.2x,"')
|
result=$(cat /tmp/converter.temp | hexdump -ve '1/1 "0x%.2x,"')
|
||||||
result=$(echo $result | sed 's/,$//')
|
result=$(echo $result | sed 's/,$//' | fold -w 135)
|
||||||
echo "static const char DATA_${file_name}[] PROGMEM = {$result,0};"
|
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
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
function constFileName {
|
function constFileName {
|
||||||
extension=$(echo $1 | egrep -io "(json|svg|css|js|html)$" | tr "[:lower:]" "[:upper:]")
|
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="_"
|
underscore="_"
|
||||||
echo $file$underscore$extension
|
echo $file$underscore$extension
|
||||||
}
|
}
|
||||||
@@ -91,12 +107,12 @@ for file in $file_list; do
|
|||||||
elif [[ "$file" == *.min.css ]]; then
|
elif [[ "$file" == *.min.css ]]; then
|
||||||
echo " CSS already minified"
|
echo " CSS already minified"
|
||||||
cat $file > /tmp/converter.temp
|
cat $file > /tmp/converter.temp
|
||||||
ascii2hexCstyle $file >> $outputfile
|
ascii2stringCstyle $file >> $outputfile
|
||||||
elif [[ "$file" == *.css ]]; then
|
elif [[ "$file" == *.css ]]; then
|
||||||
echo " CSS minify"
|
echo " CSS minify"
|
||||||
minify_css $file
|
minify_css $file
|
||||||
keepMinifiedFile $file
|
keepMinifiedFile $file
|
||||||
ascii2hexCstyle $file >> $outputfile
|
ascii2stringCstyle $file >> $outputfile
|
||||||
elif [[ "$file" == *.html ]]; then
|
elif [[ "$file" == *.html ]]; then
|
||||||
echo " HTML minify"
|
echo " HTML minify"
|
||||||
minify_html $file
|
minify_html $file
|
||||||
|
|||||||
@@ -678,7 +678,8 @@ static const char jsSaveRules[] PROGMEM = {
|
|||||||
"else{"
|
"else{"
|
||||||
"fetch('/upload',{"
|
"fetch('/upload',{"
|
||||||
"method:'POST',"
|
"method:'POST',"
|
||||||
"body:a"
|
"body:a,"
|
||||||
|
"mode:'no-cors'"
|
||||||
"}).then(e=>e.text()).then(l=>{"
|
"}).then(e=>e.text()).then(l=>{"
|
||||||
"let a='/rules'+n+'.txt?callback='+Date.now();"
|
"let a='/rules'+n+'.txt?callback='+Date.now();"
|
||||||
"fetch(a).then(e=>e.text()).then(n=>{"
|
"fetch(a).then(e=>e.text()).then(n=>{"
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -17,7 +17,8 @@ function saveRulesFile() {
|
|||||||
} else {
|
} else {
|
||||||
fetch("/upload", {
|
fetch("/upload", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: formData
|
body: formData,
|
||||||
|
mode: "no-cors"
|
||||||
}).then(response => response.text()).then(l => {
|
}).then(response => response.text()).then(l => {
|
||||||
let url = "/rules" + ruleNumber + ".txt?callback=" + Date.now();
|
let url = "/rules" + ruleNumber + ".txt?callback=" + Date.now();
|
||||||
fetch(url).then(res => res.text()).then(ruleTextNewCheck => {
|
fetch(url).then(res => res.text()).then(ruleTextNewCheck => {
|
||||||
|
|||||||
Reference in New Issue
Block a user