Skip to content

Instantly share code, notes, and snippets.

@frhd
Forked from spikeheap/build.gradle
Created April 20, 2016 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frhd/c82a12f1131ec019af96c7b028b0097f to your computer and use it in GitHub Desktop.
Save frhd/c82a12f1131ec019af96c7b028b0097f to your computer and use it in GitHub Desktop.
Gradle build script to install NodeJS packages and Bower dependencies. This assumes you create package.json (nodejs) and bower.json files in the root of your project.
import org.gradle.api.tasks.Exec
defaultTasks 'bower'
// Get the path for the locally installed binaries
task npmBin << {
new ByteArrayOutputStream().withStream { os ->
def result = exec {
executable = 'npm'
args = ['bin']
standardOutput = os
}
ext.binPath = os.toString().trim() + "/"
}
}
// Install packages from package.json
task npm(type: Exec) {
description = "Grab NodeJS dependencies (from package.json)"
commandLine = ["npm", "install"]
inputs.file "package.json"
outputs.dir "node_modules"
tasks.npmBin.execute()
}
// Install the bower components for front-end library management
task bower(dependsOn: 'npm', type: Exec){
commandLine "${npmBin.binPath}bower", 'install'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment