
println "version: $version"

def distDir = "$buildDir/dist"
def testDir = "$buildDir/test"

task clean {
    doLast {
        delete buildDir
    }
}

task cleanNpm {
    doLast {
        delete 'node_modules'
    }
}

task _npmInstall() {
    inputs.file("package.json")
    outputs.dir("node_modules")
    doLast {
        exec {
            commandLine 'npm', 'install'
        }
    }
}

task _legacyJs(type:Copy) {
    from 'src/js/'
    into distDir
}

task _packageMeta(type: Copy) {
    inputs.property("version", version)
    from('.') {
        include 'package.json', 'readme.md', 'license', 'history.md'
    }
    into distDir
    doLast {
        exec {
            workingDir distDir
            commandLine 'npm', 'version', version
        }
    }
}

task build(dependsOn: [_npmInstall, _legacyJs, _packageMeta]) {

}

task _localInstall(dependsOn: build, type: Exec) {
    inputs.file("$distDir/package.json")
    outputs.upToDateWhen { true }

    commandLine 'npm', 'install', '--no-save', '--force', distDir
}

task pack(dependsOn: build, type: Exec) {
    workingDir = buildDir

    commandLine 'npm', 'pack'
}