Skip to content

Commit b6e728f

Browse files
committed
feat:scripts目录提升
1 parent 95be0be commit b6e728f

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed

scripts/check.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* 执行脚本
3+
*/
4+
import {temExe} from "#common/utils/temExe.js";
5+
import {readStore} from "#common/utils/store.js";
6+
import {parseFilePath} from "#common/utils/parseFilePath.js";
7+
const args = process.argv.slice(2);
8+
let name;
9+
switch (args[0]) {
10+
case "-r": {
11+
const random = readStore("random-question-info")
12+
name = `${random.id}.${random.enName}`;
13+
console.log(`[leet-check]检测当前随机题目:${name}`)
14+
break;
15+
}
16+
17+
case "-i": {
18+
let id = args[1];
19+
const specified = readStore("specified-question-info")
20+
name = `${specified.id}.${specified.enName}`;
21+
if (id === undefined && name.startsWith("undefined")) {
22+
console.warn("请指定对应的编号进行检查!")
23+
}
24+
console.log(`[leet-check]检测题目:${name}`)
25+
break;
26+
}
27+
28+
case "-t":
29+
default: {
30+
const question = readStore("today-question-info")
31+
name = `${question.id}.${question.enName}`;
32+
console.log(`[leet-check]检测题目:${name}`)
33+
}
34+
break;
35+
}
36+
const filePath = parseFilePath(`./src/${name}/index.js`);
37+
temExe('node {0}',filePath)
38+
.then(res => console.log(`执行结果:\n${res}`))
39+
.catch(e => console.log("执行报错: ", e));

scripts/create.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import {createQuestion} from "#common/utils/question-handler/createQuestion.js";
2+
import {getQuestionToday} from "#common/utils/getQuestionToday.js";
3+
import {fulfillQuestion} from "#common/utils/question-handler/fulfillQuestion.js";
4+
import {writeStore} from "#common/utils/store.js";
5+
import {getQuestionById} from "#common/utils/getQuestionById.js";
6+
import {getRandomId} from "#common/utils/getRandomId.js";
7+
8+
/**
9+
* leet-create [-t|-r|-i [id]]
10+
* 默认参数 -t
11+
* -t today 今日题目
12+
* -r Random 随机题目
13+
* -i id 指定题目id
14+
* 工作区为 根目录
15+
*/
16+
export const create = () => {
17+
const args = process.argv.slice(2);
18+
switch (args[0]) {
19+
case "-r":
20+
getRandomId().then(id => {
21+
getQuestionById(id).then(question => {
22+
const random = `${question.id}.${question.enName}`;
23+
writeStore("random-question-info", question);
24+
createQuestion(random).then((filePath) => {
25+
fulfillQuestion(filePath, question);
26+
})
27+
})
28+
})
29+
break;
30+
case "-i":
31+
const id = args[1];
32+
if (id === undefined) {
33+
console.warn("请指定对应的编号!")
34+
}else{
35+
console.log(`获取指定编号[${id}]的题目...`)
36+
getQuestionById(id).then(question => {
37+
const specified = `${question.id}.${question.enName}`;
38+
writeStore("specified-question-info", question);
39+
createQuestion(specified).then((filePath) => {
40+
fulfillQuestion(filePath, question);
41+
})
42+
})
43+
}
44+
break;
45+
case "-t":
46+
default:
47+
console.log("开始获取今日题目")
48+
// 获取问题的全部信息
49+
getQuestionToday().then(question => {
50+
const today = `${question.id}.${question.enName}`;
51+
createQuestion(today).then((filePath) => {
52+
fulfillQuestion(filePath, question);
53+
})
54+
})
55+
break;
56+
}
57+
58+
59+
}
60+
create()
61+

scripts/finder.js

Whitespace-only changes.

0 commit comments

Comments
 (0)