|
| 1 | +import inquirer from "inquirer"; |
| 2 | +import path from "path"; |
| 3 | +import {getQuestionFileName} from "#common/utils/question-handler/getQuestionFileName.js"; |
| 4 | +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"; |
| 9 | +import {getQuestionByMode} from "#common/utils/store/store-realm.js"; |
| 10 | +import {checkQuestion} from "#common/utils/question-handler/checkQuestion.js"; |
| 11 | +import {getCountBySameName} from "#common/utils/file/getCountBySameName.js"; |
| 12 | +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 | +}]; |
| 19 | +// 第一个问题 选择的模式 |
| 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 | +} |
| 42 | +// 检查题目 |
| 43 | +const questionFileName = getQuestionFileName(question); |
| 44 | +const currentDir = process.cwd(); |
| 45 | +let questionDir = path.join(currentDir,questionFileName); |
| 46 | +// 创建路径确认 |
| 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 = [{ |
| 55 | + type: 'confirm', |
| 56 | + name: 'newDirRight', |
| 57 | + message: `请选择要检测的目录?`, |
| 58 | + }]; |
| 59 | + const {newDirRight} = await inquirer.prompt(newPathRightQuestion,null); |
| 60 | + if(!newDirRight){ |
| 61 | + console.log("用户取消检测操作") |
| 62 | + }else{ |
| 63 | + const newDirQuestion = [{ |
| 64 | + type: 'input', |
| 65 | + name: 'newDir', |
| 66 | + message: `请选择新目录(基础地址为${currentDir}):`, |
| 67 | + }]; |
| 68 | + const {newDir} = await inquirer.prompt(newDirQuestion,null); |
| 69 | + questionDir = path.join(path.join(process.cwd(),newDir),`${questionFileName}`) |
| 70 | + } |
| 71 | +} |
| 72 | +const questionParentDir = path.dirname(questionDir); |
| 73 | +// 先检测有几个副本 |
| 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}]进行检测`) |
| 85 | +} |
| 86 | +const filePath = path.join(questionDir,"index.js"); |
| 87 | +await checkQuestion(filePath); |
| 88 | +console.log(`题目[${questionFileName}]检查完成!\n文件地址为: ${filePath}`) |
| 89 | +process.exit(0) |
0 commit comments