From f8bd1ee9aea9917ce18c945f26cf93bf850a46d9 Mon Sep 17 00:00:00 2001 From: Christian Westgaard Date: Mon, 30 Sep 2024 14:04:03 +0200 Subject: [PATCH] Fix #161 Build fails when there are no files in the static folder --- package.json | 6 +++--- tsup/anyStaticFiles.js | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 tsup/anyStaticFiles.js diff --git a/package.json b/package.json index bec0bc9..b28dcde 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/tsup/anyStaticFiles.js b/tsup/anyStaticFiles.js new file mode 100644 index 0000000..4733911 --- /dev/null +++ b/tsup/anyStaticFiles.js @@ -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); +}