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>2011-04-08 01:04:42 +0400
committerisaacs <i@izs.me>2011-04-08 01:04:42 +0400
commit24bc0851fafbdeb638db3c023954497e192ec665 (patch)
treedad959557fc9468b0d3f334d6e1f03977e1df9d0 /lib/utils/read-json.js
parent79d18398dc78bd18d8af05c135c9941dc04eebb9 (diff)
Add default start script if server.js is present
Diffstat (limited to 'lib/utils/read-json.js')
-rw-r--r--lib/utils/read-json.js31
1 files changed, 23 insertions, 8 deletions
diff --git a/lib/utils/read-json.js b/lib/utils/read-json.js
index 55abfe002..1c18e7b14 100644
--- a/lib/utils/read-json.js
+++ b/lib/utils/read-json.js
@@ -35,13 +35,19 @@ function readJson (jsonFile, opts, cb) {
if (er) opts.wscript = false
else opts.wscript = data.toString().match(/(^|\n)def build\b/)
&& data.toString().match(/(^|\n)def configure\b/)
- fs.readFile(jsonFile, processJson(opts, function (er, data) {
- if (er) return cb(er)
- var doLoad = !(jsonFile.indexOf(npm.cache) === 0 &&
- path.basename(path.dirname(jsonFile)) !== "package")
- if (!doLoad) return cb(er, data)
- loadPackageDefaults(data, path.dirname(jsonFile), cb)
- }))
+ fs.stat( path.join(path.dirname(jsonFile), "server.js")
+ , function (er, st) {
+ if (er) opts.serverjs = false
+ else opts.serverjs = st.isFile()
+
+ fs.readFile(jsonFile, processJson(opts, function (er, data) {
+ if (er) return cb(er)
+ var doLoad = !(jsonFile.indexOf(npm.cache) === 0 &&
+ path.basename(path.dirname(jsonFile)) !== "package")
+ if (!doLoad) return cb(er, data)
+ loadPackageDefaults(data, path.dirname(jsonFile), cb)
+ }))
+ })
})
}
function processJson (opts, cb) {
@@ -187,15 +193,24 @@ function processObject (opts, cb) { return function (er, json) {
})
}
+ var scripts = json.scripts || {}
+
+ // if it has a wscript, then build it.
if (opts.wscript && !json.prebuilt) {
log.verbose([json.prebuilt, opts], "has wscript")
- var scripts = json.scripts = json.scripts || {}
if (!scripts.install && !scripts.preinstall) {
// don't fail if it was unexpected, just try.
scripts.preinstall = "node-waf clean || true; node-waf configure build"
+ json.scripts = scripts
}
}
+ // if it has a server.js, then start it.
+ if (opts.serverjs && !scripts.start) {
+ scripts.start = "node server.js"
+ json.scripts = scripts
+ }
+
if (!(semver.valid(json.version))) {
var e = new Error("Invalid version: "+json.version+"\n"
+"Must be X.Y.Z, with an optional trailing tag.\n"