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(/\