From 45e84db6d19116b7e91f0363569fc8dae8ec1827 Mon Sep 17 00:00:00 2001 From: LOG1997 <2694233102@qq.com> Date: Wed, 10 Dec 2025 00:10:33 +0800 Subject: [PATCH] =?UTF-8?q?build:=20git=E9=92=A9=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .husky/_/applypatch-msg | 2 ++ .husky/_/commit-msg | 2 ++ .husky/_/h | 22 ++++++++++++++++++++++ .husky/_/husky.sh | 9 +++++++++ .husky/_/post-applypatch | 2 ++ .husky/_/post-checkout | 2 ++ .husky/_/post-commit | 2 ++ .husky/_/post-merge | 2 ++ .husky/_/post-rewrite | 2 ++ .husky/_/pre-applypatch | 2 ++ .husky/_/pre-auto-gc | 2 ++ .husky/_/pre-commit | 2 ++ .husky/_/pre-merge-commit | 2 ++ .husky/_/pre-push | 2 ++ .husky/_/pre-rebase | 2 ++ .husky/_/prepare-commit-msg | 2 ++ .husky/pre-push | 12 ++++++++++++ .husky/scripts/verifyCommit.js | 14 +++++++------- .husky/scripts/verifyTagVersion.js | 30 ++++++++++++++++++++++++++++++ eslint.config.js | 2 +- package.json | 6 ++++-- pnpm-lock.yaml | 8 ++++++++ 22 files changed, 121 insertions(+), 10 deletions(-) create mode 100644 .husky/_/applypatch-msg create mode 100644 .husky/_/commit-msg create mode 100644 .husky/_/h create mode 100644 .husky/_/husky.sh create mode 100644 .husky/_/post-applypatch create mode 100644 .husky/_/post-checkout create mode 100644 .husky/_/post-commit create mode 100644 .husky/_/post-merge create mode 100644 .husky/_/post-rewrite create mode 100644 .husky/_/pre-applypatch create mode 100644 .husky/_/pre-auto-gc create mode 100644 .husky/_/pre-commit create mode 100644 .husky/_/pre-merge-commit create mode 100644 .husky/_/pre-push create mode 100644 .husky/_/pre-rebase create mode 100644 .husky/_/prepare-commit-msg create mode 100644 .husky/pre-push create mode 100644 .husky/scripts/verifyTagVersion.js diff --git a/.husky/_/applypatch-msg b/.husky/_/applypatch-msg new file mode 100644 index 0000000..16aae78 --- /dev/null +++ b/.husky/_/applypatch-msg @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +. "$(dirname "$0")/h" \ No newline at end of file diff --git a/.husky/_/commit-msg b/.husky/_/commit-msg new file mode 100644 index 0000000..16aae78 --- /dev/null +++ b/.husky/_/commit-msg @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +. "$(dirname "$0")/h" \ No newline at end of file diff --git a/.husky/_/h b/.husky/_/h new file mode 100644 index 0000000..bf7c896 --- /dev/null +++ b/.husky/_/h @@ -0,0 +1,22 @@ +#!/usr/bin/env sh +[ "$HUSKY" = "2" ] && set -x +n=$(basename "$0") +s=$(dirname "$(dirname "$0")")/$n + +[ ! -f "$s" ] && exit 0 + +if [ -f "$HOME/.huskyrc" ]; then + echo "husky - '~/.huskyrc' is DEPRECATED, please move your code to ~/.config/husky/init.sh" +fi +i="${XDG_CONFIG_HOME:-$HOME/.config}/husky/init.sh" +[ -f "$i" ] && . "$i" + +[ "${HUSKY-}" = "0" ] && exit 0 + +export PATH="node_modules/.bin:$PATH" +sh -e "$s" "$@" +c=$? + +[ $c != 0 ] && echo "husky - $n script failed (code $c)" +[ $c = 127 ] && echo "husky - command not found in PATH=$PATH" +exit $c diff --git a/.husky/_/husky.sh b/.husky/_/husky.sh new file mode 100644 index 0000000..f9d0637 --- /dev/null +++ b/.husky/_/husky.sh @@ -0,0 +1,9 @@ +echo "husky - DEPRECATED + +Please remove the following two lines from $0: + +#!/usr/bin/env sh +. \"\$(dirname -- \"\$0\")/_/husky.sh\" + +They WILL FAIL in v10.0.0 +" \ No newline at end of file diff --git a/.husky/_/post-applypatch b/.husky/_/post-applypatch new file mode 100644 index 0000000..16aae78 --- /dev/null +++ b/.husky/_/post-applypatch @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +. "$(dirname "$0")/h" \ No newline at end of file diff --git a/.husky/_/post-checkout b/.husky/_/post-checkout new file mode 100644 index 0000000..16aae78 --- /dev/null +++ b/.husky/_/post-checkout @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +. "$(dirname "$0")/h" \ No newline at end of file diff --git a/.husky/_/post-commit b/.husky/_/post-commit new file mode 100644 index 0000000..16aae78 --- /dev/null +++ b/.husky/_/post-commit @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +. "$(dirname "$0")/h" \ No newline at end of file diff --git a/.husky/_/post-merge b/.husky/_/post-merge new file mode 100644 index 0000000..16aae78 --- /dev/null +++ b/.husky/_/post-merge @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +. "$(dirname "$0")/h" \ No newline at end of file diff --git a/.husky/_/post-rewrite b/.husky/_/post-rewrite new file mode 100644 index 0000000..16aae78 --- /dev/null +++ b/.husky/_/post-rewrite @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +. "$(dirname "$0")/h" \ No newline at end of file diff --git a/.husky/_/pre-applypatch b/.husky/_/pre-applypatch new file mode 100644 index 0000000..16aae78 --- /dev/null +++ b/.husky/_/pre-applypatch @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +. "$(dirname "$0")/h" \ No newline at end of file diff --git a/.husky/_/pre-auto-gc b/.husky/_/pre-auto-gc new file mode 100644 index 0000000..16aae78 --- /dev/null +++ b/.husky/_/pre-auto-gc @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +. "$(dirname "$0")/h" \ No newline at end of file diff --git a/.husky/_/pre-commit b/.husky/_/pre-commit new file mode 100644 index 0000000..16aae78 --- /dev/null +++ b/.husky/_/pre-commit @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +. "$(dirname "$0")/h" \ No newline at end of file diff --git a/.husky/_/pre-merge-commit b/.husky/_/pre-merge-commit new file mode 100644 index 0000000..16aae78 --- /dev/null +++ b/.husky/_/pre-merge-commit @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +. "$(dirname "$0")/h" \ No newline at end of file diff --git a/.husky/_/pre-push b/.husky/_/pre-push new file mode 100644 index 0000000..16aae78 --- /dev/null +++ b/.husky/_/pre-push @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +. "$(dirname "$0")/h" \ No newline at end of file diff --git a/.husky/_/pre-rebase b/.husky/_/pre-rebase new file mode 100644 index 0000000..16aae78 --- /dev/null +++ b/.husky/_/pre-rebase @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +. "$(dirname "$0")/h" \ No newline at end of file diff --git a/.husky/_/prepare-commit-msg b/.husky/_/prepare-commit-msg new file mode 100644 index 0000000..16aae78 --- /dev/null +++ b/.husky/_/prepare-commit-msg @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +. "$(dirname "$0")/h" \ No newline at end of file diff --git a/.husky/pre-push b/.husky/pre-push new file mode 100644 index 0000000..66fce03 --- /dev/null +++ b/.husky/pre-push @@ -0,0 +1,12 @@ +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" + +# 获取最新的 tag +TAG=$(git describe --tags --abbrev=0 2>/dev/null) + +if [ $? -eq 0 ]; then + echo "🏷️ 检查最新的 tag: $TAG" + node .husky/scripts/verifyTagVersion.js $TAG +else + echo "⚠️ 没有找到任何 tag,跳过版本校验" +fi \ No newline at end of file diff --git a/.husky/scripts/verifyCommit.js b/.husky/scripts/verifyCommit.js index 56fd54e..083c61a 100644 --- a/.husky/scripts/verifyCommit.js +++ b/.husky/scripts/verifyCommit.js @@ -3,18 +3,18 @@ import fs from "fs"; const msg = fs.readFileSync(".git/COMMIT_EDITMSG", "utf-8").trim(); const commitRE = - /^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release)(\(.+\))?: .{1,50}/; + /^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release)(\(.+\))?: .{1,50}/; const mergeRe = /^(Merge pull request|Merge branch)/; if (!commitRE.test(msg)) { - if (!mergeRe.test(msg)) { - console.log("git commit信息校验不通过"); + if (!mergeRe.test(msg)) { + console.log("git commit信息校验不通过"); - console.error(`git commit的信息格式不对, 需要使用 title(scope): desc的格式 + console.error(`git commit的信息格式不对, 需要使用 title(scope): desc的格式 比如 fix: xxbug feat(test): add new `); - process.exit(1); - } + process.exit(1); + } } else { - console.log("git commit信息校验通过"); + console.log("git commit信息校验通过"); } diff --git a/.husky/scripts/verifyTagVersion.js b/.husky/scripts/verifyTagVersion.js new file mode 100644 index 0000000..abd5c11 --- /dev/null +++ b/.husky/scripts/verifyTagVersion.js @@ -0,0 +1,30 @@ +import fs from 'fs'; + +try { + // 读取 package.json 中的版本号 + const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf-8')); + const packageVersion = packageJson.version; + + // 获取命令行参数中的 tag 名称 + const tag = process.argv[2]; + + if (!tag) { + console.log('⚠️ 未提供 tag 参数,跳过版本校验'); + process.exit(0); + } + + // 检查 tag 是否与 package.json 版本匹配 + const validTags = [`v${packageVersion}`, packageVersion]; + + if (!validTags.includes(tag)) { + console.log('🏷️ Git tag 版本校验不通过'); + console.error(`当前 package.json 版本为: ${packageVersion}`); + console.error(`提供的 tag 为: ${tag}`); + process.exit(1); + } else { + console.log('✅ Git tag 版本校验通过'); + } +} catch (error) { + console.error('❌ 校验过程中发生错误:', error.message); + process.exit(1); +} \ No newline at end of file diff --git a/eslint.config.js b/eslint.config.js index b512ed3..4a795e5 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -2,7 +2,7 @@ import antfu from '@antfu/eslint-config' export default antfu( { - ignores: ['**/node_modules', '**/build', '**/public', '**/dist', '**/package.json', '**/*.yaml', '**/.gitignore', '**/.env*', '**/tsconfig*', '**/*.config.js'], + ignores: ['**/node_modules', '**/build', '**/.husky', '**/public', '**/dist', '**/package.json', '**/*.yaml', '**/.gitignore', '**/.env*', '**/tsconfig*', '**/*.config.js'], }, { rules: { diff --git a/package.json b/package.json index 3edaca3..bbd3758 100644 --- a/package.json +++ b/package.json @@ -9,12 +9,13 @@ "build": "vue-tsc --noEmit && vite build", "build:pre": "vue-tsc --noEmit && vite build --mode prebuild", "build:file": "vue-tsc --noEmit && vite build --mode file", - "tauri":"node ./build/syncVersion.js && tauri", + "tauri": "node ./build/syncVersion.js && tauri", "test": "vitest", "test:ui": "vitest --ui", "preview": "vite preview", "lint": "eslint ./src", - "lint:fix": "eslint ./src --fix" + "lint:fix": "eslint ./src --fix", + "prepare": "husky" }, "dependencies": { "@tweenjs/tween.js": "^23.1.2", @@ -68,6 +69,7 @@ "@vue/tsconfig": "^0.8.1", "autoprefixer": "^10.4.20", "baseline-browser-mapping": "^2.8.32", + "child_process": "^1.0.2", "daisyui": "^5.1.13", "eslint": "^9.15.0", "eslint-plugin-vue": "^10.4.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 08c9472..588e335 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -156,6 +156,9 @@ importers: baseline-browser-mapping: specifier: ^2.8.32 version: 2.8.32 + child_process: + specifier: ^1.0.2 + version: 1.0.2 daisyui: specifier: ^5.1.13 version: 5.1.13 @@ -2554,6 +2557,9 @@ packages: character-entities@2.0.2: resolution: {integrity: sha512-shx7oQ0Awen/BRIdkjkvz54PnEEI/EjwXDSIZp86/KKdbafHh1Df/RYGBhn4hbe2+uKC9FnT5UCEdyPz3ai9hQ==} + child_process@1.0.2: + resolution: {integrity: sha512-Wmza/JzL0SiWz7kl6MhIKT5ceIlnFPJX+lwUGj7Clhy5MMldsSoJR0+uvRzOS5Kv45Mq7t1PoE8TsOA9bzvb6g==} + chokidar@4.0.1: resolution: {integrity: sha512-n8enUVCED/KVRQlab1hr3MVpcVMvxtZjmEa956u+4YijlmQED223XMSYj2tLuKvr4jcCTzNNMpQDUer72MMmzA==} engines: {node: '>= 14.16.0'} @@ -8235,6 +8241,8 @@ snapshots: character-entities@2.0.2: {} + child_process@1.0.2: {} + chokidar@4.0.1: dependencies: readdirp: 4.0.2