diff --git a/.husky/commit-msg b/.husky/commit-msg index 29811785..cd4483ae 100755 --- a/.husky/commit-msg +++ b/.husky/commit-msg @@ -1,4 +1,4 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" -npx --no -- commitlint --edit ${1} \ No newline at end of file +node scripts/verifyCommit.js diff --git a/.husky/pre-commit b/.husky/pre-commit old mode 100644 new mode 100755 index ff1216f9..c37466e2 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,3 +1,4 @@ -#!/usr/bin/env sh +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" -yarn lint \ No newline at end of file +npx lint-staged \ No newline at end of file diff --git a/scripts/create-chapter.sh b/scripts/create-chapter.sh deleted file mode 100755 index eccb2eea..00000000 --- a/scripts/create-chapter.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -read -p "Enter the directory where you want to generate the files (leave blank to generate in current directory): " dir - -if [ -z "$dir" ]; then - dir="." -fi - -read -p "Enter the unit number: " unit -read -p "Enter the starting chapter number: " start_chapter -read -p "Enter the number of chapters to generate: " num_chapters -read -p "Do you want to generate files in descending order? (y/n): " descending - -if [ "$num_chapters" = "0" ]; then - filename="$unit.md" - touch "$dir/$filename" - done -fi - -if [ "" = "" ] - -if [ "$start_chapter" = "0" ]; then - filename="$unit-$chapter" - -if - for (( i=$start_chapter; i<=$start_chapter+$num_chapters-1; i++ )) - do - filename="$unit-$i.md" - touch "$dir/$filename" - done -fi - -echo "Files generated successfully in $dir." diff --git a/scripts/verifyCommit.js b/scripts/verifyCommit.js new file mode 100644 index 00000000..a29c2b77 --- /dev/null +++ b/scripts/verifyCommit.js @@ -0,0 +1,17 @@ +const msg = require('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}/ +const mergeRe = /^(Merge pull request|Merge branch)/ +if (!commitRE.test(msg)) { + if(!mergeRe.test(msg)){ + console.log('git commit message does not pass validation') + + console.error(`git commit message format error, use \" title(scope): desc\" as the format`) + process.exit(1) + } + +}else{ + console.log('git commit message validation test passes') +} \ No newline at end of file