I am trying to create a web application that uses angular2. The part of the build.gradle responsible for compiling the typescript and adding it to the war is as follows:
public class TsCompileTask extends DefaultTask {
File projectDir;
@OutputDirectory
File outputDir;
@TaskAction
void compile() {
println "compiling TypeScript files..."
project.exec {
executable = "tsc"
args "-p"
args projectDir
args "--outDir"
args outputDir.toString()
}
}
}
public class npmInstallTask extends DefaultTask {
File projectDir
@TaskAction
void compile(){
println "installing npm packages"
project.exec {
workingDir = projectDir.path
executable = "npm"
args "install"
}
}
}
task tsCompile(type:TsCompileTask) {
projectDir = file('./src/main/typescript')
outputDir = file("$buildDir/ts")
}
war{
into("js"){
from tsCompile.outputs
}
}
This adds the output of the typescript compiler to the js directory in the war archive, but it does not add the dependencies, which are in the directory node_modules.
I tried to use the following gradle snippet to add only the JavaScript files from the typescript directoryinto thw war:
war{
into("js"){
from fileTree(dir: './src/main/typescrypt/').matching{
include('**/*.js)
}.files
}
}
However, this includes all files under the directory.
I have tried several variations of the above (e.g. having the into be in a closure for from instead of the other way around, using fileTree('./src/main/typescript').include('**/*.js')
). How can I add only the files ending in .js to the js directory in the war file?