import org.gradle.internal.os.OperatingSystem

apply plugin: 'org.springframework.boot'
apply plugin: 'com.github.node-gradle.gulp'

dependencies {
    compile "org.springframework.boot:spring-boot-devtools"
}

def profiles = 'dev'
if (project.hasProperty('no-liquibase')) {
    profiles += ',no-liquibase'
}
if (project.hasProperty('tls')) {
    profiles += ',tls'
}
if (project.hasProperty('swagger')) {
    profiles += ',swagger'
}
bootRun {
    args = []
}

task copySwaggerDev(type: NpmTask, dependsOn: 'npm_install') {
    inputs.dir("src/main/webapp/")
    inputs.files(fileTree('src/main/webapp/'))
    outputs.dir("build/www/")
    outputs.file("build/www/app/main.bundle.js")
    args = ["run", "copy-swagger"]
}

war {
    webAppDirName = 'build/www/'
}

task copyIntoStatic (type: Copy) {
    from 'build/www/'
    into 'build/resources/main/static'
}

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

processResources.dependsOn copySwaggerDev
copyIntoStatic.dependsOn processResources
bootJar.dependsOn copyIntoStatic
