plugins {
	id 'com.axelor.app'
	id "com.github.node-gradle.node"
}

apply from: "../libs.gradle"
apply from: "../version.gradle"

apply {
	version = openSuiteVersion
}

axelor {
	title "Axelor Human Resource"
	description "Axelor Human Resource Module"
}

dependencies {
	api project(":modules:axelor-project")
	api project(":modules:axelor-bank-payment")

	implementation libs.commons_lang3
	implementation libs.commons_collections4
	testImplementation libs.mockito
    implementation libs.swagger_jaxrs
    implementation libs.jaxb_bind_api
}

ext {
  reactDir = 'axelor-react-timesheet'
}

node {
	version = '16.17.0'
	yarnVersion = '1.22.19'
    download = true
    distBaseUrl = null
    nodeModulesDir = file(reactDir)
}

task buildFront(type: YarnTask) {
    group = 'axelor'
    description = 'Build Front-end'

    inputs.files("${reactDir}/package.json", "${reactDir}/yarn.lock")
    inputs.dir("${reactDir}/src")
    inputs.dir("${reactDir}/public")
    inputs.dir(fileTree("${reactDir}/.yarn"))
    outputs.dir("${reactDir}/build")

	dependsOn 'installFrontDeps'
    args = ["run", "build"]
}

task installFrontDeps(type: YarnTask) {
    group = 'axelor'
    description = 'Install Front-end dependencies'

    args = ['install']
}


task copyReactWebapp(type: Copy) {
	destinationDir = file("$rootProject.buildDir/webapp")
	into("hr/timesheet") {
		from "${reactDir}/build"
	}
	
	dependsOn 'buildFront'
}


clean {
  delete "${reactDir}/.yarn/cache",
         "${reactDir}/.yarn/unplugged",
         "${reactDir}/.yarn/install-state.gz",
         "${reactDir}/dist",
         "${reactDir}/node_modules",
         "${reactDir}/build"
}

jar {
  dependsOn 'buildFront'
  into('webapp/hr/timesheet') {
    from "${reactDir}/build"
    duplicatesStrategy 'exclude'
  }
}


build.dependsOn copyReactWebapp
rootProject.tasks.war.dependsOn copyReactWebapp
