1 | var tty = require('tty');
|
2 | var object = require('mout').object;
|
3 | var bowerConfig = require('bower-config');
|
4 | var Configstore = require('configstore');
|
5 |
|
6 | var current;
|
7 |
|
8 | function defaultConfig(config) {
|
9 | config = config || {};
|
10 |
|
11 | return readCachedConfig(config.cwd || process.cwd(), config);
|
12 | }
|
13 |
|
14 | function 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 |
|
24 | if (config.interactive == null) {
|
25 | config.interactive =
|
26 | process.bin === 'bower' && tty.isatty(1) && !process.env.CI;
|
27 | }
|
28 |
|
29 |
|
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 |
|
50 | function restoreConfig() {
|
51 | if (current) {
|
52 | current.restore();
|
53 | }
|
54 | }
|
55 |
|
56 | function resetCache() {
|
57 | restoreConfig();
|
58 | current = undefined;
|
59 | }
|
60 |
|
61 | module.exports = defaultConfig;
|
62 | module.exports.restore = restoreConfig;
|
63 | module.exports.reset = resetCache;
|