diff options
Diffstat (limited to 'lib/utils/read-json.js')
-rw-r--r-- | lib/utils/read-json.js | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/lib/utils/read-json.js b/lib/utils/read-json.js index 50e8415cd..3b5b7987d 100644 --- a/lib/utils/read-json.js +++ b/lib/utils/read-json.js @@ -40,10 +40,39 @@ function readJson (jsonFile, opts, cb) { gypfile = opts.gypfile next() } else { - fs.readFile( path.join(path.dirname(jsonFile), "bindings.gyp") - , function (er, data) { - gypfile = opts.gypfile = !er + var pkgdir = path.dirname(jsonFile) + + function hasGyp (has) { + gypfile = opts.gypfile = has next() + } + + fs.readdir(pkgdir, function (er, gf) { + // this would be weird. + if (er) return hasGyp(false) + + // see if there are any *.gyp files in there. + // If there are, then copy them to binding.gyp + // if there are not, then just proceed without + gf = gf.filter(function (f) { + return f.match(/\.gyp$/) + }) + gf = gf[0] + if (!gf) return hasGyp(false) + if (gf === "binding.gyp") return hasGyp(true) + + // need to rename. windows is annoying. + // why not fs.rename? because we just saw the file, so it'll + // be cached for potentially several seconds on a network share. + return fs.readFile(path.resolve(pkgdir, gf), function (er, d) { + if (er) return hasGyp(false) + fs.writeFile(path.resolve(pkgdir, "binding.gyp"), d, function (er) { + if (er) return hasGyp(false) + fs.unlink(path.resolve(pkgdir, gf), function (er) { + return hasGyp(!er) + }) + }) + }) }) } @@ -349,8 +378,7 @@ function processObject (opts, cb) { return function (er, json) { 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)" - scripts.install = "node-gyp configure && node-gyp build" + scripts.install = "node-gyp rebuild" json.scripts = scripts } } |