Skip to content

Commit

Permalink
Merge pull request #3875 from w00000dy/cdata
Browse files Browse the repository at this point in the history
Update cdata.js to rebuild if package.json changes
  • Loading branch information
blazoncek authored Apr 4, 2024
2 parents 24c5935 + 78b37b5 commit 8691ddc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 8 additions & 1 deletion tools/cdata-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,16 @@ describe('Script', () => {
// Backup files
fs.cpSync("wled00/data", "wled00Backup", { recursive: true });
fs.cpSync("tools/cdata.js", "cdata.bak.js");
fs.cpSync("package.json", "package.bak.json");
});
after(() => {
// Restore backup
fs.rmSync("wled00/data", { recursive: true });
fs.renameSync("wled00Backup", "wled00/data");
fs.rmSync("tools/cdata.js");
fs.renameSync("cdata.bak.js", "tools/cdata.js");
fs.rmSync("package.json");
fs.renameSync("package.bak.json", "package.json");
});

// delete all html_*.h files
Expand Down Expand Up @@ -131,7 +134,7 @@ describe('Script', () => {
// run script cdata.js again and wait for it to finish
await execPromise('node tools/cdata.js');

checkIfFileWasNewlyCreated(path.join(folderPath, resultFile));
await checkIfFileWasNewlyCreated(path.join(folderPath, resultFile));
}

describe('should build if', () => {
Expand Down Expand Up @@ -182,6 +185,10 @@ describe('Script', () => {
it('cdata.js changes', async () => {
await testFileModification('tools/cdata.js', 'html_ui.h');
});

it('package.json changes', async () => {
await testFileModification('package.json', 'html_ui.h');
});
});

describe('should not build if', () => {
Expand Down
6 changes: 3 additions & 3 deletions tools/cdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Writes compressed C arrays of data files (web interface)
* How to use it?
*
* 1) Install Node 11+ and npm
* 1) Install Node 20+ and npm
* 2) npm install
* 3) npm run build
*
Expand Down Expand Up @@ -207,7 +207,7 @@ function isAnyFileInFolderNewerThan(folderPath, time) {
}

// Check if the web UI is already built
function isAlreadyBuilt(folderPath) {
function isAlreadyBuilt(webUIPath, packageJsonPath = "package.json") {
let lastBuildTime = Infinity;

for (const file of output) {
Expand All @@ -220,7 +220,7 @@ function isAlreadyBuilt(folderPath) {
}
}

return !isAnyFileInFolderNewerThan(folderPath, lastBuildTime) && !isFileNewerThan("tools/cdata.js", lastBuildTime);
return !isAnyFileInFolderNewerThan(webUIPath, lastBuildTime) && !isFileNewerThan(packageJsonPath, lastBuildTime) && !isFileNewerThan(__filename, lastBuildTime);
}

// Don't run this script if we're in a test environment
Expand Down

0 comments on commit 8691ddc

Please sign in to comment.