better-commits 1.23.2 → 1.23.3

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.
Files changed (68) hide show
  1. package/dist/branch.js +628 -19
  2. package/dist/chunk-GAAS3VS3.js +922 -0
  3. package/dist/chunk-H5CLUQIL.js +313 -0
  4. package/dist/index.js +1122 -41
  5. package/dist/init.js +44 -1
  6. package/package.json +12 -4
  7. package/readme.md +4 -2
  8. package/.better-commits.json +0 -52
  9. package/.github/workflows/publish.yml +0 -34
  10. package/.github/workflows/test.yml +0 -27
  11. package/.prettierignore +0 -5
  12. package/.prettierrc +0 -1
  13. package/dist/chunk-43H72S6V.js +0 -1
  14. package/dist/chunk-B7AGSPP3.js +0 -261
  15. package/src/args.test.ts +0 -128
  16. package/src/args.ts +0 -125
  17. package/src/branch-args.test.ts +0 -75
  18. package/src/branch-args.ts +0 -107
  19. package/src/branch-help.ts +0 -125
  20. package/src/branch.ts +0 -97
  21. package/src/default-config-template.ts +0 -258
  22. package/src/git.test.ts +0 -64
  23. package/src/git.ts +0 -72
  24. package/src/help.ts +0 -138
  25. package/src/index.test.ts +0 -7
  26. package/src/index.ts +0 -101
  27. package/src/init.test.ts +0 -123
  28. package/src/init.ts +0 -46
  29. package/src/prompts/autocomplete-multiselect.test.ts +0 -129
  30. package/src/prompts/autocomplete-multiselect.ts +0 -249
  31. package/src/prompts/branch-checkout.prompt.ts +0 -36
  32. package/src/prompts/branch-confirm.prompt.test.ts +0 -89
  33. package/src/prompts/branch-confirm.prompt.ts +0 -149
  34. package/src/prompts/branch-description.prompt.ts +0 -37
  35. package/src/prompts/branch-runnable.ts +0 -13
  36. package/src/prompts/branch-scope.prompt.ts +0 -59
  37. package/src/prompts/branch-ticket.prompt.ts +0 -41
  38. package/src/prompts/branch-type.prompt.ts +0 -46
  39. package/src/prompts/branch-user.prompt.ts +0 -50
  40. package/src/prompts/branch-version.prompt.ts +0 -41
  41. package/src/prompts/commit-body.prompt.ts +0 -51
  42. package/src/prompts/commit-confirm.prompt.ts +0 -123
  43. package/src/prompts/commit-footer.prompt.ts +0 -195
  44. package/src/prompts/commit-scope.prompt.ts +0 -91
  45. package/src/prompts/commit-status.prompt.ts +0 -66
  46. package/src/prompts/commit-ticket.prompt.ts +0 -82
  47. package/src/prompts/commit-title.prompt.ts +0 -98
  48. package/src/prompts/commit-type.prompt.ts +0 -96
  49. package/src/prompts/runnable.ts +0 -13
  50. package/src/utils/build-branch.test.ts +0 -159
  51. package/src/utils/build-branch.ts +0 -48
  52. package/src/utils/build-commit-string.test.ts +0 -273
  53. package/src/utils/build-commit-string.ts +0 -163
  54. package/src/utils/commit-title-size.ts +0 -24
  55. package/src/utils/infer.test.ts +0 -174
  56. package/src/utils/infer.ts +0 -160
  57. package/src/utils/messages.ts +0 -25
  58. package/src/utils/no-interactive-branch-validation.test.ts +0 -193
  59. package/src/utils/no-interactive-validation.test.ts +0 -174
  60. package/src/utils/no-interactive-validation.ts +0 -213
  61. package/src/utils.test.ts +0 -164
  62. package/src/utils.ts +0 -235
  63. package/src/valibot-consts.ts +0 -117
  64. package/src/valibot-state.test.ts +0 -57
  65. package/src/valibot-state.ts +0 -276
  66. package/tsconfig.json +0 -15
  67. package/tsup.config.ts +0 -12
  68. package/vitest.config.ts +0 -8
