Espeasy: WebStaticData.h automatisch aus Quelldateien generieren

Erstellt am 22. Aug. 2018  ·  5Kommentare  ·  Quelle: letscontrolit/ESPEasy

Es wäre von Vorteil, die statischen Assets in ihrem ursprünglichen Dateiformat (zB favicon.ico oder github-icon.svg ) zu speichern und ein Skript zu verwenden, um sie in C-Code zu konvertieren, der für WebStaticData.h . Auf diese Weise können die Assets gepflegt werden, ohne im C-Code herumzustöbern oder nach der Bearbeitung des CSS

Der zusätzliche Bonus wäre, dass man die Dateien mit externen Plugins wie svgo oder jsmin optimieren kann, bevor man sie in die Datei schreibt. Als Inspiration kann man sich WI-PWN ansehen, obwohl ich ein einfaches (bash/python/...) Skript verwenden würde, um die Datei zu generieren.

Build Enhancement

Alle 5 Kommentare

Dies ist ein guter Vorschlag, und wir müssen so etwas für die Zukunft tun. Danke, dass Sie ein Problem gemacht haben. :+1:

Das ist eine Sache, die in Zukunft hinzugefügt wird.
Außerdem können Benutzer selbst neue Symbole hinzufügen.

Der einzige Grund, warum dies noch nicht der Fall war, ist, dass ich mir beim Format noch nicht sicher war und ich auch darüber nachdachte, diese Assets als Dateien in das SPIFF zu laden.

Danke aber für die Links!

Nur der Vollständigkeit halber: Ich habe vor einiger Zeit ein Skript für diese Aufgabe erstellt. Es ist im Grunde eine Kopie eines Drehbuchs von Erick B. Tedeschi und spacehuhn . Das Repository für esp8266_deauther enthält auch ein weiteres ( Python-

#!/bin/bash

#
# This script walks through the assets folder and minifys all JS, HTML, CSS and SVG files. It also generates
# the corresponding constants that are added to the data.h file on esp8266_deauther folder.
#
# <strong i="8">@Author</strong> Erick B. Tedeschi < erickbt86 [at] gmail [dot] com >
# <strong i="9">@Author</strong> Wandmalfarbe https://github.com/Wandmalfarbe
#

outputfile="$(pwd)/data_h_temp"

rm $outputfile

function minify_html_css {
    file=$1
    curl -X POST -s --data-urlencode "input@$file" http://html-minifier.com/raw > /tmp/converter.temp
}

function minify_js {
    file=$1
    curl -X POST -s --data-urlencode "input@$file" https://javascript-minifier.com/raw > /tmp/converter.temp
}

function minify_svg {
    file=$1
    svgo -i /Users/User/Desktop/icons/tools.svg -o - > /tmp/converter.temp
}

function ascii2hexCstyle {
    file_name=$(constFileName $1)
    result=$(cat /tmp/converter.temp | hexdump -ve '1/1 "0x%.2x,"')
    result=$(echo $result | sed 's/,$//')
    echo "const char DATA_${file_name}[] PROGMEM = {$result};"
}

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:]")
    underscore="_"
    echo $file$underscore$extension
}


cd assets
file_list=$(find . -type f)

for file in $file_list; do
    echo "Processing: $file"
    file_name=$(constFileName $file)
    echo "  Array Name: $file_name"

    if [[ "$file" == *.min.js ]]; then
        echo "  JS already minified"
        cat $file > /tmp/converter.temp
        ascii2hexCstyle $file >> $outputfile
    elif [[ "$file" == *.js ]]; then
        echo "  JS minify"
        minify_js $file
        ascii2hexCstyle $file >> $outputfile
    elif [[ "$file" == *.min.css ]]; then
        echo "  CSS already minified"
        cat $file > /tmp/converter.temp
        ascii2hexCstyle $file >> $outputfile
    elif [[ "$file" == *.html ]] || [[ "$file" == *.css ]]; then
        echo "  HTML and CSS minify"
        minify_html_css $file
        ascii2hexCstyle $file >> $outputfile
    elif [[ "$file" == *.svg ]]; then
        echo "  SVG minify"
        minify_svg $file
        ascii2hexCstyle $file >> $outputfile
    else
        echo "  without minifier"
        cat $file > /tmp/converter.temp
        ascii2hexCstyle $file >> $outputfile
    fi
    echo ""
    sleep 1
done

Ich werde versuchen, dies zu tun, damit wir alle eingebetteten JavaScripts minimieren können.
Vielleicht ist es auch eine gute Idee, den Code für Builds mit 4 MB Flash lesbar zu lassen.

Ooooh, süße Musik in meinen Ohren @TD-er :)

War diese Seite hilfreich?
0 / 5 - 0 Bewertungen

Verwandte Themen

MarceloProjetos picture MarceloProjetos  ·  4Kommentare

TD-er picture TD-er  ·  4Kommentare

ronnythomas picture ronnythomas  ·  3Kommentare

uzi18 picture uzi18  ·  5Kommentare

DittelHome picture DittelHome  ·  5Kommentare