better-commits 1.10.0 → 1.11.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/branch.js CHANGED
@@ -43,10 +43,10 @@ var OPTIONAL_PROMPT = `${import_picocolors.default.dim("(optional)")}`;
43
43
  var CACHE_PROMPT = `${import_picocolors.default.dim("(value will be saved)")}`;
44
44
  var REGEX_SLASH_TAG = new RegExp(/\/(\w+-\d+)/);
45
45
  var REGEX_START_TAG = new RegExp(/^(\w+-\d+)/);
46
- var REGEX_SLASH_NUM = new RegExp(/\/(\d+)/);
47
- var REGEX_START_NUM = new RegExp(/^(\d+)/);
48
46
  var REGEX_START_UND = new RegExp(/^([A-Z]+-[\[a-zA-Z\]\d]+)_/);
49
47
  var REGEX_SLASH_UND = new RegExp(/\/([A-Z]+-[\[a-zA-Z\]\d]+)_/);
48
+ var REGEX_SLASH_NUM = new RegExp(/\/(\d+)/);
49
+ var REGEX_START_NUM = new RegExp(/^(\d+)/);
50
50
  var DEFAULT_TYPE_OPTIONS = [
51
51
  { value: "feat", label: "feat", hint: "A new feature", emoji: "\u2728", trailer: "Changelog: feature" },
52
52
  { value: "fix", label: "fix", hint: "A bug fix", emoji: "\u{1F41B}", trailer: "Changelog: fix" },
@@ -116,6 +116,15 @@ var Z_FOOTER_OPTIONS = import_zod.z.enum([
116
116
  "deprecated",
117
117
  "custom"
118
118
  ]);
119
+ var Z_BRANCH_FIELDS = import_zod.z.enum(["user", "version", "type", "ticket", "description"]);
120
+ var Z_BRANCH_CONFIG_FIELDS = import_zod.z.enum([
121
+ "branch_user",
122
+ "branch_version",
123
+ "branch_type",
124
+ "branch_ticket",
125
+ "branch_description"
126
+ ]);
127
+ var BRANCH_ORDER_DEFAULTS = ["user", "version", "type", "ticket", "description"];
119
128
  var Z_BRANCH_ACTIONS = import_zod.z.enum(["branch", "worktree"]);
120
129
  var FOOTER_OPTION_VALUES = [
121
130
  "closes",
@@ -286,15 +295,22 @@ var Config = import_zod2.z.object({
286
295
  enable: import_zod2.z.boolean().default(true),
287
296
  separator: import_zod2.z.enum(["/", "-", "_"]).default("/")
288
297
  }).default({}),
298
+ branch_version: import_zod2.z.object({
299
+ enable: import_zod2.z.boolean().default(false),
300
+ required: import_zod2.z.boolean().default(false),
301
+ separator: import_zod2.z.enum(["/", "-", "_"]).default("/")
302
+ }).default({}),
289
303
  branch_ticket: import_zod2.z.object({
290
304
  enable: import_zod2.z.boolean().default(true),
291
305
  required: import_zod2.z.boolean().default(false),
292
306
  separator: import_zod2.z.enum(["/", "-", "_"]).default("-")
293
307
  }).default({}),
294
308
  branch_description: import_zod2.z.object({
295
- max_length: import_zod2.z.number().positive().default(70)
309
+ max_length: import_zod2.z.number().positive().default(70),
310
+ separator: import_zod2.z.enum(["", "/", "-", "_"]).default("")
296
311
  }).default({}),
297
312
  branch_action_default: Z_BRANCH_ACTIONS.default("branch"),
313
+ branch_order: import_zod2.z.array(Z_BRANCH_FIELDS).default(BRANCH_ORDER_DEFAULTS),
298
314
  enable_worktrees: import_zod2.z.boolean().default(true),
299
315
  overrides: import_zod2.z.object({ shell: import_zod2.z.string().optional() }).default({})
300
316
  }).default({});
@@ -317,7 +333,8 @@ var BranchState = import_zod2.z.object({
317
333
  user: import_zod2.z.string().default(""),
318
334
  type: import_zod2.z.string().default(""),
319
335
  ticket: import_zod2.z.string().default(""),
320
- description: import_zod2.z.string().default("")
336
+ description: import_zod2.z.string().default(""),
337
+ version: import_zod2.z.string().default("")
321
338
  }).default({});
322
339
 
323
340
  // src/branch.ts
@@ -382,6 +399,20 @@ async function main(config) {
382
399
  process.exit(0);
383
400
  branch_state.ticket = ticket;
384
401
  }
