Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update cdata.js to rebuild if package.json changes #3875

Merged
merged 3 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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