Permalink
Browse files

Automatically node-gyp build stuff with a bindings.gyp

  • Loading branch information...
1 parent c4eb2fd commit 66db8b243991b71bd1ee2f12d049595deaa8bfea @isaacs isaacs committed Mar 7, 2012
Showing with 25 additions and 3 deletions.
  1. +25 −3 lib/utils/read-json.js
View
@@ -34,6 +34,18 @@ function readJson (jsonFile, opts, cb) {
var wscript = null
, contributors = null
, serverjs = null
+ , gypfile = null
+
+ if (options.gypfile !== null && opts.gypfile !== undefined) {
+ gypfile = opts.gypfile
+ next()
+ } else {
+ fs.readFile( path.join(path.dirname(jsonFile), "bindings.gyp")
+ , function (er, data) {
+ opts.gypfile = !er
+ next()
+ })
+ }
if (opts.wscript !== null && opts.wscript !== undefined) {
wscript = opts.wscript
@@ -76,9 +88,10 @@ function readJson (jsonFile, opts, cb) {
})
function next () {
- if (wscript === null
- || contributors === null
- || serverjs === null) {
+ if (wscript === null ||
+ contributors === null ||
+ gypfile === null ||
+ serverjs === null) {
return
}
@@ -332,6 +345,15 @@ function processObject (opts, cb) { return function (er, json) {
var scripts = json.scripts || {}
+ // if it has a bindings.gyp, then build with node-gyp
+ if (opts.gypfile && !json.prebuilt) {
+ log.verbose([json.prebuilt, opts], "has bindings.gyp")
+ if (!scripts.install && !scripts.preinstall) {
+ scripts.preinstall = "node-gyp clean || (exit 0); node-gyp configure ; node-gyp build"
+ json.scripts = scripts
+ }
+ }
+
// if it has a wscript, then build it.
if (opts.wscript && !json.prebuilt) {
log.verbose([json.prebuilt, opts], "has wscript")

0 comments on commit 66db8b2

Please sign in to comment.