better-commits 1.0.6 → 1.0.8-print-output
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 +26 -5
- package/dist/init.js +2 -1
- package/dist/zod-state.js +2 -1
- package/package.json +1 -1
- package/readme.md +26 -10
- package/src/index.ts +30 -19
- package/src/zod-state.ts +2 -1
package/dist/index.js
CHANGED
|
@@ -155,7 +155,8 @@ var Config = import_zod2.z.object({
|
|
|
155
155
|
breaking_change: import_zod2.z.object({
|
|
156
156
|
add_exclamation_to_title: import_zod2.z.boolean().default(true)
|
|
157
157
|
}).default({}),
|
|
158
|
-
confirm_commit: import_zod2.z.boolean().default(true)
|
|
158
|
+
confirm_commit: import_zod2.z.boolean().default(true),
|
|
159
|
+
print_commit_output: import_zod2.z.boolean().default(true)
|
|
159
160
|
}).default({});
|
|
160
161
|
var CommitState = import_zod2.z.object({
|
|
161
162
|
type: import_zod2.z.string().default(""),
|
|
@@ -281,7 +282,8 @@ async function main(config) {
|
|
|
281
282
|
}
|
|
282
283
|
if (config.check_ticket.confirm_ticket) {
|
|
283
284
|
const user_commit_ticket = await p.text({
|
|
284
|
-
message: commit_state.ticket ? `Ticket / issue
|
|
285
|
+
message: commit_state.ticket ? `Ticket / issue inferred from branch ${import_picocolors2.default.dim("(confirm / edit)")}` : `Add ticket / issue ${OPTIONAL_PROMPT}`,
|
|
286
|
+
placeholder: "",
|
|
285
287
|
initialValue: commit_state.ticket
|
|
286
288
|
});
|
|
287
289
|
if (p.isCancel(user_commit_ticket))
|
|
@@ -317,7 +319,7 @@ async function main(config) {
|
|
|
317
319
|
});
|
|
318
320
|
if (p.isCancel(commit_body))
|
|
319
321
|
process.exit(0);
|
|
320
|
-
commit_state.body = commit_body;
|
|
322
|
+
commit_state.body = commit_body ?? "";
|
|
321
323
|
}
|
|
322
324
|
if (config.commit_footer.enable) {
|
|
323
325
|
const commit_footer = await p.multiselect({
|
|
@@ -337,10 +339,14 @@ async function main(config) {
|
|
|
337
339
|
return "Please enter a title / summary";
|
|
338
340
|
}
|
|
339
341
|
});
|
|
342
|
+
if (p.isCancel(breaking_changes_title))
|
|
343
|
+
process.exit(0);
|
|
340
344
|
const breaking_changes_body = await p.text({
|
|
341
345
|
message: `Breaking Changes: Write a description & migration instructions ${OPTIONAL_PROMPT}`,
|
|
342
346
|
placeholder: ""
|
|
343
347
|
});
|
|
348
|
+
if (p.isCancel(breaking_changes_body))
|
|
349
|
+
process.exit(0);
|
|
344
350
|
commit_state.breaking_title = breaking_changes_title;
|
|
345
351
|
commit_state.breaking_body = breaking_changes_body;
|
|
346
352
|
}
|
|
@@ -353,10 +359,14 @@ async function main(config) {
|
|
|
353
359
|
return "Please enter a title / summary";
|
|
354
360
|
}
|
|
355
361
|
});
|
|
362
|
+
if (p.isCancel(deprecated_title))
|
|
363
|
+
process.exit(0);
|
|
356
364
|
const deprecated_body = await p.text({
|
|
357
365
|
message: `Deprecated: Write a description ${OPTIONAL_PROMPT}`,
|
|
358
366
|
placeholder: ""
|
|
359
367
|
});
|
|
368
|
+
if (p.isCancel(deprecated_body))
|
|
369
|
+
process.exit(0);
|
|
360
370
|
commit_state.deprecates_body = deprecated_body;
|
|
361
371
|
commit_state.deprecates_title = deprecated_title;
|
|
362
372
|
}
|
|
@@ -368,6 +378,8 @@ async function main(config) {
|
|
|
368
378
|
message: "Write a custom footer",
|
|
369
379
|
placeholder: ""
|
|
370
380
|
});
|
|
381
|
+
if (p.isCancel(custom_footer))
|
|
382
|
+
process.exit(0);
|
|
371
383
|
commit_state.custom_footer = custom_footer;
|
|
372
384
|
}
|
|
373
385
|
}
|
|
@@ -378,8 +390,17 @@ async function main(config) {
|
|
|
378
390
|
if (p.isCancel(continue_commit))
|
|
379
391
|
process.exit(0);
|
|
380
392
|
}
|
|
381
|
-
if (continue_commit)
|
|
382
|
-
|
|
393
|
+
if (!continue_commit) {
|
|
394
|
+
p.log.info("Exiting without commit");
|
|
395
|
+
process.exit(0);
|
|
396
|
+
}
|
|
397
|
+
try {
|
|
398
|
+
const output = (0, import_child_process2.execSync)(`git commit -m "${build_commit_string(commit_state, config, false)}"`).toString().trim();
|
|
399
|
+
if (config.print_commit_output)
|
|
400
|
+
p.log.info(output);
|
|
401
|
+
} catch (err) {
|
|
402
|
+
p.log.error("Something went wrong when committing: " + err);
|
|
403
|
+
}
|
|
383
404
|
}
|
|
384
405
|
function build_commit_string(commit_state, config, colorize = false) {
|
|
385
406
|
let commit_string = "";
|
package/dist/init.js
CHANGED
|
@@ -106,7 +106,8 @@ var Config = import_zod2.z.object({
|
|
|
106
106
|
breaking_change: import_zod2.z.object({
|
|
107
107
|
add_exclamation_to_title: import_zod2.z.boolean().default(true)
|
|
108
108
|
}).default({}),
|
|
109
|
-
confirm_commit: import_zod2.z.boolean().default(true)
|
|
109
|
+
confirm_commit: import_zod2.z.boolean().default(true),
|
|
110
|
+
print_commit_output: import_zod2.z.boolean().default(true)
|
|
110
111
|
}).default({});
|
|
111
112
|
var CommitState = import_zod2.z.object({
|
|
112
113
|
type: import_zod2.z.string().default(""),
|
package/dist/zod-state.js
CHANGED
|
@@ -115,7 +115,8 @@ var Config = import_zod2.z.object({
|
|
|
115
115
|
breaking_change: import_zod2.z.object({
|
|
116
116
|
add_exclamation_to_title: import_zod2.z.boolean().default(true)
|
|
117
117
|
}).default({}),
|
|
118
|
-
confirm_commit: import_zod2.z.boolean().default(true)
|
|
118
|
+
confirm_commit: import_zod2.z.boolean().default(true),
|
|
119
|
+
print_commit_output: import_zod2.z.boolean().default(true)
|
|
119
120
|
}).default({});
|
|
120
121
|
var CommitState = import_zod2.z.object({
|
|
121
122
|
type: import_zod2.z.string().default(""),
|
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.8-print-output",
|
|
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,13 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Better Commits
|
|
2
2
|
|
|
3
|
-
](https://www.npmjs.com/package/better-commits)
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
[](https://github.com/Everduin94/better-commits)
|
|
4
|
+
[](https://www.npmjs.com/package/better-commits)
|
|
5
|
+
<a href="https://github.com/everduin94/better-commits/issues">
|
|
6
|
+
<img alt="Issues" src="https://img.shields.io/github/issues/everduin94/better-commits?style=for-the-badge&logo=gitbook&color=cba6f7&logoColor=D9E0EE&labelColor=302D41"></a>
|
|
7
7
|
|
|
8
8
|
A CLI for writing better commits, following the conventional commit guidelines, written with Typescript | ZOD | Clack
|
|
9
9
|
|
|
10
|
-
https://user-images.githubusercontent.com/14320878/
|
|
10
|
+
https://user-images.githubusercontent.com/14320878/225088948-43073a0e-400c-4c5f-a6e3-4f4961cfe43d.mov
|
|
11
11
|
|
|
12
12
|
## ✨ Features
|
|
13
13
|
- Follows the conventional commit guidelines
|
|
@@ -43,12 +43,17 @@ To modify, these prompts, see `configuration`.
|
|
|
43
43
|
|
|
44
44
|
## ⚙️ Configuration
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
|
|
47
|
+
### Global
|
|
48
|
+
|
|
49
|
+
Your first time running `better-commits`, a default config will be generated in your `$HOME` directory, named `.better-commits.json`
|
|
50
|
+
- This config will be used if a repository-specific config cannot be found.
|
|
51
|
+
|
|
52
|
+
### Repository
|
|
47
53
|
|
|
48
54
|
To create a **repository-specific config**, navigate to the root of your project.
|
|
49
55
|
- run `better-commits-init`
|
|
50
|
-
|
|
51
|
-
This will create a config named `.better-commits.json` with all of the defaults. From there, you can modify it to suit your needs.
|
|
56
|
+
- This will create a default config named `.better-commits.json`
|
|
52
57
|
|
|
53
58
|
All properties are optional, they can be removed from your configuration and will be replaced by the defaults at run-time.
|
|
54
59
|
|
|
@@ -160,7 +165,8 @@ All properties are optional, they can be removed from your configuration and wil
|
|
|
160
165
|
"breaking_change": {
|
|
161
166
|
"add_exclamation_to_title": true
|
|
162
167
|
},
|
|
163
|
-
"confirm_commit": true
|
|
168
|
+
"confirm_commit": true,
|
|
169
|
+
"print_commit_output": true
|
|
164
170
|
}
|
|
165
171
|
```
|
|
166
172
|
|
|
@@ -176,6 +182,8 @@ To simplify the CLI, some rules are enforced at runtime to make sure the program
|
|
|
176
182
|
- `commit_footer` options are supplied from a fixed list, because they have specific functionality
|
|
177
183
|
- thus, you can remove from that list, but you can't add custom values to it
|
|
178
184
|
|
|
185
|
+
TODO: Add table explaining properties
|
|
186
|
+
|
|
179
187
|
#### 🔎 Inference
|
|
180
188
|
|
|
181
189
|
`better-commits` will attempt to infer the ticket/issue and the type from your branch name. It will auto populate the corresponding field if found.
|
|
@@ -203,6 +211,14 @@ To simplify the CLI, some rules are enforced at runtime to make sure the program
|
|
|
203
211
|
- 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**
|
|
204
212
|
- [better-commits](https://packagephobia.com/result?p=better-commits) is much smaller than its alternative [commitizen](https://packagephobia.com/result?p=commitizen)
|
|
205
213
|
- `better-commits` uses native `git` commands under the hood. So any hooks, tools, or staging should work as if it was a normal commit.
|
|
214
|
+
- You can add this badge to your repository to display that you're using a better-commits repository config
|
|
215
|
+
```
|
|
216
|
+
[](https://github.com/Everduin94/better-commits)
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
[](https://github.com/Everduin94/better-commits)
|
|
220
|
+
|
|
221
|
+
|
|
206
222
|
|
|
207
223
|
## ❓ Troubleshooting
|
|
208
224
|
|
package/src/index.ts
CHANGED
|
@@ -13,7 +13,6 @@ import { CONFIG_FILE_NAME, get_default_config_path, check_missing_stage, addNewL
|
|
|
13
13
|
main(load_setup());
|
|
14
14
|
|
|
15
15
|
function load_setup(): z.infer<typeof Config> {
|
|
16
|
-
|
|
17
16
|
console.clear();
|
|
18
17
|
p.intro(`${color.bgCyan(color.black(' better-commits '))}`);
|
|
19
18
|
|
|
@@ -34,7 +33,6 @@ function load_setup(): z.infer<typeof Config> {
|
|
|
34
33
|
p.log.step('Config not found. Generating default .better-commit.json at $HOME')
|
|
35
34
|
fs.writeFileSync(home_path, JSON.stringify(default_config, null, '\t'));
|
|
36
35
|
return default_config;
|
|
37
|
-
|
|
38
36
|
}
|
|
39
37
|
|
|
40
38
|
function read_config_from_path(config_path: string) {
|
|
@@ -102,7 +100,7 @@ async function main(config: z.infer<typeof Config>) {
|
|
|
102
100
|
initialValue: initial_value,
|
|
103
101
|
options: config.commit_type.options,
|
|
104
102
|
}
|
|
105
|
-
)
|
|
103
|
+
)
|
|
106
104
|
if (p.isCancel(commit_type)) process.exit(0)
|
|
107
105
|
commit_state.type = commit_type;
|
|
108
106
|
}
|
|
@@ -112,7 +110,7 @@ async function main(config: z.infer<typeof Config>) {
|
|
|
112
110
|
message: 'Select a commit scope',
|
|
113
111
|
initialValue: config.commit_scope.initial_value,
|
|
114
112
|
options: config.commit_scope.options
|
|
115
|
-
})
|
|
113
|
+
})
|
|
116
114
|
if (p.isCancel(commit_scope)) process.exit(0)
|
|
117
115
|
commit_state.scope = commit_scope;
|
|
118
116
|
}
|
|
@@ -130,14 +128,14 @@ async function main(config: z.infer<typeof Config>) {
|
|
|
130
128
|
// Can't find branch, fail silently
|
|
131
129
|
}
|
|
132
130
|
}
|
|
131
|
+
|
|
133
132
|
if (config.check_ticket.confirm_ticket) {
|
|
134
133
|
const user_commit_ticket = await p.text({
|
|
135
|
-
message: commit_state.ticket ? `Ticket / issue
|
|
134
|
+
message: commit_state.ticket ? `Ticket / issue inferred from branch ${color.dim('(confirm / edit)')}`: `Add ticket / issue ${OPTIONAL_PROMPT}`,
|
|
135
|
+
placeholder: '',
|
|
136
136
|
initialValue: commit_state.ticket,
|
|
137
|
-
})
|
|
137
|
+
})
|
|
138
138
|
if (p.isCancel(user_commit_ticket)) process.exit(0)
|
|
139
|
-
// TODO: Symbol can be null. Would be ideal if it just returned empty string.
|
|
140
|
-
// Seems like a bug that it only returns undefined if previously set.
|
|
141
139
|
commit_state.ticket = user_commit_ticket ?? '';
|
|
142
140
|
}
|
|
143
141
|
|
|
@@ -154,8 +152,7 @@ async function main(config: z.infer<typeof Config>) {
|
|
|
154
152
|
},
|
|
155
153
|
|
|
156
154
|
}
|
|
157
|
-
)
|
|
158
|
-
|
|
155
|
+
)
|
|
159
156
|
if (p.isCancel(commit_title)) process.exit(0)
|
|
160
157
|
commit_state.title = clean_commit_title(commit_title);
|
|
161
158
|
|
|
@@ -167,9 +164,9 @@ async function main(config: z.infer<typeof Config>) {
|
|
|
167
164
|
if (config.commit_body.required && !val) return 'Please enter a description'
|
|
168
165
|
}
|
|
169
166
|
|
|
170
|
-
})
|
|
167
|
+
})
|
|
171
168
|
if (p.isCancel(commit_body)) process.exit(0)
|
|
172
|
-
commit_state.body = commit_body;
|
|
169
|
+
commit_state.body = commit_body ?? '';
|
|
173
170
|
}
|
|
174
171
|
|
|
175
172
|
if (config.commit_footer.enable) {
|
|
@@ -188,11 +185,13 @@ async function main(config: z.infer<typeof Config>) {
|
|
|
188
185
|
validate: (value) => {
|
|
189
186
|
if (!value) return 'Please enter a title / summary'
|
|
190
187
|
}
|
|
191
|
-
})
|
|
188
|
+
})
|
|
189
|
+
if (p.isCancel(breaking_changes_title)) process.exit(0)
|
|
192
190
|
const breaking_changes_body = await p.text({
|
|
193
191
|
message: `Breaking Changes: Write a description & migration instructions ${OPTIONAL_PROMPT}`,
|
|
194
192
|
placeholder: '',
|
|
195
|
-
})
|
|
193
|
+
})
|
|
194
|
+
if (p.isCancel(breaking_changes_body)) process.exit(0)
|
|
196
195
|
commit_state.breaking_title = breaking_changes_title;
|
|
197
196
|
commit_state.breaking_body = breaking_changes_body;
|
|
198
197
|
}
|
|
@@ -204,11 +203,13 @@ async function main(config: z.infer<typeof Config>) {
|
|
|
204
203
|
validate: (value) => {
|
|
205
204
|
if (!value) return 'Please enter a title / summary'
|
|
206
205
|
}
|
|
207
|
-
})
|
|
206
|
+
})
|
|
207
|
+
if (p.isCancel(deprecated_title)) process.exit(0)
|
|
208
208
|
const deprecated_body = await p.text({
|
|
209
209
|
message: `Deprecated: Write a description ${OPTIONAL_PROMPT}`,
|
|
210
210
|
placeholder: '',
|
|
211
|
-
})
|
|
211
|
+
})
|
|
212
|
+
if (p.isCancel(deprecated_body)) process.exit(0)
|
|
212
213
|
commit_state.deprecates_body = deprecated_body;
|
|
213
214
|
commit_state.deprecates_title = deprecated_title;
|
|
214
215
|
}
|
|
@@ -221,7 +222,8 @@ async function main(config: z.infer<typeof Config>) {
|
|
|
221
222
|
const custom_footer = await p.text({
|
|
222
223
|
message: 'Write a custom footer',
|
|
223
224
|
placeholder: '',
|
|
224
|
-
})
|
|
225
|
+
})
|
|
226
|
+
if (p.isCancel(custom_footer)) process.exit(0)
|
|
225
227
|
commit_state.custom_footer = custom_footer;
|
|
226
228
|
}
|
|
227
229
|
}
|
|
@@ -234,7 +236,17 @@ async function main(config: z.infer<typeof Config>) {
|
|
|
234
236
|
if (p.isCancel(continue_commit)) process.exit(0)
|
|
235
237
|
}
|
|
236
238
|
|
|
237
|
-
if (continue_commit)
|
|
239
|
+
if (!continue_commit) {
|
|
240
|
+
p.log.info('Exiting without commit')
|
|
241
|
+
process.exit(0)
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
try {
|
|
245
|
+
const output = execSync(`git commit -m "${build_commit_string(commit_state, config, false)}"`).toString().trim();
|
|
246
|
+
if (config.print_commit_output) p.log.info(output)
|
|
247
|
+
} catch(err) {
|
|
248
|
+
p.log.error('Something went wrong when committing: ' + err)
|
|
249
|
+
}
|
|
238
250
|
}
|
|
239
251
|
|
|
240
252
|
function build_commit_string(commit_state: z.infer<typeof CommitState>, config: z.infer<typeof Config>, colorize: boolean = false): string {
|
|
@@ -300,7 +312,6 @@ function build_commit_string(commit_state: z.infer<typeof CommitState>, config:
|
|
|
300
312
|
commit_string += colorize ? `\n\n${color.reset(commit_state.closes)} ${color.magenta(commit_state.ticket)}` : `\n\n${commit_state.closes} ${commit_state.ticket}`;
|
|
301
313
|
}
|
|
302
314
|
|
|
303
|
-
|
|
304
315
|
return commit_string;
|
|
305
316
|
}
|
|
306
317
|
|
package/src/zod-state.ts
CHANGED
|
@@ -51,7 +51,8 @@ export const Config = z.object({
|
|
|
51
51
|
breaking_change: z.object({
|
|
52
52
|
add_exclamation_to_title: z.boolean().default(true)
|
|
53
53
|
}).default({}),
|
|
54
|
-
confirm_commit: z.boolean().default(true)
|
|
54
|
+
confirm_commit: z.boolean().default(true),
|
|
55
|
+
print_commit_output: z.boolean().default(true)
|
|
55
56
|
}).default({})
|
|
56
57
|
|
|
57
58
|
export const CommitState = z.object({
|