From 0544adbad3b488b1f6fc91fd4e66590a41ed1e3e Mon Sep 17 00:00:00 2001
From: Kai Reinhard <k.reinhard@micromata.de>
Date: Sun, 02 Mar 2025 21:39:02 +0000
Subject: [PATCH] Updates in progress...

---
 borgbutler-webapp/build.gradle.kts |  121 ++++++++++++++-------------------------
 1 files changed, 44 insertions(+), 77 deletions(-)

diff --git a/borgbutler-webapp/build.gradle.kts b/borgbutler-webapp/build.gradle.kts
index a5c78c0..09b6844 100644
--- a/borgbutler-webapp/build.gradle.kts
+++ b/borgbutler-webapp/build.gradle.kts
@@ -4,97 +4,64 @@
 }
 
 node {
-    // Configure the Node.js and npm versions
-    version.set("23.1.0")
-    // Version of npm to use
-    // If specified, installs it in the npmWorkDir
-    npmVersion.set("10.9.0")
-    // npmVersion.set("") // If empty, the plugin will use the npm command bundled with Node.js
-    download.set(true) // Downloads Node.js and npm instead of using a globally installed version
-
-    // Set the directories for Node.js and npm installations using the modern Gradle API
-    // Use a persistent directory outside the `build` folder
-    workDir.set(layout.projectDirectory.dir("node/nodejs")) // Directory for Node.js installation
-    npmWorkDir.set(layout.projectDirectory.dir("node/npm")) // Directory for npm installation
-    // Explicitly set the Node.js binary path
-    nodeProjectDir.set(file(layout.projectDirectory.dir(".").asFile.absolutePath))
+    version.set("16.15.0")
+    npmVersion.set("8.5.4")
+    download.set(true)
+    workDir.set(layout.projectDirectory.dir("node/nodejs"))
+    npmWorkDir.set(layout.projectDirectory.dir("node/npm"))
+    nodeProjectDir.set(layout.projectDirectory.dir("."))
 }
 
 tasks.named<Delete>("clean") {
     delete(
-        file("node"),  // Delete download directory of node and npm.
+        file("node"),
         file("node_modules"),
         layout.buildDirectory
     )
 }
 
-tasks {
-    // Configure the existing npmInstall task instead of registering a new one
-    named<com.github.gradle.node.npm.task.NpmTask>("npmInstall") {
-        group = "build"
-        description = "Installs npm dependencies"
-        args.set(listOf("install"))
-        // Skip task if node_modules exists
-        val nodeModulesDir = layout.projectDirectory.dir("node_modules")
-        onlyIf {
-            !nodeModulesDir.asFile.exists()
+tasks.register<com.github.gradle.node.npm.task.NpmTask>("npmBuild") {
+    group = "build"
+    description = "Builds the React project"
+    args.set(listOf("run", "build"))
+    dependsOn("npmInstall")
+
+    // Definiere explizit `build/webapp` als Output
+    outputs.dir(layout.buildDirectory.dir("webapp"))
+
+    doLast {
+        val webappDir = layout.buildDirectory.dir("webapp").get().asFile
+        if (!webappDir.exists()) {
+            webappDir.mkdirs() // Erstelle das Verzeichnis, falls es nicht existiert
         }
-        outputs.dir(project.layout.projectDirectory.dir("node_modules"))
+    }
+}
+
+tasks.register<Jar>("webAppJar") {
+    group = "build"
+    description = "Package React build output as a JAR"
+    archiveBaseName.set("borgbutler-webapp")
+    archiveVersion.set(project.version.toString())
+    destinationDirectory.set(layout.buildDirectory.dir("libs"))
+
+    dependsOn("npmBuild")
+
+    // Korrekte Referenz auf `webapp`-Verzeichnis
+    inputs.dir(layout.buildDirectory.dir("webapp"))
+    outputs.file(archiveFile)
+
+    from(layout.buildDirectory.dir("webapp")) {
+        into("static")
+        exclude("resources", "libs", "tmp")
     }
 
-    register<com.github.gradle.node.npm.task.NpmTask>("npmBuild") {
-        group = "build"
-        description = "Builds the React project"
-        args.set(listOf("run", "build"))
-        dependsOn("npmInstall")
-
-        inputs.files(fileTree("src")) // All source files as input
-        outputs.dir("build") // React output directory as output
+    from(layout.projectDirectory.file("src/index.html")) {
+        into("static")
     }
+}
 
-    register<Copy>("copyReactBuild") {
-        duplicatesStrategy = DuplicatesStrategy.EXCLUDE
-        group = "build"
-        description = "Copies built React files to the target directory"
-        dependsOn("npmBuild") // Depends on the React build process
-        from(file("build")) {
-            // Exclude the target directory to prevent recursion
-            exclude("resources/main/static/**")
-        }
-        from(file("src")) {
-            include("index.html")
-        }
-        into(layout.buildDirectory.dir("resources/main/static")) // Target directory in the Gradle project
-        // Skip task if target directory is up-to-date
-        inputs.dir("build") // React build directory as input
-        outputs.dir(layout.buildDirectory.dir("resources/main/static")) // Static resources directory as output
-    }
-
-    register<Jar>("webAppJar") {
-        group = "build"
-        description = "Package React build output as a JAR"
-        archiveBaseName.set("borgbutler-webapp")
-        archiveVersion.set(project.version.toString())
-        destinationDirectory.set(layout.buildDirectory.dir("libs"))
-
-        // Include files from react-build directory
-        from(layout.buildDirectory.get()) {
-            into("static") // Place files under /static in the JAR
-            exclude("resources")
-            exclude("libs")
-            exclude("tmp")
-        }
-        // Include additional files (e.g., src/index.html)
-        from(layout.projectDirectory.file("src/index.html")) {
-            into("static") // Copy index.html to /static
-        }
-        dependsOn("copyReactBuild") // Ensure React build and copy are done first
-    }
-
-    // Include the React build in the Gradle build process
-    named("build") {
-        dependsOn("copyReactBuild") // Makes React build a part of the Gradle build
-    }
+tasks.named("build") {
+    dependsOn("webAppJar")
 }
 
 description = "borgbutler-webapp"

--
Gitblit v1.10.0