better-commits 1.0.9 → 1.1.0
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/dist/index.js +21 -2
- package/dist/init.js +12 -1
- package/dist/utils.js +3 -0
- package/dist/zod-state.js +12 -1
- package/package.json +1 -1
- package/readme.md +1 -0
- package/src/index.ts +9 -2
- package/src/utils.ts +1 -0
- package/src/zod-state.ts +13 -2
package/dist/index.js
CHANGED
|
@@ -71,6 +71,7 @@ var COMMIT_FOOTER_OPTIONS = [
|
|
|
71
71
|
{ value: "deprecated", label: "deprecated", hint: "Add deprecated change" },
|
|
72
72
|
{ value: "custom", label: "custom", hint: "Add a custom footer" }
|
|
73
73
|
];
|
|
74
|
+
var CUSTOM_SCOPE_KEY = "custom";
|
|
74
75
|
var Z_FOOTER_OPTIONS = import_zod.z.enum(["closes", "breaking-change", "deprecated", "custom"]);
|
|
75
76
|
var FOOTER_OPTION_VALUES = ["closes", "breaking-change", "deprecated", "custom"];
|
|
76
77
|
function infer_type_from_branch(types) {
|
|
@@ -125,13 +126,23 @@ var Config = import_zod2.z.object({
|
|
|
125
126
|
}, (val) => ({ message: `Type: initial_value "${val.initial_value}" must exist in options` })),
|
|
126
127
|
commit_scope: import_zod2.z.object({
|
|
127
128
|
enable: import_zod2.z.boolean().default(true),
|
|
129
|
+
custom_scope: import_zod2.z.boolean().default(false),
|
|
128
130
|
initial_value: import_zod2.z.string().default("app"),
|
|
129
131
|
options: import_zod2.z.array(import_zod2.z.object({
|
|
130
132
|
value: import_zod2.z.string(),
|
|
131
133
|
label: import_zod2.z.string().optional(),
|
|
132
134
|
hint: import_zod2.z.string().optional()
|
|
133
135
|
})).default(DEFAULT_SCOPE_OPTIONS)
|
|
134
|
-
}).default({}).
|
|
136
|
+
}).default({}).transform((val) => {
|
|
137
|
+
const options = val.options.map((v) => v.value);
|
|
138
|
+
if (val.custom_scope && !options.includes(CUSTOM_SCOPE_KEY)) {
|
|
139
|
+
return {
|
|
140
|
+
...val,
|
|
141
|
+
options: [...val.options, { label: CUSTOM_SCOPE_KEY, value: CUSTOM_SCOPE_KEY, hint: "Write a custom scope" }]
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
return val;
|
|
145
|
+
}).refine((val) => {
|
|
135
146
|
const options = val.options.map((v) => v.value);
|
|
136
147
|
return options.includes(val.initial_value);
|
|
137
148
|
}, (val) => ({ message: `Scope: initial_value "${val.initial_value}" must exist in options` })),
|
|
@@ -262,13 +273,21 @@ async function main(config) {
|
|
|
262
273
|
commit_state.type = commit_type;
|
|
263
274
|
}
|
|
264
275
|
if (config.commit_scope.enable) {
|
|
265
|
-
|
|
276
|
+
let commit_scope = await p.select({
|
|
266
277
|
message: "Select a commit scope",
|
|
267
278
|
initialValue: config.commit_scope.initial_value,
|
|
268
279
|
options: config.commit_scope.options
|
|
269
280
|
});
|
|
270
281
|
if (p.isCancel(commit_scope))
|
|
271
282
|
process.exit(0);
|
|
283
|
+
if (commit_scope === CUSTOM_SCOPE_KEY && config.commit_scope.custom_scope) {
|
|
284
|
+
commit_scope = await p.text({
|
|
285
|
+
message: "Write a custom scope",
|
|
286
|
+
placeholder: ""
|
|
287
|
+
});
|
|
288
|
+
if (p.isCancel(commit_scope))
|
|
289
|
+
process.exit(0);
|
|
290
|
+
}
|
|
272
291
|
commit_state.scope = commit_scope;
|
|
273
292
|
}
|
|
274
293
|
if (config.check_ticket.infer_ticket) {
|
package/dist/init.js
CHANGED
|
@@ -55,6 +55,7 @@ var DEFAULT_SCOPE_OPTIONS = [
|
|
|
55
55
|
{ value: "tools", label: "tools" },
|
|
56
56
|
{ value: "", label: "none" }
|
|
57
57
|
];
|
|
58
|
+
var CUSTOM_SCOPE_KEY = "custom";
|
|
58
59
|
var Z_FOOTER_OPTIONS = import_zod.z.enum(["closes", "breaking-change", "deprecated", "custom"]);
|
|
59
60
|
var FOOTER_OPTION_VALUES = ["closes", "breaking-change", "deprecated", "custom"];
|
|
60
61
|
|
|
@@ -76,13 +77,23 @@ var Config = import_zod2.z.object({
|
|
|
76
77
|
}, (val) => ({ message: `Type: initial_value "${val.initial_value}" must exist in options` })),
|
|
77
78
|
commit_scope: import_zod2.z.object({
|
|
78
79
|
enable: import_zod2.z.boolean().default(true),
|
|
80
|
+
custom_scope: import_zod2.z.boolean().default(false),
|
|
79
81
|
initial_value: import_zod2.z.string().default("app"),
|
|
80
82
|
options: import_zod2.z.array(import_zod2.z.object({
|
|
81
83
|
value: import_zod2.z.string(),
|
|
82
84
|
label: import_zod2.z.string().optional(),
|
|
83
85
|
hint: import_zod2.z.string().optional()
|
|
84
86
|
})).default(DEFAULT_SCOPE_OPTIONS)
|
|
85
|
-
}).default({}).
|
|
87
|
+
}).default({}).transform((val) => {
|
|
88
|
+
const options = val.options.map((v) => v.value);
|
|
89
|
+
if (val.custom_scope && !options.includes(CUSTOM_SCOPE_KEY)) {
|
|
90
|
+
return {
|
|
91
|
+
...val,
|
|
92
|
+
options: [...val.options, { label: CUSTOM_SCOPE_KEY, value: CUSTOM_SCOPE_KEY, hint: "Write a custom scope" }]
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
return val;
|
|
96
|
+
}).refine((val) => {
|
|
86
97
|
const options = val.options.map((v) => v.value);
|
|
87
98
|
return options.includes(val.initial_value);
|
|
88
99
|
}, (val) => ({ message: `Scope: initial_value "${val.initial_value}" must exist in options` })),
|
package/dist/utils.js
CHANGED
|
@@ -32,6 +32,7 @@ var utils_exports = {};
|
|
|
32
32
|
__export(utils_exports, {
|
|
33
33
|
COMMIT_FOOTER_OPTIONS: () => COMMIT_FOOTER_OPTIONS,
|
|
34
34
|
CONFIG_FILE_NAME: () => CONFIG_FILE_NAME,
|
|
35
|
+
CUSTOM_SCOPE_KEY: () => CUSTOM_SCOPE_KEY,
|
|
35
36
|
DEFAULT_SCOPE_OPTIONS: () => DEFAULT_SCOPE_OPTIONS,
|
|
36
37
|
DEFAULT_TYPE_OPTIONS: () => DEFAULT_TYPE_OPTIONS,
|
|
37
38
|
FOOTER_OPTION_VALUES: () => FOOTER_OPTION_VALUES,
|
|
@@ -85,6 +86,7 @@ var COMMIT_FOOTER_OPTIONS = [
|
|
|
85
86
|
{ value: "deprecated", label: "deprecated", hint: "Add deprecated change" },
|
|
86
87
|
{ value: "custom", label: "custom", hint: "Add a custom footer" }
|
|
87
88
|
];
|
|
89
|
+
var CUSTOM_SCOPE_KEY = "custom";
|
|
88
90
|
var Z_FOOTER_OPTIONS = import_zod.z.enum(["closes", "breaking-change", "deprecated", "custom"]);
|
|
89
91
|
var FOOTER_OPTION_VALUES = ["closes", "breaking-change", "deprecated", "custom"];
|
|
90
92
|
function infer_type_from_branch(types) {
|
|
@@ -124,6 +126,7 @@ function clean_commit_title(title) {
|
|
|
124
126
|
0 && (module.exports = {
|
|
125
127
|
COMMIT_FOOTER_OPTIONS,
|
|
126
128
|
CONFIG_FILE_NAME,
|
|
129
|
+
CUSTOM_SCOPE_KEY,
|
|
127
130
|
DEFAULT_SCOPE_OPTIONS,
|
|
128
131
|
DEFAULT_TYPE_OPTIONS,
|
|
129
132
|
FOOTER_OPTION_VALUES,
|
package/dist/zod-state.js
CHANGED
|
@@ -64,6 +64,7 @@ var DEFAULT_SCOPE_OPTIONS = [
|
|
|
64
64
|
{ value: "tools", label: "tools" },
|
|
65
65
|
{ value: "", label: "none" }
|
|
66
66
|
];
|
|
67
|
+
var CUSTOM_SCOPE_KEY = "custom";
|
|
67
68
|
var Z_FOOTER_OPTIONS = import_zod.z.enum(["closes", "breaking-change", "deprecated", "custom"]);
|
|
68
69
|
var FOOTER_OPTION_VALUES = ["closes", "breaking-change", "deprecated", "custom"];
|
|
69
70
|
|
|
@@ -85,13 +86,23 @@ var Config = import_zod2.z.object({
|
|
|
85
86
|
}, (val) => ({ message: `Type: initial_value "${val.initial_value}" must exist in options` })),
|
|
86
87
|
commit_scope: import_zod2.z.object({
|
|
87
88
|
enable: import_zod2.z.boolean().default(true),
|
|
89
|
+
custom_scope: import_zod2.z.boolean().default(false),
|
|
88
90
|
initial_value: import_zod2.z.string().default("app"),
|
|
89
91
|
options: import_zod2.z.array(import_zod2.z.object({
|
|
90
92
|
value: import_zod2.z.string(),
|
|
91
93
|
label: import_zod2.z.string().optional(),
|
|
92
94
|
hint: import_zod2.z.string().optional()
|
|
93
95
|
})).default(DEFAULT_SCOPE_OPTIONS)
|
|
94
|
-
}).default({}).
|
|
96
|
+
}).default({}).transform((val) => {
|
|
97
|
+
const options = val.options.map((v) => v.value);
|
|
98
|
+
if (val.custom_scope && !options.includes(CUSTOM_SCOPE_KEY)) {
|
|
99
|
+
return {
|
|
100
|
+
...val,
|
|
101
|
+
options: [...val.options, { label: CUSTOM_SCOPE_KEY, value: CUSTOM_SCOPE_KEY, hint: "Write a custom scope" }]
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return val;
|
|
105
|
+
}).refine((val) => {
|
|
95
106
|
const options = val.options.map((v) => v.value);
|
|
96
107
|
return options.includes(val.initial_value);
|
|
97
108
|
}, (val) => ({ message: `Scope: initial_value "${val.initial_value}" must exist in options` })),
|
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.1.0",
|
|
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
package/src/index.ts
CHANGED
|
@@ -8,7 +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, Z_FOOTER_OPTIONS } from './utils';
|
|
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, CUSTOM_SCOPE_KEY } from './utils';
|
|
12
12
|
|
|
13
13
|
main(load_setup());
|
|
14
14
|
|
|
@@ -106,12 +106,19 @@ async function main(config: z.infer<typeof Config>) {
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
if (config.commit_scope.enable) {
|
|
109
|
-
|
|
109
|
+
let commit_scope = await p.select({
|
|
110
110
|
message: 'Select a commit scope',
|
|
111
111
|
initialValue: config.commit_scope.initial_value,
|
|
112
112
|
options: config.commit_scope.options
|
|
113
113
|
})
|
|
114
114
|
if (p.isCancel(commit_scope)) process.exit(0)
|
|
115
|
+
if (commit_scope === CUSTOM_SCOPE_KEY && config.commit_scope.custom_scope) {
|
|
116
|
+
commit_scope = await p.text({
|
|
117
|
+
message: 'Write a custom scope',
|
|
118
|
+
placeholder: ''
|
|
119
|
+
})
|
|
120
|
+
if (p.isCancel(commit_scope)) process.exit(0)
|
|
121
|
+
}
|
|
115
122
|
commit_state.scope = commit_scope;
|
|
116
123
|
}
|
|
117
124
|
|
package/src/utils.ts
CHANGED
|
@@ -36,6 +36,7 @@ export const COMMIT_FOOTER_OPTIONS = [
|
|
|
36
36
|
{ value: 'deprecated', label: 'deprecated', hint: 'Add deprecated change'},
|
|
37
37
|
{ value: 'custom', label: 'custom', hint: 'Add a custom footer'},
|
|
38
38
|
]
|
|
39
|
+
export const CUSTOM_SCOPE_KEY: 'custom' = 'custom'
|
|
39
40
|
|
|
40
41
|
export const Z_FOOTER_OPTIONS = z.enum(['closes', 'breaking-change', 'deprecated', 'custom'])
|
|
41
42
|
export const FOOTER_OPTION_VALUES: z.infer<typeof Z_FOOTER_OPTIONS>[] = ['closes', 'breaking-change', 'deprecated', 'custom']
|
package/src/zod-state.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod"
|
|
2
|
-
import { DEFAULT_SCOPE_OPTIONS, DEFAULT_TYPE_OPTIONS, FOOTER_OPTION_VALUES, Z_FOOTER_OPTIONS } from "./utils"
|
|
2
|
+
import { CUSTOM_SCOPE_KEY, DEFAULT_SCOPE_OPTIONS, DEFAULT_TYPE_OPTIONS, FOOTER_OPTION_VALUES, Z_FOOTER_OPTIONS } from "./utils"
|
|
3
3
|
|
|
4
4
|
// TODO: add "Ref", "Fixes", ability to change phrase "Closes/closes/closes:"
|
|
5
5
|
export const Config = z.object({
|
|
@@ -19,6 +19,7 @@ export const Config = z.object({
|
|
|
19
19
|
}, (val) => ({ message: `Type: initial_value "${val.initial_value}" must exist in options` })),
|
|
20
20
|
commit_scope: z.object({
|
|
21
21
|
enable: z.boolean().default(true),
|
|
22
|
+
custom_scope: z.boolean().default(false),
|
|
22
23
|
initial_value: z.string().default('app'),
|
|
23
24
|
options: z.array(z.object({
|
|
24
25
|
value: z.string(),
|
|
@@ -26,8 +27,18 @@ export const Config = z.object({
|
|
|
26
27
|
hint: z.string().optional(),
|
|
27
28
|
})).default(DEFAULT_SCOPE_OPTIONS)
|
|
28
29
|
}).default({})
|
|
30
|
+
.transform(val => {
|
|
31
|
+
const options = val.options.map(v => v.value)
|
|
32
|
+
if (val.custom_scope && !options.includes(CUSTOM_SCOPE_KEY)) {
|
|
33
|
+
return {
|
|
34
|
+
...val,
|
|
35
|
+
options: [...val.options, { label: CUSTOM_SCOPE_KEY, value: CUSTOM_SCOPE_KEY, hint: 'Write a custom scope'}]
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return val
|
|
39
|
+
})
|
|
29
40
|
.refine(val => {
|
|
30
|
-
|
|
41
|
+
const options = val.options.map(v => v.value)
|
|
31
42
|
return options.includes(val.initial_value)
|
|
32
43
|
}, (val) => ({ message: `Scope: initial_value "${val.initial_value}" must exist in options` })),
|
|
33
44
|
check_ticket: z.object({
|