def inputFiles = [
    project.file("cloudbuild.yaml"),
    project.file("package-lock.json"),
    project.file("package.json"),
    project.file("webpack.config.js"),
    project.file("tsconfig.json"),
    project.file("src")
]

task cloudBuild(type: Exec) {
    inputs.files(inputFiles)
    commandLine "gcloud", "builds", "submit", "--config", "cloudbuild.yaml", "."
}

task install(type: Exec) {
    inputs.file("package-lock.json")
    inputs.file("package.json")
    outputs.dir("node_modules")    
    outputs.cacheIf({ true }) 
    commandLine "npm", "i"
}

task clean(type: Delete) {
   delete 'dist', 'node_modules'
   followSymlinks = true
}

task build(type: Exec) {
    dependsOn clean
    dependsOn install
    inputs.files(inputFiles)
    outputs.dir("dist")
    outputs.cacheIf({ true }) 
    commandLine "$projectDir/node_modules/.bin/webpack", "--mode=production"
}

task start(type: Exec) {
    dependsOn install
    inputs.files(inputFiles)
    commandLine "$projectDir/node_modules/.bin/webpack-dev-server"
}

buildDir "dist"