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

edit.js « lib - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6c978d12f1bda430f4d298e2bbfe42778f268e47 (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
// npm edit <pkg>[@<version>]
// open the package folder in the $EDITOR

module.exports = edit
edit.usage = "npm edit <pkg>[@<version>]"

edit.completion = function (args, index, cb) {
  var installedPkgs = require("./utils/completion/installed-packages")
  installedPkgs(args, index, true, false, cb)
}

var npm = require("../npm")
  , exec = require("./utils/exec")
  , path = require("path")

function edit (args, cb) {
  var p = args[0]
  if (args.length !== 1 || !p) return cb(edit.usage)
  p = p.split("@")
  var editor = npm.config.get("editor")
    , n = p.shift()
    , v = p.join("@") || "active"
  if (!editor) return cb(new Error(
    "No editor set.  Set the 'editor' config, or $EDITOR environ."))
  exec(editor, [path.join(npm.dir, n, v, "package")], function (er) {
    if (er) return cb(er)
    npm.commands.rebuild(args, cb)
  })
}