config.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. var tty = require('tty');
  2. var object = require('mout').object;
  3. var bowerConfig = require('bower-config');
  4. var cli = require('./util/cli');
  5. var cachedConfigs = {};
  6. function defaultConfig(config) {
  7. config = config || {};
  8. var cachedConfig = readCachedConfig(config.cwd || process.cwd());
  9. return object.merge(cachedConfig, config);
  10. }
  11. function readCachedConfig(cwd) {
  12. if (cachedConfigs[cwd]) {
  13. return cachedConfigs[cwd];
  14. }
  15. var config = cachedConfigs[cwd] = bowerConfig.read(cwd);
  16. // Delete the json attribute because it is no longer supported
  17. // and conflicts with --json
  18. delete config.json;
  19. // If interactive is auto (null), guess its value
  20. if (config.interactive == null) {
  21. config.interactive = (
  22. process.bin === 'bower' &&
  23. tty.isatty(1) &&
  24. !process.env.CI
  25. );
  26. }
  27. // Merge common CLI options into the config
  28. object.mixIn(config, cli.readOptions({
  29. force: { type: Boolean, shorthand: 'f' },
  30. offline: { type: Boolean, shorthand: 'o' },
  31. verbose: { type: Boolean, shorthand: 'V' },
  32. quiet: { type: Boolean, shorthand: 'q' },
  33. loglevel: { type: String, shorthand: 'l' },
  34. json: { type: Boolean, shorthand: 'j' },
  35. silent: { type: Boolean, shorthand: 's' }
  36. }));
  37. return config;
  38. }
  39. function resetCache () {
  40. cachedConfigs = {};
  41. }
  42. module.exports = defaultConfig;
  43. module.exports.reset = resetCache;