UNPKG

1.66 kBJavaScriptView Raw
1var tty = require('tty');
2var object = require('mout').object;
3var bowerConfig = require('bower-config');
4var Configstore = require('configstore');
5
6var current;
7
8function defaultConfig(config) {
9 config = config || {};
10
11 return readCachedConfig(config.cwd || process.cwd(), config);
12}
13
14function readCachedConfig(cwd, overwrites) {
15 current = bowerConfig.create(cwd).load(overwrites);
16
17 var config = current.toObject();
18
19 var configstore = new Configstore('bower-github').all;
20
21 object.mixIn(config, configstore);
22
23 // If interactive is auto (null), guess its value
24 if (config.interactive == null) {
25 config.interactive =
26 process.bin === 'bower' && tty.isatty(1) && !process.env.CI;
27 }
28
29 // Merge common CLI options into the config
30 if (process.bin === 'bower') {
31 var cli = require('./util/cli');
32
33 object.mixIn(
34 config,
35 cli.readOptions({
36 force: { type: Boolean, shorthand: 'f' },
37 offline: { type: Boolean, shorthand: 'o' },
38 verbose: { type: Boolean, shorthand: 'V' },
39 quiet: { type: Boolean, shorthand: 'q' },
40 loglevel: { type: String, shorthand: 'l' },
41 json: { type: Boolean, shorthand: 'j' },
42 silent: { type: Boolean, shorthand: 's' }
43 })
44 );
45 }
46
47 return config;
48}
49
50function restoreConfig() {
51 if (current) {
52 current.restore();
53 }
54}
55
56function resetCache() {
57 restoreConfig();
58 current = undefined;
59}
60
61module.exports = defaultConfig;
62module.exports.restore = restoreConfig;
63module.exports.reset = resetCache;