Skip to content

Commit 2933545

Browse files
committed
Merge branch 'refactor-dir' into dev
2 parents c8fa09c + 7a3a948 commit 2933545

Some content is hidden

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

67 files changed

+421
-229
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ dist-ssr
2424
*.njsproj
2525
*.sln
2626
*.sw?
27-
coverage/**
27+
coverage/**
28+
29+
# store file
30+
resources/stores/*

Readme.md

+10-9
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ yarn leet-create
7171

7272
会通过接口获取今日题目,并会在`src`目录下根据`题目的id`+`题目的英文翻译`创建一个目录,并将今日题目和基础示例代码填充到`index.js`中。
7373

74-
![创建目录](./resources/leet-create-0.png)
75-
![填充文件](resources/leet-create-1.png)
74+
![创建目录](resources/images/leet-create-0.png)
75+
![填充文件](resources/images/leet-create-1.png)
7676

7777
### 2. 检验今天的题目
7878

@@ -102,7 +102,7 @@ Done in 0.18s.
102102

103103
```
104104

105-
![检测题目](resources/leet-check.png)
105+
![检测题目](resources/images/leet-check.png)
106106

107107
### 3. 创建自己想要练习的题目
108108

@@ -125,9 +125,9 @@ yarn leet-create -i "LCP 29"
125125
└── index.js # 模板js文件 可以替换题目
126126
```
127127

128-
![1314cmd.png](resources/1314-cmd.png)
129-
![1314.png](resources/1314.png)
130-
![1314详情.png](resources/1314-detail.png)
128+
![1314cmd.png](resources/images/1314-cmd.png)
129+
![1314.png](resources/images/1314.png)
130+
![1314详情.png](resources/images/1314-detail.png)
131131

132132
### 4. 检验自己想要练习的结果
133133

@@ -179,7 +179,7 @@ Done in 0.19s.
179179

180180
```
181181

182-
![1314-check.png](resources/1314-check.png)
182+
![1314-check.png](resources/images/1314-check.png)
183183

184184
### 5. 获取随机题目
185185

@@ -237,5 +237,6 @@ Done in 0.19s.
237237
238238
## Contributor
239239

240-
[EternalHeart](https://github.com/wh131462)
241-
[SmallTeddy](https://github.com/SmallTeddy)
240+
[<img src="https://avatars.githubusercontent.com/u/48346853" style="border-radius:50%;" width="30" height="30" alt="EternalHeart"/>](https://github.com/wh131462)
241+
[<img src="https://avatars.githubusercontent.com/u/61453917" style="border-radius:50%;" width="30" height="30" alt="SmartTeddy"/>](https://github.com/SmallTeddy)
242+
[<img src="https://avatars.githubusercontent.com/u/35305691" style="border-radius:50%;" width="30" height="30" alt="Hedwig-Fang"/>](https://github.com/Hedwig-Fang)

bin/lc.js

+33-38
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,43 @@
11
#! /usr/bin/env node
22
import {program} from "commander";
3+
import {artFontLogo} from "../resources/text/art-font-logo.js";
4+
import {examples} from "../resources/text/examples.js";
5+
import {love} from "../resources/text/love.js";
6+
import {aim} from "../resources/text/aim.js";
7+
import {referMode} from "#common/utils/create-check/refer-mode.js";
8+
import {getArgs} from "#common/utils/create-check/get-args.js";
9+
import fs from "fs";
10+
const {version} = JSON.parse(fs.readFileSync("package.json",'utf-8'));
311

412
program
5-
.version('1.0.0')
6-
.description(`
7-
8-
░▒▓█▓▒░ ░▒▓████████▓▒░▒▓████████▓▒░▒▓████████▓▒░▒▓██████▓▒░ ░▒▓██████▓▒░░▒▓███████▓▒░░▒▓████████▓▒░ ░▒▓███████▓▒░░▒▓███████▓▒░ ░▒▓██████▓▒░ ░▒▓██████▓▒░▒▓████████▓▒░▒▓█▓▒░░▒▓██████▓▒░░▒▓████████▓▒░
9-
░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░
10-
░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░
11-
░▒▓█▓▒░ ░▒▓██████▓▒░ ░▒▓██████▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓██████▓▒░ ░▒▓███████▓▒░░▒▓███████▓▒░░▒▓████████▓▒░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░▒▓█▓▒░ ░▒▓██████▓▒░
12-
░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░
13-
░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░
14-
░▒▓████████▓▒░▒▓████████▓▒░▒▓████████▓▒░ ░▒▓█▓▒░ ░▒▓██████▓▒░ ░▒▓██████▓▒░░▒▓███████▓▒░░▒▓████████▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░░▒▓██████▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓██████▓▒░░▒▓████████▓▒░
15-
16-
17-
LeetCode Practice CLI`)
18-
.argument('<string>', 'Default to get this identity.')
13+
.version(version)
14+
.description(`${artFontLogo}\n${aim}`)
15+
.addHelpText('after', examples+love)
16+
.arguments("[identity]")
1917
.option('-i, --identity <identity>', 'Specify a question by identity.')
2018
.option('-r, --random', 'Get a question randomly.')
2119
.option('-t, --today', 'Get a question today.')
22-
.parse(process.argv);
23-
// program.
24-
// examples(`
25-
// $ lc
26-
// $ lc 1314
27-
// $ lc -i 1314
28-
// $ lc -r
29-
// $ lc -t
30-
// `)
31-
const args = program.args;
32-
const opts = program.opts();
33-
console.log("[args]",args)
34-
console.log("[opts]",opts)
35-
36-
const getCase = (args,opts)=>{
37-
return 'today'
38-
}
20+
.parse(process.argv)
3921

40-
const rules = {
41-
'today':(args,opts)=>{},
42-
'random':(args,opts)=>{},
43-
'identity':(args,opts)=>{},
22+
const cmdArgs = program.args;
23+
const cmdOpts = program.opts();
24+
// 模式对应的action
25+
const callModeAction = {
26+
'today': () => {
27+
// todo 获取今日题目的进程
28+
console.log("[leetcode-practice] 获取今日题目")
29+
},
30+
'random': () => {
31+
// todo 获取随机题目的进程
32+
console.log("[leetcode-practice] 获取随机题目")
33+
},
34+
'identity': (id) => {
35+
// todo 获取指定题目的进程
36+
console.log(`[leetcode-practice] 获取指定题目[${id}]`)
37+
},
4438
}
45-
39+
// 获取模式和参数
40+
const mode = referMode(cmdArgs, cmdOpts);
41+
const args = getArgs(mode,cmdArgs,cmdOpts);
4642
// 执行指令分发
47-
const current = getCase(args,opts);
48-
rules[current](args,opts);
43+
callModeAction[mode](args);

bin/lf.js

100644100755
File mode changed.

bin/lk.js

+42-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,43 @@
11
#! /usr/bin/env node
2-
const init = async() => {
3-
await import('../common/scripts/check.js');
4-
5-
}
6-
init()
2+
import {program} from "commander";
3+
import {artFontLogo} from "../resources/text/art-font-logo.js";
4+
import {examples} from "../resources/text/examples.js";
5+
import {love} from "../resources/text/love.js";
6+
import {aim} from "../resources/text/aim.js";
7+
import {referMode} from "#common/utils/create-check/refer-mode.js";
8+
import {getArgs} from "#common/utils/create-check/get-args.js";
9+
import fs from "fs";
10+
const {version} = JSON.parse(fs.readFileSync("package.json",'utf-8'));
11+
12+
program
13+
.version(version)
14+
.description(`${artFontLogo}\n${aim}`)
15+
.addHelpText('after', examples+love)
16+
.arguments("[identity]")
17+
.option('-i, --identity <identity>', 'Check the specified question by identity.')
18+
.option('-r, --random', 'Check the last random question.')
19+
.option('-t, --today', 'Check the question today.')
20+
.parse(process.argv)
21+
22+
const cmdArgs = program.args;
23+
const cmdOpts = program.opts();
24+
// 模式对应的action
25+
const callModeAction = {
26+
'today': () => {
27+
// todo 获取今日题目的进程
28+
console.log("[leetcode-practice] 检测今日题目")
29+
},
30+
'random': () => {
31+
// todo 获取随机题目的进程
32+
console.log("[leetcode-practice] 检测随机题目")
33+
},
34+
'identity': (id) => {
35+
// todo 获取指定题目的进程
36+
console.log(`[leetcode-practice] 检测指定题目[${id}]`)
37+
},
38+
}
39+
// 获取模式和参数
40+
const mode = referMode(cmdArgs, cmdOpts);
41+
const args = getArgs(mode,cmdArgs,cmdOpts);
42+
// 执行指令分发
43+
callModeAction[mode](args);

common/resources/store.json

-1
This file was deleted.

common/utils/Readme.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
| createQuestion | newPath | 以传入名称创建src/[newPath]/index.js 并填充模板 |
1616
| fulfillQuestion | questionPath,question | 在对应题目空模板中填充具体问题信息 |
1717
| removeDomTags | input | 从传入的html字符串中剥离html标签 |
18-
| readStore | key | 从缓存中读取对应的键值 |
19-
| writeStore | key,value | 从缓存中存入值(明文存储,文件为store.json) |
20-
| getJsCode | enName | 获取JS代码 |
18+
| getJsCode | slug | 获取JS代码 |
2119
| getTestCase | question | 根据获取到的question信息组装测试用例 |
22-
| getQuestionUrl | enName | 简单组装问题的URL |
20+
| getQuestionUrl | slug | 简单组装问题的URL |
2321
| getRandomId | | 获取随机当前src目录下不存在的问题id |

common/utils/create-check/get-args.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// 获取模式对应的参数
2+
export const getArgs = (mode,cmdArgs,cmdOpts) => {
3+
switch (mode) {
4+
case "identity":
5+
return cmdArgs.length ? cmdArgs.join(" ") : cmdOpts?.identity;
6+
case "random":
7+
case "today":
8+
default:
9+
return null;
10+
}
11+
}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// 推测模式
2+
export const referMode = (args, opts) => {
3+
if (args.length > 0 || opts.identity) {
4+
return 'identity'
5+
}
6+
if (opts.random) {
7+
return 'random'
8+
}
9+
return 'today';
10+
}

common/utils/createQuestion.js

-54
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

common/utils/getQuestionUrl.js

-3
This file was deleted.

0 commit comments

Comments
 (0)