mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
772 B
30 lines
772 B
|
|
module.exports = link
|
|
link.ifExists = linkIfExists
|
|
|
|
var fs = require("graceful-fs")
|
|
, chain = require("slide").chain
|
|
, mkdir = require("./mkdir-p.js")
|
|
, rm = require("rimraf")
|
|
, log = require("./log.js")
|
|
, path = require("path")
|
|
, relativize = require("./relativize.js")
|
|
, 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
|
|
chain
|
|
( [ [fs, "stat", from]
|
|
, [rm, to, { gently: gently }]
|
|
, [mkdir, path.dirname(to)]
|
|
, [fs, "symlink", relativize(from, to), to] ]
|
|
, cb)
|
|
}
|
|
|