buildscript {
    repositories {
        maven { url 'http://maven.parim.net/nexus/content/groups/public/' }
        mavenCentral()
        jcenter()
    }

    dependencies {
        classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.3'
    }
}

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'org.asciidoctor.convert'

description "Parim Spark Console Web Application."
group = 'net.parim'
archivesBaseName = 'console-web'
version = '0.1.1-SNAPSHOT'

repositories {
    maven { url 'http://maven.parim.net/nexus/content/groups/public/' }
    mavenCentral()
    jcenter()
}

asciidoctor {
    sourceDir = file('src/adoc')
    sources {
        include 'index.adoc'//, 'another.adoc', 'third.adoc'
    }
    outputDir = file('build/docs')

    attributes  'toclevels': '3',
                'sectnums': ''
}


task ngBuild(type: Exec, description: 'Build Application.') {
   commandLine 'npm', 'run', 'build:jar'
}

task webjar(type: Jar, dependsOn: "jar") {
    dependsOn = ['ngBuild'] 
    from(fileTree(dir: "dist", include: "index.html")) {  
        into "META-INF/resources/console"
    }

    from(fileTree(dir: "dist", exclude: "index.html")) {  
        into "META-INF/resources/console/static"
    }
}

uploadArchives {
    dependsOn = ["webjar"]

    repositories {
        mavenDeployer {
        	snapshotRepository(url: "http://maven.parim.net/nexus/content/repositories/snapshots/") {
		        authentication(userName: 'admin', password: 'admin123')
		      }
            repository(url: "http://maven.parim.net/nexus/content/repositories/releases/") {
            	authentication(userName: 'admin', password: 'admin123')
            }
        }
    }
}

// gradle webjar uploadArchives

task publish() {
    dependsOn = ["uploadArchives"]
}

task docsZip(type: Zip, dependsOn: 'asciidoctor') {
    group = "Distribution"
    baseName = "console-web"
    classifier = "docs"
    description = "Builds -${classifier} archive containing api and reference " +
        "for deployment at docs website."

    from ("build/docs") {
        into "reference"
    }
}