|
| 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 | + |
0 commit comments