srs / gradle-node-plugin

Gradle plugin for integrating NodeJS in your build. :rocket:
Apache License 2.0
867 stars 210 forks source link

How to install and build additional dependency? #373

Open falk-stefan opened 3 years ago

falk-stefan commented 3 years ago

I am generating a TypeScript API-client via the task :server.generateClient in my web-app build.gradle.

In order to compile the web-app, I need to build and compile the API-client as well which will be located at $rootDir/generated/meditation-rest-client.

My problem is that I don't know how I can run these two commands

npm --prefix generated/meditation-rest-client/ run build --aot --prod
npm --prefix generated/meditation-rest-client/dist install

at the and of the makeClients task and then the following for building the web-app:

npm run ng -- build --configuration=development --base-href / --output-path build/ --deploy-url / --prod

How can I run the above commands in my gradle script?

npm_run_build {
  inputs.files fileTree('src')
  inputs.file 'package.json'
  inputs.file 'package-lock.json'
  outputs.dir 'build'
}

task makeClients {
  doFirst {
    def clientDir = tasks.getByPath(':server:generateClient').apiClientDir()
    copy {
      from clientDir
      into 'generated/meditation-rest-client' 
    }
  }
  doLast {
    // TODO
    // npm --prefix generated/meditation-rest-client/ run build --aot --prod
    // npm --prefix generated/meditation-rest-client/dist install
  }
  dependsOn ':server:generateClient'
}

task buildWebApp {
  dependsOn tasks.makeClients, npm_run_build
}

assemble.dependsOn buildWebApp
deepy commented 3 years ago

You could create a NpmTask and have your makeClients be finalizedBy that