plugins {
    id 'java'
    id "com.github.node-gradle.node" version "7.0.2"
    id "io.freefair.lombok" version "8.0.1"
    id "run.halo.plugin.devtools" version "0.2.0"
}

group 'run.halo.starter'
sourceCompatibility = JavaVersion.VERSION_17

repositories {
    mavenCentral()
    maven { url 'https://s01.oss.sonatype.org/content/repositories/releases' }
    maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' }
    maven { url 'https://repo.spring.io/milestone' }
}

dependencies {
    implementation platform('run.halo.tools.platform:plugin:2.20.0-SNAPSHOT')
    compileOnly 'run.halo.app:api'

    // 测试依赖
    testImplementation 'run.halo.app:api'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'io.projectreactor:reactor-test'
    testImplementation 'org.junit.jupiter:junit-jupiter-api'
    testImplementation 'org.junit.jupiter:junit-jupiter-engine'
    testImplementation 'org.mockito:mockito-junit-jupiter'
    testImplementation 'org.assertj:assertj-core'

    // 如果需要 Mock 服务器请求
    testImplementation 'org.springframework:spring-webflux'
    testImplementation 'io.projectreactor.netty:reactor-netty'
}

test {
    useJUnitPlatform()
}

tasks.withType(JavaCompile).configureEach {
    options.encoding = "UTF-8"
}

node {
    nodeProjectDir = file("${project.projectDir}/ui")
}

tasks.register('buildFrontend', PnpmTask) {
    args = ['build']
    dependsOn('installDepsForUI')
}

tasks.register('installDepsForUI', PnpmTask) {
    args = ['install']
}

build {
    // build frontend before build
    tasks.named('compileJava').configure {
        dependsOn('buildFrontend')
    }
}

halo {
    version = '2.20'
}
