mirror of https://github.com/micromata/borgbackup-butler.git

Kai Reinhard
17.59.2025 2fc3f0400bddd07d0c152ac1dd6e6c599e3dd7c7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
plugins {
    id("com.github.node-gradle.node") version "7.1.0"
    id("base") // Fügt die 'clean'-Task hinzu
}
 
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))
}
 
tasks.named<Delete>("clean") {
    delete(
        file("node"),  // Delete download directory of node and npm.
        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()
        }
        outputs.dir(project.layout.projectDirectory.dir("node_modules"))
    }
 
    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
    }
 
    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
    }
}
 
description = "borgbutler-webapp"