From ee6f25cc473e58a37536f4a0db36b6a1ff6c7df8 Mon Sep 17 00:00:00 2001 From: Ruslan Gainutdinov Date: Mon, 8 Jun 2020 20:59:40 +0300 Subject: [PATCH] Replace repo url and version automatically in HTML --- tools/cdata.js | 95 +++++++++++++++++++++++------------- wled00/data/settings_sec.htm | 2 +- wled00/html_settings.h | 5 +- 3 files changed, 64 insertions(+), 38 deletions(-) diff --git a/tools/cdata.js b/tools/cdata.js index 1f842f6a3..3802ceecc 100644 --- a/tools/cdata.js +++ b/tools/cdata.js @@ -16,6 +16,7 @@ */ const fs = require("fs"); +const packageJson = require("../package.json"); /** * @@ -42,9 +43,31 @@ function hexdump(buffer) { const inliner = require("inliner"); const zlib = require("zlib"); +function strReplace(str, search, replacement) { + return str.split(search).join(replacement); +} + +function adoptVersionAndRepo(html) { + let repoUrl = packageJson.repository ? packageJson.repository.url : undefined; + if (repoUrl) { + repoUrl = repoUrl.replace(/^git\+/, ""); + repoUrl = repoUrl.replace(/\.git$/, ""); + // Replace we + html = strReplace(html, "https://github.com/atuline/WLED", repoUrl); + html = strReplace(html, "https://github.com/Aircoookie/WLED", repoUrl); + } + + let version = packageJson.version; + if (version) { + html = strReplace(html, "##VERSION##", version); + } + + return html; +} + function writeHtmlGzipped(sourceFile, resultFile) { console.info("Reading " + sourceFile); - new inliner(sourceFile, function(error, html) { + new inliner(sourceFile, function (error, html) { console.info("Inlined " + html.length + " characters"); if (error) { @@ -52,7 +75,8 @@ function writeHtmlGzipped(sourceFile, resultFile) { throw error; } - zlib.gzip(html, function(error, result) { + html = adoptVersionAndRepo(html); + zlib.gzip(html, function (error, result) { if (error) { console.warn(error); throw error; @@ -77,6 +101,8 @@ const CleanCSS = require("clean-css"); const MinifyHTML = require("html-minifier").minify; function filter(str, type) { + str = adoptVersionAndRepo(str); + if (type === undefined) { return str; } else if (type == "css-minify") { @@ -87,7 +113,8 @@ function filter(str, type) { maxLineLength: 80, minifyCSS: true, minifyJS: true, - continueOnParseError: false + continueOnParseError: false, + removeComments: true, }); } else { console.warn("Unknown filter: " + type); @@ -101,10 +128,9 @@ function specToChunk(srcDir, s) { const str = buf.toString("ascii"); const chunk = ` // Autogenerated from ${srcDir}/${s.file}, do not edit!! -const char ${s.name}[] PROGMEM = R"${s.prepend || ""}${filter( - str, - s.filter - )}${s.append || ""}"; +const char ${s.name}[] PROGMEM = R"${s.prepend || ""}${filter(str, s.filter)}${ + s.append || "" + }"; `; return s.mangle ? s.mangle(chunk) : chunk; @@ -128,7 +154,7 @@ ${result} function writeChunks(srcDir, specs, resultFile) { let src = ""; - specs.forEach(s => { + specs.forEach((s) => { try { console.info("Reading " + srcDir + "/" + s.file + " as " + s.name); src += specToChunk(srcDir, s); @@ -154,7 +180,7 @@ writeChunks( prepend: "=====()=====", method: "plaintext", - filter: "css-minify" + filter: "css-minify", }, { file: "settings.htm", @@ -162,7 +188,7 @@ writeChunks( prepend: "=====(", append: ")=====", method: "plaintext", - filter: "html-minify" + filter: "html-minify", }, { file: "settings_wifi.htm", @@ -171,14 +197,14 @@ writeChunks( append: ")=====", method: "plaintext", filter: "html-minify", - mangle: str => + mangle: (str) => str .replace(/\/gms, "") .replace(/\.*\<\/style\>/gms, "%CSS%%SCSS%") .replace( /function GetV().*\<\/script\>/gms, "function GetV() {var d=document;\n" - ) + ), }, { file: "settings_leds.htm", @@ -187,14 +213,14 @@ writeChunks( append: ")=====", method: "plaintext", filter: "html-minify", - mangle: str => + mangle: (str) => str .replace(/\/gms, "") .replace(/\.*\<\/style\>/gms, "%CSS%%SCSS%") .replace( /function GetV().*\<\/script\>/gms, "function GetV() {var d=document;\n" - ) + ), }, { file: "settings_dmx.htm", @@ -203,7 +229,7 @@ writeChunks( append: ")=====", method: "plaintext", filter: "html-minify", - mangle: str => { + mangle: (str) => { const nocss = str .replace(/\/gms, "") .replace(/\.*\<\/style\>/gms, "%CSS%%SCSS%") @@ -218,7 +244,7 @@ ${nocss} const char PAGE_settings_dmx[] PROGMEM = R"=====()====="; #endif `; - } + }, }, { file: "settings_ui.htm", @@ -227,14 +253,14 @@ const char PAGE_settings_dmx[] PROGMEM = R"=====()====="; append: ")=====", method: "plaintext", filter: "html-minify", - mangle: str => + mangle: (str) => str .replace(/\/gms, "") .replace(/\.*\<\/style\>/gms, "%CSS%%SCSS%") .replace( /function GetV().*\<\/script\>/gms, "function GetV() {var d=document;\n" - ) + ), }, { file: "settings_sync.htm", @@ -243,11 +269,11 @@ const char PAGE_settings_dmx[] PROGMEM = R"=====()====="; append: ")=====", method: "plaintext", filter: "html-minify", - mangle: str => + mangle: (str) => str .replace(/\/gms, "") .replace(/\.*\<\/style\>/gms, "%CSS%%SCSS%") - .replace(/function GetV().*\<\/script\>/gms, "function GetV() {\n") + .replace(/function GetV().*\<\/script\>/gms, "function GetV() {\n"), }, { file: "settings_time.htm", @@ -256,11 +282,11 @@ const char PAGE_settings_dmx[] PROGMEM = R"=====()====="; append: ")=====", method: "plaintext", filter: "html-minify", - mangle: str => + mangle: (str) => str .replace(/\/gms, "") .replace(/\.*\<\/style\>/gms, "%CSS%%SCSS%") - .replace(/function GetV().*\<\/script\>/gms, "function GetV() {\n") + .replace(/function GetV().*\<\/script\>/gms, "function GetV() {\n"), }, { file: "settings_sec.htm", @@ -269,15 +295,15 @@ const char PAGE_settings_dmx[] PROGMEM = R"=====()====="; append: ")=====", method: "plaintext", filter: "html-minify", - mangle: str => + mangle: (str) => str .replace(/\/gms, "") .replace(/\.*\<\/style\>/gms, "%CSS%%SCSS%") .replace( /function GetV().*\<\/script\>/gms, "function GetV() {var d=document;\n" - ) - } + ), + }, ], "wled00/html_settings.h" ); @@ -292,7 +318,8 @@ writeChunks( append: ")=====", method: "plaintext", filter: "html-minify", - mangle: str => str.replace(/fetch\("http\:\/\/.*\/win/gms, "fetch(\"/win") + mangle: (str) => + str.replace(/fetch\("http\:\/\/.*\/win/gms, 'fetch("/win'), }, { file: "msg.htm", @@ -301,7 +328,7 @@ writeChunks( append: ")=====", method: "plaintext", filter: "html-minify", - mangle: str => str.replace(/\.*\<\/body\>/gms, "

%MSG%") + mangle: (str) => str.replace(/\.*\<\/body\>/gms, "

%MSG%"), }, { file: "dmxmap.htm", @@ -310,13 +337,13 @@ writeChunks( append: ")=====", method: "plaintext", filter: "html-minify", - mangle: str => ` + mangle: (str) => ` #ifdef WLED_ENABLE_DMX ${str.replace(/function FM\(\)[ ]?\{/gms, "function FM() {%DMXVARS%\n")} #else const char PAGE_dmxmap[] PROGMEM = R"=====()====="; #endif -` +`, }, { file: "update.htm", @@ -324,7 +351,7 @@ const char PAGE_dmxmap[] PROGMEM = R"=====()====="; prepend: "=====(", append: ")=====", method: "plaintext", - filter: "html-minify" + filter: "html-minify", }, { file: "welcome.htm", @@ -332,7 +359,7 @@ const char PAGE_dmxmap[] PROGMEM = R"=====()====="; prepend: "=====(", append: ")=====", method: "plaintext", - filter: "html-minify" + filter: "html-minify", }, { file: "liveview.htm", @@ -340,13 +367,13 @@ const char PAGE_dmxmap[] PROGMEM = R"=====()====="; prepend: "=====(", append: ")=====", method: "plaintext", - filter: "html-minify" + filter: "html-minify", }, { file: "favicon.ico", name: "favicon", - method: "binary" - } + method: "binary", + }, ], "wled00/html_other.h" ); diff --git a/wled00/data/settings_sec.htm b/wled00/data/settings_sec.htm index c87e75a55..2b3d415d0 100644 --- a/wled00/data/settings_sec.htm +++ b/wled00/data/settings_sec.htm @@ -89,7 +89,7 @@
Enable ArduinoOTA:

About

- WLED version 0.10.0

+ WLED version ##VERSION##

Contributors, dependencies and special thanks
A huge thank you to everyone who helped me create WLED!

(c) 2016-2019 Christian Schwinne
diff --git a/wled00/html_settings.h b/wled00/html_settings.h index c9e6e99ec..6aaa6f959 100644 --- a/wled00/html_settings.h +++ b/wled00/html_settings.h @@ -130,8 +130,7 @@ function GCH(n){for(d=document,d.getElementById("dmxchannels").innerHTML+="",i=0

-

Imma firin ma lazer (if it has DMX support)

- Proxy Universe Imma firin ma lazer (if it has DMX support)

Proxy Universe from E1.31 to DMX (0=disabled)
This will disable the LED data output to DMX configurable below

@@ -324,7 +323,7 @@ All EEPROM content (settings) will be erased.

HTTP traffic is unencrypted. An attacker in the same network can intercept form data!

Software Update


Enable ArduinoOTA:

About -

WLED +WLED version 0.10.0

Contributors, dependencies and special thanks