Skip to content

Commit acbabf3

Browse files
committed
chore:路径调整成全局路径
1 parent 28e0807 commit acbabf3

File tree

8 files changed

+118
-129
lines changed

8 files changed

+118
-129
lines changed

common/utils/question-getter/getQuestionById.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {getQuestionSearchJson} from "../../../resources/headers/questionSearchJson.js";
1+
import {getQuestionSearchJson} from "#resources/headers/questionSearchJson.js";
22
import {getQuestionDetail} from "../question-handler/getQuestionDetail.js";
33
export async function getQuestionById(id) {
44
const base = await fetch('https://leetcode.cn/graphql/', getQuestionSearchJson(id.toString())).then((res) => res.json());

common/utils/question-getter/getQuestionRandom.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {getQuestionSearchJson} from "../../../resources/headers/questionSearchJson.js";
1+
import {getQuestionSearchJson} from "#resources/headers/questionSearchJson.js";
22
import {getQuestionDetail} from "../question-handler/getQuestionDetail.js";
33
import {getRandomId} from "#common/utils/question-handler/getRandomId.js";
44

common/utils/question-getter/getQuestionToday.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {getQuestionTodayJson} from "../../../resources/headers/questionTodayJson.js";
1+
import {getQuestionTodayJson} from "#resources/headers/questionTodayJson.js";
22
import {getQuestionDetail} from "../question-handler/getQuestionDetail.js";
33

44
export async function getQuestionToday() {

common/utils/question-handler/getJSCode.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {getCodeDetailJson} from "../../../resources/headers/codeDetailJson.js";
1+
import {getCodeDetailJson} from "#resources/headers/codeDetailJson.js";
22
/**
33
* 获取JS code 必须在获取基本信息之后调用 需要传入enName
44
* @returns {Promise<unknown>}

common/utils/question-handler/getQuestionDetail.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {getJSCode} from "./getJSCode.js";
2-
import {getQuestionDetailJson} from "../../../resources/headers/questionDetailJson.js";
2+
import {getQuestionDetailJson} from "#resources/headers/questionDetailJson.js";
33

44
export async function getQuestionDetail(slug, extra) {
55
// 标题的英文字符串

common/utils/question-handler/getRandomId.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {existsSync, mkdirSync, readdirSync} from "fs";
22
import {normalize} from "path";
3-
import {getQuestionListJson} from "../../../resources/headers/questionListJson.js";
3+
import {getQuestionListJson} from "#resources/headers/questionListJson.js";
44

55
/**
66
* todo 需要先获取全部题目列表 需要处理随机的问题

common/view/check.view.js

+63-69
Original file line numberDiff line numberDiff line change
@@ -2,88 +2,82 @@ import inquirer from "inquirer";
22
import path from "path";
33
import {getQuestionFileName} from "#common/utils/question-handler/getQuestionFileName.js";
44
import {getQuestionById} from "#common/utils/question-getter/getQuestionById.js";
5-
import {getQuestionToday} from "#common/utils/question-getter/getQuestionToday.js";
6-
import {getQuestionRandom} from "#common/utils/question-getter/getQuestionRandom.js";
7-
import {createQuestion} from "#common/utils/question-handler/createQuestion.js";
8-
import {createQuestionCopy} from "#common/utils/question-handler/createQuestionCopy.js";
95
import {getQuestionByMode} from "#common/utils/store/store-realm.js";
106
import {checkQuestion} from "#common/utils/question-handler/checkQuestion.js";
117
import {getCountBySameName} from "#common/utils/file/getCountBySameName.js";
128
import {getFileListBySameName} from "#common/utils/file/getFileListBySameName.js";
13-
const modeQuestion = [{
14-
type: 'list',
15-
name: 'mode',
16-
message: '请选择检查问题的模式:',
17-
choices: ['today', 'identity', 'random'],
18-
}];
9+
10+
export const easyCheckView = async () => {
11+
const modeQuestion = [{
12+
type: 'list',
13+
name: 'mode',
14+
message: '请选择检查问题的模式:',
15+
choices: ['today', 'identity', 'random'],
16+
}];
1917
// 第一个问题 选择的模式
20-
const {mode} = await inquirer.prompt(modeQuestion,null);
21-
const identityQuestion = [{
22-
type: 'input',
23-
name: 'identity',
24-
message: '请输入题目编号:',
25-
}];
26-
let question;
27-
switch (mode){
28-
case "identity":
29-
const {identity} = await inquirer.prompt(identityQuestion,null);
30-
question = !identity?
31-
await getQuestionByMode(mode):
32-
await getQuestionById(identity);
33-
break;
34-
case "random":
35-
question = await getQuestionByMode(mode);
36-
break;
37-
case "today":
38-
default:
39-
question = await getQuestionByMode(mode);
40-
break;
41-
}
18+
const {mode} = await inquirer.prompt(modeQuestion, null);
19+
const identityQuestion = [{
20+
type: 'input',
21+
name: 'identity',
22+
message: '请输入题目编号:',
23+
}];
24+
let question;
25+
switch (mode) {
26+
case "identity":
27+
const {identity} = await inquirer.prompt(identityQuestion, null);
28+
question = !identity ?
29+
await getQuestionByMode(mode) :
30+
await getQuestionById(identity);
31+
break;
32+
case "random":
33+
question = await getQuestionByMode(mode);
34+
break;
35+
case "today":
36+
default:
37+
question = await getQuestionByMode(mode);
38+
break;
39+
}
4240
// 检查题目
43-
const questionFileName = getQuestionFileName(question);
44-
const currentDir = process.cwd();
45-
let questionDir = path.join(currentDir,questionFileName);
41+
const questionFileName = getQuestionFileName(question);
42+
const currentDir = process.cwd();
43+
let questionDir = path.join(currentDir, questionFileName);
4644
// 创建路径确认
47-
const pathRightQuestion = [{
48-
type: 'confirm',
49-
name: 'dirRight',
50-
message: `是否检测当前目录[ ${currentDir} ]下的题目[ ${questionFileName} ]?`,
51-
}];
52-
const {dirRight} = await inquirer.prompt(pathRightQuestion,null);
53-
if(!dirRight){
54-
const newPathRightQuestion = [{
45+
const pathRightQuestion = [{
5546
type: 'confirm',
56-
name: 'newDirRight',
57-
message: `请选择要检测的目录?`,
47+
name: 'dirRight',
48+
message: `是否检测当前目录[ ${currentDir} ]下的题目[ ${questionFileName} ]?`,
5849
}];
59-
const {newDirRight} = await inquirer.prompt(newPathRightQuestion,null);
60-
if(!newDirRight){
61-
console.log("用户取消检测操作")
62-
}else{
50+
const {dirRight} = await inquirer.prompt(pathRightQuestion, null);
51+
if (!dirRight) {
6352
const newDirQuestion = [{
6453
type: 'input',
6554
name: 'newDir',
66-
message: `请选择新目录(基础地址为${currentDir}):`,
55+
message: `请选择新目录(基础地址为${currentDir})[按回车[Enter]终止操作]:`,
6756
}];
68-
const {newDir} = await inquirer.prompt(newDirQuestion,null);
69-
questionDir = path.join(path.join(process.cwd(),newDir),`${questionFileName}`)
57+
const {newDir} = await inquirer.prompt(newDirQuestion, null);
58+
if (!newDir) {
59+
console.log("[LK-LOG]用户终止操作~")
60+
process.exit(0);
61+
}
62+
questionDir = path.join(path.join(process.cwd(), newDir), `${questionFileName}`)
7063
}
71-
}
72-
const questionParentDir = path.dirname(questionDir);
64+
const questionParentDir = path.dirname(questionDir);
7365
// 先检测有几个副本
74-
if(getCountBySameName(questionParentDir,questionFileName)>0){
75-
const selectQuestionQuestion = [{
76-
type: 'list',
77-
name: 'selectQuestion',
78-
message: `题目[ ${questionFileName} ]有多个副本,请选择一个进行检测:`,
79-
choices:getFileListBySameName(questionParentDir,questionFileName)
80-
}]
81-
// 选择其中一个副本进行检查
82-
const {selectQuestion} = await inquirer.prompt(selectQuestionQuestion,null);
83-
questionDir = path.join(questionParentDir,selectQuestion);
84-
console.log(`用户选择题目[ ${questionFileName}]的副本[ ${selectQuestion}]进行检测`)
66+
if (getCountBySameName(questionParentDir, questionFileName) > 1) {
67+
const selectQuestionQuestion = [{
68+
type: 'list',
69+
name: 'selectQuestion',
70+
message: `题目[ ${questionFileName} ]有多个副本,请选择要检测的副本:`,
71+
choices: getFileListBySameName(questionParentDir, questionFileName)
72+
}]
73+
// 选择其中一个副本进行检查
74+
const {selectQuestion} = await inquirer.prompt(selectQuestionQuestion, null);
75+
questionDir = path.join(questionParentDir, selectQuestion);
76+
console.log(`用户选择题目[ ${questionFileName}]的副本[ ${selectQuestion}]进行检测`)
77+
}
78+
const filePath = path.join(questionDir, "index.js");
79+
await checkQuestion(filePath);
80+
console.log(`题目[${questionFileName}]检查完成!\n文件地址为: ${filePath}`)
81+
process.exit(0)
8582
}
86-
const filePath = path.join(questionDir,"index.js");
87-
await checkQuestion(filePath);
88-
console.log(`题目[${questionFileName}]检查完成!\n文件地址为: ${filePath}`)
89-
process.exit(0)
83+
await easyCheckView()

common/view/create.view.js

+49-54
Original file line numberDiff line numberDiff line change
@@ -7,70 +7,65 @@ import {getQuestionRandom} from "#common/utils/question-getter/getQuestionRandom
77
import {createQuestion} from "#common/utils/question-handler/createQuestion.js";
88
import {createQuestionCopy} from "#common/utils/question-handler/createQuestionCopy.js";
99
import {setQuestion} from "#common/utils/store/store-realm.js";
10-
const modeQuestion = [{
11-
type: 'list',
12-
name: 'mode',
13-
message: '请选择创建问题的模式:',
14-
choices: ['today', 'identity', 'random'],
15-
}];
10+
export const easyCreateView = async ()=>{
11+
const modeQuestion = [{
12+
type: 'list',
13+
name: 'mode',
14+
message: '请选择创建问题的模式:',
15+
choices: ['today', 'identity', 'random'],
16+
}];
1617
// 第一个问题 选择的模式
17-
const {mode} = await inquirer.prompt(modeQuestion,null);
18-
const identityQuestion = [{
19-
type: 'input',
20-
name: 'identity',
21-
message: '请输入题目编号:',
22-
}];
23-
let question;
24-
switch (mode){
25-
case "identity":
26-
const {identity} = await inquirer.prompt(identityQuestion,null);
27-
console.log(identity)
28-
question = await getQuestionById(identity);
29-
break;
30-
case "random":
31-
question = await getQuestionRandom();
32-
break;
33-
case "today":
34-
default:
35-
question = await getQuestionToday()
36-
break;
37-
}
38-
const store = await setQuestion(mode,question);
39-
if(!store) console.warn(`[create][${mode}]问题[${question.title}]未成功缓存`)
40-
console.log(`[create][${mode}]问题[${question.title}]已缓存`,store)
18+
const {mode} = await inquirer.prompt(modeQuestion,null);
19+
const identityQuestion = [{
20+
type: 'input',
21+
name: 'identity',
22+
message: '请输入题目编号:',
23+
}];
24+
let question;
25+
switch (mode){
26+
case "identity":
27+
const {identity} = await inquirer.prompt(identityQuestion,null);
28+
console.log(identity)
29+
question = await getQuestionById(identity);
30+
break;
31+
case "random":
32+
question = await getQuestionRandom();
33+
break;
34+
case "today":
35+
default:
36+
question = await getQuestionToday()
37+
break;
38+
}
39+
const store = await setQuestion(mode,question);
40+
if(!store) console.warn(`[create][${mode}]问题[${question.title}]未成功缓存`)
4141
// 创建题目
42-
const questionFileName = getQuestionFileName(question);
43-
const currentDir = process.cwd();
44-
let questionDir = path.join(currentDir,questionFileName);
42+
const questionFileName = getQuestionFileName(question);
43+
const currentDir = process.cwd();
44+
let questionDir = path.join(currentDir,questionFileName);
4545
// 创建路径确认
46-
const pathRightQuestion = [{
47-
type: 'confirm',
48-
name: 'dirRight',
49-
message: `是否在目录[ ${currentDir} ]下创建题目[ ${questionFileName} ]?`,
50-
}];
51-
const {dirRight} = await inquirer.prompt(pathRightQuestion,null);
52-
if(!dirRight){
53-
const newPathRightQuestion = [{
46+
const pathRightQuestion = [{
5447
type: 'confirm',
55-
name: 'newDirRight',
56-
message: `是否需要选择一个新的目录?`,
48+
name: 'dirRight',
49+
message: `是否在目录[ ${currentDir} ]下创建题目[ ${questionFileName} ]?`,
5750
}];
58-
const {newDirRight} = await inquirer.prompt(newPathRightQuestion,null);
59-
if(!newDirRight){
60-
console.log("用户取消创建操作")
61-
}else{
51+
const {dirRight} = await inquirer.prompt(pathRightQuestion,null);
52+
if(!dirRight){
6253
const newDirQuestion = [{
6354
type: 'input',
6455
name: 'newDir',
65-
message: `请选择新目录(基础地址为${process.cwd()}):`,
56+
message: `请选择新目录(基础地址为${process.cwd()})[按回车[Enter]终止操作]:`,
6657
}];
6758
const {newDir} = await inquirer.prompt(newDirQuestion,null);
59+
if(!newDir) {
60+
console.log("[LC-LOG]用户终止操作~")
61+
process.exit(0);
62+
}
6863
questionDir = path.join(path.join(process.cwd(),newDir),`${questionFileName}`)
6964
}
65+
let filePath = await createQuestion(question,questionDir);
66+
if(!filePath){
67+
filePath = await createQuestionCopy(question,questionDir);
68+
}
69+
console.log(`题目[${questionFileName}]创建完成!\n文件地址为: ${filePath}`)
70+
process.exit(0)
7071
}
71-
let filePath = await createQuestion(question,questionDir);
72-
if(!filePath){
73-
filePath = await createQuestionCopy(question,questionDir);
74-
}
75-
console.log(`题目[${questionFileName}]创建完成!\n文件地址为: ${filePath}`)
76-
process.exit(0)

0 commit comments

Comments
 (0)