From 3b7e129b722391b50d32e48e782f244a12faad05 Mon Sep 17 00:00:00 2001 From: EternalHeart <48346853+wh131462@users.noreply.github.com> Date: Mon, 11 Mar 2024 23:35:22 +0800 Subject: [PATCH] feat: change lf feature and update docs (#27) * fix: delete hot100 add study plan list * fix: delete hot100 add study plan list * fix: change plan list question title to cn * fix: change plan list question title to cn * fix: get all is not success * fix: get all is not success * chore: pkg config * chore: del pkg config * chore: modify package.json * chore: modify code * chore: del some * * chore: modify docs * chore: del test hot 100 --------- Co-authored-by: SmallTeddy --- .gitignore | 1 + README.md | 12 +-- README_CN.md | 74 ++++++++++--------- README_JP.md | 62 ++++++++-------- .../question-getter/getPlanQuestionList.js | 10 +++ .../question-getter/getQuestionListHot100.js | 10 --- .../utils/question-getter/getStudyPlanList.js | 10 +++ .../getHot100QuestionListCode.js | 4 +- common/view/finder.view.js | 53 ++++++++----- package.json | 12 +-- ...tHot100Json.js => planQuestionListJson.js} | 4 +- resources/headers/studyPlanListJson.js | 7 ++ test/getHot100List.spec.js | 10 --- 13 files changed, 149 insertions(+), 120 deletions(-) create mode 100644 common/utils/question-getter/getPlanQuestionList.js delete mode 100644 common/utils/question-getter/getQuestionListHot100.js create mode 100644 common/utils/question-getter/getStudyPlanList.js rename resources/headers/{questionListHot100Json.js => planQuestionListJson.js} (56%) create mode 100644 resources/headers/studyPlanListJson.js delete mode 100644 test/getHot100List.spec.js diff --git a/.gitignore b/.gitignore index efaa728..5de262b 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,7 @@ resources/stores/* # cli-dist pl-cli */colorFont.js +pl-build # package manager yarn.lock diff --git a/README.md b/README.md index 07cff55..c337ed5 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Then, `leetcode-practice` is all you need! ### 0. Prerequisites | Tool | Remarks | -|----------|:-----------------------------------------------:| +| -------- | :---------------------------------------------: | | nodejs | lts | | git | lts | | computer | Ability to run Chrome and a code editor | @@ -230,7 +230,7 @@ npm i --save-dev leetcode-practice `KFC` is a simple mnemonic that can quickly remember our three core commands: `lk`, `lf`, and `lc`. | Command | Explanation | -|---------|-----------------------------------------------------------------------------------------------------------------------------------| +| ------- | --------------------------------------------------------------------------------------------------------------------------------- | | lc | Core creation command, supports three creation modes (daily question, specified question, random question) for creating questions | | lk | Core checking command, supports three modes corresponding to the question for checking questions | | lf | Core search command, which can quickly search for the question you want based on prompts | @@ -238,7 +238,7 @@ npm i --save-dev leetcode-practice #### [1]. lc | Short Parameter | Full Parameter | Explanation | -|------------------------|----------------|-------------------------------------------------------------------------| +| ---------------------- | -------------- | ----------------------------------------------------------------------- | | No parameter / `-t` | `--today` | Create today's daily question | | Question number / `-i` | `--identity` | Create the question corresponding to the specified number | | `-r` | `--random` | Create a random question that has not appeared in the current directory | @@ -247,7 +247,7 @@ npm i --save-dev leetcode-practice #### [2]. lk | Short Parameter | Full Parameter | Explanation | -|------------------------|----------------|---------------------------------------------------------------------------------------------------------------------------------------------------| +| ---------------------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | | No parameter / `-t` | `--today` | Check today's daily question | | Question number / `-i` | `--identity` | Check the question corresponding to the specified number, and check if the question with the specified ID exists in the current working directory | | `-r` | `--random` | Check the question created using the random mode last time | @@ -259,13 +259,13 @@ npm i --save-dev leetcode-practice #### [3]. lf | Short Parameter | Full Parameter | Explanation | -|-----------------|----------------|---------------------------------------------------------------------------| +| --------------- | -------------- | ------------------------------------------------------------------------- | | No parameter | None | Enter interactive search, and search or filter questions based on prompts | #### [4]. General Parameters | Short Parameter | Full Parameter | Explanation | -|------------------|---------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| ---------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `-d ` | `--directory ` | Specify the working directory (a relative address of the current execution directory), which will affect the creation and checking | | `-V` | `--version` | Check the version number | | `-h` | `--help` | Get help information | diff --git a/README_CN.md b/README_CN.md index 6a06ee3..0d364a1 100644 --- a/README_CN.md +++ b/README_CN.md @@ -24,10 +24,10 @@ ### 0. 预备条件 -| 工具 | 备注 | -|----------|:----------------:| -| nodejs | lts | -| git | lts | +| 工具 | 备注 | +| -------- | :------------------------: | +| nodejs | lts | +| git | lts | | computer | 能够运行chrome和代码编辑器 | | patience | 一颗能够坚持刷题的心 | @@ -36,7 +36,9 @@ > git:[git下载地址](https://git-scm.com/downloads) ### 1. 我可以怎么用? (三种方案供你选择) + #### 方案A.脚手架 CLI (推荐) + 此方案是最为推荐的使用方案,通过脚手架指令`lc`、`lk`、`lf`自由灵活的在任意的目录中创建并检查你的题解。 > 使用预览 @@ -45,7 +47,7 @@ 如果你想要快速的创建一个自己的题解库,可以使用我们的模板项目进行快速的创建github项目,并且获得完善的初始化内容。 -> 使用预览 +> 使用预览 #### 方案C.插件 Plugin (支持,待开发) @@ -54,11 +56,12 @@ > 使用预览 ### 2. 我应该怎么用?(三种方案的详细的安装和使用教程) + #### 方案A.脚手架 CLI ##### 1.安装 -你可以使用任意一款npm包管理软件(例如*`*npm*`*,*`*yarn*`*,*`*pnpm*`*等)的在`项目`中或者`全局`进行安装。 +你可以使用任意一款npm包管理软件(例如`npm`,`yarn`,`pnpm`等)的在`项目`中或者`全局`进行安装。 ```shell # 示例:全局安装 @@ -179,7 +182,7 @@ MODE: identity e.g. 以我个人的项目为例 -```shell +```shell # 这里只是示例,请拉取自己的项目(在你看到这进行尝试的时候,此项目可能已经被清理,正常现象请勿疑惑) git clone git@github.com:wh131462/my-leetcode-practice.git # 移动进项目目录 @@ -200,15 +203,16 @@ yarn lc ``` 你也可以使用指令`lc`来创建,当然,你只能在项目中使用我们的脚本(如果你没有全局安装`leetcode-practice`的话)。 + ```shell # 使用lc 会在当前工作目录创建 如果 需要和脚本的表现保持一致(指在src目录下创建),请使用 -d src 参数 lc ``` > 注意:在这里进行一下强调,项目内指令的说法是指指令的作用范围限制是当前的项目目录,也就是说在其他的目录,你尝试使用lc指令会发现不起作用。 -> +> > 同样的,你也会发现在第一次安装好的时候,在项目内使用lc指令,也是不起作用的,这个时候需要关闭终端(terminal)再打开进行手动的刷新缓存。 -> +> > npm脚本指在 package.json 中的 scripts 字段下封装的脚本指令。 ###### 3. 更新依赖 @@ -230,48 +234,48 @@ npm i --save-dev leetcode-practice `KFC`是一个简便记法,可以快速记忆我们的三个核心指令:`lk`,`lf`,`lc`。 -| 指令 | 说明 | -|----|--------------------------------------------------------| -| lc | 核心创建指令,支持三种创建模式 ( 每日一题、指定题目、随机题目 ) 进行题目的创建 | -| lk | 核心检查指令,支持三种模式对应的题目检测 | -| lf | 核心查找指令,可以快捷的搜索你想要的题目,支持Hot100,关键词搜索,条件筛选等模式进行搜索题目并支持创建 | +| 指令 | 说明 | +| ---- | ------------------------------------------------------------------------------------------------------ | +| lc | 核心创建指令,支持三种创建模式 ( 每日一题、指定题目、随机题目 ) 进行题目的创建 | +| lk | 核心检查指令,支持三种模式对应的题目检测 | +| lf | 核心查找指令,可以快捷的搜索你想要的题目,支持Hot100,关键词搜索,条件筛选等模式进行搜索题目并支持创建 | #### [1].lc -| 简单参数 | 完整参数 | 说明 | -|-----------|--------------|------------------| -| 无参数/`-t` | `--today` | 创建今日的每日一题 | -| 题目编号/`-i` | `--identity` | 创建指定编号对应的题目 | -| `-r` | `--random` | 创建当前目录下未出现过的随机题目 | -| `-e` | `--easy` | 交互式创建题目 | +| 简单参数 | 完整参数 | 说明 | +| ------------- | ------------ | -------------------------------- | +| 无参数/`-t` | `--today` | 创建今日的每日一题 | +| 题目编号/`-i` | `--identity` | 创建指定编号对应的题目 | +| `-r` | `--random` | 创建当前目录下未出现过的随机题目 | +| `-e` | `--easy` | 交互式创建题目 | #### [2].lk -| 简单参数 | 完整参数 | 说明 | -|-----------|--------------|--------------------------------------| -| 无参数/`-t` | `--today` | 检查今日的每日一题 | +| 简单参数 | 完整参数 | 说明 | +| ------------- | ------------ | ---------------------------------------------------------------------- | +| 无参数/`-t` | `--today` | 检查今日的每日一题 | | 题目编号/`-i` | `--identity` | 检查指定编号对应的题目,会检查当前工作目录下的是否存在指定id对应的题目 | -| `-r` | `--random` | 检查上一次使用随机模式创建的题目 | -| `-e` | `--easy` | 交互式的根据提示去检查对应的题目 | +| `-r` | `--random` | 检查上一次使用随机模式创建的题目 | +| `-e` | `--easy` | 交互式的根据提示去检查对应的题目 | > 注意: 当你检测的时候需要注意,使用什么模式去检查,请确保你已经执行过对应模式的创建操作。 > 指定编号模式除外,因为会优先检查指定的id是否在当前工作目录存在。 #### [3].lf -| 简单参数 | 完整参数 | 说明 | -|------|------|---------------------------| -| 无参数 | 无 | 进入交互式查询,可根据提示搜索或筛选题目并创建题目 | +| 简单参数 | 完整参数 | 说明 | +| -------- | -------- | -------------------------------------------------- | +| 无参数 | 无 | 进入交互式查询,可根据提示搜索或筛选题目并创建题目 | #### [4].通用参数 -| 简单参数 | 完整参数 | 说明 | -|------------------|---------------------------|---------------------------------------------------------------------------| -| `-d ` | `--directory ` | 指定工作目录(是一个当前执行目录的相对地址),会影响创建和检查 | -| `-V` | `--version` | 检查版本号 | -| `-h` | `--help` | 获取帮助信息 | +| 简单参数 | 完整参数 | 说明 | +| ---------------- | ------------------------- | ---------------------------------------------------------------------------------------------------------------------- | +| `-d ` | `--directory ` | 指定工作目录(是一个当前执行目录的相对地址),会影响创建和检查 | +| `-V` | `--version` | 检查版本号 | +| `-h` | `--help` | 获取帮助信息 | | `-l [language]` | `--language [language]` | 不指定参数为获取当前的语言环境(默认为javascript),指定参数可以设置语言环境为对应语言(如`-l java`可以指定语言环境为java) | -| `-u` | `--update` | 更新当前脚本或者依赖 | +| `-u` | `--update` | 更新当前脚本或者依赖 | > 注意:通用参数指三个脚本`lk`,`lf`,`lc`都支持的参数,使用上的语义一般来说是相同的,但是可能有些指令上的行为含义会有所不同(比如`lc`指令指定`-d`参数是指`在指定目录中创建题目`,而`lk`指令指定`-d`参数就是指`在指定目录创建题目`)。 @@ -293,4 +297,4 @@ npm i --save-dev leetcode-practice ### 3.Star趋势图 -[![Star History Chart](https://api.star-history.com/svg?repos=EternalHeartTeam/leetcode-practice&type=Date)](https://star-history.com/#EternalHeartTeam/leetcode-practice&Date) \ No newline at end of file +[![Star History Chart](https://api.star-history.com/svg?repos=EternalHeartTeam/leetcode-practice&type=Date)](https://star-history.com/#EternalHeartTeam/leetcode-practice&Date) diff --git a/README_JP.md b/README_JP.md index 100b9da..ae0b4dd 100644 --- a/README_JP.md +++ b/README_JP.md @@ -24,12 +24,12 @@ ### 0.前提条件 -| ツール | 備考 | -|--------|:---------------------------:| -| nodejs | lts | -| git | lts | +| ツール | 備考 | +| ------------ | :----------------------------------------------: | +| nodejs | lts | +| git | lts | | コンピュータ | chromeとコードエディタを実行できる必要があります | -| 我慢 | 問題を解き続けるための心 | +| 我慢 | 問題を解き続けるための心 | > ノート: nodejs:[nodejsのインストールガイド](https://nodejs.org/en/learn/getting-started/how-to-install-nodejs) > @@ -225,48 +225,48 @@ npm i --save-dev leetcode-practice `KFC`は、当社の3つの主要コマンド`lk`、`lf`、`lc`を素早く覚えるための簡単な記憶法です。 -| コマンド | 説明 | -|------|---------------------------------------------------------------| -| lc | 主要な作成コマンドであり、3つの作成モード(毎日の問題、指定された問題、ランダムな問題)をサポートし、問題の作成を行います | -| lk | 主要なチェックコマンドであり、3つのモードに対応する問題のチェックを行います | -| lf | 主要な検索コマンドであり、Hot100、キーワード検索、条件検索などのモードで問題を検索し、問題を作成します | +| コマンド | 説明 | +| -------- | ------------------------------------------------------------------------------------------------------------------------- | +| lc | 主要な作成コマンドであり、3つの作成モード(毎日の問題、指定された問題、ランダムな問題)をサポートし、問題の作成を行います | +| lk | 主要なチェックコマンドであり、3つのモードに対応する問題のチェックを行います | +| lf | 主要な検索コマンドであり、Hot100、キーワード検索、条件検索などのモードで問題を検索し、問題を作成します | #### [1]. lc (問題の作成) -| 簡易パラメータ | 完全パラメータ | 説明 | -|-----------|--------------|------------------------| -| 無し/`-t` | `--today` | 今日の毎日の問題を作成します。 | -| 問題番号/`-i` | `--identity` | 指定された番号に対応する問題を作成します。 | -| `-r` | `--random` | まだ現れていないランダムな問題を作成します。 | -| `-e` | `--easy` | インタラクティブに問題を作成します。 | +| 簡易パラメータ | 完全パラメータ | 説明 | +| -------------- | -------------- | -------------------------------------------- | +| 無し/`-t` | `--today` | 今日の毎日の問題を作成します。 | +| 問題番号/`-i` | `--identity` | 指定された番号に対応する問題を作成します。 | +| `-r` | `--random` | まだ現れていないランダムな問題を作成します。 | +| `-e` | `--easy` | インタラクティブに問題を作成します。 | #### [2]. lk (問題のチェック) -| 簡易パラメータ | 完全パラメータ | 説明 | -|-----------|--------------|------------------------------------------------------------| -| 無し/`-t` | `--today` | 今日の毎日の問題をチェックします。 | -| 問題番号/`-i` | `--identity` | 指定された番号に対応する問題をチェックします。指定されたIDが現在の作業ディレクトリに存在するかどうかも確認します。 | -| `-r` | `--random` | 最後に使用されたランダムモードで作成された問題をチェックします。 | -| `-e` | `--easy` | インタラクティブにプロンプトに従って問題をチェックします。 | +| 簡易パラメータ | 完全パラメータ | 説明 | +| -------------- | -------------- | ------------------------------------------------------------------------------------------------------------------ | +| 無し/`-t` | `--today` | 今日の毎日の問題をチェックします。 | +| 問題番号/`-i` | `--identity` | 指定された番号に対応する問題をチェックします。指定されたIDが現在の作業ディレクトリに存在するかどうかも確認します。 | +| `-r` | `--random` | 最後に使用されたランダムモードで作成された問題をチェックします。 | +| `-e` | `--easy` | インタラクティブにプロンプトに従って問題をチェックします。 | > 注意: チェックする際は、どのモードを使用するかに注意してください。対応するモードの作成操作をすでに実行したことを確認してください。 > 指定番号モードは例外であり、作成されていない問題をチェックすることもできます。 #### [3]. lf (問題の検索) -| 簡易パラメータ | 完全パラメータ | 説明 | -|---------|---------|------------------------------------------------------| -| 無し | 無し | インタラクティブにクエリに入り、ヒントに従って問題を検索したりフィルタリングしたりして問題を作成します。 | +| 簡易パラメータ | 完全パラメータ | 説明 | +| -------------- | -------------- | -------------------------------------------------------------------------------------------------------- | +| 無し | 無し | インタラクティブにクエリに入り、ヒントに従って問題を検索したりフィルタリングしたりして問題を作成します。 | #### [4]. 汎用パラメータ -| 簡易パラメータ | 完全パラメータ | 説明 | -|------------------|---------------------------|-------------------------------------------------------------------------------------------------| -| `-d ` | `--directory ` | 作業ディレクトリを指定します(現在の実行ディレクトリの相対パス)。これは作成とチェックの両方に影響を与えます。 | -| `-V` | `--version` | バージョン番号を確認します。 | -| `-h` | `--help` | ヘルプ情報を取得します。 | +| 簡易パラメータ | 完全パラメータ | 説明 | +| ---------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `-d ` | `--directory ` | 作業ディレクトリを指定します(現在の実行ディレクトリの相対パス)。これは作成とチェックの両方に影響を与えます。 | +| `-V` | `--version` | バージョン番号を確認します。 | +| `-h` | `--help` | ヘルプ情報を取得します。 | | `-l [language]` | `--language [language]` | パラメータなしで現在の言語環境を取得します(デフォルトはJavaScript)。言語を指定すると、その言語の環境が設定されます(たとえば、`-l java`でJavaの環境が設定されます)。 | -| `-u` | `--update` | 現在のスクリプトまたは依存関係を更新します。 | +| `-u` | `--update` | 現在のスクリプトまたは依存関係を更新します。 | > 注意: 汎用パラメータは`lk`,`lf`,`lc`の3つのスクリプトでサポートされていますが、その使用法の意味論は一般的には同じですが、いくつかの指示には異なる挙動が含まれる場合があります(たとえば、`lc`コマンドで`-d`パラメータを指定した場合は、`指定したディレクトリ内で問題を作成`するのに対し、`lk`コマンドで`-d`パラメータを指定すると`指定したディレクトリに問題をチェック`します)。 diff --git a/common/utils/question-getter/getPlanQuestionList.js b/common/utils/question-getter/getPlanQuestionList.js new file mode 100644 index 0000000..0b5e54f --- /dev/null +++ b/common/utils/question-getter/getPlanQuestionList.js @@ -0,0 +1,10 @@ +import { graphql } from '#common/utils/http/graphql.js' +import { getPlanQuestionListJson } from '#resources/headers/planQuestionListJson.js' + +export async function getPlanQuestionList(slug) { + const res = await graphql(getPlanQuestionListJson(slug)) + const { + data: { studyPlanV2Detail } + } = res + return studyPlanV2Detail +} diff --git a/common/utils/question-getter/getQuestionListHot100.js b/common/utils/question-getter/getQuestionListHot100.js deleted file mode 100644 index 2c1f32b..0000000 --- a/common/utils/question-getter/getQuestionListHot100.js +++ /dev/null @@ -1,10 +0,0 @@ -import { graphql } from '#common/utils/http/graphql.js' -import { getQuestionListHot100Json } from '#resources/headers/questionListHot100Json.js' - -export async function getQuestionListHot100() { - const res = await graphql(getQuestionListHot100Json()) - const { - data: { studyPlanV2Detail } - } = res - return studyPlanV2Detail -} diff --git a/common/utils/question-getter/getStudyPlanList.js b/common/utils/question-getter/getStudyPlanList.js new file mode 100644 index 0000000..e1cc5fd --- /dev/null +++ b/common/utils/question-getter/getStudyPlanList.js @@ -0,0 +1,10 @@ +import { graphql } from '#common/utils/http/graphql.js' +import { getStudyPlanListJson } from '#resources/headers/studyPlanListJson.js' + +export async function getStudyPlanList() { + const res = await graphql(getStudyPlanListJson()) + const { + data: { studyPlansV2AdQuestionPage } + } = res + return studyPlansV2AdQuestionPage +} diff --git a/common/utils/question-handler/getHot100QuestionListCode.js b/common/utils/question-handler/getHot100QuestionListCode.js index 752f88b..d3a6d8b 100644 --- a/common/utils/question-handler/getHot100QuestionListCode.js +++ b/common/utils/question-handler/getHot100QuestionListCode.js @@ -1,10 +1,10 @@ import path from 'node:path' import { createQuestionByTitleSlug } from '../create-check/createUtil.js' -import { getQuestionListHot100 } from '#common/utils/question-getter/getQuestionListHot100.js' +import { getPlanQuestionList } from '#common/utils/question-getter/getPlanQuestionList.js' // 获取题目列表 export async function getTitleSlugList() { - const res = await getQuestionListHot100() + const res = await getPlanQuestionList() const { planSubGroups } = res return planSubGroups.reduce((acc, cur) => { acc.push(...cur.questions.map((res) => res.titleSlug)) diff --git a/common/view/finder.view.js b/common/view/finder.view.js index b190155..c10ef78 100644 --- a/common/view/finder.view.js +++ b/common/view/finder.view.js @@ -1,38 +1,58 @@ import select from '@inquirer/select' import input from '@inquirer/input' -import { - getHot100QuestionListCode, - getTitleSlugList -} from '#common/utils/question-handler/getHot100QuestionListCode.js' +// import { getHot100QuestionListCode } from '#common/utils/question-handler/getHot100QuestionListCode.js' import { createQuestionById, createQuestionByTitleSlug } from '#common/utils/create-check/createUtil.js' import { getQuestionByKeyword } from '#common/utils/question-getter/getQuestionByKeyword.js' +import { getStudyPlanList } from '#common/utils/question-getter/getStudyPlanList.js' +import { getPlanQuestionList } from '#common/utils/question-getter/getPlanQuestionList.js' -async function hotMode(baseDir = process.cwd()) { +async function studyMode(baseDir = process.cwd()) { + const questionList = await getStudyPlanList() + const planListMode = { + message: '请选择学习计划', + choices: questionList.map((item) => ({ + name: `${item.name}${item.premiumOnly ? '(VIP)' : ''}`, + value: item.slug + })) + } + const planSlug = await select(planListMode) const createMode = await select({ message: '拉题模式', choices: [ { name: '单个选择', value: 'single' }, - { name: '全部拉取', value: 'all' } + { name: '全部拉取(暂不支持)', value: 'all' } ] }) if (createMode === 'single') { - const titleSlugList = await getTitleSlugList() + const { planSubGroups } = await getPlanQuestionList(planSlug) + const planList = planSubGroups.reduce((acc, cur) => { + acc.push( + ...cur.questions.map((res) => { + return { + cnTitle: res.translatedTitle, + enTitle: res.titleSlug + } + }) + ) + return acc + }, []) const singleMode = { message: '请选择题目?', - choices: titleSlugList.map((res) => ({ - name: res, - value: res + choices: planList.map((res) => ({ + name: res.cnTitle, + value: res.enTitle })) } const singleChoice = await select(singleMode) await createQuestionByTitleSlug(singleChoice, baseDir) } - if (createMode === 'all') await getHot100QuestionListCode() + if (createMode === 'all') console.log('暂不支持') + // await getHot100QuestionListCode() } async function keywordMode(baseDir = process.cwd()) { @@ -54,6 +74,7 @@ async function keywordMode(baseDir = process.cwd()) { console.log(chooseQuestion) await createQuestionById(chooseQuestion, baseDir) } + async function selectMode(baseDir) { console.log(baseDir) } @@ -61,12 +82,8 @@ async function selectMode(baseDir) { export async function easyFinderView(baseDir = process.cwd()) { const choices = [ { name: '关键词搜索', value: 'keyword', description: '关键词描述' }, - { - name: 'hot 100列表查询', - value: 'hot', - description: '最受欢迎的100道题目' - } - // { name: '筛选模式', value: 'select', description: '筛选题目' } + { name: '学习计划', value: 'study', description: '企业和经典面试题目列表' }, + { name: '筛选模式', value: 'select', description: '筛选题目' } ] const modeQuestion = { @@ -76,7 +93,7 @@ export async function easyFinderView(baseDir = process.cwd()) { const mode = await select(modeQuestion) const modeMap = { - hot: hotMode, + study: studyMode, keyword: keywordMode, select: selectMode } diff --git a/package.json b/package.json index 1f13d79..d56cdca 100644 --- a/package.json +++ b/package.json @@ -51,14 +51,9 @@ "chalk": "^5.3.0", "commander": "^12.0.0", "console-table-printer": "^2.12.0", - "eslint-config-prettier": "^9.1.0", - "eslint-plugin-prettier": "^5.1.3", "glob": "^10.3.10", "inquirer": "^9.2.14", - "lint-staged": "^15.2.2", - "prettier": "^3.2.5", - "realm": "^11.0.0", - "request": "^2.88.2" + "realm": "^11.0.0" }, "devDependencies": { "@antfu/eslint-config": "^2.8.0", @@ -73,11 +68,16 @@ "esbuild": "^0.20.0", "eslint": "^8.57.0", "eslint-config-airbnb-base": "^15.0.0", + "eslint-config-prettier": "^9.1.0", "eslint-plugin-import": "^2.29.1", + "eslint-plugin-prettier": "^5.1.3", "gradient-string": "^2.0.2", "husky": "^8.0.1", + "lint-staged": "^15.2.2", + "prettier": "^3.2.5", "release-it": "^17.1.1", "rimraf": "^5.0.5", + "typescript": "^5.4.2", "vite": "^5.0.11", "vitest": "^1.2.2" }, diff --git a/resources/headers/questionListHot100Json.js b/resources/headers/planQuestionListJson.js similarity index 56% rename from resources/headers/questionListHot100Json.js rename to resources/headers/planQuestionListJson.js index 2d3707d..e08d174 100644 --- a/resources/headers/questionListHot100Json.js +++ b/resources/headers/planQuestionListJson.js @@ -2,10 +2,10 @@ * 获取hot 100 的请求header * @returns {{headers: {"content-type": string}, method: string, body: string}} */ -export function getQuestionListHot100Json() { +export function getPlanQuestionListJson(slug) { return { headers: { 'content-type': 'application/json' }, - body: '{"query":"\\n query studyPlanPastSolved($slug: String!) {\\n studyPlanV2Detail(planSlug: $slug) {\\n planSubGroups {\\n slug\\n questions {\\n titleSlug\\n status\\n }\\n }\\n }\\n}\\n ","variables":{"slug":"top-100-liked"},"operationName":"studyPlanPastSolved"}', + body: `{"query":"\\n query studyPlanPastSolved($slug: String!) {\\n studyPlanV2Detail(planSlug: $slug) {\\n planSubGroups {\\n slug\\n questions {\\n titleSlug\\n translatedTitle\\n status\\n }\\n }\\n }\\n}\\n ","variables":{"slug":"${slug}"},"operationName":"studyPlanPastSolved"}`, method: 'POST' } } diff --git a/resources/headers/studyPlanListJson.js b/resources/headers/studyPlanListJson.js new file mode 100644 index 0000000..ef910a7 --- /dev/null +++ b/resources/headers/studyPlanListJson.js @@ -0,0 +1,7 @@ +export function getStudyPlanListJson() { + return { + headers: { 'content-type': 'application/json' }, + body: '{"query":"\\n query GetProblemSetStudyPlanAds {\\n studyPlansV2AdQuestionPage {\\n cover\\n highlight\\n name\\n onGoing\\n premiumOnly\\n questionNum\\n slug\\n }\\n}\\n ","variables":{},"operationName":"GetProblemSetStudyPlanAds"}', + method: 'POST' + } +} diff --git a/test/getHot100List.spec.js b/test/getHot100List.spec.js deleted file mode 100644 index 8b74225..0000000 --- a/test/getHot100List.spec.js +++ /dev/null @@ -1,10 +0,0 @@ -import { describe, expect, it } from 'vitest' -import { getQuestionListHot100 } from '#common/utils/question-getter/getQuestionListHot100.js' - -describe('hot 100获取数据测试', () => { - it('是否正确获取了hot 100合集', async () => { - const res = await getQuestionListHot100() - - expect(Object.keys(res)).toStrictEqual(['planSubGroups']) - }) -})