mirror of
https://github.com/wled/WLED.git
synced 2025-04-26 07:47:16 +00:00
Fix bug where some changes were not recognized
This commit is contained in:
parent
71b0c5f805
commit
5bdb2c9e86
2
.gitignore
vendored
2
.gitignore
vendored
@ -22,5 +22,3 @@ wled-update.sh
|
|||||||
/wled00/Release
|
/wled00/Release
|
||||||
/wled00/wled00.ino.cpp
|
/wled00/wled00.ino.cpp
|
||||||
/wled00/html_*.h
|
/wled00/html_*.h
|
||||||
|
|
||||||
/tools/cdataCache.json
|
|
@ -16,42 +16,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
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");
|
||||||
|
|
||||||
const CACHE_FILE = __dirname + "/cdataCache.json";
|
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 cache = loadCache();
|
|
||||||
cache.version = 1;
|
|
||||||
|
|
||||||
function loadCache() {
|
|
||||||
try {
|
|
||||||
return JSON.parse(fs.readFileSync(CACHE_FILE));
|
|
||||||
} catch (e) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function saveCache(file) {
|
|
||||||
const stat = fs.statSync(file);
|
|
||||||
cache[file] = {
|
|
||||||
mtime: stat.mtimeMs,
|
|
||||||
size: stat.size,
|
|
||||||
};
|
|
||||||
fs.writeFileSync(CACHE_FILE, JSON.stringify(cache));
|
|
||||||
}
|
|
||||||
|
|
||||||
function isCached(sourceFile, resultFile) {
|
|
||||||
// If command line argument is set, always rebuild
|
|
||||||
if (process.argv[2] == "--force" || process.argv[2] == "-f") return false;
|
|
||||||
// If result file does not exist, rebuild
|
|
||||||
if (!fs.existsSync(resultFile)) return false;
|
|
||||||
const stat = fs.statSync(sourceFile);
|
|
||||||
const cached = cache[sourceFile];
|
|
||||||
return cached && cached.mtime == stat.mtimeMs && cached.size == stat.size;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -141,10 +113,6 @@ function filter(str, type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function writeHtmlGzipped(sourceFile, resultFile, page) {
|
function writeHtmlGzipped(sourceFile, resultFile, page) {
|
||||||
if (isCached(sourceFile, resultFile)) {
|
|
||||||
console.info(`Skipping ${resultFile} as it is cached`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
console.info("Reading " + sourceFile);
|
console.info("Reading " + sourceFile);
|
||||||
new inliner(sourceFile, function (error, html) {
|
new inliner(sourceFile, function (error, html) {
|
||||||
console.info("Inlined " + html.length + " characters");
|
console.info("Inlined " + html.length + " characters");
|
||||||
@ -181,7 +149,6 @@ ${array}
|
|||||||
`;
|
`;
|
||||||
console.info("Writing " + resultFile);
|
console.info("Writing " + resultFile);
|
||||||
fs.writeFileSync(resultFile, src);
|
fs.writeFileSync(resultFile, src);
|
||||||
saveCache(sourceFile);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -232,11 +199,6 @@ ${result}
|
|||||||
}
|
}
|
||||||
|
|
||||||
function writeChunks(srcDir, specs, resultFile) {
|
function writeChunks(srcDir, specs, resultFile) {
|
||||||
if (specs.every(s => isCached(srcDir + "/" + s.file, resultFile))) {
|
|
||||||
console.info(`Skipping ${resultFile} as all files are cached`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
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.
|
||||||
@ -249,7 +211,6 @@ function writeChunks(srcDir, specs, resultFile) {
|
|||||||
try {
|
try {
|
||||||
console.info("Reading " + file + " as " + s.name);
|
console.info("Reading " + file + " as " + s.name);
|
||||||
src += specToChunk(srcDir, s);
|
src += specToChunk(srcDir, s);
|
||||||
saveCache(file);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn(
|
console.warn(
|
||||||
"Failed " + s.name + " from " + file,
|
"Failed " + s.name + " from " + file,
|
||||||
@ -261,6 +222,52 @@ function writeChunks(srcDir, specs, resultFile) {
|
|||||||
fs.writeFileSync(resultFile, src);
|
fs.writeFileSync(resultFile, src);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if a file is newer than a given time
|
||||||
|
function isFileNewerThan(filePath, time) {
|
||||||
|
try {
|
||||||
|
const stats = fs.statSync(filePath);
|
||||||
|
return stats.mtimeMs > time;
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`Failed to get stats for file ${filePath}:`, e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if any file in a folder (or its subfolders) is newer than a given time
|
||||||
|
function isAnyFileInFolderNewerThan(folderPath, time) {
|
||||||
|
const files = fs.readdirSync(folderPath, { withFileTypes: true });
|
||||||
|
for (const file of files) {
|
||||||
|
const filePath = path.join(folderPath, file.name);
|
||||||
|
if (isFileNewerThan(filePath, time)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (file.isDirectory() && isAnyFileInFolderNewerThan(filePath, time)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isAlreadyBuilt(folderPath) {
|
||||||
|
let lastBuildTime = Infinity;
|
||||||
|
|
||||||
|
for (const file of output) {
|
||||||
|
try {
|
||||||
|
lastBuildTime = Math.min(lastBuildTime, fs.statSync(file).mtimeMs);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return !isAnyFileInFolderNewerThan(folderPath, lastBuildTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isAlreadyBuilt("wled00/data") && process.argv[2] !== '--force' && process.argv[2] !== '-f') {
|
||||||
|
console.info("Web UI is already built");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
writeHtmlGzipped("wled00/data/index.htm", "wled00/html_ui.h", 'index');
|
writeHtmlGzipped("wled00/data/index.htm", "wled00/html_ui.h", 'index');
|
||||||
writeHtmlGzipped("wled00/data/pixart/pixart.htm", "wled00/html_pixart.h", 'pixart');
|
writeHtmlGzipped("wled00/data/pixart/pixart.htm", "wled00/html_pixart.h", 'pixart');
|
||||||
writeHtmlGzipped("wled00/data/cpal/cpal.htm", "wled00/html_cpal.h", 'cpal');
|
writeHtmlGzipped("wled00/data/cpal/cpal.htm", "wled00/html_cpal.h", 'cpal');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user