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

deactivate.js « lib - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f8b25c2d8e67e6b4285654a946de954595346765 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

var mkdir = require("./utils/mkdir-p")
  , npm = require("../npm")
  , fs = require("fs")
  , log = require("./utils/log")
  , path = require("path")
  , rm = require("./utils/rm-rf")
  , chain = require("./utils/chain")
  , lifecycle = require("./utils/lifecycle")
  , readJson = require("./utils/read-json")

module.exports = deactivate

function deactivate (args, cb) {
  // run the "deactivate" lifecycle event
  // unlink the "active" folder
  // unlink the libs and main.js from the npm.root
  // run the "postdeactivate" lifecycle event
  var pkg = args.shift()
    , active = path.join(npm.dir, pkg, "active")
    , jsonFile = path.join(active, "/package/package.json")
    , activeMain = path.join(npm.root, pkg+".js")
    , activeLib = path.join(npm.root, pkg)
    , pkgData = null

  readJson(jsonFile, function (er, data) {
    if (er) return cb(er)
    npm.set(data)
    chain
      ( [lifecycle, data, "predeactivate"]
      , [lifecycle, data, "deactivate"]
      , [rm, active]
      , function (cb) { rm(activeMain, function () { cb() }) }
      , function (cb) { rm(activeLib, function () { cb() }) }
      , function (cb) {
          if (!data.bin) return cb()
          chain(Object.getOwnPropertyNames(data.bin)
            .map(function (bin) {
              return [rm, path.join(process.installPrefix, "bin", bin)]
            }).concat(cb))
        }
      , [lifecycle, data, "postdeactivate"]
      , cb
      )
  })
}