@deot/dev-commitlint 2.9.8 → 2.9.9
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/README.md +12 -0
- package/dist/index.cjs +94 -37
- package/dist/index.d.ts +9 -1
- package/dist/index.js +92 -37
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
1
|
# @deot/dev-commitlint
|
|
2
2
|
|
|
3
|
+
- commit message
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
dd-commitlint --message [file-path] --message-exclude
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
- commit file-path (kebabCase: `xxx-xxx-xxx`)
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
dd-commitlint --file-path [file-path1] [file-path2] --file-path-exclude
|
|
13
|
+
```
|
|
14
|
+
|
package/dist/index.cjs
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
5
|
const fs = require('node:fs');
|
|
6
|
+
const path = require('node:path');
|
|
6
7
|
|
|
7
8
|
function _interopNamespaceDefault(e) {
|
|
8
9
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
|
|
@@ -22,69 +23,125 @@ function _interopNamespaceDefault(e) {
|
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
const fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
26
|
+
const path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
25
27
|
|
|
26
28
|
const commitRE = /^(revert:? "?|Revert "?)?(void|fix|feat|docs|style|perf|test|types|build|chore|refactor|workflow|ci|wip|release|breaking change)(\(.+\))?: .{1,50}/;
|
|
27
29
|
const mergeRE = /Merge (remote-tracking )?branch /;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
class Message {
|
|
31
|
+
static lint = (commitMessage) => {
|
|
32
|
+
let content = "";
|
|
33
|
+
if (!commitRE.test(commitMessage) && !mergeRE.test(commitMessage)) {
|
|
34
|
+
content += `
|
|
35
|
+
Invalid Commit Message: "${commitMessage}".
|
|
36
|
+
`;
|
|
37
|
+
content += `
|
|
35
38
|
Examples:
|
|
36
39
|
`;
|
|
37
|
-
|
|
40
|
+
content += ` - fix(Button): incorrect style
|
|
38
41
|
`;
|
|
39
|
-
|
|
42
|
+
content += ` - feat(Button): incorrect style
|
|
40
43
|
`;
|
|
41
|
-
|
|
44
|
+
content += ` - docs(Button): fix typo
|
|
42
45
|
`;
|
|
43
|
-
|
|
46
|
+
content += `
|
|
44
47
|
Allowed Types:
|
|
45
48
|
`;
|
|
46
|
-
|
|
49
|
+
content += ` - fix:修补bug
|
|
47
50
|
`;
|
|
48
|
-
|
|
51
|
+
content += ` - feat:新功能(feature)
|
|
49
52
|
`;
|
|
50
|
-
|
|
53
|
+
content += ` - docs:文档(documentation)
|
|
51
54
|
`;
|
|
52
|
-
|
|
55
|
+
content += ` - style:不影响代码含义的更改,可能与代码格式有关,例如空格、缺少分号等
|
|
53
56
|
`;
|
|
54
|
-
|
|
57
|
+
content += ` - test:包括新的或更正以前的测试
|
|
55
58
|
`;
|
|
56
|
-
|
|
59
|
+
content += ` - chore:构建过程或辅助工具的变动
|
|
57
60
|
`;
|
|
58
|
-
|
|
61
|
+
content += ` - refactor:重构(即不是新增功能,也不是修改bug的代码变动)
|
|
59
62
|
`;
|
|
60
|
-
|
|
63
|
+
content += ` - perf:性能改进(performance improvements)
|
|
61
64
|
`;
|
|
62
|
-
|
|
65
|
+
content += ` - types:类型
|
|
63
66
|
`;
|
|
64
|
-
|
|
67
|
+
content += ` - build:影响构建系统或外部依赖项的更改
|
|
65
68
|
`;
|
|
66
|
-
|
|
69
|
+
content += ` - ci: 持续集成相关
|
|
67
70
|
`;
|
|
68
|
-
|
|
71
|
+
content += ` - breaking change:破坏性修改
|
|
69
72
|
`;
|
|
70
|
-
|
|
73
|
+
content += ` - void:无类型,通常用于初始化
|
|
71
74
|
`;
|
|
72
|
-
|
|
75
|
+
content += ` - Merge branch 'foo' into 'bar'
|
|
73
76
|
`;
|
|
74
|
-
|
|
77
|
+
content += ` - Revert ""
|
|
75
78
|
`;
|
|
79
|
+
}
|
|
80
|
+
return content;
|
|
81
|
+
};
|
|
82
|
+
/* istanbul ignore next -- @preserve */
|
|
83
|
+
static run = (argvStartIndex, argv = process.argv) => {
|
|
84
|
+
const filepath = argv[argvStartIndex];
|
|
85
|
+
const message = filepath && fs__namespace.existsSync(filepath) ? fs__namespace.readFileSync(filepath, "utf-8").trim() : filepath || "";
|
|
86
|
+
const excludeIndex = argv.findIndex((i) => i === "--message-exclude");
|
|
87
|
+
const excludes = excludeIndex !== -1 && argv[excludeIndex + 1] ? new RegExp(`(${argv[excludeIndex + 1].replace(/,/g, "|")})`) : void 0;
|
|
88
|
+
if (message) {
|
|
89
|
+
if (excludes && excludes.test(message)) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
return Message.lint(message);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const cwd = process.cwd();
|
|
98
|
+
class FilePath {
|
|
99
|
+
static lint = (filePath) => {
|
|
100
|
+
if (/[A-Z]/g.test(filePath)) {
|
|
101
|
+
return filePath;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
/* istanbul ignore next -- @preserve */
|
|
105
|
+
static run = (argvStartIndex, argv = process.argv) => {
|
|
106
|
+
const filePaths = argv.slice(argvStartIndex, argv.length);
|
|
107
|
+
const excludeIndex = argv.findIndex((i) => i === "--file-path-exclude");
|
|
108
|
+
const excludes = excludeIndex !== -1 && argv[excludeIndex + 1] ? new RegExp(`(${argv[excludeIndex + 1].replace(/,/g, "|")})`) : void 0;
|
|
109
|
+
const errors = [];
|
|
110
|
+
for (let i = 0; i < filePaths.length; i++) {
|
|
111
|
+
const filePath = filePaths[i];
|
|
112
|
+
if (filePath && fs__namespace.existsSync(filePath) && path__namespace.extname(filePath) !== ".md") {
|
|
113
|
+
const filePathV2 = path__namespace.relative(cwd, filePath);
|
|
114
|
+
if (excludes && excludes.test(filePath)) continue;
|
|
115
|
+
const error = FilePath.lint(filePathV2);
|
|
116
|
+
error && errors.push(error);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (errors.length) {
|
|
120
|
+
return `Invalid Commit FilePaths:
|
|
121
|
+
|
|
122
|
+
${errors.join("\n")}
|
|
123
|
+
|
|
124
|
+
Allowed Filepath: xxx-xxx-xxx
|
|
125
|
+
`;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const check = () => {
|
|
131
|
+
for (let i = 0; i < process.argv.length; i++) {
|
|
132
|
+
if (["--edit", "--message"].includes(process.argv[i])) {
|
|
133
|
+
return Message.run(i + 1);
|
|
134
|
+
}
|
|
135
|
+
if (["--file-path"].includes(process.argv[i])) {
|
|
136
|
+
return FilePath.run(i + 1);
|
|
137
|
+
}
|
|
76
138
|
}
|
|
77
|
-
return content;
|
|
78
139
|
};
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const error = run(message);
|
|
84
|
-
if (error) {
|
|
85
|
-
console.error(error);
|
|
86
|
-
process.exit(1);
|
|
87
|
-
}
|
|
140
|
+
const error = check();
|
|
141
|
+
if (error) {
|
|
142
|
+
console.error(error);
|
|
143
|
+
process.exit(1);
|
|
88
144
|
}
|
|
89
145
|
|
|
90
|
-
exports.
|
|
146
|
+
exports.FilePath = FilePath;
|
|
147
|
+
exports.Message = Message;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
export declare
|
|
1
|
+
export declare class FilePath {
|
|
2
|
+
static lint: (filePath: string) => string | undefined;
|
|
3
|
+
static run: (argvStartIndex: number, argv?: string[]) => string | undefined;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export declare class Message {
|
|
7
|
+
static lint: (commitMessage: string) => string;
|
|
8
|
+
static run: (argvStartIndex: number, argv?: string[]) => string | undefined;
|
|
9
|
+
}
|
|
2
10
|
|
|
3
11
|
export { }
|
package/dist/index.js
CHANGED
|
@@ -1,67 +1,122 @@
|
|
|
1
1
|
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
2
3
|
|
|
3
4
|
const commitRE = /^(revert:? "?|Revert "?)?(void|fix|feat|docs|style|perf|test|types|build|chore|refactor|workflow|ci|wip|release|breaking change)(\(.+\))?: .{1,50}/;
|
|
4
5
|
const mergeRE = /Merge (remote-tracking )?branch /;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
class Message {
|
|
7
|
+
static lint = (commitMessage) => {
|
|
8
|
+
let content = "";
|
|
9
|
+
if (!commitRE.test(commitMessage) && !mergeRE.test(commitMessage)) {
|
|
10
|
+
content += `
|
|
11
|
+
Invalid Commit Message: "${commitMessage}".
|
|
12
|
+
`;
|
|
13
|
+
content += `
|
|
12
14
|
Examples:
|
|
13
15
|
`;
|
|
14
|
-
|
|
16
|
+
content += ` - fix(Button): incorrect style
|
|
15
17
|
`;
|
|
16
|
-
|
|
18
|
+
content += ` - feat(Button): incorrect style
|
|
17
19
|
`;
|
|
18
|
-
|
|
20
|
+
content += ` - docs(Button): fix typo
|
|
19
21
|
`;
|
|
20
|
-
|
|
22
|
+
content += `
|
|
21
23
|
Allowed Types:
|
|
22
24
|
`;
|
|
23
|
-
|
|
25
|
+
content += ` - fix:修补bug
|
|
24
26
|
`;
|
|
25
|
-
|
|
27
|
+
content += ` - feat:新功能(feature)
|
|
26
28
|
`;
|
|
27
|
-
|
|
29
|
+
content += ` - docs:文档(documentation)
|
|
28
30
|
`;
|
|
29
|
-
|
|
31
|
+
content += ` - style:不影响代码含义的更改,可能与代码格式有关,例如空格、缺少分号等
|
|
30
32
|
`;
|
|
31
|
-
|
|
33
|
+
content += ` - test:包括新的或更正以前的测试
|
|
32
34
|
`;
|
|
33
|
-
|
|
35
|
+
content += ` - chore:构建过程或辅助工具的变动
|
|
34
36
|
`;
|
|
35
|
-
|
|
37
|
+
content += ` - refactor:重构(即不是新增功能,也不是修改bug的代码变动)
|
|
36
38
|
`;
|
|
37
|
-
|
|
39
|
+
content += ` - perf:性能改进(performance improvements)
|
|
38
40
|
`;
|
|
39
|
-
|
|
41
|
+
content += ` - types:类型
|
|
40
42
|
`;
|
|
41
|
-
|
|
43
|
+
content += ` - build:影响构建系统或外部依赖项的更改
|
|
42
44
|
`;
|
|
43
|
-
|
|
45
|
+
content += ` - ci: 持续集成相关
|
|
44
46
|
`;
|
|
45
|
-
|
|
47
|
+
content += ` - breaking change:破坏性修改
|
|
46
48
|
`;
|
|
47
|
-
|
|
49
|
+
content += ` - void:无类型,通常用于初始化
|
|
48
50
|
`;
|
|
49
|
-
|
|
51
|
+
content += ` - Merge branch 'foo' into 'bar'
|
|
50
52
|
`;
|
|
51
|
-
|
|
53
|
+
content += ` - Revert ""
|
|
52
54
|
`;
|
|
55
|
+
}
|
|
56
|
+
return content;
|
|
57
|
+
};
|
|
58
|
+
/* istanbul ignore next -- @preserve */
|
|
59
|
+
static run = (argvStartIndex, argv = process.argv) => {
|
|
60
|
+
const filepath = argv[argvStartIndex];
|
|
61
|
+
const message = filepath && fs.existsSync(filepath) ? fs.readFileSync(filepath, "utf-8").trim() : filepath || "";
|
|
62
|
+
const excludeIndex = argv.findIndex((i) => i === "--message-exclude");
|
|
63
|
+
const excludes = excludeIndex !== -1 && argv[excludeIndex + 1] ? new RegExp(`(${argv[excludeIndex + 1].replace(/,/g, "|")})`) : void 0;
|
|
64
|
+
if (message) {
|
|
65
|
+
if (excludes && excludes.test(message)) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
return Message.lint(message);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const cwd = process.cwd();
|
|
74
|
+
class FilePath {
|
|
75
|
+
static lint = (filePath) => {
|
|
76
|
+
if (/[A-Z]/g.test(filePath)) {
|
|
77
|
+
return filePath;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
/* istanbul ignore next -- @preserve */
|
|
81
|
+
static run = (argvStartIndex, argv = process.argv) => {
|
|
82
|
+
const filePaths = argv.slice(argvStartIndex, argv.length);
|
|
83
|
+
const excludeIndex = argv.findIndex((i) => i === "--file-path-exclude");
|
|
84
|
+
const excludes = excludeIndex !== -1 && argv[excludeIndex + 1] ? new RegExp(`(${argv[excludeIndex + 1].replace(/,/g, "|")})`) : void 0;
|
|
85
|
+
const errors = [];
|
|
86
|
+
for (let i = 0; i < filePaths.length; i++) {
|
|
87
|
+
const filePath = filePaths[i];
|
|
88
|
+
if (filePath && fs.existsSync(filePath) && path.extname(filePath) !== ".md") {
|
|
89
|
+
const filePathV2 = path.relative(cwd, filePath);
|
|
90
|
+
if (excludes && excludes.test(filePath)) continue;
|
|
91
|
+
const error = FilePath.lint(filePathV2);
|
|
92
|
+
error && errors.push(error);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (errors.length) {
|
|
96
|
+
return `Invalid Commit FilePaths:
|
|
97
|
+
|
|
98
|
+
${errors.join("\n")}
|
|
99
|
+
|
|
100
|
+
Allowed Filepath: xxx-xxx-xxx
|
|
101
|
+
`;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const check = () => {
|
|
107
|
+
for (let i = 0; i < process.argv.length; i++) {
|
|
108
|
+
if (["--edit", "--message"].includes(process.argv[i])) {
|
|
109
|
+
return Message.run(i + 1);
|
|
110
|
+
}
|
|
111
|
+
if (["--file-path"].includes(process.argv[i])) {
|
|
112
|
+
return FilePath.run(i + 1);
|
|
113
|
+
}
|
|
53
114
|
}
|
|
54
|
-
return content;
|
|
55
115
|
};
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const error = run(message);
|
|
61
|
-
if (error) {
|
|
62
|
-
console.error(error);
|
|
63
|
-
process.exit(1);
|
|
64
|
-
}
|
|
116
|
+
const error = check();
|
|
117
|
+
if (error) {
|
|
118
|
+
console.error(error);
|
|
119
|
+
process.exit(1);
|
|
65
120
|
}
|
|
66
121
|
|
|
67
|
-
export {
|
|
122
|
+
export { FilePath, Message };
|