@@ -2,88 +2,82 @@ import inquirer from "inquirer";
2
2
import path from "path" ;
3
3
import { getQuestionFileName } from "#common/utils/question-handler/getQuestionFileName.js" ;
4
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
5
import { getQuestionByMode } from "#common/utils/store/store-realm.js" ;
10
6
import { checkQuestion } from "#common/utils/question-handler/checkQuestion.js" ;
11
7
import { getCountBySameName } from "#common/utils/file/getCountBySameName.js" ;
12
8
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
+ } ] ;
19
17
// 第一个问题 选择的模式
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
+ }
42
40
// 检查题目
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 ) ;
46
44
// 创建路径确认
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 = [ {
55
46
type : 'confirm' ,
56
- name : 'newDirRight ' ,
57
- message : `请选择要检测的目录 ?` ,
47
+ name : 'dirRight ' ,
48
+ message : `是否检测当前目录[ ${ currentDir } ]下的题目[ ${ questionFileName } ] ?` ,
58
49
} ] ;
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 ) {
63
52
const newDirQuestion = [ {
64
53
type : 'input' ,
65
54
name : 'newDir' ,
66
- message : `请选择新目录(基础地址为${ currentDir } ):` ,
55
+ message : `请选择新目录(基础地址为${ currentDir } )[按回车[Enter]终止操作] :` ,
67
56
} ] ;
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 } ` )
70
63
}
71
- }
72
- const questionParentDir = path . dirname ( questionDir ) ;
64
+ const questionParentDir = path . dirname ( questionDir ) ;
73
65
// 先检测有几个副本
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 )
85
82
}
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 ( )
0 commit comments