]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/lib/utils/completion/installed-shallow.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / lib / utils / completion / installed-shallow.js
1
2 module.exports = installedShallow
3
4 var npm = require("../../npm.js")
5   , fs = require("graceful-fs")
6   , path = require("path")
7   , readJson = require("read-package-json")
8   , asyncMap = require("slide").asyncMap
9
10 function installedShallow (opts, filter, cb) {
11   if (typeof cb !== "function") cb = filter, filter = null
12   var conf = opts.conf
13     , args = conf.argv.remain
14   if (args.length > 3) return cb()
15   var local
16     , global
17     , localDir = npm.dir
18     , globalDir = npm.globalDir
19   if (npm.config.get("global")) local = [], next()
20   else fs.readdir(localDir, function (er, pkgs) {
21     local = (pkgs || []).filter(function (p) {
22       return p.charAt(0) !== "."
23     })
24     next()
25   })
26   fs.readdir(globalDir, function (er, pkgs) {
27     global = (pkgs || []).filter(function (p) {
28       return p.charAt(0) !== "."
29     })
30     next()
31   })
32   function next () {
33     if (!local || !global) return
34     filterInstalled(local, global, filter, cb)
35   }
36 }
37
38 function filterInstalled (local, global, filter, cb) {
39   var fl
40     , fg
41
42   if (!filter) {
43     fl = local
44     fg = global
45     return next()
46   }
47
48   asyncMap(local, function (p, cb) {
49     readJson(path.join(npm.dir, p, "package.json"), function (er, d) {
50       if (!d || !filter(d)) return cb(null, [])
51       return cb(null, d.name)
52     })
53   }, function (er, local) {
54     fl = local || []
55     next()
56   })
57
58   var globalDir = npm.globalDir
59   asyncMap(global, function (p, cb) {
60     readJson(path.join(globalDir, p, "package.json"), function (er, d) {
61       if (!d || !filter(d)) return cb(null, [])
62       return cb(null, d.name)
63     })
64   }, function (er, global) {
65     fg = global || []
66     next()
67   })
68
69   function next () {
70     if (!fg || !fl) return
71     if (!npm.config.get("global")) {
72       fg = fg.map(function (g) {
73         return [g, "-g"]
74       })
75     }
76     console.error("filtered", fl, fg)
77     return cb(null, fl.concat(fg))
78   }
79 }