2011-11-22 01:48:45 +08:00
|
|
|
|
|
|
|
module.exports = link
|
|
|
|
link.ifExists = linkIfExists
|
|
|
|
|
|
|
|
var fs = require("graceful-fs")
|
|
|
|
, chain = require("slide").chain
|
2012-05-06 13:33:06 +08:00
|
|
|
, mkdir = require("mkdirp")
|
|
|
|
, rm = require("./gently-rm.js")
|
2011-11-22 01:48:45 +08:00
|
|
|
, path = require("path")
|
|
|
|
, npm = require("../npm.js")
|
|
|
|
|
|
|
|
function linkIfExists (from, to, gently, cb) {
|
|
|
|
fs.stat(from, function (er) {
|
|
|
|
if (er) return cb()
|
|
|
|
link(from, to, gently, cb)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function link (from, to, gently, cb) {
|
|
|
|
if (typeof cb !== "function") cb = gently, gently = null
|
|
|
|
if (npm.config.get("force")) gently = false
|
2012-06-11 12:29:47 +08:00
|
|
|
|
2011-11-22 01:48:45 +08:00
|
|
|
chain
|
|
|
|
( [ [fs, "stat", from]
|
2012-05-06 13:33:06 +08:00
|
|
|
, [rm, to, gently]
|
2011-11-22 01:48:45 +08:00
|
|
|
, [mkdir, path.dirname(to)]
|
2012-06-16 01:00:30 +08:00
|
|
|
, [fs, "symlink", from, to, "junction"] ]
|
2011-11-22 01:48:45 +08:00
|
|
|
, cb)
|
|
|
|
}
|