Blame view

node_modules/bower/lib/commands/prune.js 1.34 KB
2dda2e10   Administrator   generator ignore
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
47
48
49
50
51
52
53
54
55
  var mout = require('mout');
  var Project = require('../core/Project');
  var defaultConfig = require('../config');
  
  function prune(logger, options, config) {
      var project;
  
      options = options || {};
      config = defaultConfig(config);
      project = new Project(config, logger);
  
      return clean(project, options);
  }
  
  function clean(project, options, removed) {
      removed = removed || {};
  
      // Continually call clean until there is no more extraneous
      // dependencies to remove
      return project.getTree(options)
      .spread(function (tree, flattened, extraneous) {
          var names = extraneous.map(function (extra) {
              return extra.endpoint.name;
          });
  
          // Uninstall extraneous
          return project.uninstall(names, options)
          .then(function (uninstalled) {
              // Are we done?
              if (!mout.object.size(uninstalled)) {
                  return removed;
              }
  
              // Not yet, recurse!
              mout.object.mixIn(removed, uninstalled);
              return clean(project, options, removed);
          });
      });
  }
  
  // -------------------
  
  prune.readOptions = function (argv) {
      var cli = require('../util/cli');
  
      var options = cli.readOptions({
          'production': { type: Boolean, shorthand: 'p' },
      }, argv);
  
      delete options.argv;
  
      return [options];
  };
  
  module.exports = prune;