|
1 | 1 | var _ = require('underscore');
|
| 2 | +var nconf = require('nconf'); |
2 | 3 |
|
3 | 4 | var h = require('./helper');
|
4 | 5 |
|
5 | | -// usually you don't wanna change those |
6 | | -var DEFAULT_SYS_CONFIG = { |
7 | | - URL_BASE: 'https://leetcode.com', |
8 | | - URL_LOGIN: 'https://leetcode.com/accounts/login/', |
9 | | - URL_PROBLEMS: 'https://leetcode.com/api/problems/$category/', |
10 | | - URL_PROBLEM: 'https://leetcode.com/problems/$slug/description/', |
11 | | - URL_PROBLEM_DETAIL: 'https://leetcode.com/graphql', |
12 | | - URL_TEST: 'https://leetcode.com/problems/$slug/interpret_solution/', |
13 | | - URL_SUBMIT: 'https://leetcode.com/problems/$slug/submit/', |
14 | | - URL_SUBMISSIONS: 'https://leetcode.com/api/submissions/$slug', |
15 | | - URL_SUBMISSION: 'https://leetcode.com/submissions/detail/$id/', |
16 | | - URL_VERIFY: 'https://leetcode.com/submissions/detail/$id/check/', |
17 | | - URL_FAVORITES: 'https://leetcode.com/list/api/questions', |
18 | | - URL_FAVORITE_DELETE: 'https://leetcode.com/list/api/questions/$hash/$id', |
| 6 | +var DEFAULT_CONFIG = { |
| 7 | + // usually you don't wanna change those |
| 8 | + sys: { |
| 9 | + categories: [ |
| 10 | + 'algorithms', |
| 11 | + 'database', |
| 12 | + 'shell' |
| 13 | + ], |
| 14 | + langs: [ |
| 15 | + 'bash', |
| 16 | + 'c', |
| 17 | + 'cpp', |
| 18 | + 'csharp', |
| 19 | + 'golang', |
| 20 | + 'java', |
| 21 | + 'javascript', |
| 22 | + 'kotlin', |
| 23 | + 'mysql', |
| 24 | + 'python', |
| 25 | + 'python3', |
| 26 | + 'ruby', |
| 27 | + 'scala', |
| 28 | + 'swift' |
| 29 | + ], |
| 30 | + urls: { |
| 31 | + base: 'https://leetcode.com', |
| 32 | + login: 'https://leetcode.com/accounts/login/', |
| 33 | + problems: 'https://leetcode.com/api/problems/$category/', |
| 34 | + problem: 'https://leetcode.com/problems/$slug/description/', |
| 35 | + problem_detail: 'https://leetcode.com/graphql', |
| 36 | + test: 'https://leetcode.com/problems/$slug/interpret_solution/', |
| 37 | + submit: 'https://leetcode.com/problems/$slug/submit/', |
| 38 | + submissions: 'https://leetcode.com/api/submissions/$slug', |
| 39 | + submission: 'https://leetcode.com/submissions/detail/$id/', |
| 40 | + verify: 'https://leetcode.com/submissions/detail/$id/check/', |
| 41 | + favorites: 'https://leetcode.com/list/api/questions', |
| 42 | + favorite_delete: 'https://leetcode.com/list/api/questions/$hash/$id', |
| 43 | + plugin: 'https://github.com/skygragon/leetcode-cli-plugins/raw/master/plugins/$name.js' |
| 44 | + } |
| 45 | + }, |
19 | 46 |
|
20 | | - LANGS: [ |
21 | | - 'bash', |
22 | | - 'c', |
23 | | - 'cpp', |
24 | | - 'csharp', |
25 | | - 'golang', |
26 | | - 'java', |
27 | | - 'javascript', |
28 | | - 'kotlin', |
29 | | - 'mysql', |
30 | | - 'python', |
31 | | - 'python3', |
32 | | - 'ruby', |
33 | | - 'scala', |
34 | | - 'swift' |
35 | | - ], |
36 | | - |
37 | | - CATEGORIES: [ |
38 | | - 'algorithms', |
39 | | - 'database', |
40 | | - 'shell' |
41 | | - ], |
42 | | - |
43 | | - PLUGINS: {} |
44 | | -}; |
45 | | - |
46 | | -// but you will want change these |
47 | | -var DEFAULT_USER_CONFIG = { |
48 | | - AUTO_LOGIN: false, |
49 | | - COLOR_THEME: 'default', |
50 | | - EDITOR: 'vim', |
51 | | - ICON_THEME: '', |
52 | | - LANG: 'cpp', |
53 | | - MAX_WORKERS: 10, |
54 | | - USE_COLOR: true |
| 47 | + // but you will want change these |
| 48 | + autologin: { |
| 49 | + enable: false |
| 50 | + }, |
| 51 | + code: { |
| 52 | + editor: 'vim', |
| 53 | + lang: 'cpp' |
| 54 | + }, |
| 55 | + color: { |
| 56 | + enable: true, |
| 57 | + theme: 'default' |
| 58 | + }, |
| 59 | + icon: { |
| 60 | + theme: '' |
| 61 | + }, |
| 62 | + network: { |
| 63 | + concurrency: 10 |
| 64 | + }, |
| 65 | + plugins: {} |
55 | 66 | };
|
56 | 67 |
|
57 | 68 | function Config() {}
|
58 | 69 |
|
59 | 70 | Config.prototype.init = function() {
|
60 | | - // check local config: ~/.lcconfig |
61 | | - var localConfig = JSON.parse(h.getFileData(h.getConfigFile())) || {}; |
62 | | - _.extendOwn(this, this.getDefaultConfig()); |
63 | | - _.extendOwn(this, localConfig); |
64 | | -}; |
| 71 | + nconf.file(h.getConfigFile()) |
| 72 | + .defaults(DEFAULT_CONFIG); |
65 | 73 |
|
66 | | -Config.prototype.getDefaultConfig = function() { |
67 | | - var cfg = {}; |
68 | | - _.extendOwn(cfg, DEFAULT_SYS_CONFIG); |
69 | | - _.extendOwn(cfg, DEFAULT_USER_CONFIG); |
70 | | - return cfg; |
| 74 | + var cfg = nconf.get(); |
| 75 | + // HACK: remove old style configs |
| 76 | + for (var x in cfg) { |
| 77 | + if (x === x.toUpperCase()) delete cfg[x]; |
| 78 | + } |
| 79 | + delete DEFAULT_CONFIG.type; |
| 80 | + delete cfg.type; |
| 81 | + |
| 82 | + _.extendOwn(this, cfg); |
71 | 83 | };
|
72 | 84 |
|
73 | | -Config.prototype.getUserConfig = function() { |
74 | | - return_.pick(this,function(v,k){ |
75 | | - returnkinDEFAULT_USER_CONFIG; |
76 | | - }); |
| 85 | +Config.prototype.getAll = function(useronly) { |
| 86 | + varcfg=_.extendOwn({},this); |
| 87 | + if(useronly)deletecfg.sys; |
| 88 | + returncfg; |
77 | 89 | };
|
78 | 90 |
|
79 | 91 | module.exports = new Config();
|
0 commit comments