@huaiyou/hooks-git 2.2.3 → 2.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @huaiyou/hooks-git
2
2
 
3
+ ## 2.2.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Fix commitmsg hook - properly capture and translate output
8
+
3
9
  ## 2.2.3
4
10
 
5
11
  ### Patch Changes
package/dist/cli.cjs CHANGED
@@ -14,7 +14,7 @@ const cac__default = /*#__PURE__*/_interopDefaultCompat(cac);
14
14
  const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
15
15
  const picocolors__default = /*#__PURE__*/_interopDefaultCompat(picocolors);
16
16
 
17
- const version = "2.2.3";
17
+ const version = "2.2.4";
18
18
 
19
19
  const logger = {
20
20
  /**
@@ -120,7 +120,7 @@ const init = async () => {
120
120
  logger.info("Adding hooks...");
121
121
  const huskyDir = node_path.resolve(process.cwd(), ".husky");
122
122
  const commitMsgPath = node_path.resolve(huskyDir, "commit-msg");
123
- const commitMsgContent = `npx --no -- hy-hooks-commitlint commitlint --edit \${1}
123
+ const commitMsgContent = `npx --no -- hy-hooks-commitlint --edit \${1}
124
124
  `;
125
125
  await fs__default.outputFile(commitMsgPath, commitMsgContent, { mode: 493 });
126
126
  const preCommitPath = node_path.resolve(huskyDir, "pre-commit");
package/dist/cli.mjs CHANGED
@@ -6,7 +6,7 @@ import { consola } from 'consola';
6
6
  import { execa } from 'execa';
7
7
  import picocolors from 'picocolors';
8
8
 
9
- const version = "2.2.3";
9
+ const version = "2.2.4";
10
10
 
11
11
  const logger = {
12
12
  /**
@@ -112,7 +112,7 @@ const init = async () => {
112
112
  logger.info("Adding hooks...");
113
113
  const huskyDir = resolve(process.cwd(), ".husky");
114
114
  const commitMsgPath = resolve(huskyDir, "commit-msg");
115
- const commitMsgContent = `npx --no -- hy-hooks-commitlint commitlint --edit \${1}
115
+ const commitMsgContent = `npx --no -- hy-hooks-commitlint --edit \${1}
116
116
  `;
117
117
  await fs.outputFile(commitMsgPath, commitMsgContent, { mode: 493 });
118
118
  const preCommitPath = resolve(huskyDir, "pre-commit");
@@ -1,63 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- const cac = require('cac');
5
4
  const execa = require('execa');
6
5
 
7
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
8
-
9
- const cac__default = /*#__PURE__*/_interopDefaultCompat(cac);
10
-
11
6
  const errorMessages$1 = {
12
- // 类型相关
13
- "type must be one of": "\u63D0\u4EA4\u7C7B\u578B\u5FC5\u987B\u662F\u4EE5\u4E0B\u4E4B\u4E00",
14
- "type must not be empty": "\u63D0\u4EA4\u7C7B\u578B\u4E0D\u80FD\u4E3A\u7A7A",
15
- "type must be lower case": "\u63D0\u4EA4\u7C7B\u578B\u5FC5\u987B\u662F\u5C0F\u5199",
16
- // 主题相关
17
- "subject must not be empty": "\u63D0\u4EA4\u4E3B\u9898\u4E0D\u80FD\u4E3A\u7A7A",
18
- "subject must not end with full stop": "\u63D0\u4EA4\u4E3B\u9898\u4E0D\u80FD\u4EE5\u53E5\u53F7\u7ED3\u5C3E",
19
- "subject must be lower case": "\u63D0\u4EA4\u4E3B\u9898\u5FC5\u987B\u662F\u5C0F\u5199",
20
- // 长度相关
21
- "header must not be longer than": "\u63D0\u4EA4\u5934\u957F\u5EA6\u4E0D\u80FD\u8D85\u8FC7",
22
- "body lines must not be longer than": "\u63D0\u4EA4\u6B63\u6587\u6BCF\u884C\u957F\u5EA6\u4E0D\u80FD\u8D85\u8FC7",
23
- "footer lines must not be longer than": "\u63D0\u4EA4\u811A\u6CE8\u6BCF\u884C\u957F\u5EA6\u4E0D\u80FD\u8D85\u8FC7",
24
- // 通用
25
- "must match the format": "\u5FC5\u987B\u5339\u914D\u683C\u5F0F",
26
- "must be": "\u5FC5\u987B\u662F"
27
- };
28
- function translateError$1(message) {
29
- for (const [en, zh] of Object.entries(errorMessages$1)) {
30
- if (message.includes(en)) {
31
- return message.replace(en, zh);
32
- }
33
- }
34
- return message;
35
- }
36
- async function runCommitlint(args) {
37
- try {
38
- await execa.execa("commitlint", args, {
39
- stdio: "inherit",
40
- reject: false
41
- });
42
- } catch (error) {
43
- const err = error;
44
- if (err.stdout) {
45
- const translated = translateError$1(err.stdout);
46
- process.stderr.write(translated + "\n");
47
- }
48
- if (err.stderr) {
49
- const translated = translateError$1(err.stderr);
50
- process.stderr.write(translated + "\n");
51
- }
52
- if (err.message) {
53
- const translated = translateError$1(err.message);
54
- process.stderr.write(translated + "\n");
55
- }
56
- process.exit(1);
57
- }
58
- }
59
-
60
- const errorMessages = {
61
7
  // 配置相关
62
8
  "Failed to read config from file": "\u65E0\u6CD5\u8BFB\u53D6\u914D\u7F6E\u6587\u4EF6",
63
9
  "could not find any valid configuration": "\u627E\u4E0D\u5230\u6709\u6548\u7684\u914D\u7F6E",
@@ -78,6 +24,77 @@ const errorMessages = {
78
24
  passed: "\u901A\u8FC7",
79
25
  skipped: "\u8DF3\u8FC7"
80
26
  };
27
+ function translateError$1(message) {
28
+ let translated = message;
29
+ for (const [en, zh] of Object.entries(errorMessages$1)) {
30
+ translated = translated.replace(new RegExp(en, "g"), zh);
31
+ }
32
+ return translated;
33
+ }
34
+ function translateLine$1(line) {
35
+ if (!line.trim() || /^[\s─│┌┐└┘]+$/g.test(line)) {
36
+ return line;
37
+ }
38
+ return translateError$1(line);
39
+ }
40
+ async function runLintStaged() {
41
+ try {
42
+ const { stdout, stderr } = await execa.execa("lint-staged", [], {
43
+ stdio: "pipe"
44
+ });
45
+ if (stdout) {
46
+ const lines = stdout.split("\n");
47
+ lines.forEach((line) => {
48
+ process.stdout.write(translateLine$1(line) + "\n");
49
+ });
50
+ }
51
+ if (stderr) {
52
+ const lines = stderr.split("\n");
53
+ lines.forEach((line) => {
54
+ process.stderr.write(translateLine$1(line) + "\n");
55
+ });
56
+ }
57
+ } catch (error) {
58
+ const err = error;
59
+ if (err.stdout) {
60
+ const lines = err.stdout.split("\n");
61
+ lines.forEach((line) => {
62
+ process.stdout.write(translateLine$1(line) + "\n");
63
+ });
64
+ }
65
+ if (err.stderr) {
66
+ const lines = err.stderr.split("\n");
67
+ lines.forEach((line) => {
68
+ process.stderr.write(translateLine$1(line) + "\n");
69
+ });
70
+ }
71
+ process.exit(1);
72
+ }
73
+ }
74
+
75
+ const errorMessages = {
76
+ // 类型相关
77
+ "type must be one of": "\u63D0\u4EA4\u7C7B\u578B\u5FC5\u987B\u662F\u4EE5\u4E0B\u4E4B\u4E00",
78
+ "type must not be empty": "\u63D0\u4EA4\u7C7B\u578B\u4E0D\u80FD\u4E3A\u7A7A",
79
+ "type must be lower case": "\u63D0\u4EA4\u7C7B\u578B\u5FC5\u987B\u662F\u5C0F\u5199",
80
+ "may not be empty": "\u4E0D\u80FD\u4E3A\u7A7A",
81
+ // 主题相关
82
+ "subject must not be empty": "\u63D0\u4EA4\u4E3B\u9898\u4E0D\u80FD\u4E3A\u7A7A",
83
+ "subject must not end with full stop": "\u63D0\u4EA4\u4E3B\u9898\u4E0D\u80FD\u4EE5\u53E5\u53F7\u7ED3\u5C3E",
84
+ "subject must be lower case": "\u63D0\u4EA4\u4E3B\u9898\u5FC5\u987B\u662F\u5C0F\u5199",
85
+ // 长度相关
86
+ "header must not be longer than": "\u63D0\u4EA4\u5934\u957F\u5EA6\u4E0D\u80FD\u8D85\u8FC7",
87
+ "body lines must not be longer than": "\u63D0\u4EA4\u6B63\u6587\u6BCF\u884C\u957F\u5EA6\u4E0D\u80FD\u8D85\u8FC7",
88
+ "footer lines must not be longer than": "\u63D0\u4EA4\u811A\u6CE8\u6BCF\u884C\u957F\u5EA6\u4E0D\u80FD\u8D85\u8FC7",
89
+ // 通用
90
+ "must match the format": "\u5FC5\u987B\u5339\u914D\u683C\u5F0F",
91
+ "must be": "\u5FC5\u987B\u662F",
92
+ "may not": "\u4E0D\u80FD",
93
+ "found": "\u53D1\u73B0",
94
+ "problems": "\u4E2A\u95EE\u9898",
95
+ "warnings": "\u4E2A\u8B66\u544A",
96
+ "Get help": "\u83B7\u53D6\u5E2E\u52A9"
97
+ };
81
98
  function translateError(message) {
82
99
  let translated = message;
83
100
  for (const [en, zh] of Object.entries(errorMessages)) {
@@ -86,14 +103,14 @@ function translateError(message) {
86
103
  return translated;
87
104
  }
88
105
  function translateLine(line) {
89
- if (!line.trim() || /^[\s─│┌┐└┘]+$/g.test(line)) {
106
+ if (!line.trim() || /^[\s⧗│┌┐└┘✖✓ⓘ]+$/g.test(line)) {
90
107
  return line;
91
108
  }
92
109
  return translateError(line);
93
110
  }
94
- async function runLintStaged() {
111
+ async function runCommitlint(args) {
95
112
  try {
96
- const { stdout, stderr } = await execa.execa("lint-staged", [], {
113
+ const { stdout, stderr } = await execa.execa("commitlint", args, {
97
114
  stdio: "pipe"
98
115
  });
99
116
  if (stdout) {
@@ -122,16 +139,19 @@ async function runLintStaged() {
122
139
  process.stderr.write(translateLine(line) + "\n");
123
140
  });
124
141
  }
125
- process.exit(1);
142
+ process.exit(err.exitCode || 1);
126
143
  }
127
144
  }
128
145
 
129
- const cli = cac__default("hy-hooks-git-wrapper");
130
- cli.command("commitlint [...args]", "Run commitlint with Chinese error messages").action(async (args) => {
131
- await runCommitlint(args);
132
- });
133
- cli.command("lint-staged", "Run lint-staged with Chinese error messages").action(async () => {
134
- await runLintStaged();
135
- });
136
- cli.help();
137
- cli.parse();
146
+ const args = process.argv.slice(2);
147
+ if (args[0] === "lint-staged") {
148
+ runLintStaged().catch((error) => {
149
+ console.error(error);
150
+ process.exit(1);
151
+ });
152
+ } else {
153
+ runCommitlint(args).catch((error) => {
154
+ console.error(error);
155
+ process.exit(1);
156
+ });
157
+ }
@@ -1,57 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import cac from 'cac';
3
2
  import { execa } from 'execa';
4
3
 
5
4
  const errorMessages$1 = {
6
- // 类型相关
7
- "type must be one of": "\u63D0\u4EA4\u7C7B\u578B\u5FC5\u987B\u662F\u4EE5\u4E0B\u4E4B\u4E00",
8
- "type must not be empty": "\u63D0\u4EA4\u7C7B\u578B\u4E0D\u80FD\u4E3A\u7A7A",
9
- "type must be lower case": "\u63D0\u4EA4\u7C7B\u578B\u5FC5\u987B\u662F\u5C0F\u5199",
10
- // 主题相关
11
- "subject must not be empty": "\u63D0\u4EA4\u4E3B\u9898\u4E0D\u80FD\u4E3A\u7A7A",
12
- "subject must not end with full stop": "\u63D0\u4EA4\u4E3B\u9898\u4E0D\u80FD\u4EE5\u53E5\u53F7\u7ED3\u5C3E",
13
- "subject must be lower case": "\u63D0\u4EA4\u4E3B\u9898\u5FC5\u987B\u662F\u5C0F\u5199",
14
- // 长度相关
15
- "header must not be longer than": "\u63D0\u4EA4\u5934\u957F\u5EA6\u4E0D\u80FD\u8D85\u8FC7",
16
- "body lines must not be longer than": "\u63D0\u4EA4\u6B63\u6587\u6BCF\u884C\u957F\u5EA6\u4E0D\u80FD\u8D85\u8FC7",
17
- "footer lines must not be longer than": "\u63D0\u4EA4\u811A\u6CE8\u6BCF\u884C\u957F\u5EA6\u4E0D\u80FD\u8D85\u8FC7",
18
- // 通用
19
- "must match the format": "\u5FC5\u987B\u5339\u914D\u683C\u5F0F",
20
- "must be": "\u5FC5\u987B\u662F"
21
- };
22
- function translateError$1(message) {
23
- for (const [en, zh] of Object.entries(errorMessages$1)) {
24
- if (message.includes(en)) {
25
- return message.replace(en, zh);
26
- }
27
- }
28
- return message;
29
- }
30
- async function runCommitlint(args) {
31
- try {
32
- await execa("commitlint", args, {
33
- stdio: "inherit",
34
- reject: false
35
- });
36
- } catch (error) {
37
- const err = error;
38
- if (err.stdout) {
39
- const translated = translateError$1(err.stdout);
40
- process.stderr.write(translated + "\n");
41
- }
42
- if (err.stderr) {
43
- const translated = translateError$1(err.stderr);
44
- process.stderr.write(translated + "\n");
45
- }
46
- if (err.message) {
47
- const translated = translateError$1(err.message);
48
- process.stderr.write(translated + "\n");
49
- }
50
- process.exit(1);
51
- }
52
- }
53
-
54
- const errorMessages = {
55
5
  // 配置相关
56
6
  "Failed to read config from file": "\u65E0\u6CD5\u8BFB\u53D6\u914D\u7F6E\u6587\u4EF6",
57
7
  "could not find any valid configuration": "\u627E\u4E0D\u5230\u6709\u6548\u7684\u914D\u7F6E",
@@ -72,6 +22,77 @@ const errorMessages = {
72
22
  passed: "\u901A\u8FC7",
73
23
  skipped: "\u8DF3\u8FC7"
74
24
  };
25
+ function translateError$1(message) {
26
+ let translated = message;
27
+ for (const [en, zh] of Object.entries(errorMessages$1)) {
28
+ translated = translated.replace(new RegExp(en, "g"), zh);
29
+ }
30
+ return translated;
31
+ }
32
+ function translateLine$1(line) {
33
+ if (!line.trim() || /^[\s─│┌┐└┘]+$/g.test(line)) {
34
+ return line;
35
+ }
36
+ return translateError$1(line);
37
+ }
38
+ async function runLintStaged() {
39
+ try {
40
+ const { stdout, stderr } = await execa("lint-staged", [], {
41
+ stdio: "pipe"
42
+ });
43
+ if (stdout) {
44
+ const lines = stdout.split("\n");
45
+ lines.forEach((line) => {
46
+ process.stdout.write(translateLine$1(line) + "\n");
47
+ });
48
+ }
49
+ if (stderr) {
50
+ const lines = stderr.split("\n");
51
+ lines.forEach((line) => {
52
+ process.stderr.write(translateLine$1(line) + "\n");
53
+ });
54
+ }
55
+ } catch (error) {
56
+ const err = error;
57
+ if (err.stdout) {
58
+ const lines = err.stdout.split("\n");
59
+ lines.forEach((line) => {
60
+ process.stdout.write(translateLine$1(line) + "\n");
61
+ });
62
+ }
63
+ if (err.stderr) {
64
+ const lines = err.stderr.split("\n");
65
+ lines.forEach((line) => {
66
+ process.stderr.write(translateLine$1(line) + "\n");
67
+ });
68
+ }
69
+ process.exit(1);
70
+ }
71
+ }
72
+
73
+ const errorMessages = {
74
+ // 类型相关
75
+ "type must be one of": "\u63D0\u4EA4\u7C7B\u578B\u5FC5\u987B\u662F\u4EE5\u4E0B\u4E4B\u4E00",
76
+ "type must not be empty": "\u63D0\u4EA4\u7C7B\u578B\u4E0D\u80FD\u4E3A\u7A7A",
77
+ "type must be lower case": "\u63D0\u4EA4\u7C7B\u578B\u5FC5\u987B\u662F\u5C0F\u5199",
78
+ "may not be empty": "\u4E0D\u80FD\u4E3A\u7A7A",
79
+ // 主题相关
80
+ "subject must not be empty": "\u63D0\u4EA4\u4E3B\u9898\u4E0D\u80FD\u4E3A\u7A7A",
81
+ "subject must not end with full stop": "\u63D0\u4EA4\u4E3B\u9898\u4E0D\u80FD\u4EE5\u53E5\u53F7\u7ED3\u5C3E",
82
+ "subject must be lower case": "\u63D0\u4EA4\u4E3B\u9898\u5FC5\u987B\u662F\u5C0F\u5199",
83
+ // 长度相关
84
+ "header must not be longer than": "\u63D0\u4EA4\u5934\u957F\u5EA6\u4E0D\u80FD\u8D85\u8FC7",
85
+ "body lines must not be longer than": "\u63D0\u4EA4\u6B63\u6587\u6BCF\u884C\u957F\u5EA6\u4E0D\u80FD\u8D85\u8FC7",
86
+ "footer lines must not be longer than": "\u63D0\u4EA4\u811A\u6CE8\u6BCF\u884C\u957F\u5EA6\u4E0D\u80FD\u8D85\u8FC7",
87
+ // 通用
88
+ "must match the format": "\u5FC5\u987B\u5339\u914D\u683C\u5F0F",
89
+ "must be": "\u5FC5\u987B\u662F",
90
+ "may not": "\u4E0D\u80FD",
91
+ "found": "\u53D1\u73B0",
92
+ "problems": "\u4E2A\u95EE\u9898",
93
+ "warnings": "\u4E2A\u8B66\u544A",
94
+ "Get help": "\u83B7\u53D6\u5E2E\u52A9"
95
+ };
75
96
  function translateError(message) {
76
97
  let translated = message;
77
98
  for (const [en, zh] of Object.entries(errorMessages)) {
@@ -80,14 +101,14 @@ function translateError(message) {
80
101
  return translated;
81
102
  }
82
103
  function translateLine(line) {
83
- if (!line.trim() || /^[\s─│┌┐└┘]+$/g.test(line)) {
104
+ if (!line.trim() || /^[\s⧗│┌┐└┘✖✓ⓘ]+$/g.test(line)) {
84
105
  return line;
85
106
  }
86
107
  return translateError(line);
87
108
  }
88
- async function runLintStaged() {
109
+ async function runCommitlint(args) {
89
110
  try {
90
- const { stdout, stderr } = await execa("lint-staged", [], {
111
+ const { stdout, stderr } = await execa("commitlint", args, {
91
112
  stdio: "pipe"
92
113
  });
93
114
  if (stdout) {
@@ -116,16 +137,19 @@ async function runLintStaged() {
116
137
  process.stderr.write(translateLine(line) + "\n");
117
138
  });
118
139
  }
119
- process.exit(1);
140
+ process.exit(err.exitCode || 1);
120
141
  }
121
142
  }
122
143
 
123
- const cli = cac("hy-hooks-git-wrapper");
124
- cli.command("commitlint [...args]", "Run commitlint with Chinese error messages").action(async (args) => {
125
- await runCommitlint(args);
126
- });
127
- cli.command("lint-staged", "Run lint-staged with Chinese error messages").action(async () => {
128
- await runLintStaged();
129
- });
130
- cli.help();
131
- cli.parse();
144
+ const args = process.argv.slice(2);
145
+ if (args[0] === "lint-staged") {
146
+ runLintStaged().catch((error) => {
147
+ console.error(error);
148
+ process.exit(1);
149
+ });
150
+ } else {
151
+ runCommitlint(args).catch((error) => {
152
+ console.error(error);
153
+ process.exit(1);
154
+ });
155
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huaiyou/hooks-git",
3
- "version": "2.2.3",
3
+ "version": "2.2.4",
4
4
  "description": "Git hooks configuration with Husky, Commitlint and Lint-staged",
5
5
  "bin": {
6
6
  "hy-hooks-git": "./dist/cli.mjs",