@huaiyou/hooks-git
Advanced tools
+6
-0
| # @huaiyou/hooks-git | ||
| ## 2.2.4 | ||
| ### Patch Changes | ||
| - Fix commitmsg hook - properly capture and translate output | ||
| ## 2.2.3 | ||
@@ -4,0 +10,0 @@ |
+2
-2
@@ -17,3 +17,3 @@ #!/usr/bin/env node | ||
| const version = "2.2.3"; | ||
| const version = "2.2.4"; | ||
@@ -124,3 +124,3 @@ const logger = { | ||
| const commitMsgPath = node_path.resolve(huskyDir, "commit-msg"); | ||
| const commitMsgContent = `npx --no -- hy-hooks-commitlint commitlint --edit \${1} | ||
| const commitMsgContent = `npx --no -- hy-hooks-commitlint --edit \${1} | ||
| `; | ||
@@ -127,0 +127,0 @@ await fs__default.outputFile(commitMsgPath, commitMsgContent, { mode: 493 }); |
+2
-2
@@ -9,3 +9,3 @@ #!/usr/bin/env node | ||
| const version = "2.2.3"; | ||
| const version = "2.2.4"; | ||
@@ -116,3 +116,3 @@ const logger = { | ||
| const commitMsgPath = resolve(huskyDir, "commit-msg"); | ||
| const commitMsgContent = `npx --no -- hy-hooks-commitlint commitlint --edit \${1} | ||
| const commitMsgContent = `npx --no -- hy-hooks-commitlint --edit \${1} | ||
| `; | ||
@@ -119,0 +119,0 @@ await fs.outputFile(commitMsgPath, commitMsgContent, { mode: 493 }); |
+87
-67
| #!/usr/bin/env node | ||
| 'use strict'; | ||
| const cac = require('cac'); | ||
| const execa = require('execa'); | ||
| function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; } | ||
| const cac__default = /*#__PURE__*/_interopDefaultCompat(cac); | ||
| const errorMessages$1 = { | ||
| // 类型相关 | ||
| "type must be one of": "\u63D0\u4EA4\u7C7B\u578B\u5FC5\u987B\u662F\u4EE5\u4E0B\u4E4B\u4E00", | ||
| "type must not be empty": "\u63D0\u4EA4\u7C7B\u578B\u4E0D\u80FD\u4E3A\u7A7A", | ||
| "type must be lower case": "\u63D0\u4EA4\u7C7B\u578B\u5FC5\u987B\u662F\u5C0F\u5199", | ||
| // 主题相关 | ||
| "subject must not be empty": "\u63D0\u4EA4\u4E3B\u9898\u4E0D\u80FD\u4E3A\u7A7A", | ||
| "subject must not end with full stop": "\u63D0\u4EA4\u4E3B\u9898\u4E0D\u80FD\u4EE5\u53E5\u53F7\u7ED3\u5C3E", | ||
| "subject must be lower case": "\u63D0\u4EA4\u4E3B\u9898\u5FC5\u987B\u662F\u5C0F\u5199", | ||
| // 长度相关 | ||
| "header must not be longer than": "\u63D0\u4EA4\u5934\u957F\u5EA6\u4E0D\u80FD\u8D85\u8FC7", | ||
| "body lines must not be longer than": "\u63D0\u4EA4\u6B63\u6587\u6BCF\u884C\u957F\u5EA6\u4E0D\u80FD\u8D85\u8FC7", | ||
| "footer lines must not be longer than": "\u63D0\u4EA4\u811A\u6CE8\u6BCF\u884C\u957F\u5EA6\u4E0D\u80FD\u8D85\u8FC7", | ||
| // 通用 | ||
| "must match the format": "\u5FC5\u987B\u5339\u914D\u683C\u5F0F", | ||
| "must be": "\u5FC5\u987B\u662F" | ||
| }; | ||
| function translateError$1(message) { | ||
| for (const [en, zh] of Object.entries(errorMessages$1)) { | ||
| if (message.includes(en)) { | ||
| return message.replace(en, zh); | ||
| } | ||
| } | ||
| return message; | ||
| } | ||
| async function runCommitlint(args) { | ||
| try { | ||
| await execa.execa("commitlint", args, { | ||
| stdio: "inherit", | ||
| reject: false | ||
| }); | ||
| } catch (error) { | ||
| const err = error; | ||
| if (err.stdout) { | ||
| const translated = translateError$1(err.stdout); | ||
| process.stderr.write(translated + "\n"); | ||
| } | ||
| if (err.stderr) { | ||
| const translated = translateError$1(err.stderr); | ||
| process.stderr.write(translated + "\n"); | ||
| } | ||
| if (err.message) { | ||
| const translated = translateError$1(err.message); | ||
| process.stderr.write(translated + "\n"); | ||
| } | ||
| process.exit(1); | ||
| } | ||
| } | ||
| const errorMessages = { | ||
| // 配置相关 | ||
@@ -81,2 +27,73 @@ "Failed to read config from file": "\u65E0\u6CD5\u8BFB\u53D6\u914D\u7F6E\u6587\u4EF6", | ||
| }; | ||
| function translateError$1(message) { | ||
| let translated = message; | ||
| for (const [en, zh] of Object.entries(errorMessages$1)) { | ||
| translated = translated.replace(new RegExp(en, "g"), zh); | ||
| } | ||
| return translated; | ||
| } | ||
| function translateLine$1(line) { | ||
| if (!line.trim() || /^[\s─│┌┐└┘]+$/g.test(line)) { | ||
| return line; | ||
| } | ||
| return translateError$1(line); | ||
| } | ||
| async function runLintStaged() { | ||
| try { | ||
| const { stdout, stderr } = await execa.execa("lint-staged", [], { | ||
| stdio: "pipe" | ||
| }); | ||
| if (stdout) { | ||
| const lines = stdout.split("\n"); | ||
| lines.forEach((line) => { | ||
| process.stdout.write(translateLine$1(line) + "\n"); | ||
| }); | ||
| } | ||
| if (stderr) { | ||
| const lines = stderr.split("\n"); | ||
| lines.forEach((line) => { | ||
| process.stderr.write(translateLine$1(line) + "\n"); | ||
| }); | ||
| } | ||
| } catch (error) { | ||
| const err = error; | ||
| if (err.stdout) { | ||
| const lines = err.stdout.split("\n"); | ||
| lines.forEach((line) => { | ||
| process.stdout.write(translateLine$1(line) + "\n"); | ||
| }); | ||
| } | ||
| if (err.stderr) { | ||
| const lines = err.stderr.split("\n"); | ||
| lines.forEach((line) => { | ||
| process.stderr.write(translateLine$1(line) + "\n"); | ||
| }); | ||
| } | ||
| process.exit(1); | ||
| } | ||
| } | ||
| const errorMessages = { | ||
| // 类型相关 | ||
| "type must be one of": "\u63D0\u4EA4\u7C7B\u578B\u5FC5\u987B\u662F\u4EE5\u4E0B\u4E4B\u4E00", | ||
| "type must not be empty": "\u63D0\u4EA4\u7C7B\u578B\u4E0D\u80FD\u4E3A\u7A7A", | ||
| "type must be lower case": "\u63D0\u4EA4\u7C7B\u578B\u5FC5\u987B\u662F\u5C0F\u5199", | ||
| "may not be empty": "\u4E0D\u80FD\u4E3A\u7A7A", | ||
| // 主题相关 | ||
| "subject must not be empty": "\u63D0\u4EA4\u4E3B\u9898\u4E0D\u80FD\u4E3A\u7A7A", | ||
| "subject must not end with full stop": "\u63D0\u4EA4\u4E3B\u9898\u4E0D\u80FD\u4EE5\u53E5\u53F7\u7ED3\u5C3E", | ||
| "subject must be lower case": "\u63D0\u4EA4\u4E3B\u9898\u5FC5\u987B\u662F\u5C0F\u5199", | ||
| // 长度相关 | ||
| "header must not be longer than": "\u63D0\u4EA4\u5934\u957F\u5EA6\u4E0D\u80FD\u8D85\u8FC7", | ||
| "body lines must not be longer than": "\u63D0\u4EA4\u6B63\u6587\u6BCF\u884C\u957F\u5EA6\u4E0D\u80FD\u8D85\u8FC7", | ||
| "footer lines must not be longer than": "\u63D0\u4EA4\u811A\u6CE8\u6BCF\u884C\u957F\u5EA6\u4E0D\u80FD\u8D85\u8FC7", | ||
| // 通用 | ||
| "must match the format": "\u5FC5\u987B\u5339\u914D\u683C\u5F0F", | ||
| "must be": "\u5FC5\u987B\u662F", | ||
| "may not": "\u4E0D\u80FD", | ||
| "found": "\u53D1\u73B0", | ||
| "problems": "\u4E2A\u95EE\u9898", | ||
| "warnings": "\u4E2A\u8B66\u544A", | ||
| "Get help": "\u83B7\u53D6\u5E2E\u52A9" | ||
| }; | ||
| function translateError(message) { | ||
@@ -90,3 +107,3 @@ let translated = message; | ||
| function translateLine(line) { | ||
| if (!line.trim() || /^[\s─│┌┐└┘]+$/g.test(line)) { | ||
| if (!line.trim() || /^[\s⧗│┌┐└┘✖✓ⓘ]+$/g.test(line)) { | ||
| return line; | ||
@@ -96,5 +113,5 @@ } | ||
| } | ||
| async function runLintStaged() { | ||
| async function runCommitlint(args) { | ||
| try { | ||
| const { stdout, stderr } = await execa.execa("lint-staged", [], { | ||
| const { stdout, stderr } = await execa.execa("commitlint", args, { | ||
| stdio: "pipe" | ||
@@ -128,14 +145,17 @@ }); | ||
| } | ||
| process.exit(1); | ||
| process.exit(err.exitCode || 1); | ||
| } | ||
| } | ||
| const cli = cac__default("hy-hooks-git-wrapper"); | ||
| cli.command("commitlint [...args]", "Run commitlint with Chinese error messages").action(async (args) => { | ||
| await runCommitlint(args); | ||
| }); | ||
| cli.command("lint-staged", "Run lint-staged with Chinese error messages").action(async () => { | ||
| await runLintStaged(); | ||
| }); | ||
| cli.help(); | ||
| cli.parse(); | ||
| const args = process.argv.slice(2); | ||
| if (args[0] === "lint-staged") { | ||
| runLintStaged().catch((error) => { | ||
| console.error(error); | ||
| process.exit(1); | ||
| }); | ||
| } else { | ||
| runCommitlint(args).catch((error) => { | ||
| console.error(error); | ||
| process.exit(1); | ||
| }); | ||
| } |
+87
-63
| #!/usr/bin/env node | ||
| import cac from 'cac'; | ||
| import { execa } from 'execa'; | ||
| const errorMessages$1 = { | ||
| // 类型相关 | ||
| "type must be one of": "\u63D0\u4EA4\u7C7B\u578B\u5FC5\u987B\u662F\u4EE5\u4E0B\u4E4B\u4E00", | ||
| "type must not be empty": "\u63D0\u4EA4\u7C7B\u578B\u4E0D\u80FD\u4E3A\u7A7A", | ||
| "type must be lower case": "\u63D0\u4EA4\u7C7B\u578B\u5FC5\u987B\u662F\u5C0F\u5199", | ||
| // 主题相关 | ||
| "subject must not be empty": "\u63D0\u4EA4\u4E3B\u9898\u4E0D\u80FD\u4E3A\u7A7A", | ||
| "subject must not end with full stop": "\u63D0\u4EA4\u4E3B\u9898\u4E0D\u80FD\u4EE5\u53E5\u53F7\u7ED3\u5C3E", | ||
| "subject must be lower case": "\u63D0\u4EA4\u4E3B\u9898\u5FC5\u987B\u662F\u5C0F\u5199", | ||
| // 长度相关 | ||
| "header must not be longer than": "\u63D0\u4EA4\u5934\u957F\u5EA6\u4E0D\u80FD\u8D85\u8FC7", | ||
| "body lines must not be longer than": "\u63D0\u4EA4\u6B63\u6587\u6BCF\u884C\u957F\u5EA6\u4E0D\u80FD\u8D85\u8FC7", | ||
| "footer lines must not be longer than": "\u63D0\u4EA4\u811A\u6CE8\u6BCF\u884C\u957F\u5EA6\u4E0D\u80FD\u8D85\u8FC7", | ||
| // 通用 | ||
| "must match the format": "\u5FC5\u987B\u5339\u914D\u683C\u5F0F", | ||
| "must be": "\u5FC5\u987B\u662F" | ||
| }; | ||
| function translateError$1(message) { | ||
| for (const [en, zh] of Object.entries(errorMessages$1)) { | ||
| if (message.includes(en)) { | ||
| return message.replace(en, zh); | ||
| } | ||
| } | ||
| return message; | ||
| } | ||
| async function runCommitlint(args) { | ||
| try { | ||
| await execa("commitlint", args, { | ||
| stdio: "inherit", | ||
| reject: false | ||
| }); | ||
| } catch (error) { | ||
| const err = error; | ||
| if (err.stdout) { | ||
| const translated = translateError$1(err.stdout); | ||
| process.stderr.write(translated + "\n"); | ||
| } | ||
| if (err.stderr) { | ||
| const translated = translateError$1(err.stderr); | ||
| process.stderr.write(translated + "\n"); | ||
| } | ||
| if (err.message) { | ||
| const translated = translateError$1(err.message); | ||
| process.stderr.write(translated + "\n"); | ||
| } | ||
| process.exit(1); | ||
| } | ||
| } | ||
| const errorMessages = { | ||
| // 配置相关 | ||
@@ -75,2 +25,73 @@ "Failed to read config from file": "\u65E0\u6CD5\u8BFB\u53D6\u914D\u7F6E\u6587\u4EF6", | ||
| }; | ||
| function translateError$1(message) { | ||
| let translated = message; | ||
| for (const [en, zh] of Object.entries(errorMessages$1)) { | ||
| translated = translated.replace(new RegExp(en, "g"), zh); | ||
| } | ||
| return translated; | ||
| } | ||
| function translateLine$1(line) { | ||
| if (!line.trim() || /^[\s─│┌┐└┘]+$/g.test(line)) { | ||
| return line; | ||
| } | ||
| return translateError$1(line); | ||
| } | ||
| async function runLintStaged() { | ||
| try { | ||
| const { stdout, stderr } = await execa("lint-staged", [], { | ||
| stdio: "pipe" | ||
| }); | ||
| if (stdout) { | ||
| const lines = stdout.split("\n"); | ||
| lines.forEach((line) => { | ||
| process.stdout.write(translateLine$1(line) + "\n"); | ||
| }); | ||
| } | ||
| if (stderr) { | ||
| const lines = stderr.split("\n"); | ||
| lines.forEach((line) => { | ||
| process.stderr.write(translateLine$1(line) + "\n"); | ||
| }); | ||
| } | ||
| } catch (error) { | ||
| const err = error; | ||
| if (err.stdout) { | ||
| const lines = err.stdout.split("\n"); | ||
| lines.forEach((line) => { | ||
| process.stdout.write(translateLine$1(line) + "\n"); | ||
| }); | ||
| } | ||
| if (err.stderr) { | ||
| const lines = err.stderr.split("\n"); | ||
| lines.forEach((line) => { | ||
| process.stderr.write(translateLine$1(line) + "\n"); | ||
| }); | ||
| } | ||
| process.exit(1); | ||
| } | ||
| } | ||
| const errorMessages = { | ||
| // 类型相关 | ||
| "type must be one of": "\u63D0\u4EA4\u7C7B\u578B\u5FC5\u987B\u662F\u4EE5\u4E0B\u4E4B\u4E00", | ||
| "type must not be empty": "\u63D0\u4EA4\u7C7B\u578B\u4E0D\u80FD\u4E3A\u7A7A", | ||
| "type must be lower case": "\u63D0\u4EA4\u7C7B\u578B\u5FC5\u987B\u662F\u5C0F\u5199", | ||
| "may not be empty": "\u4E0D\u80FD\u4E3A\u7A7A", | ||
| // 主题相关 | ||
| "subject must not be empty": "\u63D0\u4EA4\u4E3B\u9898\u4E0D\u80FD\u4E3A\u7A7A", | ||
| "subject must not end with full stop": "\u63D0\u4EA4\u4E3B\u9898\u4E0D\u80FD\u4EE5\u53E5\u53F7\u7ED3\u5C3E", | ||
| "subject must be lower case": "\u63D0\u4EA4\u4E3B\u9898\u5FC5\u987B\u662F\u5C0F\u5199", | ||
| // 长度相关 | ||
| "header must not be longer than": "\u63D0\u4EA4\u5934\u957F\u5EA6\u4E0D\u80FD\u8D85\u8FC7", | ||
| "body lines must not be longer than": "\u63D0\u4EA4\u6B63\u6587\u6BCF\u884C\u957F\u5EA6\u4E0D\u80FD\u8D85\u8FC7", | ||
| "footer lines must not be longer than": "\u63D0\u4EA4\u811A\u6CE8\u6BCF\u884C\u957F\u5EA6\u4E0D\u80FD\u8D85\u8FC7", | ||
| // 通用 | ||
| "must match the format": "\u5FC5\u987B\u5339\u914D\u683C\u5F0F", | ||
| "must be": "\u5FC5\u987B\u662F", | ||
| "may not": "\u4E0D\u80FD", | ||
| "found": "\u53D1\u73B0", | ||
| "problems": "\u4E2A\u95EE\u9898", | ||
| "warnings": "\u4E2A\u8B66\u544A", | ||
| "Get help": "\u83B7\u53D6\u5E2E\u52A9" | ||
| }; | ||
| function translateError(message) { | ||
@@ -84,3 +105,3 @@ let translated = message; | ||
| function translateLine(line) { | ||
| if (!line.trim() || /^[\s─│┌┐└┘]+$/g.test(line)) { | ||
| if (!line.trim() || /^[\s⧗│┌┐└┘✖✓ⓘ]+$/g.test(line)) { | ||
| return line; | ||
@@ -90,5 +111,5 @@ } | ||
| } | ||
| async function runLintStaged() { | ||
| async function runCommitlint(args) { | ||
| try { | ||
| const { stdout, stderr } = await execa("lint-staged", [], { | ||
| const { stdout, stderr } = await execa("commitlint", args, { | ||
| stdio: "pipe" | ||
@@ -122,14 +143,17 @@ }); | ||
| } | ||
| process.exit(1); | ||
| process.exit(err.exitCode || 1); | ||
| } | ||
| } | ||
| const cli = cac("hy-hooks-git-wrapper"); | ||
| cli.command("commitlint [...args]", "Run commitlint with Chinese error messages").action(async (args) => { | ||
| await runCommitlint(args); | ||
| }); | ||
| cli.command("lint-staged", "Run lint-staged with Chinese error messages").action(async () => { | ||
| await runLintStaged(); | ||
| }); | ||
| cli.help(); | ||
| cli.parse(); | ||
| const args = process.argv.slice(2); | ||
| if (args[0] === "lint-staged") { | ||
| runLintStaged().catch((error) => { | ||
| console.error(error); | ||
| process.exit(1); | ||
| }); | ||
| } else { | ||
| runCommitlint(args).catch((error) => { | ||
| console.error(error); | ||
| process.exit(1); | ||
| }); | ||
| } |
+1
-1
| { | ||
| "name": "@huaiyou/hooks-git", | ||
| "version": "2.2.3", | ||
| "version": "2.2.4", | ||
| "description": "Git hooks configuration with Husky, Commitlint and Lint-staged", | ||
@@ -5,0 +5,0 @@ "bin": { |
54178
2.11%1311
3.64%