Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b72d4d6

Browse files
move plugins' specific data into separate dirs.
* now leetcode/lintcode have different cache Signed-off-by: Eric Wang <skygragon@gmail.com>
1 parent 318983c commit b72d4d6

File tree

5 files changed

+32
-21
lines changed

5 files changed

+32
-21
lines changed

‎lib/cli.js‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,23 @@ function initLogLevel() {
5252
log.setLevel(level);
5353
}
5454

55+
function initPlugins(cb) {
56+
if (Plugin.init()) {
57+
Plugin.save();
58+
return cb();
59+
} else {
60+
Plugin.installMissings(function(e) {
61+
if (e) return cb(e);
62+
Plugin.init();
63+
return cb();
64+
});
65+
}
66+
}
67+
5568
var cli = {};
5669

5770
function runCommand() {
71+
//console.log(Plugin.getType())
5872
var yargs = require('yargs');
5973
h.width = yargs.terminalWidth();
6074
yargs.commandDir('commands')
@@ -73,22 +87,15 @@ cli.run = function() {
7387
});
7488

7589
config.init();
76-
cache.init();
7790

7891
initColor();
7992
initIcon();
8093
initLogLevel();
81-
82-
if (Plugin.init()){
83-
Plugin.save();
94+
initPlugins(function(e){
95+
if (e)returnlog.error(e);
96+
cache.init();
8497
runCommand();
85-
} else {
86-
Plugin.installMissings(function(e) {
87-
if (e) return log.error(e);
88-
Plugin.init();
89-
runCommand();
90-
});
91-
}
98+
});
9299
};
93100

94101
module.exports = cli;

‎lib/helper.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const h = {};
5353
h.KEYS = {
5454
user: '../user',
5555
stat: '../stat',
56-
plugins: '../plugins',
56+
plugins: '../../plugins',
5757
problems: 'problems',
5858
problem: p => p.fid + '.' + p.slug + '.' + p.category
5959
};
@@ -186,8 +186,13 @@ h.getHomeDir = function() {
186186
return path.join(this.getUserHomeDir(), '.lc');
187187
};
188188

189+
h.getAppDir = function() {
190+
const config = require('./config');
191+
return path.join(this.getHomeDir(), config.app || 'leetcode');
192+
};
193+
189194
h.getCacheDir = function() {
190-
return path.join(this.getHomeDir(), 'cache');
195+
return path.join(this.getAppDir(), 'cache');
191196
};
192197

193198
h.getCodeDir = function(dir) {

‎lib/plugins/cache.js‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ var session = require('../session');
99

1010
const plugin = new Plugin(50, 'cache', '', 'Plugin to provide local cache.');
1111

12-
plugin.init = function() {
13-
Plugin.prototype.init.call(this);
14-
cache.init();
15-
};
16-
1712
plugin.getProblems = function(cb) {
1813
const problems = cache.get(h.KEYS.problems);
1914
if (problems) {

‎lib/plugins/leetcode.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ function checkError(e, resp, expectedStatus) {
5050
return e;
5151
}
5252

53+
plugin.init = function() {
54+
config.app = 'leetcode';
55+
}
56+
5357
plugin.getProblems = function(cb) {
5458
log.debug('running leetcode.getProblems');
5559
let problems = [];

‎test/test_helper.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,10 @@ describe('helper', function() {
188188

189189
assert.equal(h.getUserHomeDir(), '/home/skygragon');
190190
assert.equal(h.getHomeDir(), '/home/skygragon/.lc');
191-
assert.equal(h.getCacheDir(), '/home/skygragon/.lc/cache');
192-
assert.equal(h.getCacheFile('xxx'), '/home/skygragon/.lc/cache/xxx.json');
191+
assert.equal(h.getCacheDir(), '/home/skygragon/.lc/leetcode/cache');
192+
assert.equal(h.getCacheFile('xxx'), '/home/skygragon/.lc/leetcode/cache/xxx.json');
193193
assert.equal(h.getConfigFile(), '/home/skygragon/.lc/config.json');
194-
assert.equal(h.getFilename('/home/skygragon/.lc/cache/xxx.json'), 'xxx');
194+
assert.equal(h.getFilename('/home/skygragon/.lc/leetcode/cache/xxx.json'), 'xxx');
195195

196196
process.env.HOME = '';
197197
process.env.USERPROFILE = 'C:\\Users\\skygragon';

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /