Skip to content

Commit 188f584

Browse files
committed
Add local config file: ~/.lcconfig
Signed-off-by: Eric Wang <[email protected]>
1 parent 2bb86f2 commit 188f584

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

lib/cache.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
var fs = require('fs');
22

3+
var h = require('./helper');
4+
35
// try to save cache in user home.
4-
var BASE_DIR = (process.env.HOME || process.env.USERPROFILE) + '/.lc/';
6+
var BASE_DIR = h.getHomeDir() + '/.lc/';
57

68
function getFullPath(k) {
79
if (!fs.existsSync(BASE_DIR))

lib/config.js

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
module.exports = {
1+
var _ = require('underscore');
2+
var fs = require('fs');
3+
4+
var h = require('./helper');
5+
6+
var defaultConfig = {
27
// usually you don't wanna change those
38
BASE_URL: 'https://leetcode.com',
49
LOGIN_URL: 'https://leetcode.com/accounts/login/',
@@ -9,5 +14,20 @@ module.exports = {
914

1015
// but you will want change these
1116
LANG: 'cpp', // avail: [c,cpp,csharp,golang,java,javascript,python,ruby,swift]
12-
USE_COLOR: false
17+
USE_COLOR: true
1318
};
19+
20+
function initConfig() {
21+
var config = defaultConfig;
22+
23+
// check local config: ~/.lcconfig
24+
var f = h.getHomeDir() + '/.lcconfig';
25+
if (fs.existsSync(f)) {
26+
var localConfig = JSON.parse(fs.readFileSync(f));
27+
_.extend(defaultConfig, localConfig);
28+
}
29+
30+
return config;
31+
}
32+
33+
module.exports = initConfig();

lib/helper.js

+4
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ h.getFilename = function(fullpath) {
7070
return path.basename(fullpath, path.extname(fullpath));
7171
};
7272

73+
h.getHomeDir = function() {
74+
return process.env.HOME || process.env.USERPROFILE;
75+
};
76+
7377
h.readStdin = function() {
7478
// FIXME: not work for win32
7579
return fs.readFileSync('/dev/stdin').toString();

0 commit comments

Comments
 (0)