@@ -7,7 +7,16 @@ import {aim} from "../resources/text/aim.js";
7
7
import { referMode } from "#common/utils/create-check/refer-mode.js" ;
8
8
import { getArgs } from "#common/utils/create-check/get-args.js" ;
9
9
import fs from "fs" ;
10
- const { version} = JSON . parse ( fs . readFileSync ( "package.json" , 'utf-8' ) ) ;
10
+ import { getQuestionToday } from "#common/utils/question-getter/getQuestionToday.js" ;
11
+ import { createQuestion } from "#common/utils/question-handler/createQuestion.js" ;
12
+ import path from "path" ;
13
+ import { getQuestionFileName } from "#common/utils/question-handler/getQuestionFileName.js" ;
14
+ import { createQuestionCopy } from "#common/utils/question-handler/createQuestionCopy.js" ;
15
+ import { getQuestionRandom } from "#common/utils/question-getter/getQuestionRandom.js" ;
16
+ import { getQuestionById } from "#common/utils/question-getter/getQuestionById.js" ;
17
+ import { setQuestion } from "#common/utils/store/store-realm.js" ;
18
+ import { rootPath } from "#common/utils/file/getRootPath.js" ;
19
+ const { version} = JSON . parse ( fs . readFileSync ( path . resolve ( rootPath , "package.json" ) , 'utf-8' ) ) ;
11
20
12
21
program
13
22
. version ( version )
@@ -24,20 +33,42 @@ const cmdOpts = program.opts();
24
33
// 模式对应的action
25
34
const callModeAction = {
26
35
'today' : ( ) => {
27
- // todo 获取今日题目的进程
28
- console . log ( "[leetcode-practice] 获取今日题目" )
36
+ getQuestionToday ( ) . then ( question => {
37
+ setQuestion ( "today" , question ) ;
38
+ const questionDir = path . join ( process . cwd ( ) , getQuestionFileName ( question ) )
39
+ createQuestion ( question , questionDir ) . then ( async ( path ) => {
40
+ if ( ! path ) path = await createQuestionCopy ( question , questionDir ) ;
41
+ console . log ( `[lc] 获取今日题目成功\n题目为[${ question . title } ]\n文件地址为:${ path } ` )
42
+ process . exit ( 0 ) ;
43
+ } )
44
+ } )
29
45
} ,
30
46
'random' : ( ) => {
31
- // todo 获取随机题目的进程
32
- console . log ( "[leetcode-practice] 获取随机题目" )
47
+ getQuestionRandom ( ) . then ( question => {
48
+ setQuestion ( "random" , question ) ;
49
+ const questionDir = path . join ( process . cwd ( ) , getQuestionFileName ( question ) )
50
+ createQuestion ( question , questionDir ) . then ( async ( path ) => {
51
+ if ( ! path ) path = await createQuestionCopy ( question , questionDir ) ;
52
+ console . log ( `[lc] 获取随机题目成功\n题目为[${ question . title } ]\n文件地址为:${ path } ` )
53
+ process . exit ( 0 ) ;
54
+ } )
55
+ } )
33
56
} ,
34
57
'identity' : ( id ) => {
35
- // todo 获取指定题目的进程
36
- console . log ( `[leetcode-practice] 获取指定题目[${ id } ]` )
58
+ getQuestionById ( id ) . then ( question => {
59
+ setQuestion ( "identity" , question ) ;
60
+ const questionDir = path . join ( process . cwd ( ) , getQuestionFileName ( question ) )
61
+ createQuestion ( question , questionDir ) . then ( async ( path ) => {
62
+ if ( ! path ) path = await createQuestionCopy ( question , questionDir ) ;
63
+ console . log ( `[lc] 获取指定题目成功\n题目为[${ question . title } ]\n文件地址为:${ path } ` )
64
+ process . exit ( 0 ) ;
65
+ } )
66
+ } )
37
67
} ,
38
68
}
39
69
// 获取模式和参数
40
70
const mode = referMode ( cmdArgs , cmdOpts ) ;
41
71
const args = getArgs ( mode , cmdArgs , cmdOpts ) ;
42
72
// 执行指令分发
43
- callModeAction [ mode ] ( args ) ;
73
+ await callModeAction [ mode ] ( args ) ;
74
+ //
0 commit comments