import org.gradle.internal.os.OperatingSystem

apply plugin: 'org.springframework.boot'
apply plugin: 'com.moowork.node'

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

def profiles = 'dev'
if (project.hasProperty('no-liquibase')) {
    profiles += ',no-liquibase'
}
if (project.hasProperty('tls')) {
    profiles += ',tls'
}

springBoot {
    buildInfo {
		properties {
			time = null
		}
	}
}

bootRun {
    args = []
}

task webpackBuildDev(type: NpmTask) {
    inputs.files(fileTree('src/main/webapp/'))

    def webpackDevFiles = fileTree('webpack//')
    webpackDevFiles.exclude('webpack.prod.js')
    inputs.files(webpackDevFiles)

    outputs.files(fileTree("build/www/"))

    dependsOn npmInstall

    args = ["run", "webpack:build"]
}

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 webpackBuildDev
copyIntoStatic.dependsOn processResources
bootJar.dependsOn copyIntoStatic