Skip to content

Commit

Permalink
Fix #161 Build fails when there are no files in the static folder
Browse files Browse the repository at this point in the history
  • Loading branch information
ComLock committed Sep 30, 2024
1 parent d83e62e commit f8bd1ee
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@
"build": "concurrently -c auto -g --timings npm:build:*",
"build:sass": "npx sass src/main/resources/assets/styles:build/resources/main/assets/styles",
"build:server": "npx tsup -d build/resources/main",
"build:static": "npx tsup -d build/resources/main/static",
"build:static": "node tsup/anyStaticFiles.js && npx tsup -d build/resources/main/static || exit 0",
"check": "concurrently -c auto -g --timings npm:lint npm:check:types",
"check:types": "concurrently -g -r --timings npm:check:types:*",
"check:types:server": "npx tsc --noEmit",
"check:types:static": "npx tsc --noEmit -p src/main/resources/static/tsconfig.json",
"check:types:static": "node tsup/anyStaticFiles.js && npx tsc --noEmit -p src/main/resources/static/tsconfig.json || exit 0",
"lint": "eslint --cache src/main/resources/**/*.ts",
"minify": "concurrently -c auto -g --timings 'npm:build:sass -- --style compressed' 'npm:build:server -- --minify' 'npm:build:static -- --minify'",
"watch": "concurrently -c auto npm:watch:*",
"watch:browserSync": "npx browser-sync start --files \"src/main/resources/**/*.html\" \"src/main/resources/**/*.xml\" \"build/resources/main\" --reload-delay 0 --port 3100 --no-snippet --watch",
"watch:sass": "npm run build:sass -- --watch",
"watch:server": "npm run build:server -- --watch",
"watch:static": "npm run build:static -- --watch",
"watch:static": "node tsup/anyStaticFiles.js && npm run build:static -- --watch || exit 0",
"test": "npm run lint"
},
"repository": {
Expand Down
26 changes: 26 additions & 0 deletions tsup/anyStaticFiles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const fs = require('fs');

const folderPath = 'src/main/resources/static';
const regExpPattern = '(^.?|\.[^d]|[^.]d|[^.][^d])\.tsx?$';

function checkFilesRecursively(folderPath) {
const files = fs.readdirSync(folderPath);
for (const file of files) {
const filePath = `${folderPath}/${file}`;
if (fs.lstatSync(filePath).isDirectory()) {
const found = checkFilesRecursively(filePath);
if (found) {
return true; // Exit with code 0 if a matching file is found
}
} else if (file.match(regExpPattern)) {
return true; // Exit with code 0 if a matching file is found
}
}
return false; // No matching files found in this directory
}

if (checkFilesRecursively(folderPath)) {
process.exit(0);
} else {
process.exit(1);
}

0 comments on commit f8bd1ee

Please sign in to comment.