better-commits 1.0.4 → 1.0.6
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/.better-commits.json +27 -0
- package/dist/index.js +36 -14
- package/dist/init.js +12 -9
- package/dist/utils.js +12 -9
- package/dist/zod-state.js +12 -9
- package/package.json +1 -1
- package/readme.md +30 -7
- package/src/index.ts +23 -9
- package/src/utils.ts +11 -10
- package/src/zod-state.ts +1 -1
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"commit_scope": {
|
|
3
|
+
"enable": true,
|
|
4
|
+
"initial_value": "main",
|
|
5
|
+
"options": [
|
|
6
|
+
{
|
|
7
|
+
"value": "main",
|
|
8
|
+
"label": "main"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"value": "init",
|
|
12
|
+
"label": "init"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"value": "util",
|
|
16
|
+
"label": "util"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"value": "",
|
|
20
|
+
"label": "none"
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
"check_ticket": {
|
|
25
|
+
"append_hashtag": true
|
|
26
|
+
}
|
|
27
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -47,12 +47,14 @@ var REGEX_START_TAG = new RegExp(/^(\w+-\d+)/);
|
|
|
47
47
|
var REGEX_SLASH_NUM = new RegExp(/\/(\d+)/);
|
|
48
48
|
var REGEX_START_NUM = new RegExp(/^(\d+)/);
|
|
49
49
|
var DEFAULT_TYPE_OPTIONS = [
|
|
50
|
-
{ value: "feat", label: "feat" },
|
|
51
|
-
{ value: "fix", label: "fix" },
|
|
52
|
-
{ value: "docs", label: "docs" },
|
|
53
|
-
{ value: "refactor", label: "refactor" },
|
|
54
|
-
{ value: "perf", label: "perf" },
|
|
55
|
-
{ value: "test", label: "test" },
|
|
50
|
+
{ value: "feat", label: "feat", hint: "A new feature" },
|
|
51
|
+
{ value: "fix", label: "fix", hint: "A bug fix" },
|
|
52
|
+
{ value: "docs", label: "docs", hint: "Documentation only changes" },
|
|
53
|
+
{ value: "refactor", label: "refactor", hint: "A code change that neither fixes a bug nor adds a feature" },
|
|
54
|
+
{ value: "perf", label: "perf", hint: "A code change that improves performance" },
|
|
55
|
+
{ value: "test", label: "test", hint: "Adding missing tests or correcting existing tests" },
|
|
56
|
+
{ value: "build", label: "build", hint: "Changes that affect the build system or external dependencies" },
|
|
57
|
+
{ value: "ci", label: "ci", hint: "Changes to our CI configuration files and scripts" },
|
|
56
58
|
{ value: "", label: "none" }
|
|
57
59
|
];
|
|
58
60
|
var DEFAULT_SCOPE_OPTIONS = [
|
|
@@ -65,10 +67,11 @@ var DEFAULT_SCOPE_OPTIONS = [
|
|
|
65
67
|
var COMMIT_FOOTER_OPTIONS = [
|
|
66
68
|
{ value: "closes", label: "closes <issue/ticket>", hint: "Attempts to infer ticket from branch" },
|
|
67
69
|
{ value: "breaking-change", label: "breaking change", hint: "Add breaking change" },
|
|
68
|
-
{ value: "deprecated", label: "deprecated", hint: "Add deprecated change" }
|
|
70
|
+
{ value: "deprecated", label: "deprecated", hint: "Add deprecated change" },
|
|
71
|
+
{ value: "custom", label: "custom", hint: "Add a custom footer" }
|
|
69
72
|
];
|
|
70
|
-
var Z_FOOTER_OPTIONS = import_zod.z.enum(["closes", "breaking-change", "deprecated"]);
|
|
71
|
-
var FOOTER_OPTION_VALUES = ["closes", "breaking-change", "deprecated"];
|
|
73
|
+
var Z_FOOTER_OPTIONS = import_zod.z.enum(["closes", "breaking-change", "deprecated", "custom"]);
|
|
74
|
+
var FOOTER_OPTION_VALUES = ["closes", "breaking-change", "deprecated", "custom"];
|
|
72
75
|
function infer_type_from_branch(types) {
|
|
73
76
|
let branch = "";
|
|
74
77
|
try {
|
|
@@ -165,7 +168,8 @@ var CommitState = import_zod2.z.object({
|
|
|
165
168
|
breaking_body: import_zod2.z.string().default(""),
|
|
166
169
|
deprecates: import_zod2.z.string().default(""),
|
|
167
170
|
deprecates_title: import_zod2.z.string().default(""),
|
|
168
|
-
deprecates_body: import_zod2.z.string().default("")
|
|
171
|
+
deprecates_body: import_zod2.z.string().default(""),
|
|
172
|
+
custom_footer: import_zod2.z.string().default("")
|
|
169
173
|
}).default({});
|
|
170
174
|
|
|
171
175
|
// src/index.ts
|
|
@@ -277,7 +281,7 @@ async function main(config) {
|
|
|
277
281
|
}
|
|
278
282
|
if (config.check_ticket.confirm_ticket) {
|
|
279
283
|
const user_commit_ticket = await p.text({
|
|
280
|
-
message: commit_state.ticket ?
|
|
284
|
+
message: commit_state.ticket ? `Ticket / issue infered from branch ${import_picocolors2.default.dim("(confirm / edit)")}` : `Add ticket / issue ${OPTIONAL_PROMPT}`,
|
|
281
285
|
initialValue: commit_state.ticket
|
|
282
286
|
});
|
|
283
287
|
if (p.isCancel(user_commit_ticket))
|
|
@@ -322,7 +326,9 @@ async function main(config) {
|
|
|
322
326
|
options: COMMIT_FOOTER_OPTIONS,
|
|
323
327
|
required: false
|
|
324
328
|
});
|
|
325
|
-
if (commit_footer
|
|
329
|
+
if (p.isCancel(commit_footer))
|
|
330
|
+
process.exit(0);
|
|
331
|
+
if (commit_footer.includes("breaking-change")) {
|
|
326
332
|
const breaking_changes_title = await p.text({
|
|
327
333
|
message: "Breaking changes: Write a short title / summary",
|
|
328
334
|
placeholder: "",
|
|
@@ -338,7 +344,7 @@ async function main(config) {
|
|
|
338
344
|
commit_state.breaking_title = breaking_changes_title;
|
|
339
345
|
commit_state.breaking_body = breaking_changes_body;
|
|
340
346
|
}
|
|
341
|
-
if (commit_footer
|
|
347
|
+
if (commit_footer.includes("deprecated")) {
|
|
342
348
|
const deprecated_title = await p.text({
|
|
343
349
|
message: "Deprecated: Write a short title / summary",
|
|
344
350
|
placeholder: "",
|
|
@@ -354,9 +360,16 @@ async function main(config) {
|
|
|
354
360
|
commit_state.deprecates_body = deprecated_body;
|
|
355
361
|
commit_state.deprecates_title = deprecated_title;
|
|
356
362
|
}
|
|
357
|
-
if (commit_footer
|
|
363
|
+
if (commit_footer.includes("closes")) {
|
|
358
364
|
commit_state.closes = "Closes:";
|
|
359
365
|
}
|
|
366
|
+
if (commit_footer.includes("custom")) {
|
|
367
|
+
const custom_footer = await p.text({
|
|
368
|
+
message: "Write a custom footer",
|
|
369
|
+
placeholder: ""
|
|
370
|
+
});
|
|
371
|
+
commit_state.custom_footer = custom_footer;
|
|
372
|
+
}
|
|
360
373
|
}
|
|
361
374
|
let continue_commit = true;
|
|
362
375
|
p.note(build_commit_string(commit_state, config, true), "Commit Preview");
|
|
@@ -421,6 +434,15 @@ ${title}`;
|
|
|
421
434
|
commit_string += `
|
|
422
435
|
|
|
423
436
|
${body}`;
|
|
437
|
+
}
|
|
438
|
+
if (commit_state.custom_footer) {
|
|
439
|
+
const temp = commit_state.custom_footer.split("\\n");
|
|
440
|
+
const res = temp.map((v) => colorize ? import_picocolors2.default.reset(v.trim()) : v.trim()).join("\n");
|
|
441
|
+
commit_string += colorize ? `
|
|
442
|
+
|
|
443
|
+
${res}` : `
|
|
444
|
+
|
|
445
|
+
${res}`;
|
|
424
446
|
}
|
|
425
447
|
if (commit_state.closes && commit_state.ticket) {
|
|
426
448
|
commit_string += colorize ? `
|
package/dist/init.js
CHANGED
|
@@ -37,12 +37,14 @@ var REGEX_START_TAG = new RegExp(/^(\w+-\d+)/);
|
|
|
37
37
|
var REGEX_SLASH_NUM = new RegExp(/\/(\d+)/);
|
|
38
38
|
var REGEX_START_NUM = new RegExp(/^(\d+)/);
|
|
39
39
|
var DEFAULT_TYPE_OPTIONS = [
|
|
40
|
-
{ value: "feat", label: "feat" },
|
|
41
|
-
{ value: "fix", label: "fix" },
|
|
42
|
-
{ value: "docs", label: "docs" },
|
|
43
|
-
{ value: "refactor", label: "refactor" },
|
|
44
|
-
{ value: "perf", label: "perf" },
|
|
45
|
-
{ value: "test", label: "test" },
|
|
40
|
+
{ value: "feat", label: "feat", hint: "A new feature" },
|
|
41
|
+
{ value: "fix", label: "fix", hint: "A bug fix" },
|
|
42
|
+
{ value: "docs", label: "docs", hint: "Documentation only changes" },
|
|
43
|
+
{ value: "refactor", label: "refactor", hint: "A code change that neither fixes a bug nor adds a feature" },
|
|
44
|
+
{ value: "perf", label: "perf", hint: "A code change that improves performance" },
|
|
45
|
+
{ value: "test", label: "test", hint: "Adding missing tests or correcting existing tests" },
|
|
46
|
+
{ value: "build", label: "build", hint: "Changes that affect the build system or external dependencies" },
|
|
47
|
+
{ value: "ci", label: "ci", hint: "Changes to our CI configuration files and scripts" },
|
|
46
48
|
{ value: "", label: "none" }
|
|
47
49
|
];
|
|
48
50
|
var DEFAULT_SCOPE_OPTIONS = [
|
|
@@ -52,8 +54,8 @@ var DEFAULT_SCOPE_OPTIONS = [
|
|
|
52
54
|
{ value: "tools", label: "tools" },
|
|
53
55
|
{ value: "", label: "none" }
|
|
54
56
|
];
|
|
55
|
-
var Z_FOOTER_OPTIONS = import_zod.z.enum(["closes", "breaking-change", "deprecated"]);
|
|
56
|
-
var FOOTER_OPTION_VALUES = ["closes", "breaking-change", "deprecated"];
|
|
57
|
+
var Z_FOOTER_OPTIONS = import_zod.z.enum(["closes", "breaking-change", "deprecated", "custom"]);
|
|
58
|
+
var FOOTER_OPTION_VALUES = ["closes", "breaking-change", "deprecated", "custom"];
|
|
57
59
|
|
|
58
60
|
// src/zod-state.ts
|
|
59
61
|
var Config = import_zod2.z.object({
|
|
@@ -117,7 +119,8 @@ var CommitState = import_zod2.z.object({
|
|
|
117
119
|
breaking_body: import_zod2.z.string().default(""),
|
|
118
120
|
deprecates: import_zod2.z.string().default(""),
|
|
119
121
|
deprecates_title: import_zod2.z.string().default(""),
|
|
120
|
-
deprecates_body: import_zod2.z.string().default("")
|
|
122
|
+
deprecates_body: import_zod2.z.string().default(""),
|
|
123
|
+
custom_footer: import_zod2.z.string().default("")
|
|
121
124
|
}).default({});
|
|
122
125
|
|
|
123
126
|
// src/init.ts
|
package/dist/utils.js
CHANGED
|
@@ -61,12 +61,14 @@ var REGEX_START_TAG = new RegExp(/^(\w+-\d+)/);
|
|
|
61
61
|
var REGEX_SLASH_NUM = new RegExp(/\/(\d+)/);
|
|
62
62
|
var REGEX_START_NUM = new RegExp(/^(\d+)/);
|
|
63
63
|
var DEFAULT_TYPE_OPTIONS = [
|
|
64
|
-
{ value: "feat", label: "feat" },
|
|
65
|
-
{ value: "fix", label: "fix" },
|
|
66
|
-
{ value: "docs", label: "docs" },
|
|
67
|
-
{ value: "refactor", label: "refactor" },
|
|
68
|
-
{ value: "perf", label: "perf" },
|
|
69
|
-
{ value: "test", label: "test" },
|
|
64
|
+
{ value: "feat", label: "feat", hint: "A new feature" },
|
|
65
|
+
{ value: "fix", label: "fix", hint: "A bug fix" },
|
|
66
|
+
{ value: "docs", label: "docs", hint: "Documentation only changes" },
|
|
67
|
+
{ value: "refactor", label: "refactor", hint: "A code change that neither fixes a bug nor adds a feature" },
|
|
68
|
+
{ value: "perf", label: "perf", hint: "A code change that improves performance" },
|
|
69
|
+
{ value: "test", label: "test", hint: "Adding missing tests or correcting existing tests" },
|
|
70
|
+
{ value: "build", label: "build", hint: "Changes that affect the build system or external dependencies" },
|
|
71
|
+
{ value: "ci", label: "ci", hint: "Changes to our CI configuration files and scripts" },
|
|
70
72
|
{ value: "", label: "none" }
|
|
71
73
|
];
|
|
72
74
|
var DEFAULT_SCOPE_OPTIONS = [
|
|
@@ -79,10 +81,11 @@ var DEFAULT_SCOPE_OPTIONS = [
|
|
|
79
81
|
var COMMIT_FOOTER_OPTIONS = [
|
|
80
82
|
{ value: "closes", label: "closes <issue/ticket>", hint: "Attempts to infer ticket from branch" },
|
|
81
83
|
{ value: "breaking-change", label: "breaking change", hint: "Add breaking change" },
|
|
82
|
-
{ value: "deprecated", label: "deprecated", hint: "Add deprecated change" }
|
|
84
|
+
{ value: "deprecated", label: "deprecated", hint: "Add deprecated change" },
|
|
85
|
+
{ value: "custom", label: "custom", hint: "Add a custom footer" }
|
|
83
86
|
];
|
|
84
|
-
var Z_FOOTER_OPTIONS = import_zod.z.enum(["closes", "breaking-change", "deprecated"]);
|
|
85
|
-
var FOOTER_OPTION_VALUES = ["closes", "breaking-change", "deprecated"];
|
|
87
|
+
var Z_FOOTER_OPTIONS = import_zod.z.enum(["closes", "breaking-change", "deprecated", "custom"]);
|
|
88
|
+
var FOOTER_OPTION_VALUES = ["closes", "breaking-change", "deprecated", "custom"];
|
|
86
89
|
function infer_type_from_branch(types) {
|
|
87
90
|
let branch = "";
|
|
88
91
|
try {
|
package/dist/zod-state.js
CHANGED
|
@@ -46,12 +46,14 @@ var REGEX_START_TAG = new RegExp(/^(\w+-\d+)/);
|
|
|
46
46
|
var REGEX_SLASH_NUM = new RegExp(/\/(\d+)/);
|
|
47
47
|
var REGEX_START_NUM = new RegExp(/^(\d+)/);
|
|
48
48
|
var DEFAULT_TYPE_OPTIONS = [
|
|
49
|
-
{ value: "feat", label: "feat" },
|
|
50
|
-
{ value: "fix", label: "fix" },
|
|
51
|
-
{ value: "docs", label: "docs" },
|
|
52
|
-
{ value: "refactor", label: "refactor" },
|
|
53
|
-
{ value: "perf", label: "perf" },
|
|
54
|
-
{ value: "test", label: "test" },
|
|
49
|
+
{ value: "feat", label: "feat", hint: "A new feature" },
|
|
50
|
+
{ value: "fix", label: "fix", hint: "A bug fix" },
|
|
51
|
+
{ value: "docs", label: "docs", hint: "Documentation only changes" },
|
|
52
|
+
{ value: "refactor", label: "refactor", hint: "A code change that neither fixes a bug nor adds a feature" },
|
|
53
|
+
{ value: "perf", label: "perf", hint: "A code change that improves performance" },
|
|
54
|
+
{ value: "test", label: "test", hint: "Adding missing tests or correcting existing tests" },
|
|
55
|
+
{ value: "build", label: "build", hint: "Changes that affect the build system or external dependencies" },
|
|
56
|
+
{ value: "ci", label: "ci", hint: "Changes to our CI configuration files and scripts" },
|
|
55
57
|
{ value: "", label: "none" }
|
|
56
58
|
];
|
|
57
59
|
var DEFAULT_SCOPE_OPTIONS = [
|
|
@@ -61,8 +63,8 @@ var DEFAULT_SCOPE_OPTIONS = [
|
|
|
61
63
|
{ value: "tools", label: "tools" },
|
|
62
64
|
{ value: "", label: "none" }
|
|
63
65
|
];
|
|
64
|
-
var Z_FOOTER_OPTIONS = import_zod.z.enum(["closes", "breaking-change", "deprecated"]);
|
|
65
|
-
var FOOTER_OPTION_VALUES = ["closes", "breaking-change", "deprecated"];
|
|
66
|
+
var Z_FOOTER_OPTIONS = import_zod.z.enum(["closes", "breaking-change", "deprecated", "custom"]);
|
|
67
|
+
var FOOTER_OPTION_VALUES = ["closes", "breaking-change", "deprecated", "custom"];
|
|
66
68
|
|
|
67
69
|
// src/zod-state.ts
|
|
68
70
|
var Config = import_zod2.z.object({
|
|
@@ -126,7 +128,8 @@ var CommitState = import_zod2.z.object({
|
|
|
126
128
|
breaking_body: import_zod2.z.string().default(""),
|
|
127
129
|
deprecates: import_zod2.z.string().default(""),
|
|
128
130
|
deprecates_title: import_zod2.z.string().default(""),
|
|
129
|
-
deprecates_body: import_zod2.z.string().default("")
|
|
131
|
+
deprecates_body: import_zod2.z.string().default(""),
|
|
132
|
+
custom_footer: import_zod2.z.string().default("")
|
|
130
133
|
}).default({});
|
|
131
134
|
// Annotate the CommonJS export names for ESM import in node:
|
|
132
135
|
0 && (module.exports = {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "better-commits",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.6",
|
|
5
5
|
"description": "A CLI for creating better commits following the conventional commit guidelines",
|
|
6
6
|
"author": "Erik Verduin (https://github.com/everduin94)",
|
|
7
7
|
"keywords": [
|
package/readme.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# 📝 Better Commits
|
|
2
2
|
|
|
3
|
+

|
|
4
|
+
[](https://www.npmjs.com/package/better-commits)
|
|
5
|
+
[](https://packagephobia.com/result?p=better-commits)
|
|
6
|
+

|
|
7
|
+
|
|
3
8
|
A CLI for writing better commits, following the conventional commit guidelines, written with Typescript | ZOD | Clack
|
|
4
9
|
|
|
5
10
|
https://user-images.githubusercontent.com/14320878/224050591-c6035ac5-1120-40c8-97b0-c33ebcb11b3e.mov
|
|
@@ -59,27 +64,43 @@ All properties are optional, they can be removed from your configuration and wil
|
|
|
59
64
|
"options": [
|
|
60
65
|
{
|
|
61
66
|
"value": "feat",
|
|
62
|
-
"label": "feat"
|
|
67
|
+
"label": "feat",
|
|
68
|
+
"hint": "A new feature"
|
|
63
69
|
},
|
|
64
70
|
{
|
|
65
71
|
"value": "fix",
|
|
66
|
-
"label": "fix"
|
|
72
|
+
"label": "fix",
|
|
73
|
+
"hint": "A bug fix"
|
|
67
74
|
},
|
|
68
75
|
{
|
|
69
76
|
"value": "docs",
|
|
70
|
-
"label": "docs"
|
|
77
|
+
"label": "docs",
|
|
78
|
+
"hint": "Documentation only changes"
|
|
71
79
|
},
|
|
72
80
|
{
|
|
73
81
|
"value": "refactor",
|
|
74
|
-
"label": "refactor"
|
|
82
|
+
"label": "refactor",
|
|
83
|
+
"hint": "A code change that neither fixes a bug nor adds a feature"
|
|
75
84
|
},
|
|
76
85
|
{
|
|
77
86
|
"value": "perf",
|
|
78
|
-
"label": "perf"
|
|
87
|
+
"label": "perf",
|
|
88
|
+
"hint": "A code change that improves performance"
|
|
79
89
|
},
|
|
80
90
|
{
|
|
81
91
|
"value": "test",
|
|
82
|
-
"label": "test"
|
|
92
|
+
"label": "test",
|
|
93
|
+
"hint": "Adding missing tests or correcting existing tests"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"value": "build",
|
|
97
|
+
"label": "build",
|
|
98
|
+
"hint": "Changes that affect the build system or external dependencies"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"value": "ci",
|
|
102
|
+
"label": "ci",
|
|
103
|
+
"hint": "Changes to our CI configuration files and scripts"
|
|
83
104
|
},
|
|
84
105
|
{
|
|
85
106
|
"value": "",
|
|
@@ -132,7 +153,8 @@ All properties are optional, they can be removed from your configuration and wil
|
|
|
132
153
|
"options": [
|
|
133
154
|
"closes",
|
|
134
155
|
"breaking-change",
|
|
135
|
-
"deprecated"
|
|
156
|
+
"deprecated",
|
|
157
|
+
"custom"
|
|
136
158
|
]
|
|
137
159
|
},
|
|
138
160
|
"breaking_change": {
|
|
@@ -180,6 +202,7 @@ To simplify the CLI, some rules are enforced at runtime to make sure the program
|
|
|
180
202
|
- `USER/TYPE/TICKET-description`
|
|
181
203
|
- if you're using Github issues to track your work, and select the `closes` footer option when writing your commit. Github will **automatically link and close** that issue when your **pr is merged**
|
|
182
204
|
- [better-commits](https://packagephobia.com/result?p=better-commits) is much smaller than its alternative [commitizen](https://packagephobia.com/result?p=commitizen)
|
|
205
|
+
- `better-commits` uses native `git` commands under the hood. So any hooks, tools, or staging should work as if it was a normal commit.
|
|
183
206
|
|
|
184
207
|
## ❓ Troubleshooting
|
|
185
208
|
|
package/src/index.ts
CHANGED
|
@@ -8,8 +8,7 @@ import { execSync } from 'child_process';
|
|
|
8
8
|
import { z } from "zod";
|
|
9
9
|
import { fromZodError } from 'zod-validation-error';
|
|
10
10
|
import { CommitState, Config } from './zod-state';
|
|
11
|
-
import { CONFIG_FILE_NAME, get_default_config_path, check_missing_stage, addNewLine, SPACE_TO_SELECT, REGEX_SLASH_TAG, REGEX_SLASH_NUM, REGEX_START_TAG, REGEX_START_NUM, OPTIONAL_PROMPT, clean_commit_title, COMMIT_FOOTER_OPTIONS, infer_type_from_branch } from './utils';
|
|
12
|
-
|
|
11
|
+
import { CONFIG_FILE_NAME, get_default_config_path, check_missing_stage, addNewLine, SPACE_TO_SELECT, REGEX_SLASH_TAG, REGEX_SLASH_NUM, REGEX_START_TAG, REGEX_START_NUM, OPTIONAL_PROMPT, clean_commit_title, COMMIT_FOOTER_OPTIONS, infer_type_from_branch, Z_FOOTER_OPTIONS } from './utils';
|
|
13
12
|
|
|
14
13
|
main(load_setup());
|
|
15
14
|
|
|
@@ -133,7 +132,7 @@ async function main(config: z.infer<typeof Config>) {
|
|
|
133
132
|
}
|
|
134
133
|
if (config.check_ticket.confirm_ticket) {
|
|
135
134
|
const user_commit_ticket = await p.text({
|
|
136
|
-
message: commit_state.ticket ?
|
|
135
|
+
message: commit_state.ticket ? `Ticket / issue infered from branch ${color.dim('(confirm / edit)')}`: `Add ticket / issue ${OPTIONAL_PROMPT}`,
|
|
137
136
|
initialValue: commit_state.ticket,
|
|
138
137
|
}) as string
|
|
139
138
|
if (p.isCancel(user_commit_ticket)) process.exit(0)
|
|
@@ -173,16 +172,16 @@ async function main(config: z.infer<typeof Config>) {
|
|
|
173
172
|
commit_state.body = commit_body;
|
|
174
173
|
}
|
|
175
174
|
|
|
176
|
-
// TODO: Fix type -- should be able to infer?
|
|
177
175
|
if (config.commit_footer.enable) {
|
|
178
176
|
const commit_footer = await p.multiselect({
|
|
179
177
|
message: `Select optional footers ${SPACE_TO_SELECT}`,
|
|
180
178
|
initialValues: config.commit_footer.initial_value,
|
|
181
|
-
options: COMMIT_FOOTER_OPTIONS as {value:
|
|
179
|
+
options: COMMIT_FOOTER_OPTIONS as {value: z.infer<typeof Z_FOOTER_OPTIONS>, label: string, hint: string}[],
|
|
182
180
|
required: false
|
|
183
|
-
})
|
|
181
|
+
})
|
|
182
|
+
if (p.isCancel(commit_footer)) process.exit(0)
|
|
184
183
|
|
|
185
|
-
if (commit_footer
|
|
184
|
+
if (commit_footer.includes('breaking-change')) {
|
|
186
185
|
const breaking_changes_title = await p.text({
|
|
187
186
|
message: 'Breaking changes: Write a short title / summary',
|
|
188
187
|
placeholder: '',
|
|
@@ -198,7 +197,7 @@ async function main(config: z.infer<typeof Config>) {
|
|
|
198
197
|
commit_state.breaking_body = breaking_changes_body;
|
|
199
198
|
}
|
|
200
199
|
|
|
201
|
-
if (commit_footer
|
|
200
|
+
if (commit_footer.includes('deprecated')) {
|
|
202
201
|
const deprecated_title = await p.text({
|
|
203
202
|
message: 'Deprecated: Write a short title / summary',
|
|
204
203
|
placeholder: '',
|
|
@@ -214,9 +213,17 @@ async function main(config: z.infer<typeof Config>) {
|
|
|
214
213
|
commit_state.deprecates_title = deprecated_title;
|
|
215
214
|
}
|
|
216
215
|
|
|
217
|
-
if (commit_footer
|
|
216
|
+
if (commit_footer.includes('closes')) {
|
|
218
217
|
commit_state.closes = 'Closes:'
|
|
219
218
|
}
|
|
219
|
+
|
|
220
|
+
if (commit_footer.includes('custom')) {
|
|
221
|
+
const custom_footer = await p.text({
|
|
222
|
+
message: 'Write a custom footer',
|
|
223
|
+
placeholder: '',
|
|
224
|
+
}) as string
|
|
225
|
+
commit_state.custom_footer = custom_footer;
|
|
226
|
+
}
|
|
220
227
|
}
|
|
221
228
|
|
|
222
229
|
|
|
@@ -283,10 +290,17 @@ function build_commit_string(commit_state: z.infer<typeof CommitState>, config:
|
|
|
283
290
|
commit_string += `\n\n${body}`
|
|
284
291
|
}
|
|
285
292
|
|
|
293
|
+
if (commit_state.custom_footer) {
|
|
294
|
+
const temp = commit_state.custom_footer.split('\\n')
|
|
295
|
+
const res = temp.map(v => colorize ? color.reset(v.trim()) : v.trim()).join('\n')
|
|
296
|
+
commit_string += colorize ? `\n\n${res}` : `\n\n${res}`;
|
|
297
|
+
}
|
|
298
|
+
|
|
286
299
|
if (commit_state.closes && commit_state.ticket) {
|
|
287
300
|
commit_string += colorize ? `\n\n${color.reset(commit_state.closes)} ${color.magenta(commit_state.ticket)}` : `\n\n${commit_state.closes} ${commit_state.ticket}`;
|
|
288
301
|
}
|
|
289
302
|
|
|
303
|
+
|
|
290
304
|
return commit_string;
|
|
291
305
|
}
|
|
292
306
|
|
package/src/utils.ts
CHANGED
|
@@ -12,12 +12,14 @@ export const REGEX_START_TAG = new RegExp(/^(\w+-\d+)/)
|
|
|
12
12
|
export const REGEX_SLASH_NUM = new RegExp(/\/(\d+)/)
|
|
13
13
|
export const REGEX_START_NUM = new RegExp(/^(\d+)/)
|
|
14
14
|
export const DEFAULT_TYPE_OPTIONS = [
|
|
15
|
-
{ value: 'feat', label: 'feat' },
|
|
16
|
-
{ value: 'fix', label: 'fix' },
|
|
17
|
-
{ value: 'docs', label: 'docs'},
|
|
18
|
-
{ value: 'refactor', label: 'refactor'},
|
|
19
|
-
{ value: 'perf', label: 'perf'},
|
|
20
|
-
{ value: 'test', label: 'test'},
|
|
15
|
+
{ value: 'feat', label: 'feat' , hint: 'A new feature'},
|
|
16
|
+
{ value: 'fix', label: 'fix' , hint: 'A bug fix'},
|
|
17
|
+
{ value: 'docs', label: 'docs', hint: 'Documentation only changes'},
|
|
18
|
+
{ value: 'refactor', label: 'refactor', hint: 'A code change that neither fixes a bug nor adds a feature'},
|
|
19
|
+
{ value: 'perf', label: 'perf', hint: 'A code change that improves performance'},
|
|
20
|
+
{ value: 'test', label: 'test', hint: 'Adding missing tests or correcting existing tests'},
|
|
21
|
+
{ value: 'build', label: 'build', hint: 'Changes that affect the build system or external dependencies'},
|
|
22
|
+
{ value: 'ci', label: 'ci', hint: 'Changes to our CI configuration files and scripts'},
|
|
21
23
|
{ value: '', label: 'none'},
|
|
22
24
|
]
|
|
23
25
|
export const DEFAULT_SCOPE_OPTIONS = [
|
|
@@ -27,16 +29,15 @@ export const DEFAULT_SCOPE_OPTIONS = [
|
|
|
27
29
|
{ value: 'tools', label: 'tools' },
|
|
28
30
|
{ value: '', label: 'none'},
|
|
29
31
|
]
|
|
30
|
-
export type FOOTER_OPTIONS = 'closes' | 'breaking-change' | 'deprecated'
|
|
31
32
|
export const COMMIT_FOOTER_OPTIONS = [
|
|
32
33
|
{ value: 'closes', label: 'closes <issue/ticket>', hint: 'Attempts to infer ticket from branch'},
|
|
33
34
|
{ value: 'breaking-change', label: 'breaking change', hint: 'Add breaking change'},
|
|
34
35
|
{ value: 'deprecated', label: 'deprecated', hint: 'Add deprecated change'},
|
|
36
|
+
{ value: 'custom', label: 'custom', hint: 'Add a custom footer'},
|
|
35
37
|
]
|
|
36
38
|
|
|
37
|
-
|
|
38
|
-
export const Z_FOOTER_OPTIONS =
|
|
39
|
-
export const FOOTER_OPTION_VALUES: FOOTER_OPTIONS[] = ['closes', 'breaking-change', 'deprecated']
|
|
39
|
+
export const Z_FOOTER_OPTIONS = z.enum(['closes', 'breaking-change', 'deprecated', 'custom'])
|
|
40
|
+
export const FOOTER_OPTION_VALUES: z.infer<typeof Z_FOOTER_OPTIONS>[] = ['closes', 'breaking-change', 'deprecated', 'custom']
|
|
40
41
|
|
|
41
42
|
export function infer_type_from_branch(types: string[]): string {
|
|
42
43
|
let branch = ''
|
package/src/zod-state.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { z } from "zod"
|
|
2
2
|
import { DEFAULT_SCOPE_OPTIONS, DEFAULT_TYPE_OPTIONS, FOOTER_OPTION_VALUES, Z_FOOTER_OPTIONS } from "./utils"
|
|
3
3
|
|
|
4
|
-
|
|
5
4
|
// TODO: add "Ref", "Fixes", ability to change phrase "Closes/closes/closes:"
|
|
6
5
|
export const Config = z.object({
|
|
7
6
|
check_status: z.boolean().default(true),
|
|
@@ -67,4 +66,5 @@ export const CommitState = z.object({
|
|
|
67
66
|
deprecates: z.string().default(''),
|
|
68
67
|
deprecates_title: z.string().default(''),
|
|
69
68
|
deprecates_body: z.string().default(''),
|
|
69
|
+
custom_footer: z.string().default(''),
|
|
70
70
|
}).default({})
|