Skip to content

Commit 4485182

Browse files
committed
feat: add fetch qurtion list
1 parent f3fd27c commit 4485182

File tree

6 files changed

+67
-45
lines changed

6 files changed

+67
-45
lines changed

common/utils/logger/logger.js

+24-9
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,36 @@ import { getStore } from '#common/utils/store/controller/store.js'
33

44
class Logger {
55
constructor(env) {
6-
console.log(
7-
chalk.bgGray(`[logger init] The current env is ${env ?? 'not plugin'}.`)
8-
)
6+
// console.log(
7+
// chalk.bgGray(`[logger init] The current env is ${env ?? 'not plugin'}.`)
8+
// )
99
}
1010

11-
info(message) {
12-
console.log(chalk.blue(message))
11+
/**
12+
* 普通消息
13+
* @param message
14+
* @param args
15+
*/
16+
info(message, ...args) {
17+
console.log(chalk.blue(message, ...args))
1318
}
1419

15-
warn(message) {
16-
console.log(chalk.yellow(message))
20+
/**
21+
* 警告
22+
* @param message
23+
* @param args
24+
*/
25+
warn(message, ...args) {
26+
console.log(chalk.yellow(message, ...args))
1727
}
1828

19-
error(message) {
20-
console.log(chalk.red(message))
29+
/**
30+
* 错误信息
31+
* @param message
32+
* @param args
33+
*/
34+
error(message, ...args) {
35+
console.log(chalk.red(message, ...args))
2136
}
2237
}
2338
const { env = null } = (await getStore('config')) ?? {}

common/utils/question-handler/code.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { DefaultLang } from '#common/constants/question.const.js'
1414
*/
1515
export async function getCodeBySlug(slug, lang) {
1616
const list = await getQuestionCodeList(slug)
17-
return list.find((o) => o.langSlug === lang)?.code
17+
return list?.find((o) => o.langSlug === lang)?.code
1818
}
1919
/**
2020
* 获取支持的代码语言

common/utils/question-handler/getHot100QuestionListCode.js

-26
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { createQuestionByTitleSlug } from '../create-check/createUtil.js'
2+
import { getPlanQuestionList } from '#common/utils/question-getter/getPlanQuestionList.js'
3+
import { logger } from '#common/utils/logger/logger.js'
4+
5+
// 获取创建promise列表
6+
async function createCreatePromiseList(slugList, baseDir = process.cwd()) {
7+
return slugList.map((titleSlug) => {
8+
return createQuestionByTitleSlug(titleSlug, baseDir)
9+
})
10+
}
11+
12+
/**
13+
* 創建題目列表通過plan slug
14+
* @param slug
15+
* @param baseDir
16+
*/
17+
export async function getQuestionListCodeBySlug(slug, baseDir) {
18+
const { planSubGroups } = await getPlanQuestionList(slug)
19+
const questionTitleList = planSubGroups.reduce((acc, cur) => {
20+
acc.push(...cur.questions.map((res) => res.titleSlug))
21+
return acc
22+
}, [])
23+
const promiseList = await createCreatePromiseList(questionTitleList, baseDir)
24+
return await Promise.allSettled(promiseList)
25+
}

common/view/finder.view.js

+16-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import select, { Separator } from '@inquirer/select'
22
import input from '@inquirer/input'
3-
4-
// import { getHot100QuestionListCode } from '#common/utils/question-handler/getHot100QuestionListCode.js'
53
import {
64
createQuestionById,
75
createQuestionByTitleSlug
@@ -10,6 +8,8 @@ import { getQuestionByKeyword } from '#common/utils/question-getter/getQuestionB
108
import { getStudyPlanList } from '#common/utils/question-getter/getStudyPlanList.js'
119
import { getPlanQuestionList } from '#common/utils/question-getter/getPlanQuestionList.js'
1210
import { logger } from '#common/utils/logger/logger.js'
11+
import { getQuestionListCodeBySlug } from '#common/utils/question-handler/getQuestionListCodeBySlug.js'
12+
import path from 'node:path'
1313

1414
function handleQuestionList(list) {
1515
return list.map((item) => ({
@@ -19,11 +19,15 @@ function handleQuestionList(list) {
1919
}
2020

2121
async function studyMode(baseDir = process.cwd()) {
22-
const sprintInterviewCompanylist = await getStudyPlanList('sprint-interview-company')
23-
const crackingCodingInterviewList = await getStudyPlanList('cracking-coding-interview')
22+
const sprintInterviewCompanyList = await getStudyPlanList(
23+
'sprint-interview-company'
24+
)
25+
const crackingCodingInterviewList = await getStudyPlanList(
26+
'cracking-coding-interview'
27+
)
2428
const deepDiveTopicsList = await getStudyPlanList('deep-dive-topics')
2529
const questionList = [
26-
...handleQuestionList(sprintInterviewCompanylist),
30+
...handleQuestionList(sprintInterviewCompanyList),
2731
new Separator(),
2832
...handleQuestionList(crackingCodingInterviewList),
2933
new Separator(),
@@ -39,7 +43,7 @@ async function studyMode(baseDir = process.cwd()) {
3943
message: '拉题模式',
4044
choices: [
4145
{ name: '单个选择', value: 'single' },
42-
{ name: '全部拉取(暂不支持)', value: 'all' }
46+
{ name: '全部拉取(不穩定)', value: 'all' }
4347
]
4448
})
4549
if (createMode === 'single') {
@@ -67,8 +71,12 @@ async function studyMode(baseDir = process.cwd()) {
6771

6872
await createQuestionByTitleSlug(singleChoice, baseDir)
6973
}
70-
if (createMode === 'all') logger.warn('暂不支持')
71-
// await getHot100QuestionListCode()
74+
if (createMode === 'all') {
75+
await getQuestionListCodeBySlug(
76+
planSlug,
77+
path.resolve(baseDir, planSlug.toString())
78+
)
79+
}
7280
}
7381

7482
async function keywordMode(baseDir = process.cwd()) {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@
6565
"@vitest/coverage-v8": "^1.2.2",
6666
"commitizen": "^4.2.5",
6767
"cz-conventional-changelog": "^3.3.0",
68-
"eslint-plugin-prettier": "^5.1.3",
6968
"esbuild": "^0.20.0",
7069
"eslint": "^8.57.0",
7170
"eslint-config-airbnb-base": "^15.0.0",
7271
"eslint-config-prettier": "^9.1.0",
7372
"eslint-plugin-import": "^2.29.1",
73+
"eslint-plugin-prettier": "^5.1.3",
7474
"gradient-string": "^2.0.2",
7575
"husky": "^8.0.1",
7676
"lint-staged": "^15.2.2",

0 commit comments

Comments
 (0)