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 = "";
if (project.hasProperty('pgsql')) {
    profiles += 'pgsql'
} else if (project.hasProperty('h2file')) {
    profiles += 'h2file'
} else {
    profiles += 'h2mem'
}
if (project.hasProperty('no-liquibase')) {
    profiles += ',no-liquibase'
}
if (project.hasProperty('tls')) {
    profiles += ',tls'
}

println 'activating profiles: ' + profiles

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
