dependencies {
    testImplementation "com.h2database:h2"
}

def profiles = "prod"
if (project.hasProperty("no-liquibase")) {
    profiles += ",no-liquibase"
}

if (project.hasProperty("api-docs")) {
    profiles += ",api-docs"
}

springBoot {
    buildInfo()
}

bootRun {
    args = []
}

task webapp_test(type: NpmTask, dependsOn: "npm_install") {
    args = ["run", "webapp:test"]
}

task webapp(type: NpmTask, dependsOn: "npm_install") {
    args = ["run", "webapp:prod"]
    environment = [APP_VERSION: project.version]
    environment = [TYPE: project.type]

}

processResources {
    inputs.property('version', version)
    inputs.property('type', project.type)
    inputs.property('springProfiles', profiles)
    filesMatching("**/application.yml") {
        filter {
            it.replace("#project.version#", version)
        }
        filter {
            it.replace("#spring.profiles.active#", profiles)
        }
    }
}

test.dependsOn webapp_test
processResources.dependsOn webapp
bootJar.dependsOn processResources
