From 70377d0f547a0402ee639437b581b0aa7a840608 Mon Sep 17 00:00:00 2001 From: Kaiyi Date: Tue, 28 Feb 2023 12:18:43 +0800 Subject: [PATCH] chore: add prettier-plugin-tailwindcss, upgrade husky and lint-staged (#329) --- .github/stale.yml | 3 +- .husky/pre-commit | 6 + .prettierrc | 3 +- docker-compose.yaml | 11 +- docs/tobuildwordbook.md | 26 +- package.json | 44 +- src/components/Footer/index.tsx | 26 +- src/components/Header/index.tsx | 10 +- src/components/InfoPanel/index.tsx | 14 +- src/components/Layout.tsx | 2 +- src/components/Main/index.tsx | 2 +- src/components/Modals/index.tsx | 26 +- src/components/Phonetic/index.tsx | 2 +- src/components/ResultScreen/ConclusionBar.tsx | 4 +- src/components/ResultScreen/RemarkRing.tsx | 8 +- src/components/ResultScreen/index.tsx | 28 +- src/components/Speed/InfoBox.tsx | 4 +- src/components/Speed/index.tsx | 2 +- src/components/Tooltip/index.tsx | 4 +- src/components/Translation/index.tsx | 2 +- src/components/Word/Letter/index.tsx | 4 +- src/index.css | 20 +- src/pages/Gallery/ChapterButton.tsx | 6 +- src/pages/Gallery/ChapterGroup.tsx | 2 +- src/pages/Gallery/DictionaryCard.tsx | 4 +- src/pages/Gallery/DictionaryGroup.tsx | 2 +- src/pages/Gallery/index.tsx | 14 +- src/pages/Typing/Progress/index.tsx | 6 +- .../Typing/PronunciationSwitcher/index.tsx | 2 +- src/pages/Typing/Switcher/index.tsx | 2 +- src/pages/Typing/index.tsx | 8 +- tsconfig.json | 12 +- yarn.lock | 436 ++++++++---------- 33 files changed, 342 insertions(+), 403 deletions(-) create mode 100755 .husky/pre-commit diff --git a/.github/stale.yml b/.github/stale.yml index b3641924..e2563a5c 100644 --- a/.github/stale.yml +++ b/.github/stale.yml @@ -7,7 +7,6 @@ exemptLabels: - pinned - security - Category: Announcement - - # Label to use when marking an issue as stale staleLabel: stale-issue # Comment to post when marking an issue as stale. Set to `false` to disable @@ -16,4 +15,4 @@ markComment: > recent activity. It will be closed if no further activity occurs. Thank you for your contributions. # Comment to post when closing a stale issue. Set to `false` to disable -closeComment: false \ No newline at end of file +closeComment: false diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 00000000..e5fe8338 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,6 @@ +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" + +yarn run lint-staged +yarn run eslint . --fix +yarn run prettier --write . \ No newline at end of file diff --git a/.prettierrc b/.prettierrc index 2abe9c0a..44f4cc29 100644 --- a/.prettierrc +++ b/.prettierrc @@ -11,5 +11,6 @@ "files": ".prettierrc", "options": { "parser": "json" } } - ] + ], + "plugins": ["prettier-plugin-tailwindcss"] } diff --git a/docker-compose.yaml b/docker-compose.yaml index d44f3551..63930852 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,12 +1,11 @@ -version: "3" +version: '3' services: qwertylearner: - image: "node:16" - user: "root" - working_dir: "/app/qwerty-learner" - ports: - [8990:3000] + image: 'node:16' + user: 'root' + working_dir: '/app/qwerty-learner' + ports: [8990:3000] volumes: - $PWD/:/app/qwerty-learner command: diff --git a/docs/tobuildwordbook.md b/docs/tobuildwordbook.md index b1311f14..fa562989 100644 --- a/docs/tobuildwordbook.md +++ b/docs/tobuildwordbook.md @@ -1,30 +1,35 @@ ## 如何导入自己的词单 + > 这是一种方法 有更方便的可以继续分享 ### 制作 csv -> 工具: 欧路词典、excel、Numbers表格 +> 工具: 欧路词典、excel、Numbers 表格 #### STEP1 构建自己生词本 + 1. 在欧路词典中 添加一个生词本,并勾选默认添加到此生词本 2. 正常看单词,不会的点击收藏 -> 此收藏会自动添加到设置默认添加的生词本中,请确保默认添加生词本的正确性。 -3. 登陆`my.eudic.net` --> 我的生词本 --> 生词本工具 --> 打印当前列表 --> 复制到excel中 + > 此收藏会自动添加到设置默认添加的生词本中,请确保默认添加生词本的正确性。 + +3. 登陆`my.eudic.net` --> 我的生词本 --> 生词本工具 --> 打印当前列表 --> 复制到 excel 中 + +4. excel 中的格式 -4. excel中的格式 ``` name | trans 单词 | [翻译] ``` -> 翻译一览可以在新的列C使用 `="["&B2&"]"` + +> 翻译一览可以在新的列 C 使用 `="["&B2&"]"` 5. 导出为`csv`格式 ### STEP2 格式处理 -使用`apple`的 `number表格` 删除B列,保留`[翻译]`这一列,同时务必确保只有`name`和 `trans`这两列 +使用`apple`的 `number表格` 删除 B 列,保留`[翻译]`这一列,同时务必确保只有`name`和 `trans`这两列 保存导出为`csv`格式 ### STEP3 csv to json @@ -39,6 +44,7 @@ name | trans 保存 ### STEP5 导入项目文件 + 将该`json`文件导入到`/public/dicts`中 同时修改`/resources/dictionary.ts` 修改格式为: @@ -46,18 +52,22 @@ name | trans ```json { id: 'test', name: 'test', description: 'test', category: '英语学习', url: './dicts/test.json', length: 0 }, ``` + #### 注意 + `length`该字段可以使用`node ./scripts/update-dict-size.js`来进行统计 ## 项目参数 默认端口`3000` `Local:http://localhost:3000` + ## 疑难杂症 -### yarn start失败 +### yarn start 失败 + > 报错:ERR_PACKAGE_PATH_NOT_EXPORTED -尝试删除 `node_modules` 重新`yarn`安装依赖,然后再 `yarn start` +尝试删除 `node_modules` 重新`yarn`安装依赖,然后再 `yarn start` 如果还是失败,请确保`node`版本一致,自行修改当前版本 diff --git a/package.json b/package.json index 4c2854b0..f1ea2a32 100644 --- a/package.json +++ b/package.json @@ -12,31 +12,14 @@ "@fortawesome/react-fontawesome": "^0.1.14", "@headlessui/react": "^0.2.0", "@tailwindcss/postcss7-compat": "^2.0.2", - "@testing-library/jest-dom": "^5.11.4", - "@testing-library/react": "^11.1.0", - "@testing-library/user-event": "^12.1.10", - "@types/howler": "^2.2.3", - "@types/jest": "^26.0.15", - "@types/lodash": "^4.14.168", - "@types/mixpanel-browser": "^2.38.1", - "@types/node": "16", - "@types/react": "^16.9.53", - "@types/react-dom": "^16.9.8", "autoprefixer": "^10.4.13", "classnames": "^2.3.2", "dayjs": "^1.11.7", "eslint": "^7.18.0", - "eslint-config-prettier": "^7.2.0", - "eslint-plugin-prettier": "^3.3.1", - "eslint-plugin-react": "^7.32.2", - "eslint-plugin-react-hooks": "^4.6.0", "howler": "^2.2.3", - "husky": "^4.3.8", - "lint-staged": "^10.5.3", "lodash": "^4.17.20", "mixpanel-browser": "^2.45.0", "postcss": "^8.4.21", - "prettier": "^2.2.1", "react": "^17.0.1", "react-app-polyfill": "^2.0.0", "react-dom": "^17.0.1", @@ -56,7 +39,9 @@ "build": "cross-env CI=false vite build --base=./", "test": "echo \"No tests\"", "lint": "eslint .", - "analyze": "source-map-explorer 'build/static/js/*.js'" + "analyze": "source-map-explorer 'build/static/js/*.js'", + "prettier": "prettier --write .", + "prepare": "husky install" }, "eslintConfig": { "plugins": [ @@ -78,11 +63,6 @@ "prettier/prettier": "error" } }, - "husky": { - "hooks": { - "pre-commit": "lint-staged && eslint . --fix" - } - }, "lint-staged": { "src/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [ "prettier --write" @@ -107,10 +87,28 @@ ] }, "devDependencies": { + "@testing-library/jest-dom": "^5.11.4", + "@testing-library/react": "^11.1.0", + "@testing-library/user-event": "^12.1.10", + "@types/howler": "^2.2.3", + "@types/jest": "^26.0.15", + "@types/lodash": "^4.14.168", + "@types/mixpanel-browser": "^2.38.1", + "@types/node": "16", + "@types/react": "^16.9.53", + "@types/react-dom": "^16.9.8", "@types/react-router-dom": "^5.1.7", "@vitejs/plugin-react": "^3.1.0", "cross-env": "^7.0.3", + "eslint-config-prettier": "^7.2.0", "eslint-config-react-app": "^7.0.1", + "eslint-plugin-prettier": "^3.3.1", + "eslint-plugin-react": "^7.32.2", + "eslint-plugin-react-hooks": "^4.6.0", + "husky": "^8.0.0", + "lint-staged": "^13.1.2", + "prettier": "^2.8.4", + "prettier-plugin-tailwindcss": "^0.2.3", "tailwindcss": "^3.2.6", "vite": "^4.1.1", "vite-plugin-svgr": "^2.4.0" diff --git a/src/components/Footer/index.tsx b/src/components/Footer/index.tsx index e667b332..436e193d 100644 --- a/src/components/Footer/index.tsx +++ b/src/components/Footer/index.tsx @@ -26,7 +26,7 @@ const Footer: React.FC = () => { > {content === 'donate' ? ( <> -
@@ -37,12 +37,12 @@ const Footer: React.FC = () => {

如果您喜欢我们软件,非常感谢您对我们未来的支持!


- alipay + alipay
) : ( <> -
@@ -51,7 +51,7 @@ const Footer: React.FC = () => { 可以在任意文件中一键开启,开启后单词显示在状态栏中,且插件会拦截用户对文档的输入,不会影响到原始文档。



- + GitHub 项目 @@ -63,9 +63,9 @@ const Footer: React.FC = () => { )} )} -
e.currentTarget.blur()}> +
e.currentTarget.blur()}> - + { e.currentTarget.blur() }} > - + { e.currentTarget.blur()}> - +
- + 🇨🇳 -
- 中国大陆镜像 +
+ 中国大陆镜像
{ setShowContent('donate') setShowModal(true) @@ -113,7 +113,7 @@ const Footer: React.FC = () => { @ Qwerty Learner { return ( -