Blame view

node_modules/bower/lib/config.js 1.59 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
56
57
58
59
60
61
62
63
  var tty = require('tty');
  var object = require('mout').object;
  var bowerConfig = require('bower-config');
  var Configstore = require('configstore');
  
  var current;
  
  function defaultConfig(config) {
      config = config || {};
  
      return readCachedConfig(config.cwd || process.cwd(), config);
  }
  
  function readCachedConfig(cwd, overwrites) {
      current = bowerConfig.create(cwd).load(overwrites);
  
      var config = current.toObject();
  
      var configstore = new Configstore('bower-github').all;
  
      object.mixIn(config, configstore);
  
      // If interactive is auto (null), guess its value
      if (config.interactive == null) {
          config.interactive = (
              process.bin === 'bower' &&
              tty.isatty(1) &&
              !process.env.CI
          );
      }
  
      // Merge common CLI options into the config
      if (process.bin === 'bower') {
          var cli = require('./util/cli');
  
          object.mixIn(config, cli.readOptions({
              force: { type: Boolean, shorthand: 'f' },
              offline: { type: Boolean, shorthand: 'o' },
              verbose: { type: Boolean, shorthand: 'V' },
              quiet: { type: Boolean, shorthand: 'q' },
              loglevel: { type: String, shorthand: 'l' },
              json: { type: Boolean, shorthand: 'j' },
              silent: { type: Boolean, shorthand: 's' }
          }));
      }
  
      return config;
  }
  
  function restoreConfig() {
      if (current) {
          current.restore();
      }
  }
  
  function resetCache() {
      restoreConfig();
      current = undefined;
  }
  
  module.exports = defaultConfig;
  module.exports.restore = restoreConfig;
  module.exports.reset = resetCache;