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-07 00:12:15 +0400
committerisaacs <i@izs.me>2011-04-07 01:08:38 +0400
commit6cd7a13eae02116a7adcbb1969643523dd5704a8 (patch)
treea2a1f606dffd3aad11df4ed21b769fd4d432b5e2
parent0de96e6603ffdb4377cd1e4a1f8408275ab90d1c (diff)
Closes GH-752 Add pre/post publish script support
-rw-r--r--doc/scripts.md6
-rw-r--r--lib/publish.js59
2 files changed, 41 insertions, 24 deletions
diff --git a/doc/scripts.md b/doc/scripts.md
index 0be621173..681e95656 100644
--- a/doc/scripts.md
+++ b/doc/scripts.md
@@ -18,8 +18,10 @@ following scripts:
Run BEFORE the package is updated with the update command.
* update, postupdate:
Run AFTER the package is updated with the update command.
-* (pre,post,)updatedependency-foo:
- Run (before,after) the "foo" dependency is modified.
+* prepublish:
+ Run BEFORE the package is published.
+* publish, postpublish:
+ Run AFTER the package is published.
* pretest, test, posttest:
Run by the `npm test` command.
* prestop, stop, poststop:
diff --git a/lib/publish.js b/lib/publish.js
index 3fab6f35d..e695de277 100644
--- a/lib/publish.js
+++ b/lib/publish.js
@@ -9,6 +9,8 @@ var npm = require("../npm")
, path = require("path")
, readJson = require("./utils/read-json")
, fs = require("fs")
+ , lifecycle = require("./utils/lifecycle")
+ , chain = require("./utils/chain")
publish.usage = "npm publish <tarball>"
+ "\nnpm publish <folder>"
@@ -28,34 +30,47 @@ function publish (args, isRetry, cb) {
npm.commands.cache.add(args[0], args[1], true, function (er, data) {
if (er) return cb(er)
log.silly(data, "publish")
+ var cachedir = path.resolve( npm.cache
+ , data.name
+ , data.version
+ , "package" )
+ chain
+ ( [lifecycle, data, "prepublish", cachedir]
+ , [publish_, args, data, isRetry]
+ , [lifecycle, data, "publish", cachedir]
+ , [lifecycle, data, "postpublish", cachedir]
+ , cb )
+ })
+}
- // check for publishConfig hash
- if (data.publishConfig) {
- Object.keys(data.publishConfig).forEach(function (k) {
- log.info(k + "=" + data.publishConfig[k], "publishConfig")
- npm.config.set(k, data.publishConfig[k])
- })
- }
+function publish_ (args, data, isRetry, cb) {
+ // check for publishConfig hash
+ if (data.publishConfig) {
+ Object.keys(data.publishConfig).forEach(function (k) {
+ log.info(k + "=" + data.publishConfig[k], "publishConfig")
+ npm.config.set(k, data.publishConfig[k])
+ })
+ }
- if (!data) return cb(new Error("no package.json file found"))
- delete data.modules
- if (data.private) return cb(new Error
- ("This package has been marked as private\n"
- +"Remove the 'private' field from the package.json to publish it."))
+ if (!data) return cb(new Error("no package.json file found"))
+ delete data.modules
+ if (data.private) return cb(new Error
+ ("This package has been marked as private\n"
+ +"Remove the 'private' field from the package.json to publish it."))
- // pre-build
- var bd = data.scripts
- && ( data.scripts.preinstall
- || data.scripts.install
- || data.scripts.postinstall )
- && npm.config.get("bindist")
- preBuild(data, bd, function (er, tb) {
- if (er) return cb(er)
- return regPublish(data, tb, isRetry, args, cb)
- })
+ // pre-build
+ var bd = data.scripts
+ && ( data.scripts.preinstall
+ || data.scripts.install
+ || data.scripts.postinstall )
+ && npm.config.get("bindist")
+ preBuild(data, bd, function (er, tb) {
+ if (er) return cb(er)
+ return regPublish(data, tb, isRetry, args, cb)
})
}
+
function preBuild (data, bd, cb) {
if (!bd) return cb()
// unpack to cache/n/v/build