Skip to content

Commit 6c48334

Browse files
author
jminz
authored
pull from remote (#2)
* move plugins' specific data into separate dirs. * now leetcode/lintcode have different cache Signed-off-by: Eric Wang <[email protected]> * Bump to 2.5.3 Signed-off-by: Eric Wang <[email protected]> * fixes skygragon#130: create home dir if necessary Signed-off-by: Eric Wang <[email protected]> * [refactor] extract into file utils Signed-off-by: Eric Wang <[email protected]> * Embed meta in comment instead of filename. refs skygragon#55 skygragon#65 Signed-off-by: Eric Wang <[email protected]> * Update dev dependecies. Signed-off-by: Eric Wang <[email protected]> * Update dependencies. Signed-off-by: Eric Wang <[email protected]> * Bump to 2.5.4 Signed-off-by: Eric Wang <[email protected]> * fixes skygragon#112: use "--" as comment in sql file Signed-off-by: Eric Wang <[email protected]> * [refactor] simplify template format. Signed-off-by: Eric Wang <[email protected]> * refs skygragon#121: support customized filename. Signed-off-by: Eric Wang <[email protected]> * [refactor] use file utils. Signed-off-by: Eric Wang <[email protected]> * fixes typo in filename. Signed-off-by: Eric Wang <[email protected]> * [pkg] add pkg config. Signed-off-by: Eric Wang <[email protected]> * [plugin] enable/disable wont touch plugins js. Signed-off-by: Eric Wang <[email protected]> * fixes plugin init order issue. Signed-off-by: Eric Wang <[email protected]> * [plugin] always enable builtin plugin by default. Signed-off-by: Eric Wang <[email protected]> * [pkg] add script for linux/macos * refs skygragon#133 Signed-off-by: Eric Wang <[email protected]> * fixes format in `list` Signed-off-by: Eric Wang <[email protected]> * fixes UT issues on windows. Signed-off-by: Eric Wang <[email protected]> * [travis] enable more platforms Signed-off-by: Eric Wang <[email protected]> * [pkg] refactor script for linux Signed-off-by: Eric Wang <[email protected]> * [pkg] add script for windows Signed-off-by: Eric Wang <[email protected]> * exit with error code if necessary Signed-off-by: Eric Wang <[email protected]> * [pkg] bail out if error occurs Signed-off-by: Eric Wang <[email protected]> * [pkg] build from travis Signed-off-by: Eric Wang <[email protected]> * Bump to 2.6.0 Signed-off-by: Eric Wang <[email protected]> * [pages] update docs. Signed-off-by: Eric Wang <[email protected]> * expose more code to plugins. * leetcode.cn/lintcode could reuse this. Signed-off-by: Eric Wang <[email protected]> * remove sprintf-js Signed-off-by: Eric Wang <[email protected]> * fixes UT bug. Signed-off-by: Eric Wang <[email protected]> * refs skygragon#134: remove whitespace on windows. Signed-off-by: Eric Wang <[email protected]> * Bump to 2.6.1 Signed-off-by: Eric Wang <[email protected]>
1 parent 013e12a commit 6c48334

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+970
-463
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
.git
2+
.github
23
.npm
34
.nyc_output
45
.DS_Store
6+
57
coverage
8+
dist
69
node_modules
710
npm-debug.log*
811
tmp
12+
913
*.log
1014
*.swp

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
"curly": 0,
1818
"key-spacing": [2, {align: "value"}],
1919
"max-len": [1, 120],
20+
"no-control-regex": 0,
2021
"no-console": 1,
2122
"no-empty": [2, { "allowEmptyCatch": true }],
2223
"no-eval": 1, // we use it on purpose

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jspm_packages
3636
# Optional REPL history
3737
.node_repl_history
3838

39+
dist/
3940
tmp/
4041
*.swp
4142
.DS_Store

.travis.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
language: node_js
22
node_js:
3-
- stable
3+
- 10
4+
5+
os:
6+
- linux
7+
- osx
8+
- windows
9+
410
install:
511
- npm install
12+
13+
script:
14+
- npm test
15+
- if [ -n "$TRAVIS_TAG" ]; then npm run travis; fi
16+
17+
deploy:
18+
provider: releases
19+
api_key:
20+
secure: "ayYe6HlYFrFposeIh2xX1DbdF3CRFnAHM5VvdtfVh/TtpcEvg4GRCanvzaSvsVajLjFZOZhGVgm+uZ1H6ba6jQuoOUvFJ667EVwQk7c8KDJrvZIMvzMxCgvSHb6N8VBh/5svWYa+7Kbd++3WP7XmkLpWli/DXvOSu6I6M7w+m/OI157mWPp0a7iy+Q+o1vSl/3INNIrd/vMT5F+ae1iBLFn3aHndtezhdQr+HrQCHaVP8OiK96rtjzaiRp+dyoMf4U71LoJGRpGZURv9imyXholoQutlT+bhRaumPqrqiwFRGMaL+xhfBZMySMND8wcO9rQnabiQf5Wo9J5aJMnixWjEIg9gGhJ8E96j9VwdUBA7yfHAbVhLrQ0h2TkZuUdqU1EnOWIbnPtjC9exv8R5X2WRs1fMz9j+XpNYclB4YdLclQ662nfsquccqfksDG1rS249WkSl1RIxr9fcD+60xYXgkG78wrTN8cr9NMGk5/AyMyHcvYjA+rGg1V8DZhzC3WZn9Q0NRJoc3b+xx9pxkaO7epBck5sAsNPO8b/bMGGKmgmR5tKSZUN+lTUKLI2znJcUC1dMKKpRCqr1To94ZYVe0G7SFbe+MH4guQXkd7sB6GnsR8/7g8OsVcAtV4DoEWfHwJQIE0bg/UzqubyBPSGPs1JBZm8nks/zTpOJ65o="
21+
file: leetcode-cli.*
22+
file_glob: true
23+
skip_cleanup: true
24+
overwrite: true
25+
on:
26+
tags: true

bin/pkg

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env node
2+
3+
const arch = require('os').arch();
4+
var os = process.platform;
5+
const ver = process.versions.node.split('.')[0];
6+
7+
var bin = './bin/pkg.sh';
8+
var args = [arch, os, ver];
9+
10+
if (os === 'darwin') {
11+
args[1] = 'macos';
12+
} else if (os === 'win32') {
13+
bin = 'cmd.exe';
14+
args = ['/c', 'bin\\pkg.bat'].concat(args);
15+
}
16+
17+
var proc = require('child_process').spawn(bin, args);
18+
proc.stdout.on('data', x => console.log(x.toString().trimRight('\n')));
19+
proc.stderr.on('data', x => console.log(x.toString().trimRight('\n')));
20+
proc.on('close', process.exit);

bin/pkg.bat

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@echo off
2+
set arch=%1
3+
set os=%2
4+
set ver=%3
5+
6+
set dist=dist\
7+
set file=leetcode-cli.node%ver%.%os%.%arch%.zip
8+
9+
mkdir %dist%
10+
del /q %dist%\*
11+
del /q *.zip
12+
13+
for %%x in (company cookie.chrome cookie.firefox cpp.lint cpp.run github leetcode.cn lintcode solution.discuss) do (
14+
echo [%%x]
15+
node bin\leetcode ext -i %%x
16+
if %ERRORLEVEL% gtr 0 exit /b 1
17+
)
18+
19+
for /r . %%x in (*.node) do copy %%x %dist%
20+
call npm run pkg -- node%ver%-%os%-%arch%
21+
if %ERRORLEVEL% gtr 0 exit /b 1
22+
23+
7z a %file% %dist%
24+
if %ERRORLEVEL% gtr 0 exit /b 1
25+
exit 0

bin/pkg.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash -e
2+
3+
arch=$1
4+
os=$2
5+
ver=$3
6+
7+
DIST=./dist
8+
FILE=leetcode-cli.node$ver.$os.$arch.tar.gz
9+
10+
mkdir -p $DIST
11+
rm -rf $DIST/*
12+
rm -rf $FILE
13+
14+
plugins="company cookie.chrome cookie.firefox cpp.lint cpp.run github leetcode.cn lintcode solution.discuss"
15+
16+
for plugin in $plugins; do
17+
echo "[$plugin]"
18+
./bin/leetcode ext -i $plugin
19+
done
20+
21+
find node_modules -name "*.node" -exec cp {} $DIST \;
22+
npm run pkg -- node$ver-$os-$arch
23+
24+
tar zcvf $FILE $DIST
25+
ls -al $FILE
26+
exit 0

docs/advanced.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ title: Advanced Topic
99
* [Cache](#cache)
1010
* [Configuration](#configuration)
1111
* [Color Themes](#color-themes)
12+
* [File Name](#file-name)
1213
* [Log Levels](#log-levels)
1314
* [Plugins](#plugins)
1415

@@ -91,6 +92,10 @@ The config file is saved in `~/.lc/config.json`, here is a full exmaple (include
9192
"enable": true,
9293
"theme": "default"
9394
},
95+
"file": {
96+
"show": "${fid}.${slug}",
97+
"submission": "${fid}.${slug}.${sid}.${ac}"
98+
},
9499
"icon": {
95100
"theme": ""
96101
},
@@ -107,6 +112,7 @@ Here are some useful settings:
107112
* `code:lang` to set your default language used in coding.
108113
* `color:enable` to enable colorful output.
109114
* `color:theme` to set color theme used in output. (see [Color Theme](#color-theme))
115+
* `file.show` to set filename pattern for generated code file. (see [File Name](#file-name))
110116
* `icon:theme` to set icon them used in output.
111117
* `plugins` to config each installed plugins. (see [Plugins](#plugins))
112118

@@ -167,6 +173,23 @@ Of course you can create your own themes if you like, look into `colors` folder
167173
"yellow": "#ffff00"
168174
}
169175

176+
# File Name
177+
178+
You could configure file name pattern in code generation.
179+
180+
* config `file.show` for generated file in `show`.
181+
* config `file.submission` for downloaded file in `submission`.
182+
183+
Followings are some variables you could used in the pattern:
184+
185+
* `${fid}` for question id. (e.g. `123`)
186+
* `${slug}` for dash-separated question name. (e.g. `add-two`)
187+
* `${name}` for space-separated questions name. (e.g. `Add Two`)
188+
* `${level}` for question level. (e.g. `Hard`)
189+
* `${category}` for question category. (e.g. `algorithms`)
190+
* `${sid}` for submission id.
191+
* `${ac}` for accept status of existing submission.
192+
170193
# Log Levels
171194

172195
* `-v` to enable debug output.

docs/commands.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ Display version information.
465465
Short:
466466

467467
$ leetcode version
468-
2.5.2
468+
2.6.1
469469

470470
Verbose:
471471

@@ -475,7 +475,7 @@ Verbose:
475475
| | ___ ___| |_ ___ ___ __| | ___
476476
| |/ _ \/ _ \ __|/ __|/ _ \ / _` |/ _ \
477477
| | __/ __/ |_ (__| (_) | (_| | __/
478-
|_|\___|\___|\__|\___|\___/ \__,_|\___| CLI v2.5.2
478+
|_|\___|\___|\__|\___|\___/ \__,_|\___| CLI v2.6.1
479479

480480
[Environment]
481481
Node v8.1.4

docs/install.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ layout: default
33
title: Installation
44
---
55

6+
# All in One (beta)
7+
8+
No need to install node.js. Now available on 64bits linux, mac, and windows.
9+
10+
[Download](https://github.com/skygragon/leetcode-cli/releases)
11+
612
# Prerequisites
713

814
Install the latest LTS version of `node.js` (`npm` included):
@@ -49,6 +55,11 @@ Similar with above, while you can introduce your own changes as you wish.
4955
$ cd leetcode-cli && ./bin/install
5056
$ leetcode version
5157

58+
### From source (all-in-one)
59+
60+
$ git clone http://github.com/skygragon/leetcode-cli
61+
$ cd leetcode-cli && node ./bin/pkg
62+
5263
### From docker
5364

5465
NOTE: This is just a tiny taste to let you feel that leetcode-cli is. Please use other ways above to install leetcode-cli if you like it.

docs/releases.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,32 @@
22
layout: default
33
title: Release Notes
44
---
5+
# 2.6.1
6+
* `submit`
7+
* fixes 500 error on windows.
8+
9+
# 2.6.0
10+
* build all-in-one binary for linux/macos/windows.
11+
* `show`
12+
* support customized filename.
13+
* use "--" as comment in sql file.
14+
* `list`
15+
* fixes format issue.
16+
* fixes UT failures on windows.
17+
18+
# 2.5.4
19+
* fixes error in fresh env without .lc existed.
20+
* embed meta in file content instead of file name.
21+
* update dependencies.
22+
23+
# 2.5.3
24+
25+
* fixes "Failed to load locked problem" issue.
26+
* move plugin's data into separate folders:
27+
* login info
28+
* problems list
29+
* problem cache
30+
531
# 2.5.2
632

733
* `show`

icons/ascii.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"like": "*",
55
"unlike": " ",
66
"lock": "$",
7+
"nolock": " ",
78
"empty": " ",
89
"ac": "O",
910
"notac": "X",

icons/default.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"like": "",
55
"unlike": "",
66
"lock": "🔒",
7+
"nolock": " ",
78
"empty": " ",
89
"ac": "",
910
"notac": "",

icons/win7.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"like": "",
55
"unlike": " ",
66
"lock": "$",
7+
"nolock": " ",
78
"empty": " ",
89
"ac": "O",
910
"notac": "X",

lib/cache.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
11
'use strict';
2-
var fs = require('fs');
32
var path = require('path');
43

5-
var h = require('./helper');
4+
var file = require('./file');
65

76
const cache = {};
87

98
cache.init = function() {
10-
h.mkdir(h.getCacheDir());
9+
file.mkdir(file.cacheDir());
1110
};
1211

1312
cache.get = function(k) {
14-
const fullpath = h.getCacheFile(k);
15-
if (!fs.existsSync(fullpath)) return null;
13+
const fullpath = file.cacheFile(k);
14+
if (!file.exist(fullpath)) return null;
1615

17-
return JSON.parse(fs.readFileSync(fullpath));
16+
return JSON.parse(file.data(fullpath));
1817
};
1918

2019
cache.set = function(k, v) {
21-
const fullpath = h.getCacheFile(k);
22-
fs.writeFileSync(fullpath, JSON.stringify(v));
20+
const fullpath = file.cacheFile(k);
21+
file.write(fullpath, JSON.stringify(v));
2322
return true;
2423
};
2524

2625
cache.del = function(k) {
27-
const fullpath = h.getCacheFile(k);
28-
if (!fs.existsSync(fullpath)) return false;
26+
const fullpath = file.cacheFile(k);
27+
if (!file.exist(fullpath)) return false;
2928

30-
fs.unlinkSync(fullpath);
29+
file.rm(fullpath);
3130
return true;
3231
};
3332

3433
cache.list = function() {
35-
return fs.readdirSync(h.getCacheDir())
34+
return file.list(file.cacheDir())
3635
.filter(x => path.extname(x) === '.json')
3736
.map(function(filename) {
3837
const k = path.basename(filename, '.json');
39-
const stat = fs.statSync(h.getCacheFile(k));
38+
const stat = file.stat(file.cacheFile(k));
4039
return {
4140
name: k,
4241
size: stat.size,

lib/chalk.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ var _ = require('underscore');
33
var style = require('ansi-styles');
44
var supportsColor = require('supports-color');
55

6+
var file = require('./file');
7+
68
const chalk = {
79
enabled: supportsColor.stdout,
810
use256: supportsColor.stdout && supportsColor.stdout.has256,
@@ -54,8 +56,7 @@ chalk.wrap = function(pre, post) {
5456
const bgName = x => 'bg' + x[0].toUpperCase() + x.substr(1);
5557

5658
chalk.init = function() {
57-
const h = require('./helper');
58-
for (let f of h.getCodeDirData('colors')) {
59+
for (let f of file.listCodeDir('colors')) {
5960
const theme = {};
6061
const data = _.extendOwn({}, DEFAULT, f.data);
6162
for (let x of _.pairs(data)) {

0 commit comments

Comments
 (0)