mirror of
https://github.com/wled/WLED.git
synced 2025-07-27 20:56:40 +00:00
Update dependencies for cdata.js
This commit is contained in:
parent
5dd8f0a0b7
commit
a84627a465
2072
package-lock.json
generated
2072
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -22,10 +22,10 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/Aircoookie/WLED#readme",
|
"homepage": "https://github.com/Aircoookie/WLED#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"clean-css": "^4.2.3",
|
"clean-css": "^5.3.3",
|
||||||
"html-minifier-terser": "^5.1.1",
|
"html-minifier-terser": "^7.2.0",
|
||||||
"inliner": "^1.13.1",
|
"inliner": "^1.13.1",
|
||||||
"nodemon": "^2.0.20",
|
"nodemon": "^3.0.2",
|
||||||
"zlib": "^1.0.5"
|
"zlib": "^1.0.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
135
tools/cdata.js
135
tools/cdata.js
@ -20,24 +20,23 @@ const path = require('path');
|
|||||||
const inliner = require("inliner");
|
const inliner = require("inliner");
|
||||||
const zlib = require("zlib");
|
const zlib = require("zlib");
|
||||||
const CleanCSS = require("clean-css");
|
const CleanCSS = require("clean-css");
|
||||||
const MinifyHTML = require("html-minifier-terser").minify;
|
const minifyHtml = require('html-minifier-terser').minify;
|
||||||
const packageJson = require("../package.json");
|
const packageJson = require("../package.json");
|
||||||
|
|
||||||
|
module.exports = { isFileNewerThan, isAnyFileInFolderNewerThan };
|
||||||
|
|
||||||
const output = ["wled00/html_ui.h", "wled00/html_pixart.h", "wled00/html_cpal.h", "wled00/html_pxmagic.h", "wled00/html_settings.h", "wled00/html_other.h"]
|
const output = ["wled00/html_ui.h", "wled00/html_pixart.h", "wled00/html_cpal.h", "wled00/html_pxmagic.h", "wled00/html_settings.h", "wled00/html_other.h"]
|
||||||
|
|
||||||
/**
|
function hexdump(buffer, isHex = false) {
|
||||||
*
|
|
||||||
*/
|
|
||||||
function hexdump(buffer,isHex=false) {
|
|
||||||
let lines = [];
|
let lines = [];
|
||||||
|
|
||||||
for (let i = 0; i < buffer.length; i +=(isHex?32:16)) {
|
for (let i = 0; i < buffer.length; i += (isHex ? 32 : 16)) {
|
||||||
var block;
|
var block;
|
||||||
let hexArray = [];
|
let hexArray = [];
|
||||||
if (isHex) {
|
if (isHex) {
|
||||||
block = buffer.slice(i, i + 32)
|
block = buffer.slice(i, i + 32)
|
||||||
for (let j = 0; j < block.length; j +=2 ) {
|
for (let j = 0; j < block.length; j += 2) {
|
||||||
hexArray.push("0x" + block.slice(j,j+2))
|
hexArray.push("0x" + block.slice(j, j + 2))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
block = buffer.slice(i, i + 16); // cut buffer into blocks of 16
|
block = buffer.slice(i, i + 16); // cut buffer into blocks of 16
|
||||||
@ -74,60 +73,47 @@ function adoptVersionAndRepo(html) {
|
|||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
function filter(str, type) {
|
async function minify(str, type = "plain") {
|
||||||
str = adoptVersionAndRepo(str);
|
const options = {
|
||||||
if (type === undefined) {
|
|
||||||
return str;
|
|
||||||
} else if (type == "css-minify") {
|
|
||||||
return new CleanCSS({}).minify(str).styles;
|
|
||||||
} else if (type == "js-minify") {
|
|
||||||
return MinifyHTML('<script>' + str + '</script>', {
|
|
||||||
collapseWhitespace: true,
|
|
||||||
minifyJS: true,
|
|
||||||
continueOnParseError: false,
|
|
||||||
removeComments: true,
|
|
||||||
}).replace(/<[\/]*script>/g,'');
|
|
||||||
} else if (type == "html-minify") {
|
|
||||||
return MinifyHTML(str, {
|
|
||||||
collapseWhitespace: true,
|
|
||||||
maxLineLength: 80,
|
|
||||||
minifyCSS: true,
|
|
||||||
minifyJS: true,
|
|
||||||
continueOnParseError: false,
|
|
||||||
removeComments: true,
|
|
||||||
});
|
|
||||||
} else if (type == "html-minify-ui") {
|
|
||||||
return MinifyHTML(str, {
|
|
||||||
collapseWhitespace: true,
|
collapseWhitespace: true,
|
||||||
conservativeCollapse: true,
|
conservativeCollapse: true,
|
||||||
maxLineLength: 80,
|
maxLineLength: 80,
|
||||||
minifyCSS: true,
|
minifyCSS: true,
|
||||||
minifyJS: true,
|
minifyJS: true,
|
||||||
continueOnParseError: false,
|
continueOnParseError: false,
|
||||||
removeComments: true,
|
removeComments: true
|
||||||
});
|
};
|
||||||
} else {
|
|
||||||
console.warn("Unknown filter: " + type);
|
if (type == "plain") {
|
||||||
return str;
|
return str;
|
||||||
|
} else if (type == "css-minify") {
|
||||||
|
return new CleanCSS({}).minify(str).styles;
|
||||||
|
} else if (type == "js-minify") {
|
||||||
|
return await minifyHtml('<script>' + str + '</script>', options).replace(/<[\/]*script>/g, '');
|
||||||
|
} else if (type == "html-minify") {
|
||||||
|
return await minifyHtml(str, options);
|
||||||
|
} else if (type == "html-minify-ui") {
|
||||||
|
return await minifyHtml(str, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw new Error("Unknown filter: " + type);
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeHtmlGzipped(sourceFile, resultFile, page) {
|
async function writeHtmlGzipped(sourceFile, resultFile, page) {
|
||||||
console.info("Reading " + sourceFile);
|
console.info("Reading " + sourceFile);
|
||||||
new inliner(sourceFile, function (error, html) {
|
new inliner(sourceFile, async function (error, html) {
|
||||||
console.info("Inlined " + html.length + " characters");
|
|
||||||
html = filter(html, "html-minify-ui");
|
|
||||||
console.info("Minified to " + html.length + " characters");
|
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
console.warn(error);
|
console.error(error);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
html = adoptVersionAndRepo(html);
|
html = adoptVersionAndRepo(html);
|
||||||
|
console.info("Inlined " + html.length + " characters");
|
||||||
|
html = await minify(html, "html-minify-ui");
|
||||||
|
console.info("Minified to " + html.length + " characters");
|
||||||
zlib.gzip(html, { level: zlib.constants.Z_BEST_COMPRESSION }, function (error, result) {
|
zlib.gzip(html, { level: zlib.constants.Z_BEST_COMPRESSION }, function (error, result) {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.warn(error);
|
console.error(error);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,37 +139,36 @@ ${array}
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function specToChunk(srcDir, s) {
|
async function specToChunk(srcDir, s) {
|
||||||
if (s.method == "plaintext") {
|
|
||||||
const buf = fs.readFileSync(srcDir + "/" + s.file);
|
const buf = fs.readFileSync(srcDir + "/" + s.file);
|
||||||
const str = buf.toString("utf-8");
|
|
||||||
|
if (s.method == "plaintext" || s.method == "gzip") {
|
||||||
|
let str = buf.toString("utf-8");
|
||||||
|
str = adoptVersionAndRepo(str);
|
||||||
|
if (s.method == "gzip") {
|
||||||
|
if (s.mangle) str = s.mangle(str);
|
||||||
|
const zip = zlib.gzipSync(await minify(str, s.filter), { level: zlib.constants.Z_BEST_COMPRESSION });
|
||||||
|
const result = hexdump(zip.toString('hex'), true);
|
||||||
|
return `
|
||||||
|
// Autogenerated from ${srcDir}/${s.file}, do not edit!!
|
||||||
|
const uint16_t ${s.name}_length = ${zip.length};
|
||||||
|
const uint8_t ${s.name}[] PROGMEM = {
|
||||||
|
${result}
|
||||||
|
};
|
||||||
|
|
||||||
|
`;
|
||||||
|
} else {
|
||||||
const chunk = `
|
const chunk = `
|
||||||
// Autogenerated from ${srcDir}/${s.file}, do not edit!!
|
// Autogenerated from ${srcDir}/${s.file}, do not edit!!
|
||||||
const char ${s.name}[] PROGMEM = R"${s.prepend || ""}${filter(str, s.filter)}${
|
const char ${s.name}[] PROGMEM = R"${s.prepend || ""}${await minify(str, s.filter)}${s.append || ""
|
||||||
s.append || ""
|
|
||||||
}";
|
}";
|
||||||
|
|
||||||
`;
|
`;
|
||||||
return s.mangle ? s.mangle(chunk) : chunk;
|
return s.mangle ? s.mangle(chunk) : chunk;
|
||||||
} else if (s.method == "gzip") {
|
}
|
||||||
const buf = fs.readFileSync(srcDir + "/" + s.file);
|
|
||||||
var str = buf.toString('utf-8');
|
|
||||||
if (s.mangle) str = s.mangle(str);
|
|
||||||
const zip = zlib.gzipSync(filter(str, s.filter), { level: zlib.constants.Z_BEST_COMPRESSION });
|
|
||||||
const result = hexdump(zip.toString('hex'), true);
|
|
||||||
const chunk = `
|
|
||||||
// Autogenerated from ${srcDir}/${s.file}, do not edit!!
|
|
||||||
const uint16_t ${s.name}_length = ${zip.length};
|
|
||||||
const uint8_t ${s.name}[] PROGMEM = {
|
|
||||||
${result}
|
|
||||||
};
|
|
||||||
|
|
||||||
`;
|
|
||||||
return chunk;
|
|
||||||
} else if (s.method == "binary") {
|
} else if (s.method == "binary") {
|
||||||
const buf = fs.readFileSync(srcDir + "/" + s.file);
|
|
||||||
const result = hexdump(buf);
|
const result = hexdump(buf);
|
||||||
const chunk = `
|
return `
|
||||||
// Autogenerated from ${srcDir}/${s.file}, do not edit!!
|
// Autogenerated from ${srcDir}/${s.file}, do not edit!!
|
||||||
const uint16_t ${s.name}_length = ${buf.length};
|
const uint16_t ${s.name}_length = ${buf.length};
|
||||||
const uint8_t ${s.name}[] PROGMEM = {
|
const uint8_t ${s.name}[] PROGMEM = {
|
||||||
@ -191,14 +176,14 @@ ${result}
|
|||||||
};
|
};
|
||||||
|
|
||||||
`;
|
`;
|
||||||
return chunk;
|
|
||||||
} else {
|
|
||||||
console.warn("Unknown method: " + s.method);
|
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.warn("Unknown method: " + s.method);
|
||||||
|
throw new Error("Unknown method: " + s.method);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeChunks(srcDir, specs, resultFile) {
|
async function writeChunks(srcDir, specs, resultFile) {
|
||||||
let src = `/*
|
let src = `/*
|
||||||
* More web UI HTML source arrays.
|
* More web UI HTML source arrays.
|
||||||
* This file is auto generated, please don't make any changes manually.
|
* This file is auto generated, please don't make any changes manually.
|
||||||
@ -206,18 +191,18 @@ function writeChunks(srcDir, specs, resultFile) {
|
|||||||
* to find out how to easily modify the web UI source!
|
* to find out how to easily modify the web UI source!
|
||||||
*/
|
*/
|
||||||
`;
|
`;
|
||||||
specs.forEach((s) => {
|
for (const s of specs) {
|
||||||
const file = srcDir + "/" + s.file;
|
const file = srcDir + "/" + s.file;
|
||||||
try {
|
try {
|
||||||
console.info("Reading " + file + " as " + s.name);
|
console.info("Reading " + file + " as " + s.name);
|
||||||
src += specToChunk(srcDir, s);
|
src += await specToChunk(srcDir, s);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn(
|
console.warn(
|
||||||
"Failed " + s.name + " from " + file,
|
"Failed " + s.name + " from " + file,
|
||||||
e.message.length > 60 ? e.message.substring(0, 60) : e.message
|
e.message.length > 60 ? e.message.substring(0, 60) : e.message
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
console.info("Writing " + src.length + " characters into " + resultFile);
|
console.info("Writing " + src.length + " characters into " + resultFile);
|
||||||
fs.writeFileSync(resultFile, src);
|
fs.writeFileSync(resultFile, src);
|
||||||
}
|
}
|
||||||
@ -283,7 +268,7 @@ writeChunks(
|
|||||||
filter: "css-minify",
|
filter: "css-minify",
|
||||||
mangle: (str) =>
|
mangle: (str) =>
|
||||||
str
|
str
|
||||||
.replace("%%","%")
|
.replace("%%", "%")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
file: "settings.htm",
|
file: "settings.htm",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user