Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2012-03-13 02:33:06 +0400
committerisaacs <i@izs.me>2012-03-13 02:33:06 +0400
commit3ec0a8dc9148e376862dd60e92c2f8ad65d19f41 (patch)
tree5ff190dc0c8f70c639791c90b5e1fc9d2bd5f00e
parentdbae7f2ad92a4427d7289c0227c74b0e74f9164e (diff)
Rewrite gyp files to 'binding.gyp'
-rw-r--r--lib/utils/read-json.js38
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
}
}