402
+ if (config.branch_version.enable) {
403
+ const version_required = config.branch_version.required;
404
+ const version = await p2.text({
405
+ message: `Type version number ${version_required ? "" : OPTIONAL_PROMPT}`.trim(),
406
+ placeholder: "",
407
+ validate: (val) => {
408
+ if (version_required && !val)
409
+ return "Please enter a version";
410
+ }
411
+ });
412
+ if (p2.isCancel(version))
413
+ process.exit(0);
414
+ branch_state.version = version;
415
+ }
385
416
  const description_max_length = config.branch_description.max_length;
386
417
  const description = await p2.text({
387
418
  message: "Type a short description",
@@ -457,15 +488,15 @@ async function main(config) {
457
488
  }
458
489
  function build_branch(branch, config) {
459
490
  let res = "";
460
- if (branch.user)
461
- res += branch.user + config.branch_user.separator;
462
- if (branch.type)
463
- res += branch.type + config.branch_type.separator;
464
- if (branch.ticket)
465
- res += branch.ticket + config.branch_ticket.separator;
466
- if (branch.description)
467
- res += branch.description;
468
- return res;
491
+ config.branch_order.forEach((b) => {
492
+ const config_key = `branch_${b}`;
493
+ if (branch[b])
494
+ res += branch[b] + config[config_key].separator;
495
+ });
496
+ if (res.endsWith("-") || res.endsWith("/") || res.endsWith("_")) {
497
+ return res.slice(0, -1).trim();
498
+ }
499
+ return res.trim();
469
500
  }
470
501
  function get_user_from_cache() {
471
502
  try {
package/dist/index.js CHANGED
@@ -59,10 +59,10 @@ var OPTIONAL_PROMPT = `${import_picocolors.default.dim("(optional)")}`;
59
59
  var CACHE_PROMPT = `${import_picocolors.default.dim("(value will be saved)")}`;
60
60
  var REGEX_SLASH_TAG = new RegExp(/\/(\w+-\d+)/);
61
61
  var REGEX_START_TAG = new RegExp(/^(\w+-\d+)/);
62
- var REGEX_SLASH_NUM = new RegExp(/\/(\d+)/);
63
- var REGEX_START_NUM = new RegExp(/^(\d+)/);
64
62
  var REGEX_START_UND = new RegExp(/^([A-Z]+-[\[a-zA-Z\]\d]+)_/);
65
63
  var REGEX_SLASH_UND = new RegExp(/\/([A-Z]+-[\[a-zA-Z\]\d]+)_/);
64
+ var REGEX_SLASH_NUM = new RegExp(/\/(\d+)/);
65
+ var REGEX_START_NUM = new RegExp(/^(\d+)/);
66
66
  var DEFAULT_TYPE_OPTIONS = [
67
67
  { value: "feat", label: "feat", hint: "A new feature", emoji: "\u2728", trailer: "Changelog: feature" },
68
68
  { value: "fix", label: "fix", hint: "A bug fix", emoji: "\u{1F41B}", trailer: "Changelog: fix" },
@@ -151,6 +151,15 @@ var Z_FOOTER_OPTIONS = import_zod.z.enum([
151
151
  "deprecated",
152
152
  "custom"
153
153
  ]);
154
+ var Z_BRANCH_FIELDS = import_zod.z.enum(["user", "version", "type", "ticket", "description"]);
155
+ var Z_BRANCH_CONFIG_FIELDS = import_zod.z.enum([
156
+ "branch_user",
157
+ "branch_version",
158
+ "branch_type",
159
+ "branch_ticket",
160
+ "branch_description"
161
+ ]);
162
+ var BRANCH_ORDER_DEFAULTS = ["user", "version", "type", "ticket", "description"];
154
163
  var Z_BRANCH_ACTIONS = import_zod.z.enum(["branch", "worktree"]);
155
164
  var FOOTER_OPTION_VALUES = [
156
165
  "closes",
@@ -350,15 +359,22 @@ var Config = import_zod2.z.object({
350
359
  enable: import_zod2.z.boolean().default(true),
351
360
  separator: import_zod2.z.enum(["/", "-", "_"]).default("/")
352
361
  }).default({}),
362
+ branch_version: import_zod2.z.object({
363
+ enable: import_zod2.z.boolean().default(false),
364
+ required: import_zod2.z.boolean().default(false),
365
+ separator: import_zod2.z.enum(["/", "-", "_"]).default("/")
366
+ }).default({}),
353
367
  branch_ticket: import_zod2.z.object({
354
368
  enable: import_zod2.z.boolean().default(true),
355
369
  required: import_zod2.z.boolean().default(false),
356
370
  separator: import_zod2.z.enum(["/", "-", "_"]).default("-")
357
371
  }).default({}),
358
372
  branch_description: import_zod2.z.object({
359
- max_length: import_zod2.z.number().positive().default(70)
373
+ max_length: import_zod2.z.number().positive().default(70),
374
+ separator: import_zod2.z.enum(["", "/", "-", "_"]).default("")
360
375
  }).default({}),
361
376
  branch_action_default: Z_BRANCH_ACTIONS.default("branch"),
377
+ branch_order: import_zod2.z.array(Z_BRANCH_FIELDS).default(BRANCH_ORDER_DEFAULTS),
362
378
  enable_worktrees: import_zod2.z.boolean().default(true),
363
379
  overrides: import_zod2.z.object({ shell: import_zod2.z.string().optional() }).default({})
364
380
  }).default({});
@@ -381,7 +397,8 @@ var BranchState = import_zod2.z.object({
381
397
  user: import_zod2.z.string().default(""),
382
398
  type: import_zod2.z.string().default(""),
383
399
  ticket: import_zod2.z.string().default(""),
384
- description: import_zod2.z.string().default("")
400
+ description: import_zod2.z.string().default(""),
401
+ version: import_zod2.z.string().default("")
385
402
  }).default({});
386
403
 
387
404
  // src/git.ts
package/dist/init.js CHANGED
@@ -41,10 +41,10 @@ var OPTIONAL_PROMPT = `${import_picocolors.default.dim("(optional)")}`;
41
41
  var CACHE_PROMPT = `${import_picocolors.default.dim("(value will be saved)")}`;
42
42
  var REGEX_SLASH_TAG = new RegExp(/\/(\w+-\d+)/);
43
43
  var REGEX_START_TAG = new RegExp(/^(\w+-\d+)/);
44
- var REGEX_SLASH_NUM = new RegExp(/\/(\d+)/);
45
- var REGEX_START_NUM = new RegExp(/^(\d+)/);
46
44
  var REGEX_START_UND = new RegExp(/^([A-Z]+-[\[a-zA-Z\]\d]+)_/);
47
45
  var REGEX_SLASH_UND = new RegExp(/\/([A-Z]+-[\[a-zA-Z\]\d]+)_/);
46
+ var REGEX_SLASH_NUM = new RegExp(/\/(\d+)/);
47
+ var REGEX_START_NUM = new RegExp(/^(\d+)/);
48
48
  var DEFAULT_TYPE_OPTIONS = [
49
49
  { value: "feat", label: "feat", hint: "A new feature", emoji: "\u2728", trailer: "Changelog: feature" },
50
50
  { value: "fix", label: "fix", hint: "A bug fix", emoji: "\u{1F41B}", trailer: "Changelog: fix" },
@@ -114,6 +114,15 @@ var Z_FOOTER_OPTIONS = import_zod.z.enum([
114
114
  "deprecated",
115
115
  "custom"
116
116
  ]);
117
+ var Z_BRANCH_FIELDS = import_zod.z.enum(["user", "version", "type", "ticket", "description"]);
118
+ var Z_BRANCH_CONFIG_FIELDS = import_zod.z.enum([
119
+ "branch_user",
120
+ "branch_version",
121
+ "branch_type",
122
+ "branch_ticket",
123
+ "branch_description"
124
+ ]);
125
+ var BRANCH_ORDER_DEFAULTS = ["user", "version", "type", "ticket", "description"];
117
126
  var Z_BRANCH_ACTIONS = import_zod.z.enum(["branch", "worktree"]);
118
127
  var FOOTER_OPTION_VALUES = [
119
128
  "closes",
@@ -238,15 +247,22 @@ var Config = import_zod2.z.object({
238
247
  enable: import_zod2.z.boolean().default(true),
239
248
  separator: import_zod2.z.enum(["/", "-", "_"]).default("/")
240
249
  }).default({}),
250
+ branch_version: import_zod2.z.object({
251
+ enable: import_zod2.z.boolean().default(false),
252
+ required: import_zod2.z.boolean().default(false),
253
+ separator: import_zod2.z.enum(["/", "-", "_"]).default("/")
254
+ }).default({}),
241
255
  branch_ticket: import_zod2.z.object({
242
256
  enable: import_zod2.z.boolean().default(true),
243
257
  required: import_zod2.z.boolean().default(false),
244
258
  separator: import_zod2.z.enum(["/", "-", "_"]).default("-")
245
259
  }).default({}),
246
260
  branch_description: import_zod2.z.object({
247
- max_length: import_zod2.z.number().positive().default(70)
261
+ max_length: import_zod2.z.number().positive().default(70),
262
+ separator: import_zod2.z.enum(["", "/", "-", "_"]).default("")
248
263
  }).default({}),
249
264
  branch_action_default: Z_BRANCH_ACTIONS.default("branch"),
265
+ branch_order: import_zod2.z.array(Z_BRANCH_FIELDS).default(BRANCH_ORDER_DEFAULTS),
250
266
  enable_worktrees: import_zod2.z.boolean().default(true),
251
267
  overrides: import_zod2.z.object({ shell: import_zod2.z.string().optional() }).default({})
252
268
  }).default({});
@@ -269,7 +285,8 @@ var BranchState = import_zod2.z.object({
269
285
  user: import_zod2.z.string().default(""),
270
286
  type: import_zod2.z.string().default(""),
271
287
  ticket: import_zod2.z.string().default(""),
272
- description: import_zod2.z.string().default("")
288
+ description: import_zod2.z.string().default(""),
289
+ version: import_zod2.z.string().default("")
273
290
  }).default({});
274
291
 
275
292
  // src/init.ts
package/dist/utils.js CHANGED
@@ -32,6 +32,7 @@ var utils_exports = {};
32
32
  __export(utils_exports, {
33
33
  A_FOR_ALL: () => A_FOR_ALL,
34
34
  BRANCH_ACTION_OPTIONS: () => BRANCH_ACTION_OPTIONS,
35
+ BRANCH_ORDER_DEFAULTS: () => BRANCH_ORDER_DEFAULTS,
35
36
  CACHE_PROMPT: () => CACHE_PROMPT,
36
37
  COMMIT_FOOTER_OPTIONS: () => COMMIT_FOOTER_OPTIONS,
37
38
  CONFIG_FILE_NAME: () => CONFIG_FILE_NAME,
@@ -48,6 +49,8 @@ __export(utils_exports, {
48
49
  REGEX_START_UND: () => REGEX_START_UND,
49
50
  SPACE_TO_SELECT: () => SPACE_TO_SELECT,
50
51
  Z_BRANCH_ACTIONS: () => Z_BRANCH_ACTIONS,
52
+ Z_BRANCH_CONFIG_FIELDS: () => Z_BRANCH_CONFIG_FIELDS,
53
+ Z_BRANCH_FIELDS: () => Z_BRANCH_FIELDS,
51
54
  Z_FOOTER_OPTIONS: () => Z_FOOTER_OPTIONS,
52
55
  addNewLine: () => addNewLine,
53
56
  clean_commit_title: () => clean_commit_title,
@@ -170,15 +173,22 @@ var Config = import_zod.z.object({
170
173
  enable: import_zod.z.boolean().default(true),
171
174
  separator: import_zod.z.enum(["/", "-", "_"]).default("/")
172
175
  }).default({}),
176
+ branch_version: import_zod.z.object({
177
+ enable: import_zod.z.boolean().default(false),
178
+ required: import_zod.z.boolean().default(false),
179
+ separator: import_zod.z.enum(["/", "-", "_"]).default("/")
180
+ }).default({}),
173
181
  branch_ticket: import_zod.z.object({
174
182
  enable: import_zod.z.boolean().default(true),
175
183
  required: import_zod.z.boolean().default(false),
176
184
  separator: import_zod.z.enum(["/", "-", "_"]).default("-")
177
185
  }).default({}),
178
186
  branch_description: import_zod.z.object({
179
- max_length: import_zod.z.number().positive().default(70)
187
+ max_length: import_zod.z.number().positive().default(70),
188
+ separator: import_zod.z.enum(["", "/", "-", "_"]).default("")
180
189
  }).default({}),
181
190
  branch_action_default: Z_BRANCH_ACTIONS.default("branch"),
191
+ branch_order: import_zod.z.array(Z_BRANCH_FIELDS).default(BRANCH_ORDER_DEFAULTS),
182
192
  enable_worktrees: import_zod.z.boolean().default(true),
183
193
  overrides: import_zod.z.object({ shell: import_zod.z.string().optional() }).default({})
184
194
  }).default({});
@@ -201,7 +211,8 @@ var BranchState = import_zod.z.object({
201
211
  user: import_zod.z.string().default(""),
202
212
  type: import_zod.z.string().default(""),
203
213
  ticket: import_zod.z.string().default(""),
204
- description: import_zod.z.string().default("")
214
+ description: import_zod.z.string().default(""),
215
+ version: import_zod.z.string().default("")
205
216
  }).default({});
206
217
 
207
218
  // src/utils.ts
@@ -214,10 +225,10 @@ var OPTIONAL_PROMPT = `${import_picocolors.default.dim("(optional)")}`;
214
225
  var CACHE_PROMPT = `${import_picocolors.default.dim("(value will be saved)")}`;
215
226
  var REGEX_SLASH_TAG = new RegExp(/\/(\w+-\d+)/);
216
227
  var REGEX_START_TAG = new RegExp(/^(\w+-\d+)/);
217
- var REGEX_SLASH_NUM = new RegExp(/\/(\d+)/);
218
- var REGEX_START_NUM = new RegExp(/^(\d+)/);
219
228
  var REGEX_START_UND = new RegExp(/^([A-Z]+-[\[a-zA-Z\]\d]+)_/);
220
229
  var REGEX_SLASH_UND = new RegExp(/\/([A-Z]+-[\[a-zA-Z\]\d]+)_/);
230
+ var REGEX_SLASH_NUM = new RegExp(/\/(\d+)/);
231
+ var REGEX_START_NUM = new RegExp(/^(\d+)/);
221
232
  var DEFAULT_TYPE_OPTIONS = [
222
233
  { value: "feat", label: "feat", hint: "A new feature", emoji: "\u2728", trailer: "Changelog: feature" },
223
234
  { value: "fix", label: "fix", hint: "A bug fix", emoji: "\u{1F41B}", trailer: "Changelog: fix" },
@@ -306,6 +317,15 @@ var Z_FOOTER_OPTIONS = import_zod2.z.enum([
306
317
  "deprecated",
307
318
  "custom"
308
319
  ]);
320
+ var Z_BRANCH_FIELDS = import_zod2.z.enum(["user", "version", "type", "ticket", "description"]);
321
+ var Z_BRANCH_CONFIG_FIELDS = import_zod2.z.enum([
322
+ "branch_user",
323
+ "branch_version",
324
+ "branch_type",
325
+ "branch_ticket",
326
+ "branch_description"
327
+ ]);
328
+ var BRANCH_ORDER_DEFAULTS = ["user", "version", "type", "ticket", "description"];
309
329
  var Z_BRANCH_ACTIONS = import_zod2.z.enum(["branch", "worktree"]);
310
330
  var FOOTER_OPTION_VALUES = [
311
331
  "closes",
@@ -408,6 +428,7 @@ function clean_commit_title(title) {
408
428
  0 && (module.exports = {
409
429
  A_FOR_ALL,
410
430
  BRANCH_ACTION_OPTIONS,
431
+ BRANCH_ORDER_DEFAULTS,
411
432
  CACHE_PROMPT,
412
433
  COMMIT_FOOTER_OPTIONS,
413
434
  CONFIG_FILE_NAME,
@@ -424,6 +445,8 @@ function clean_commit_title(title) {
424
445
  REGEX_START_UND,
425
446
  SPACE_TO_SELECT,
426
447
  Z_BRANCH_ACTIONS,
448
+ Z_BRANCH_CONFIG_FIELDS,
449
+ Z_BRANCH_FIELDS,
427
450
  Z_FOOTER_OPTIONS,
428
451
  addNewLine,
429
452
  clean_commit_title,
package/dist/zod-state.js CHANGED
@@ -50,10 +50,10 @@ var OPTIONAL_PROMPT = `${import_picocolors.default.dim("(optional)")}`;
50
50
  var CACHE_PROMPT = `${import_picocolors.default.dim("(value will be saved)")}`;
51
51
  var REGEX_SLASH_TAG = new RegExp(/\/(\w+-\d+)/);
52
52
  var REGEX_START_TAG = new RegExp(/^(\w+-\d+)/);
53
- var REGEX_SLASH_NUM = new RegExp(/\/(\d+)/);
54
- var REGEX_START_NUM = new RegExp(/^(\d+)/);
55
53
  var REGEX_START_UND = new RegExp(/^([A-Z]+-[\[a-zA-Z\]\d]+)_/);
56
54
  var REGEX_SLASH_UND = new RegExp(/\/([A-Z]+-[\[a-zA-Z\]\d]+)_/);
55
+ var REGEX_SLASH_NUM = new RegExp(/\/(\d+)/);
56
+ var REGEX_START_NUM = new RegExp(/^(\d+)/);
57
57
  var DEFAULT_TYPE_OPTIONS = [
58
58
  { value: "feat", label: "feat", hint: "A new feature", emoji: "\u2728", trailer: "Changelog: feature" },
59
59
  { value: "fix", label: "fix", hint: "A bug fix", emoji: "\u{1F41B}", trailer: "Changelog: fix" },
@@ -123,6 +123,15 @@ var Z_FOOTER_OPTIONS = import_zod.z.enum([
123
123
  "deprecated",
124
124
  "custom"
125
125
  ]);
126
+ var Z_BRANCH_FIELDS = import_zod.z.enum(["user", "version", "type", "ticket", "description"]);
127
+ var Z_BRANCH_CONFIG_FIELDS = import_zod.z.enum([
128
+ "branch_user",
129
+ "branch_version",
130
+ "branch_type",
131
+ "branch_ticket",
132
+ "branch_description"
133
+ ]);
134
+ var BRANCH_ORDER_DEFAULTS = ["user", "version", "type", "ticket", "description"];
126
135
  var Z_BRANCH_ACTIONS = import_zod.z.enum(["branch", "worktree"]);
127
136
  var FOOTER_OPTION_VALUES = [
128
137
  "closes",
@@ -236,15 +245,22 @@ var Config = import_zod2.z.object({
236
245
  enable: import_zod2.z.boolean().default(true),
237
246
  separator: import_zod2.z.enum(["/", "-", "_"]).default("/")
238
247
  }).default({}),
248
+ branch_version: import_zod2.z.object({
249
+ enable: import_zod2.z.boolean().default(false),
250
+ required: import_zod2.z.boolean().default(false),
251
+ separator: import_zod2.z.enum(["/", "-", "_"]).default("/")
252
+ }).default({}),
239
253
  branch_ticket: import_zod2.z.object({
240
254
  enable: import_zod2.z.boolean().default(true),
241
255
  required: import_zod2.z.boolean().default(false),
242
256
  separator: import_zod2.z.enum(["/", "-", "_"]).default("-")
243
257
  }).default({}),
244
258
  branch_description: import_zod2.z.object({
245
- max_length: import_zod2.z.number().positive().default(70)
259
+ max_length: import_zod2.z.number().positive().default(70),
260
+ separator: import_zod2.z.enum(["", "/", "-", "_"]).default("")
246
261
  }).default({}),
247
262
  branch_action_default: Z_BRANCH_ACTIONS.default("branch"),
263
+ branch_order: import_zod2.z.array(Z_BRANCH_FIELDS).default(BRANCH_ORDER_DEFAULTS),
248
264
  enable_worktrees: import_zod2.z.boolean().default(true),
249
265
  overrides: import_zod2.z.object({ shell: import_zod2.z.string().optional() }).default({})
250
266
  }).default({});
@@ -267,7 +283,8 @@ var BranchState = import_zod2.z.object({
267
283
  user: import_zod2.z.string().default(""),
268
284
  type: import_zod2.z.string().default(""),
269
285
  ticket: import_zod2.z.string().default(""),
270
- description: import_zod2.z.string().default("")
286
+ description: import_zod2.z.string().default(""),
287
+ version: import_zod2.z.string().default("")
271
288
  }).default({});
272
289
  // Annotate the CommonJS export names for ESM import in node:
273
290
  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.10.0",
4
+ "version": "1.11.0",
5
5
  "description": "A CLI for creating better commits following the conventional commits specification",
6
6
  "author": "Erik Verduin (https://github.com/everduin94)",
7
7
  "keywords": [
package/readme.md CHANGED
@@ -192,8 +192,8 @@ Better-commits (& better-branch) are highly flexible with sane defaults. These o
192
192
  "confirm_ticket": true,
193
193
  "add_to_title": true,
194
194
  "append_hashtag": false,
195
- "title_position": "start",
196
- "surround": ""
195
+ "surround": "",
196
+ "title_position": "start"
197
197
  },
198
198
  "commit_title": {
199
199
  "max_size": 70
@@ -231,15 +231,28 @@ Better-commits (& better-branch) are highly flexible with sane defaults. These o
231
231
  "enable": true,
232
232
  "separator": "/"
233
233
  },
234
+ "branch_version": {
235
+ "enable": false,
236
+ "required": false,
237
+ "separator": "/"
238
+ },
234
239
  "branch_ticket": {
235
240
  "enable": true,
236
241
  "required": false,
237
242
  "separator": "-"
238
243
  },
239
244
  "branch_description": {
240
- "max_length": 70
245
+ "max_length": 70,
246
+ "separator": ""
241
247
  },
242
248
  "branch_action_default": "branch",
249
+ "branch_order": [
250
+ "user",
251
+ "version",
252
+ "type",
253
+ "ticket",
254
+ "description"
255
+ ],
243
256
  "enable_worktrees": true,
244
257
  "overrides": {
245
258
  "shell": "/bin/sh"
@@ -295,18 +308,33 @@ Better-commits (& better-branch) are highly flexible with sane defaults. These o
295
308
  | `breaking_change.add_exclamation_to_title` | If true adds exclamation mark to title for breaking changes |
296
309
  | `confirm_commit` | If true manually confirm commit at end |
297
310
  | `print_commit_output` | If true pretty print commit preview |
311
+ | `overrides.shell` | Override default shell, useful for windows users |
312
+
313
+ Branch configuration (same config file, split for readability)
314
+
315
+ | Property | Description |
316
+ | -------- | ----------- |
298
317
  | `branch_pre_commands` | Array of shell commands to run before branching |
299
318
  | `branch_post_commands` | Array of shell commands to run after branching |
300
319
  | `worktree_pre_commands` | Array of shell commands to run before creating worktree |
301
320
  | `worktree_post_commands` | Array of shell commands to run after creating worktree |
302
321
  | `branch_user.enable` | If enabled include user name |
303
322
  | `branch_user.required` | If enabled require user name |
304
- | `branch_user.separator` | Branch delimeter |
323
+ | `branch_user.separator` | Branch delimeter - "/" (default), "-", "_" |
324
+ | `branch_type.enable` | If enabled include type |
325
+ | `branch_type.separator` | Branch delimeter - "/" (default), "-", "_" |
326
+ | `branch_ticket.enable` | If enabled include ticket |
327
+ | `branch_ticket.required` | If enabled require ticket |
328
+ | `branch_ticket.separator` | Branch delimeter - "/", "-" (default), "_" |
305
329
  | `branch_description.max_length` | Max length branch name |
306
- | `branch_action_default` | 'branch' or 'worktree' |
330
+ | `branch_description.separator` | Branch delimeter - "" (default), "/", "-", "_" |
331
+ | `branch_version.enable` | If enabled include version |
332
+ | `branch_version.required` | If enabled require version |
333
+ | `branch_version.separator` | Branch delimeter - "", "/" (default), "-", "_" |
334
+ | `branch_order` | Order of branch name values (doesn't effect prompt order) |
335
+ | `branch_action_default` | "branch" or "worktree" |
307
336
  | `enable_worktrees` | If false, always default to branch action |
308
- | `overrides.shell` | Override default shell, useful for windows users |
309
-
337
+
310
338
  </details>
311
339
 
312
340
  ### 🔎 Inference
package/src/branch.ts CHANGED
@@ -7,6 +7,8 @@ import {
7
7
  load_setup,
8
8
  OPTIONAL_PROMPT,
9
9
  Z_BRANCH_ACTIONS,
10
+ Z_BRANCH_CONFIG_FIELDS,
11
+ Z_BRANCH_FIELDS,
10
12
  } from "./utils";
11
13
  import { BranchState } from "./zod-state";
12
14
  import * as p from "@clack/prompts";
@@ -77,6 +79,21 @@ async function main(config: z.infer<typeof Config>) {
77
79
  branch_state.ticket = ticket;
78
80
  }
79
81
 
82
+ if (config.branch_version.enable) {
83
+ const version_required = config.branch_version.required;
84
+ const version = await p.text({
85
+ message: `Type version number ${
86
+ version_required ? "" : OPTIONAL_PROMPT
87
+ }`.trim(),
88
+ placeholder: "",
89
+ validate: (val) => {
90
+ if (version_required && !val) return "Please enter a version";
91
+ },
92
+ });
93
+ if (p.isCancel(version)) process.exit(0);
94
+ branch_state.version = version;
95
+ }
96
+
80
97
  const description_max_length = config.branch_description.max_length;
81
98
  const description = await p.text({
82
99
  message: "Type a short description",
@@ -165,11 +182,14 @@ function build_branch(
165
182
  config: z.infer<typeof Config>
166
183
  ) {
167
184
  let res = "";
168
- if (branch.user) res += branch.user + config.branch_user.separator;
169
- if (branch.type) res += branch.type + config.branch_type.separator;
170
- if (branch.ticket) res += branch.ticket + config.branch_ticket.separator;
171
- if (branch.description) res += branch.description;
172
- return res;
185
+ config.branch_order.forEach((b: z.infer<typeof Z_BRANCH_FIELDS>) => {
186
+ const config_key: z.infer<typeof Z_BRANCH_CONFIG_FIELDS> = `branch_${b}`
187
+ if (branch[b]) res += branch[b] + config[config_key].separator
188
+ })
189
+ if (res.endsWith('-') || res.endsWith('/') || res.endsWith('_')) {
190
+ return res.slice(0, -1).trim();
191
+ }
192
+ return res.trim();
173
193
  }
174
194
 
175
195
  function get_user_from_cache(): string {
package/src/utils.ts CHANGED
@@ -16,11 +16,16 @@ export const OPTIONAL_PROMPT = `${color.dim("(optional)")}`;
16
16
  export const CACHE_PROMPT = `${color.dim("(value will be saved)")}`;
17
17
  export const REGEX_SLASH_TAG = new RegExp(/\/(\w+-\d+)/);
18
18
  export const REGEX_START_TAG = new RegExp(/^(\w+-\d+)/);
19
- export const REGEX_SLASH_NUM = new RegExp(/\/(\d+)/);
20
- export const REGEX_START_NUM = new RegExp(/^(\d+)/);
21
19
  export const REGEX_START_UND = new RegExp(/^([A-Z]+-[\[a-zA-Z\]\d]+)_/);
22
20
  export const REGEX_SLASH_UND = new RegExp(/\/([A-Z]+-[\[a-zA-Z\]\d]+)_/);
23
21
 
22
+ // TODO: This might conflict with version from better-branch
23
+ // - Maybe negative lookup against .
24
+ // - Maybe check the order
25
+ // - Maybe use order to split and check values
26
+ export const REGEX_SLASH_NUM = new RegExp(/\/(\d+)/);
27
+ export const REGEX_START_NUM = new RegExp(/^(\d+)/);
28
+
24
29
  export const DEFAULT_TYPE_OPTIONS = [
25
30
  { value: "feat", label: "feat", hint: "A new feature", emoji: "✨", trailer: "Changelog: feature"},
26
31
  { value: "fix", label: "fix", hint: "A bug fix", emoji: "🐛", trailer: "Changelog: fix"},
@@ -110,6 +115,15 @@ export const Z_FOOTER_OPTIONS = z.enum([
110
115
  "deprecated",
111
116
  "custom",
112
117
  ]);
118
+ export const Z_BRANCH_FIELDS = z.enum(["user", "version", "type", "ticket", "description"]);
119
+ export const Z_BRANCH_CONFIG_FIELDS = z.enum([
120
+ "branch_user",
121
+ "branch_version",
122
+ "branch_type",
123
+ "branch_ticket",
124
+ "branch_description"
125
+ ]);
126
+ export const BRANCH_ORDER_DEFAULTS: z.infer<typeof Z_BRANCH_FIELDS>[] = ["user", "version", "type", "ticket", "description"]
113
127
  export const Z_BRANCH_ACTIONS = z.enum(["branch", "worktree"]);
114
128
  export const FOOTER_OPTION_VALUES: z.infer<typeof Z_FOOTER_OPTIONS>[] = [
115
129
  "closes",
package/src/zod-state.ts CHANGED
@@ -1,10 +1,12 @@
1
1
  import { z } from "zod";
2
2
  import {
3
+ BRANCH_ORDER_DEFAULTS,
3
4
  CUSTOM_SCOPE_KEY,
4
5
  DEFAULT_SCOPE_OPTIONS,
5
6
  DEFAULT_TYPE_OPTIONS,
6
7
  FOOTER_OPTION_VALUES,
7
8
  Z_BRANCH_ACTIONS,
9
+ Z_BRANCH_FIELDS,
8
10
  Z_FOOTER_OPTIONS,
9
11
  } from "./utils";
10
12
 
@@ -141,6 +143,13 @@ export const Config = z
141
143
  separator: z.enum(["/", "-", "_"]).default("/"),
142
144
  })
143
145
  .default({}),
146
+ branch_version: z
147
+ .object({
148
+ enable: z.boolean().default(false),
149
+ required: z.boolean().default(false),
150
+ separator: z.enum(["/", "-", "_"]).default("/"),
151
+ })
152
+ .default({}),
144
153
  branch_ticket: z
145
154
  .object({
146
155
  enable: z.boolean().default(true),
@@ -151,9 +160,11 @@ export const Config = z
151
160
  branch_description: z
152
161
  .object({
153
162
  max_length: z.number().positive().default(70),
163
+ separator: z.enum(["", "/", "-", "_"]).default(""),
154
164
  })
155
165
  .default({}),
156
166
  branch_action_default: Z_BRANCH_ACTIONS.default("branch"),
167
+ branch_order: z.array(Z_BRANCH_FIELDS).default(BRANCH_ORDER_DEFAULTS),
157
168
  enable_worktrees: z.boolean().default(true),
158
169
  overrides: z.object({ shell: z.string().optional() }).default({}),
159
170
  })
@@ -183,5 +194,6 @@ export const BranchState = z
183
194
  type: z.string().default(""),
184
195
  ticket: z.string().default(""),
185
196
  description: z.string().default(""),
197
+ version: z.string().default("")
186
198
  })
187
199
  .default({});