@@ -0,0 +1,922 @@
1
+ // src/valibot-state.ts
2
+ import * as v2 from "valibot";
3
+
4
+ // src/valibot-consts.ts
5
+ import * as v from "valibot";
6
+ var CUSTOM_SCOPE_KEY = "custom";
7
+ var FOOTER_OPTION_VALUES = [
8
+ "closes",
9
+ "trailer",
10
+ "breaking-change",
11
+ "deprecated",
12
+ "custom"
13
+ ];
14
+ var V_BRANCH_ACTIONS = v.picklist(["branch", "worktree"]);
15
+ var V_FOOTER_OPTIONS = v.picklist([
16
+ "closes",
17
+ "trailer",
18
+ "breaking-change",
19
+ "deprecated",
20
+ "custom"
21
+ ]);
22
+ var V_BRANCH_FIELDS = v.picklist([
23
+ "user",
24
+ "version",
25
+ "type",
26
+ "scope",
27
+ "ticket",
28
+ "description"
29
+ ]);
30
+ var V_BRANCH_CONFIG_FIELDS = v.picklist([
31
+ "branch_user",
32
+ "branch_version",
33
+ "branch_type",
34
+ "branch_scope",
35
+ "branch_ticket",
36
+ "branch_description"
37
+ ]);
38
+ var BRANCH_ORDER_DEFAULTS = [
39
+ "user",
40
+ "version",
41
+ "type",
42
+ "ticket",
43
+ "scope",
44
+ "description"
45
+ ];
46
+ var DEFAULT_SCOPE_OPTIONS = [
47
+ { value: "app", label: "app" },
48
+ { value: "shared", label: "shared" },
49
+ { value: "server", label: "server" },
50
+ { value: "tools", label: "tools" },
51
+ { value: "", label: "none" }
52
+ ];
53
+ var DEFAULT_TYPE_OPTIONS = [
54
+ {
55
+ value: "feat",
56
+ label: "feat",
57
+ hint: "A new feature",
58
+ emoji: "\u{1F31F}",
59
+ trailer: "Changelog: feature"
60
+ },
61
+ {
62
+ value: "fix",
63
+ label: "fix",
64
+ hint: "A bug fix",
65
+ emoji: "\u{1F41B}",
66
+ trailer: "Changelog: fix"
67
+ },
68
+ {
69
+ value: "docs",
70
+ label: "docs",
71
+ hint: "Documentation only changes",
72
+ emoji: "\u{1F4DA}",
73
+ trailer: "Changelog: documentation"
74
+ },
75
+ {
76
+ value: "refactor",
77
+ label: "refactor",
78
+ hint: "A code change that neither fixes a bug nor adds a feature",
79
+ emoji: "\u{1F528}",
80
+ trailer: "Changelog: refactor"
81
+ },
82
+ {
83
+ value: "perf",
84
+ label: "perf",
85
+ hint: "A code change that improves performance",
86
+ emoji: "\u{1F680}",
87
+ trailer: "Changelog: performance"
88
+ },
89
+ {
90
+ value: "test",
91
+ label: "test",
92
+ hint: "Adding missing tests or correcting existing tests",
93
+ emoji: "\u{1F6A8}",
94
+ trailer: "Changelog: test"
95
+ },
96
+ {
97
+ value: "build",
98
+ label: "build",
99
+ hint: "Changes that affect the build system or external dependencies",
100
+ emoji: "\u{1F6A7}",
101
+ trailer: "Changelog: build"
102
+ },
103
+ {
104
+ value: "ci",
105
+ label: "ci",
106
+ hint: "Changes to our CI configuration files and scripts",
107
+ emoji: "\u{1F916}",
108
+ trailer: "Changelog: ci"
109
+ },
110
+ {
111
+ value: "chore",
112
+ label: "chore",
113
+ hint: "Other changes that do not modify src or test files",
114
+ emoji: "\u{1F9F9}",
115
+ trailer: "Changelog: chore"
116
+ },
117
+ { value: "", label: "none" }
118
+ ];
119
+
120
+ // src/valibot-state.ts
121
+ var CommitTypeConfig = v2.pipe(
122
+ v2.optional(
123
+ v2.object({
124
+ enable: v2.optional(v2.boolean(), true),
125
+ initial_value: v2.optional(v2.string(), "feat"),
126
+ max_items: v2.optional(v2.pipe(v2.number(), v2.minValue(1)), 20),
127
+ infer_type_from_branch: v2.optional(v2.boolean(), true),
128
+ append_emoji_to_label: v2.optional(v2.boolean(), false),
129
+ append_emoji_to_commit: v2.optional(v2.boolean(), false),
130
+ emoji_commit_position: v2.optional(
131
+ v2.picklist(["Start", "After-Colon"]),
132
+ "Start"
133
+ ),
134
+ autocomplete: v2.optional(v2.boolean(), true),
135
+ options: v2.optional(
136
+ v2.array(
137
+ v2.object({
138
+ value: v2.string(),
139
+ label: v2.optional(v2.string()),
140
+ hint: v2.optional(v2.string()),
141
+ emoji: v2.optional(v2.pipe(v2.string(), v2.emoji())),
142
+ trailer: v2.optional(v2.string())
143
+ })
144
+ ),
145
+ DEFAULT_TYPE_OPTIONS
146
+ )
147
+ }),
148
+ {}
149
+ ),
150
+ v2.rawCheck(({ dataset, addIssue }) => {
151
+ if (dataset.typed && !dataset.value.options.some(
152
+ (option) => option.value === dataset.value.initial_value
153
+ )) {
154
+ addIssue({
155
+ message: `Type: initial_value "${dataset.value.initial_value}" must exist in options`
156
+ });
157
+ }
158
+ }),
159
+ v2.transform((value) => ({
160
+ ...value,
161
+ options: value.options.map((option) => ({
162
+ ...option,
163
+ label: option.emoji && value.append_emoji_to_label ? `${option.emoji} ${option.label}` : option.label
164
+ }))
165
+ }))
166
+ );
167
+ var CommitScopeConfig = v2.pipe(
168
+ v2.optional(
169
+ v2.object({
170
+ enable: v2.optional(v2.boolean(), true),
171
+ custom_scope: v2.optional(v2.boolean(), false),
172
+ max_items: v2.optional(v2.pipe(v2.number(), v2.minValue(1)), 20),
173
+ initial_value: v2.optional(v2.string(), "app"),
174
+ infer_scope_from_branch: v2.optional(v2.boolean(), true),
175
+ autocomplete: v2.optional(v2.boolean(), true),
176
+ options: v2.optional(
177
+ v2.array(
178
+ v2.object({
179
+ value: v2.string(),
180
+ label: v2.optional(v2.string()),
181
+ hint: v2.optional(v2.string())
182
+ })
183
+ ),
184
+ DEFAULT_SCOPE_OPTIONS
185
+ )
186
+ }),
187
+ {}
188
+ ),
189
+ v2.rawCheck(({ dataset, addIssue }) => {
190
+ if (!dataset.typed)
191
+ return;
192
+ const option_values = dataset.value.options.map((option) => option.value);
193
+ if (dataset.value.custom_scope)
194
+ option_values.push(CUSTOM_SCOPE_KEY);
195
+ if (!option_values.includes(dataset.value.initial_value)) {
196
+ addIssue({
197
+ message: `Scope: initial_value "${dataset.value.initial_value}" must exist in options`
198
+ });
199
+ }
200
+ }),
201
+ v2.transform((value) => {
202
+ const option_values = value.options.map((option) => option.value);
203
+ if (value.custom_scope && !option_values.includes(CUSTOM_SCOPE_KEY)) {
204
+ return {
205
+ ...value,
206
+ options: [
207
+ ...value.options,
208
+ {
209
+ label: CUSTOM_SCOPE_KEY,
210
+ value: CUSTOM_SCOPE_KEY,
211
+ hint: "Write a custom scope"
212
+ }
213
+ ]
214
+ };
215
+ }
216
+ return value;
217
+ })
218
+ );
219
+ var Config = v2.object({
220
+ check_status: v2.optional(v2.boolean(), true),
221
+ check_status_autocomplete: v2.optional(v2.boolean(), true),
222
+ commit_type: CommitTypeConfig,
223
+ commit_scope: CommitScopeConfig,
224
+ check_ticket: v2.optional(
225
+ v2.object({
226
+ infer_ticket: v2.optional(v2.boolean(), true),
227
+ confirm_ticket: v2.optional(v2.boolean(), true),
228
+ add_to_title: v2.optional(v2.boolean(), true),
229
+ append_hashtag: v2.optional(v2.boolean(), false),
230
+ prepend_hashtag: v2.optional(
231
+ v2.picklist(["Never", "Always", "Prompt"]),
232
+ "Never"
233
+ ),
234
+ surround: v2.optional(v2.picklist(["", "()", "[]", "{}"]), ""),
235
+ title_position: v2.optional(
236
+ v2.picklist(["start", "end", "before-colon", "beginning"]),
237
+ "start"
238
+ )
239
+ }),
240
+ {}
241
+ ),
242
+ commit_title: v2.optional(
243
+ v2.object({
244
+ max_size: v2.optional(v2.pipe(v2.number(), v2.minValue(1)), 70)
245
+ }),
246
+ {}
247
+ ),
248
+ commit_body: v2.optional(
249
+ v2.object({
250
+ enable: v2.optional(v2.boolean(), true),
251
+ required: v2.optional(v2.boolean(), false),
252
+ split_by_period: v2.optional(v2.boolean(), false)
253
+ }),
254
+ {}
255
+ ),
256
+ commit_footer: v2.optional(
257
+ v2.object({
258
+ enable: v2.optional(v2.boolean(), true),
259
+ initial_value: v2.optional(v2.array(V_FOOTER_OPTIONS), []),
260
+ options: v2.optional(v2.array(V_FOOTER_OPTIONS), FOOTER_OPTION_VALUES)
261
+ }),
262
+ {}
263
+ ),
264
+ breaking_change: v2.optional(
265
+ v2.object({
266
+ add_exclamation_to_title: v2.optional(v2.boolean(), true)
267
+ }),
268
+ {}
269
+ ),
270
+ cache_last_value: v2.optional(v2.boolean(), true),
271
+ confirm_with_editor: v2.optional(v2.boolean(), false),
272
+ confirm_commit: v2.optional(v2.boolean(), true),
273
+ print_commit_output: v2.optional(v2.boolean(), true),
274
+ branch_pre_commands: v2.optional(v2.array(v2.string()), []),
275
+ branch_post_commands: v2.optional(v2.array(v2.string()), []),
276
+ worktree_pre_commands: v2.optional(v2.array(v2.string()), []),
277
+ worktree_post_commands: v2.optional(v2.array(v2.string()), []),
278
+ branch_user: v2.optional(
279
+ v2.object({
280
+ enable: v2.optional(v2.boolean(), true),
281
+ required: v2.optional(v2.boolean(), false),
282
+ separator: v2.optional(v2.picklist(["/", "-", "_"]), "/")
283
+ }),
284
+ {}
285
+ ),
286
+ branch_type: v2.optional(
287
+ v2.object({
288
+ enable: v2.optional(v2.boolean(), true),
289
+ separator: v2.optional(v2.picklist(["/", "-", "_"]), "/"),
290
+ autocomplete: v2.optional(v2.boolean(), true)
291
+ }),
292
+ {}
293
+ ),
294
+ branch_scope: v2.optional(
295
+ v2.object({
296
+ enable: v2.optional(v2.boolean(), true),
297
+ separator: v2.optional(v2.picklist(["/", "-", "_"]), "-"),
298
+ autocomplete: v2.optional(v2.boolean(), true)
299
+ }),
300
+ {}
301
+ ),
302
+ branch_version: v2.optional(
303
+ v2.object({
304
+ enable: v2.optional(v2.boolean(), false),
305
+ required: v2.optional(v2.boolean(), false),
306
+ separator: v2.optional(v2.picklist(["/", "-", "_"]), "/")
307
+ }),
308
+ {}
309
+ ),
310
+ branch_ticket: v2.optional(
311
+ v2.object({
312
+ enable: v2.optional(v2.boolean(), true),
313
+ required: v2.optional(v2.boolean(), false),
314
+ separator: v2.optional(v2.picklist(["/", "-", "_"]), "-")
315
+ }),
316
+ {}
317
+ ),
318
+ branch_description: v2.optional(
319
+ v2.object({
320
+ max_length: v2.optional(v2.pipe(v2.number(), v2.minValue(1)), 70),
321
+ separator: v2.optional(v2.picklist(["", "/", "-", "_"]), "")
322
+ }),
323
+ {}
324
+ ),
325
+ branch_action_default: v2.optional(V_BRANCH_ACTIONS, "branch"),
326
+ branch_order: v2.optional(v2.array(V_BRANCH_FIELDS), BRANCH_ORDER_DEFAULTS),
327
+ enable_worktrees: v2.optional(v2.boolean(), true),
328
+ worktrees: v2.optional(
329
+ v2.object({
330
+ enable: v2.optional(v2.boolean(), true),
331
+ base_path: v2.optional(v2.string(), ".."),
332
+ folder_template: v2.optional(
333
+ v2.string(),
334
+ "{{repo_name}}-{{ticket}}-{{branch_description}}"
335
+ )
336
+ }),
337
+ {}
338
+ ),
339
+ overrides: v2.optional(
340
+ v2.object({
341
+ shell: v2.optional(v2.string())
342
+ }),
343
+ {}
344
+ )
345
+ });
346
+ var COMMIT_STATE_ENTRIES = {
347
+ type: v2.optional(v2.string(), ""),
348
+ scope: v2.optional(v2.string(), ""),
349
+ title: v2.optional(v2.string(), ""),
350
+ body: v2.optional(v2.string(), ""),
351
+ closes: v2.optional(v2.string(), ""),
352
+ ticket: v2.optional(v2.string(), ""),
353
+ breaking_title: v2.optional(v2.string(), ""),
354
+ breaking_body: v2.optional(v2.string(), ""),
355
+ deprecates: v2.optional(v2.string(), ""),
356
+ deprecates_title: v2.optional(v2.string(), ""),
357
+ deprecates_body: v2.optional(v2.string(), ""),
358
+ custom_footer: v2.optional(v2.string(), ""),
359
+ trailer: v2.optional(v2.string(), "")
360
+ };
361
+ var CommitState = v2.optional(v2.object(COMMIT_STATE_ENTRIES), {});
362
+ var BRANCH_STATE_ENTRIES = {
363
+ user: v2.optional(v2.string(), ""),
364
+ type: v2.optional(v2.string(), ""),
365
+ scope: v2.optional(v2.string(), ""),
366
+ ticket: v2.optional(v2.string(), ""),
367
+ description: v2.optional(v2.string(), ""),
368
+ version: v2.optional(v2.string(), ""),
369
+ checkout: v2.optional(V_BRANCH_ACTIONS, "branch")
370
+ };
371
+ var BranchState = v2.optional(v2.object(BRANCH_STATE_ENTRIES), {});
372
+
373
+ // src/args.ts
374
+ import { parse } from "@bomb.sh/args";
375
+ var COMMIT_OPTIONS = [
376
+ "type",
377
+ "scope",
378
+ "title",
379
+ "body",
380
+ "ticket",
381
+ "closes",
382
+ "trailer",
383
+ "breaking-title",
384
+ "breaking-body",
385
+ "deprecates-title",
386
+ "deprecates-body",
387
+ "custom-footer"
388
+ ];
389
+ var GIT_OPTIONS = ["git-dir", "work-tree"];
390
+ var BOOLEAN_FLAGS = [
391
+ "interactive",
392
+ "dry-run",
393
+ "help",
394
+ "version"
395
+ ];
396
+ var Flags = class {
397
+ #runtime;
398
+ constructor(runtime) {
399
+ this.#runtime = runtime;
400
+ }
401
+ get git_args() {
402
+ return this.#runtime.git_args;
403
+ }
404
+ get interactive() {
405
+ return !this.#runtime.no_interactive;
406
+ }
407
+ get dry_run() {
408
+ return this.#runtime.dry_run;
409
+ }
410
+ get help() {
411
+ return this.#runtime.help;
412
+ }
413
+ get version() {
414
+ return this.#runtime.version;
415
+ }
416
+ get commit_state() {
417
+ return this.#runtime.commit_state;
418
+ }
419
+ };
420
+ var flags = new Flags(parse_runtime_flags(process.argv.slice(2)));
421
+ function parse_runtime_flags(argv) {
422
+ const parsed = parse(argv, {
423
+ alias: { h: "help", v: "version" },
424
+ boolean: BOOLEAN_FLAGS,
425
+ string: [...COMMIT_OPTIONS, ...GIT_OPTIONS]
426
+ });
427
+ const commit_state = {};
428
+ COMMIT_OPTIONS.forEach((value) => {
429
+ const cli_value = parsed[value];
430
+ const normalized_value = normalize_commit_flag(value, cli_value);
431
+ if (normalized_value !== void 0) {
432
+ const str = value.replace("-", "_");
433
+ commit_state[str] = normalized_value;
434
+ }
435
+ });
436
+ return {
437
+ help: parsed["help"] === true,
438
+ version: parsed["version"] === true,
439
+ git_args: get_git_args(parsed["git-dir"], parsed["work-tree"]),
440
+ no_interactive: parsed.interactive === false,
441
+ dry_run: parsed["dry-run"] === true,
442
+ commit_state
443
+ };
444
+ }
445
+ function normalize_commit_flag(option, value) {
446
+ if (value === void 0)
447
+ return void 0;
448
+ if (option !== "closes")
449
+ return value;
450
+ const normalized = value.trim().toLowerCase();
451
+ if (normalized === "false") {
452
+ return void 0;
453
+ }
454
+ if (value === "" || normalized) {
455
+ return "Closes:";
456
+ }
457
+ return void 0;
458
+ }
459
+ function get_git_args(git_dir, work_tree) {
460
+ return `${git_dir ? `--git-dir=${git_dir}` : ""} ${work_tree ? `--work-tree=${work_tree}` : ""}`.trim();
461
+ }
462
+
463
+ // src/default-config-template.ts
464
+ var DEFAULT_CONFIG_TEMPLATE = `{
465
+ // Run interactive \`git status\` before composing a commit
466
+ "check_status": true,
467
+ "check_status_autocomplete": true,
468
+
469
+ /* COMMIT FIELDS */
470
+ "commit_type": {
471
+ "enable": true,
472
+
473
+ // Default selected type from options
474
+ "initial_value": "feat",
475
+
476
+ "max_items": 20,
477
+
478
+ // Infer type from the current branch name: user/TYPE/my-branch
479
+ "infer_type_from_branch": true,
480
+
481
+ // Include emoji in prompt label
482
+ "append_emoji_to_label": false,
483
+
484
+ // Include emoji from prompt label in commit message
485
+ "append_emoji_to_commit": false,
486
+
487
+ // "Start" | "After-Colon"
488
+ "emoji_commit_position": "Start",
489
+
490
+ "autocomplete": true,
491
+
492
+ "options": [
493
+ {
494
+ "value": "feat",
495
+ "label": "feat",
496
+ "hint": "A new feature",
497
+ "emoji": "\u{1F31F}",
498
+ "trailer": "Changelog: feature"
499
+ },
500
+ {
501
+ "value": "fix",
502
+ "label": "fix",
503
+ "hint": "A bug fix",
504
+ "emoji": "\u{1F41B}",
505
+ "trailer": "Changelog: fix"
506
+ },
507
+ {
508
+ "value": "docs",
509
+ "label": "docs",
510
+ "hint": "Documentation only changes",
511
+ "emoji": "\u{1F4DA}",
512
+ "trailer": "Changelog: documentation"
513
+ },
514
+ {
515
+ "value": "refactor",
516
+ "label": "refactor",
517
+ "hint": "A code change that neither fixes a bug nor adds a feature",
518
+ "emoji": "\u{1F528}",
519
+ "trailer": "Changelog: refactor"
520
+ },
521
+ {
522
+ "value": "perf",
523
+ "label": "perf",
524
+ "hint": "A code change that improves performance",
525
+ "emoji": "\u{1F680}",
526
+ "trailer": "Changelog: performance"
527
+ },
528
+ {
529
+ "value": "test",
530
+ "label": "test",
531
+ "hint": "Adding missing tests or correcting existing tests",
532
+ "emoji": "\u{1F6A8}",
533
+ "trailer": "Changelog: test"
534
+ },
535
+ {
536
+ "value": "build",
537
+ "label": "build",
538
+ "hint": "Changes that affect the build system or external dependencies",
539
+ "emoji": "\u{1F6A7}",
540
+ "trailer": "Changelog: build"
541
+ },
542
+ {
543
+ "value": "ci",
544
+ "label": "ci",
545
+ "hint": "Changes to our CI configuration files and scripts",
546
+ "emoji": "\u{1F916}",
547
+ "trailer": "Changelog: ci"
548
+ },
549
+ {
550
+ "value": "chore",
551
+ "label": "chore",
552
+ "hint": "Other changes that do not modify src or test files",
553
+ "emoji": "\u{1F9F9}",
554
+ "trailer": "Changelog: chore"
555
+ },
556
+ {
557
+ "value": "",
558
+ "label": "none"
559
+ }
560
+ ]
561
+ },
562
+
563
+ "commit_scope": {
564
+ "enable": true,
565
+
566
+ // If true, users can type a scope not listed in options
567
+ "custom_scope": false,
568
+
569
+ // Default selected scope from options
570
+ "initial_value": "app",
571
+
572
+ // Infer scope from the current branch name: user/type/ticket-SCOPE-my-branch
573
+ "infer_scope_from_branch": true,
574
+
575
+ "max_items": 20,
576
+ "autocomplete": true,
577
+ "options": [
578
+ { "value": "app", "label": "app" },
579
+ { "value": "shared", "label": "shared" },
580
+ { "value": "server", "label": "server" },
581
+ { "value": "tools", "label": "tools" },
582
+ { "value": "", "label": "none" }
583
+ ]
584
+ },
585
+
586
+ "check_ticket": {
587
+ // Infer ticket / issue from the branch name - user/type/TICKET-my-branch
588
+ "infer_ticket": true,
589
+
590
+ // Prompt for confirmation / edit before using an inferred ticket
591
+ "confirm_ticket": true,
592
+
593
+ // Add the ticket to the commit title - feat(app): TICKET my commit title
594
+ "add_to_title": true,
595
+
596
+ // Deprecated, prefer \`prepend_hashtag\`
597
+ "append_hashtag": false,
598
+
599
+ // "Never" | "Prompt" | "Always" - 12345 --> #12345
600
+ "prepend_hashtag": "Never",
601
+
602
+ // Wrap the ticket in the commit title: "" | "[]" | "()" | "{}"
603
+ "surround": "",
604
+
605
+ // "start" | "end" | "before-colon" | "beginning"
606
+ "title_position": "start"
607
+ },
608
+
609
+ "commit_title": {
610
+ // Includes total size of title + type + scope + ticket
611
+ "max_size": 70
612
+ },
613
+
614
+ "commit_body": {
615
+ "enable": true,
616
+ "required": false,
617
+
618
+ // Split sentences into multiple lines automatically
619
+ "split_by_period": false
620
+ },
621
+
622
+ "commit_footer": {
623
+ "enable": true,
624
+ "initial_value": [],
625
+
626
+ // "closes", "trailer", "breaking-change", "deprecated", "custom"
627
+ "options": ["closes", "trailer", "breaking-change", "deprecated", "custom"]
628
+ },
629
+
630
+ "breaking_change": {
631
+ // Adds \`!\` to the commit title when a breaking change is selected
632
+ "add_exclamation_to_title": true
633
+ },
634
+
635
+ // Confirm / edit with $GIT_EDITOR or $EDITOR
636
+ "confirm_with_editor": false,
637
+
638
+ // Show a final confirmation prompt before running git commit
639
+ "confirm_commit": true,
640
+
641
+ // Reuse the last known value from a previous canceled or failed commit
642
+ "cache_last_value": true,
643
+
644
+ // Pretty-print the final commit preview before execution
645
+ "print_commit_output": true,
646
+
647
+ /* BRANCH FIELDS */
648
+ // Optional shell commands to run before / after creating branches or worktrees
649
+ "branch_pre_commands": [],
650
+ "branch_post_commands": [],
651
+ "worktree_pre_commands": [],
652
+ "worktree_post_commands": [],
653
+
654
+ "branch_user": {
655
+ "enable": true,
656
+ "required": false,
657
+
658
+ // "/" | "-" | "_" - user/feat/my-branch
659
+ "separator": "/"
660
+ },
661
+
662
+ "branch_type": {
663
+ "enable": true,
664
+ "separator": "/",
665
+ "autocomplete": true,
666
+ },
667
+
668
+ "branch_scope": {
669
+ "enable": true,
670
+ "separator": "-",
671
+ "autocomplete": true,
672
+ },
673
+
674
+ "branch_ticket": {
675
+ "enable": true,
676
+ "required": false,
677
+ "separator": "-"
678
+ },
679
+
680
+ "branch_version": {
681
+ "enable": false,
682
+ "required": false,
683
+ "separator": "/"
684
+ },
685
+
686
+ "branch_description": {
687
+ // Maximum length for the description segment of the branch name
688
+ "max_length": 70,
689
+
690
+ // Allowed values: "" | "/" | "-" | "_"
691
+ "separator": ""
692
+ },
693
+
694
+ // "branch" | "worktree"
695
+ "branch_action_default": "branch",
696
+
697
+ // Order of values in the final branch name
698
+ "branch_order": ["user", "version", "type", "ticket", "scope", "description"],
699
+
700
+ // Deprecated, prefer \`worktrees.enable\`
701
+ "enable_worktrees": true,
702
+
703
+ "worktrees": {
704
+ // If false, always create a branch instead of prompting for a worktree
705
+ "enable": true,
706
+
707
+ // Directory where worktrees are created
708
+ "base_path": "..",
709
+
710
+ // Available template variables include:
711
+ // {{repo_name}}, {{branch_description}}, {{user}}, {{type}}, {{scope}}, {{ticket}}, {{version}}
712
+ "folder_template": "{{repo_name}}-{{ticket}}-{{branch_description}}"
713
+ },
714
+
715
+ /* OTHER FIELDS */
716
+ "overrides": {
717
+ // Useful on Windows or for shells with different multiline behavior
718
+ "shell": "/bin/sh"
719
+ }
720
+ }
721
+ `;
722
+
723
+ // src/utils.ts
724
+ import * as p from "@clack/prompts";
725
+ import { execSync } from "child_process";
726
+ import fs from "fs";
727
+ import { homedir } from "os";
728
+ import { parse as parse_jsonc } from "jsonc-parser";
729
+ import color from "picocolors";
730
+ import { ValiError, parse as parse2 } from "valibot";
731
+ var CONFIG_FILE_NAMES = [
732
+ ".better-commits.jsonc",
733
+ ".better-commits.json"
734
+ ];
735
+ var CONFIG_FILE_NAME = CONFIG_FILE_NAMES[0];
736
+ var COMMIT_FOOTER_OPTIONS = [
737
+ {
738
+ value: "closes",
739
+ label: "closes <issue/ticket>",
740
+ hint: "Attempts to infer ticket from branch"
741
+ },
742
+ {
743
+ value: "trailer",
744
+ label: "trailer",
745
+ hint: "Appends trailer based on commit type"
746
+ },
747
+ {
748
+ value: "breaking-change",
749
+ label: "breaking change",
750
+ hint: "Add breaking change"
751
+ },
752
+ { value: "deprecated", label: "deprecated", hint: "Add deprecated change" },
753
+ { value: "custom", label: "custom", hint: "Add a custom footer" }
754
+ ];
755
+ var BRANCH_ACTION_OPTIONS = [
756
+ { value: "branch", label: "Branch" },
757
+ { value: "worktree", label: "Worktree" }
758
+ ];
759
+ var NOOP_PROMPT_CACHE = {
760
+ get: () => "",
761
+ set: (key, value) => {
762
+ },
763
+ clear: () => {
764
+ }
765
+ };
766
+ function load_setup(cli_name = " better-commits ", git_args = flags.git_args) {
767
+ console.clear();
768
+ p.intro(`${color.bgCyan(color.black(cli_name))}`);
769
+ let global_config = null;
770
+ const home_path = get_default_config_path();
771
+ if (fs.existsSync(home_path)) {
772
+ global_config = read_config_from_path(home_path);
773
+ }
774
+ const root = get_git_root(git_args);
775
+ const root_path = get_repository_config_path(root);
776
+ if (root_path) {
777
+ p.log.step("Reading from Repository Config");
778
+ const repo_config = read_config_from_path(root_path);
779
+ return {
780
+ config: global_config ? {
781
+ ...repo_config,
782
+ overrides: global_config.overrides.shell ? global_config.overrides : repo_config.overrides,
783
+ confirm_with_editor: global_config.confirm_with_editor,
784
+ cache_last_value: global_config.cache_last_value
785
+ } : repo_config,
786
+ config_source: "repository"
787
+ };
788
+ }
789
+ if (global_config) {
790
+ p.log.step("Reading from Global Config");
791
+ return {
792
+ config: global_config,
793
+ config_source: "global"
794
+ };
795
+ }
796
+ const default_config = parse2(Config, {});
797
+ p.log.step(
798
+ `Config not found. Generating default ${CONFIG_FILE_NAME} at $HOME`
799
+ );
800
+ fs.writeFileSync(home_path, DEFAULT_CONFIG_TEMPLATE);
801
+ return {
802
+ config: default_config,
803
+ config_source: "none"
804
+ };
805
+ }
806
+ function read_config_from_path(config_path) {
807
+ let res = null;
808
+ try {
809
+ res = parse_jsonc(fs.readFileSync(config_path, "utf8"));
810
+ } catch (err) {
811
+ p.log.error(
812
+ `Invalid JSON/JSONC config file at ${config_path}. Exiting.
813
+ ` + err
814
+ );
815
+ process.exit(0);
816
+ }
817
+ return validate_config(res);
818
+ }
819
+ function validate_config(config) {
820
+ try {
821
+ return parse2(Config, config);
822
+ } catch (err) {
823
+ if (err instanceof ValiError) {
824
+ const first_issue_path = err.issues[0].path ?? [];
825
+ const dot_path = first_issue_path.map((item) => item.key).filter(
826
+ (key) => typeof key === "string" || typeof key === "number"
827
+ ).join(".");
828
+ p.log.error(
829
+ `Invalid Configuration: ${color.red(dot_path)}
830
+ ` + err.message
831
+ );
832
+ }
833
+ process.exit(0);
834
+ }
835
+ }
836
+ function get_git_root(git_args = flags.git_args) {
837
+ let path = ".";
838
+ try {
839
+ path = execSync(`git ${git_args} rev-parse --show-toplevel`).toString().trim();
840
+ } catch (err) {
841
+ p.log.warn(
842
+ "Could not find git root. If in a --bare repository, ignore this warning."
843
+ );
844
+ }
845
+ return path;
846
+ }
847
+ function get_default_config_path() {
848
+ return get_config_path(homedir()) ?? homedir() + "/" + CONFIG_FILE_NAME;
849
+ }
850
+ function get_repository_config_path(root) {
851
+ return get_config_path(root);
852
+ }
853
+ function get_config_path(base_path) {
854
+ for (const file_name of CONFIG_FILE_NAMES) {
855
+ const config_path = `${base_path}/${file_name}`;
856
+ if (fs.existsSync(config_path))
857
+ return config_path;
858
+ }
859
+ return null;
860
+ }
861
+ function get_package_version() {
862
+ try {
863
+ const package_json = JSON.parse(
864
+ fs.readFileSync(new URL("../package.json", import.meta.url), "utf8")
865
+ );
866
+ return package_json.version ?? "unknown";
867
+ } catch {
868
+ return "unknown";
869
+ }
870
+ }
871
+ function addNewLine(arr, i) {
872
+ return i === arr.length - 1 ? "" : "\n";
873
+ }
874
+ function clean_commit_title(title) {
875
+ const title_trimmed = title.trim();
876
+ const remove_period = title_trimmed.endsWith(".");
877
+ if (remove_period) {
878
+ return title_trimmed.substring(0, title_trimmed.length - 1).trim();
879
+ }
880
+ return title.trim();
881
+ }
882
+ function get_value_from_cache(config_store, key) {
883
+ try {
884
+ return config_store.get(key) ?? "";
885
+ } catch (err) {
886
+ p.log.warn(
887
+ `Could not access ${key} from cache. Check that "~/.config" exists. Set "cache_last_value" to false to disable.`
888
+ );
889
+ }
890
+ return "";
891
+ }
892
+ function set_value_cache(config_store, key, value) {
893
+ try {
894
+ config_store.set(key, value);
895
+ } catch (err) {
896
+ p.log.warn(
897
+ `Could not access ${key} from cache. Check that "~/.config" exists. Set "cache_last_value" to false to disable.`
898
+ );
899
+ }
900
+ }
901
+
902
+ export {
903
+ CUSTOM_SCOPE_KEY,
904
+ COMMIT_STATE_ENTRIES,
905
+ CommitState,
906
+ BRANCH_STATE_ENTRIES,
907
+ BranchState,
908
+ flags,
909
+ DEFAULT_CONFIG_TEMPLATE,
910
+ CONFIG_FILE_NAME,
911
+ COMMIT_FOOTER_OPTIONS,
912
+ BRANCH_ACTION_OPTIONS,
913
+ NOOP_PROMPT_CACHE,
914
+ load_setup,
915
+ get_git_root,
916
+ get_repository_config_path,
917
+ get_package_version,
918
+ addNewLine,
919
+ clean_commit_title,
920
+ get_value_from_cache,
921
+ set_value_cache
922
+ };