better-commits 1.15.2 → 1.15.4
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 +1 -651
- package/dist/chunk-KFU55MTN.js +4 -0
- package/dist/index.js +18 -918
- package/dist/init.js +1 -415
- package/package.json +7 -4
- package/src/branch.ts +6 -7
- package/src/index.ts +2 -3
- package/src/init.ts +1 -1
- package/src/utils.ts +3 -113
- package/src/valibot-consts.ts +114 -0
- package/src/valibot-state.ts +242 -0
- package/tsup.config.ts +12 -0
- package/dist/git.js +0 -89
- package/dist/utils.js +0 -574
- package/dist/vali-state.js +0 -396
- package/src/vali-state.ts +0 -253
package/dist/branch.js
CHANGED
|
@@ -1,652 +1,2 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
|
-
"
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
-
mod
|
|
24
|
-
));
|
|
25
|
-
|
|
26
|
-
// src/branch.ts
|
|
27
|
-
var p2 = __toESM(require("@clack/prompts"));
|
|
28
|
-
var import_child_process2 = require("child_process");
|
|
29
|
-
var import_configstore = __toESM(require("configstore"));
|
|
30
|
-
var import_picocolors2 = __toESM(require("picocolors"));
|
|
31
|
-
var import_process = require("process");
|
|
32
|
-
var import_valibot3 = require("valibot");
|
|
33
|
-
|
|
34
|
-
// src/vali-state.ts
|
|
35
|
-
var import_valibot2 = require("valibot");
|
|
36
|
-
|
|
37
|
-
// src/utils.ts
|
|
38
|
-
var p = __toESM(require("@clack/prompts"));
|
|
39
|
-
var import_child_process = require("child_process");
|
|
40
|
-
var import_fs = __toESM(require("fs"));
|
|
41
|
-
var import_os = require("os");
|
|
42
|
-
var import_picocolors = __toESM(require("picocolors"));
|
|
43
|
-
var import_valibot = require("valibot");
|
|
44
|
-
var CONFIG_FILE_NAME = ".better-commits.json";
|
|
45
|
-
var SPACE_TO_SELECT = `${import_picocolors.default.dim("(<space> to select)")}`;
|
|
46
|
-
var A_FOR_ALL = `${import_picocolors.default.dim(
|
|
47
|
-
"(<space> to select, <a> to select all)"
|
|
48
|
-
)}`;
|
|
49
|
-
var OPTIONAL_PROMPT = `${import_picocolors.default.dim("(optional)")}`;
|
|
50
|
-
var CACHE_PROMPT = `${import_picocolors.default.dim("(value will be saved)")}`;
|
|
51
|
-
var REGEX_SLASH_TAG = new RegExp(/\/(\w+-\d+)/);
|
|
52
|
-
var REGEX_START_TAG = new RegExp(/^(\w+-\d+)/);
|
|
53
|
-
var REGEX_START_UND = new RegExp(/^([A-Z]+-[\[a-zA-Z\]\d]+)_/);
|
|
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
|
-
var DEFAULT_TYPE_OPTIONS = [
|
|
58
|
-
{
|
|
59
|
-
value: "feat",
|
|
60
|
-
label: "feat",
|
|
61
|
-
hint: "A new feature",
|
|
62
|
-
emoji: "\u2728",
|
|
63
|
-
trailer: "Changelog: feature"
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
value: "fix",
|
|
67
|
-
label: "fix",
|
|
68
|
-
hint: "A bug fix",
|
|
69
|
-
emoji: "\u{1F41B}",
|
|
70
|
-
trailer: "Changelog: fix"
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
value: "docs",
|
|
74
|
-
label: "docs",
|
|
75
|
-
hint: "Documentation only changes",
|
|
76
|
-
emoji: "\u{1F4DA}",
|
|
77
|
-
trailer: "Changelog: documentation"
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
value: "refactor",
|
|
81
|
-
label: "refactor",
|
|
82
|
-
hint: "A code change that neither fixes a bug nor adds a feature",
|
|
83
|
-
emoji: "\u{1F528}",
|
|
84
|
-
trailer: "Changelog: refactor"
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
value: "perf",
|
|
88
|
-
label: "perf",
|
|
89
|
-
hint: "A code change that improves performance",
|
|
90
|
-
emoji: "\u{1F680}",
|
|
91
|
-
trailer: "Changelog: performance"
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
value: "test",
|
|
95
|
-
label: "test",
|
|
96
|
-
hint: "Adding missing tests or correcting existing tests",
|
|
97
|
-
emoji: "\u{1F6A8}",
|
|
98
|
-
trailer: "Changelog: test"
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
value: "build",
|
|
102
|
-
label: "build",
|
|
103
|
-
hint: "Changes that affect the build system or external dependencies",
|
|
104
|
-
emoji: "\u{1F6A7}",
|
|
105
|
-
trailer: "Changelog: build"
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
value: "ci",
|
|
109
|
-
label: "ci",
|
|
110
|
-
hint: "Changes to our CI configuration files and scripts",
|
|
111
|
-
emoji: "\u{1F916}",
|
|
112
|
-
trailer: "Changelog: ci"
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
value: "chore",
|
|
116
|
-
label: "chore",
|
|
117
|
-
hint: "Other changes that do not modify src or test files",
|
|
118
|
-
emoji: "\u{1F9F9}",
|
|
119
|
-
trailer: "Changelog: chore"
|
|
120
|
-
},
|
|
121
|
-
{ value: "", label: "none" }
|
|
122
|
-
];
|
|
123
|
-
var DEFAULT_SCOPE_OPTIONS = [
|
|
124
|
-
{ value: "app", label: "app" },
|
|
125
|
-
{ value: "shared", label: "shared" },
|
|
126
|
-
{ value: "server", label: "server" },
|
|
127
|
-
{ value: "tools", label: "tools" },
|
|
128
|
-
{ value: "", label: "none" }
|
|
129
|
-
];
|
|
130
|
-
var CUSTOM_SCOPE_KEY = "custom";
|
|
131
|
-
var V_FOOTER_OPTIONS = (0, import_valibot.picklist)([
|
|
132
|
-
"closes",
|
|
133
|
-
"trailer",
|
|
134
|
-
"breaking-change",
|
|
135
|
-
"deprecated",
|
|
136
|
-
"custom"
|
|
137
|
-
]);
|
|
138
|
-
var V_BRANCH_FIELDS = (0, import_valibot.picklist)([
|
|
139
|
-
"user",
|
|
140
|
-
"version",
|
|
141
|
-
"type",
|
|
142
|
-
"ticket",
|
|
143
|
-
"description"
|
|
144
|
-
]);
|
|
145
|
-
var V_BRANCH_CONFIG_FIELDS = (0, import_valibot.picklist)([
|
|
146
|
-
"branch_user",
|
|
147
|
-
"branch_version",
|
|
148
|
-
"branch_type",
|
|
149
|
-
"branch_ticket",
|
|
150
|
-
"branch_description"
|
|
151
|
-
]);
|
|
152
|
-
var BRANCH_ORDER_DEFAULTS = [
|
|
153
|
-
"user",
|
|
154
|
-
"version",
|
|
155
|
-
"type",
|
|
156
|
-
"ticket",
|
|
157
|
-
"description"
|
|
158
|
-
];
|
|
159
|
-
var V_BRANCH_ACTIONS = (0, import_valibot.picklist)(["branch", "worktree"]);
|
|
160
|
-
var FOOTER_OPTION_VALUES = [
|
|
161
|
-
"closes",
|
|
162
|
-
"trailer",
|
|
163
|
-
"breaking-change",
|
|
164
|
-
"deprecated",
|
|
165
|
-
"custom"
|
|
166
|
-
];
|
|
167
|
-
var BRANCH_ACTION_OPTIONS = [
|
|
168
|
-
{ value: "branch", label: "Branch" },
|
|
169
|
-
{ value: "worktree", label: "Worktree" }
|
|
170
|
-
];
|
|
171
|
-
function load_setup(cli_name = " better-commits ") {
|
|
172
|
-
console.clear();
|
|
173
|
-
p.intro(`${import_picocolors.default.bgCyan(import_picocolors.default.black(cli_name))}`);
|
|
174
|
-
let global_config = null;
|
|
175
|
-
const home_path = get_default_config_path();
|
|
176
|
-
if (import_fs.default.existsSync(home_path)) {
|
|
177
|
-
p.log.step("Found global config");
|
|
178
|
-
global_config = read_config_from_path(home_path);
|
|
179
|
-
}
|
|
180
|
-
const root = get_git_root();
|
|
181
|
-
const root_path = `${root}/${CONFIG_FILE_NAME}`;
|
|
182
|
-
if (import_fs.default.existsSync(root_path)) {
|
|
183
|
-
p.log.step("Found repository config");
|
|
184
|
-
const repo_config = read_config_from_path(root_path);
|
|
185
|
-
return global_config ? {
|
|
186
|
-
...repo_config,
|
|
187
|
-
overrides: global_config.overrides.shell ? global_config.overrides : repo_config.overrides,
|
|
188
|
-
confirm_with_editor: global_config.confirm_with_editor
|
|
189
|
-
} : repo_config;
|
|
190
|
-
}
|
|
191
|
-
if (global_config)
|
|
192
|
-
return global_config;
|
|
193
|
-
const default_config = (0, import_valibot.parse)(Config, {});
|
|
194
|
-
p.log.step(
|
|
195
|
-
"Config not found. Generating default .better-commit.json at $HOME"
|
|
196
|
-
);
|
|
197
|
-
import_fs.default.writeFileSync(home_path, JSON.stringify(default_config, null, 4));
|
|
198
|
-
return default_config;
|
|
199
|
-
}
|
|
200
|
-
function read_config_from_path(config_path) {
|
|
201
|
-
let res = null;
|
|
202
|
-
try {
|
|
203
|
-
res = JSON.parse(import_fs.default.readFileSync(config_path, "utf8"));
|
|
204
|
-
} catch (err) {
|
|
205
|
-
p.log.error("Invalid JSON file. Exiting.\n" + err);
|
|
206
|
-
process.exit(0);
|
|
207
|
-
}
|
|
208
|
-
return validate_config(res);
|
|
209
|
-
}
|
|
210
|
-
function validate_config(config) {
|
|
211
|
-
try {
|
|
212
|
-
return (0, import_valibot.parse)(Config, config);
|
|
213
|
-
} catch (err) {
|
|
214
|
-
if (err instanceof import_valibot.ValiError) {
|
|
215
|
-
const first_issue_path = err.issues[0].path ?? [];
|
|
216
|
-
const dot_path = first_issue_path.map((item) => item.key).join(".");
|
|
217
|
-
p.log.error(
|
|
218
|
-
`Invalid Configuration: ${import_picocolors.default.red(dot_path)}
|
|
219
|
-
` + err.message
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
process.exit(0);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
function get_git_root() {
|
|
226
|
-
let path = ".";
|
|
227
|
-
try {
|
|
228
|
-
path = (0, import_child_process.execSync)("git rev-parse --show-toplevel").toString().trim();
|
|
229
|
-
} catch (err) {
|
|
230
|
-
p.log.warn(
|
|
231
|
-
"Could not find git root. If in a --bare repository, ignore this warning."
|
|
232
|
-
);
|
|
233
|
-
}
|
|
234
|
-
return path;
|
|
235
|
-
}
|
|
236
|
-
function get_default_config_path() {
|
|
237
|
-
return (0, import_os.homedir)() + "/" + CONFIG_FILE_NAME;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
// src/vali-state.ts
|
|
241
|
-
var Config = (0, import_valibot2.object)({
|
|
242
|
-
check_status: (0, import_valibot2.optional)((0, import_valibot2.boolean)(), true),
|
|
243
|
-
commit_type: (0, import_valibot2.transform)(
|
|
244
|
-
(0, import_valibot2.optional)(
|
|
245
|
-
(0, import_valibot2.object)(
|
|
246
|
-
{
|
|
247
|
-
enable: (0, import_valibot2.optional)((0, import_valibot2.boolean)(), true),
|
|
248
|
-
initial_value: (0, import_valibot2.optional)((0, import_valibot2.string)(), "feat"),
|
|
249
|
-
infer_type_from_branch: (0, import_valibot2.optional)((0, import_valibot2.boolean)(), true),
|
|
250
|
-
append_emoji_to_label: (0, import_valibot2.optional)((0, import_valibot2.boolean)(), false),
|
|
251
|
-
append_emoji_to_commit: (0, import_valibot2.optional)((0, import_valibot2.boolean)(), false),
|
|
252
|
-
options: (0, import_valibot2.optional)(
|
|
253
|
-
(0, import_valibot2.array)(
|
|
254
|
-
(0, import_valibot2.object)({
|
|
255
|
-
value: (0, import_valibot2.string)(),
|
|
256
|
-
label: (0, import_valibot2.optional)((0, import_valibot2.string)()),
|
|
257
|
-
hint: (0, import_valibot2.optional)((0, import_valibot2.string)()),
|
|
258
|
-
emoji: (0, import_valibot2.optional)((0, import_valibot2.string)([(0, import_valibot2.emoji)()]), void 0),
|
|
259
|
-
trailer: (0, import_valibot2.optional)((0, import_valibot2.string)())
|
|
260
|
-
})
|
|
261
|
-
),
|
|
262
|
-
DEFAULT_TYPE_OPTIONS
|
|
263
|
-
)
|
|
264
|
-
},
|
|
265
|
-
[
|
|
266
|
-
(0, import_valibot2.custom)(
|
|
267
|
-
(val) => val.options.map((v) => v.value).includes(val.initial_value),
|
|
268
|
-
(val) => {
|
|
269
|
-
const input = val.input;
|
|
270
|
-
return `Type: initial_value "${input.initial_value}" must exist in options`;
|
|
271
|
-
}
|
|
272
|
-
)
|
|
273
|
-
]
|
|
274
|
-
),
|
|
275
|
-
{}
|
|
276
|
-
),
|
|
277
|
-
(val) => {
|
|
278
|
-
const options = val.options.map((v) => ({
|
|
279
|
-
...v,
|
|
280
|
-
label: v.emoji && val.append_emoji_to_label ? `${v.emoji} ${v.label}` : v.label
|
|
281
|
-
}));
|
|
282
|
-
return { ...val, options };
|
|
283
|
-
}
|
|
284
|
-
),
|
|
285
|
-
commit_scope: (0, import_valibot2.transform)(
|
|
286
|
-
(0, import_valibot2.optional)(
|
|
287
|
-
(0, import_valibot2.object)(
|
|
288
|
-
{
|
|
289
|
-
enable: (0, import_valibot2.optional)((0, import_valibot2.boolean)(), true),
|
|
290
|
-
custom_scope: (0, import_valibot2.optional)((0, import_valibot2.boolean)(), false),
|
|
291
|
-
initial_value: (0, import_valibot2.optional)((0, import_valibot2.string)(), "app"),
|
|
292
|
-
options: (0, import_valibot2.optional)(
|
|
293
|
-
(0, import_valibot2.array)(
|
|
294
|
-
(0, import_valibot2.object)({
|
|
295
|
-
value: (0, import_valibot2.string)(),
|
|
296
|
-
label: (0, import_valibot2.optional)((0, import_valibot2.string)()),
|
|
297
|
-
hint: (0, import_valibot2.optional)((0, import_valibot2.string)())
|
|
298
|
-
})
|
|
299
|
-
),
|
|
300
|
-
DEFAULT_SCOPE_OPTIONS
|
|
301
|
-
)
|
|
302
|
-
},
|
|
303
|
-
[
|
|
304
|
-
(0, import_valibot2.custom)(
|
|
305
|
-
(val) => {
|
|
306
|
-
const options = val.options.map((v) => v.value);
|
|
307
|
-
return options.includes(val.initial_value);
|
|
308
|
-
},
|
|
309
|
-
(val) => {
|
|
310
|
-
const input = val.input;
|
|
311
|
-
return `Scope: initial_value "${input.initial_value}" must exist in options`;
|
|
312
|
-
}
|
|
313
|
-
)
|
|
314
|
-
]
|
|
315
|
-
),
|
|
316
|
-
{}
|
|
317
|
-
),
|
|
318
|
-
(val) => {
|
|
319
|
-
const options = val.options.map((v) => v.value);
|
|
320
|
-
if (val.custom_scope && !options.includes(CUSTOM_SCOPE_KEY)) {
|
|
321
|
-
return {
|
|
322
|
-
...val,
|
|
323
|
-
options: [
|
|
324
|
-
...val.options,
|
|
325
|
-
{
|
|
326
|
-
label: CUSTOM_SCOPE_KEY,
|
|
327
|
-
value: CUSTOM_SCOPE_KEY,
|
|
328
|
-
hint: "Write a custom scope"
|
|
329
|
-
}
|
|
330
|
-
]
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
|
-
return val;
|
|
334
|
-
}
|
|
335
|
-
),
|
|
336
|
-
check_ticket: (0, import_valibot2.optional)(
|
|
337
|
-
(0, import_valibot2.object)({
|
|
338
|
-
infer_ticket: (0, import_valibot2.optional)((0, import_valibot2.boolean)(), true),
|
|
339
|
-
confirm_ticket: (0, import_valibot2.optional)((0, import_valibot2.boolean)(), true),
|
|
340
|
-
add_to_title: (0, import_valibot2.optional)((0, import_valibot2.boolean)(), true),
|
|
341
|
-
append_hashtag: (0, import_valibot2.optional)((0, import_valibot2.boolean)(), false),
|
|
342
|
-
prepend_hashtag: (0, import_valibot2.optional)(
|
|
343
|
-
(0, import_valibot2.picklist)(["Never", "Always", "Prompt"]),
|
|
344
|
-
"Never"
|
|
345
|
-
),
|
|
346
|
-
surround: (0, import_valibot2.optional)((0, import_valibot2.picklist)(["", "()", "[]", "{}"]), ""),
|
|
347
|
-
title_position: (0, import_valibot2.optional)(
|
|
348
|
-
(0, import_valibot2.picklist)(["start", "end", "before-colon", "beginning"]),
|
|
349
|
-
"start"
|
|
350
|
-
)
|
|
351
|
-
}),
|
|
352
|
-
{}
|
|
353
|
-
),
|
|
354
|
-
commit_title: (0, import_valibot2.optional)(
|
|
355
|
-
(0, import_valibot2.object)({
|
|
356
|
-
max_size: (0, import_valibot2.optional)((0, import_valibot2.number)([(0, import_valibot2.minValue)(1)]), 70)
|
|
357
|
-
}),
|
|
358
|
-
{}
|
|
359
|
-
),
|
|
360
|
-
commit_body: (0, import_valibot2.optional)(
|
|
361
|
-
(0, import_valibot2.object)({
|
|
362
|
-
enable: (0, import_valibot2.optional)((0, import_valibot2.boolean)(), true),
|
|
363
|
-
required: (0, import_valibot2.optional)((0, import_valibot2.boolean)(), false)
|
|
364
|
-
}),
|
|
365
|
-
{}
|
|
366
|
-
),
|
|
367
|
-
commit_footer: (0, import_valibot2.optional)(
|
|
368
|
-
(0, import_valibot2.object)({
|
|
369
|
-
enable: (0, import_valibot2.optional)((0, import_valibot2.boolean)(), true),
|
|
370
|
-
initial_value: (0, import_valibot2.optional)((0, import_valibot2.array)(V_FOOTER_OPTIONS), []),
|
|
371
|
-
options: (0, import_valibot2.optional)((0, import_valibot2.array)(V_FOOTER_OPTIONS), FOOTER_OPTION_VALUES)
|
|
372
|
-
}),
|
|
373
|
-
{}
|
|
374
|
-
),
|
|
375
|
-
breaking_change: (0, import_valibot2.optional)(
|
|
376
|
-
(0, import_valibot2.object)({
|
|
377
|
-
add_exclamation_to_title: (0, import_valibot2.optional)((0, import_valibot2.boolean)(), false)
|
|
378
|
-
}),
|
|
379
|
-
{}
|
|
380
|
-
),
|
|
381
|
-
confirm_with_editor: (0, import_valibot2.optional)((0, import_valibot2.boolean)(), false),
|
|
382
|
-
confirm_commit: (0, import_valibot2.optional)((0, import_valibot2.boolean)(), true),
|
|
383
|
-
print_commit_output: (0, import_valibot2.optional)((0, import_valibot2.boolean)(), true),
|
|
384
|
-
branch_pre_commands: (0, import_valibot2.optional)((0, import_valibot2.array)((0, import_valibot2.string)()), []),
|
|
385
|
-
branch_post_commands: (0, import_valibot2.optional)((0, import_valibot2.array)((0, import_valibot2.string)()), []),
|
|
386
|
-
worktree_pre_commands: (0, import_valibot2.optional)((0, import_valibot2.array)((0, import_valibot2.string)()), []),
|
|
387
|
-
worktree_post_commands: (0, import_valibot2.optional)((0, import_valibot2.array)((0, import_valibot2.string)()), []),
|
|
388
|
-
branch_user: (0, import_valibot2.optional)(
|
|
389
|
-
(0, import_valibot2.object)({
|
|
390
|
-
enable: (0, import_valibot2.optional)((0, import_valibot2.boolean)(), true),
|
|
391
|
-
required: (0, import_valibot2.optional)((0, import_valibot2.boolean)(), false),
|
|
392
|
-
separator: (0, import_valibot2.optional)((0, import_valibot2.picklist)(["/", "-", "_"]), "/")
|
|
393
|
-
}),
|
|
394
|
-
{}
|
|
395
|
-
),
|
|
396
|
-
branch_type: (0, import_valibot2.optional)(
|
|
397
|
-
(0, import_valibot2.object)({
|
|
398
|
-
enable: (0, import_valibot2.optional)((0, import_valibot2.boolean)(), true),
|
|
399
|
-
separator: (0, import_valibot2.optional)((0, import_valibot2.picklist)(["/", "-", "_"]), "/")
|
|
400
|
-
}),
|
|
401
|
-
{}
|
|
402
|
-
),
|
|
403
|
-
branch_version: (0, import_valibot2.optional)(
|
|
404
|
-
(0, import_valibot2.object)({
|
|
405
|
-
enable: (0, import_valibot2.optional)((0, import_valibot2.boolean)(), false),
|
|
406
|
-
required: (0, import_valibot2.optional)((0, import_valibot2.boolean)(), false),
|
|
407
|
-
separator: (0, import_valibot2.optional)((0, import_valibot2.picklist)(["/", "-", "_"]), "/")
|
|
408
|
-
}),
|
|
409
|
-
{}
|
|
410
|
-
),
|
|
411
|
-
branch_ticket: (0, import_valibot2.optional)(
|
|
412
|
-
(0, import_valibot2.object)({
|
|
413
|
-
enable: (0, import_valibot2.optional)((0, import_valibot2.boolean)(), true),
|
|
414
|
-
required: (0, import_valibot2.optional)((0, import_valibot2.boolean)(), false),
|
|
415
|
-
separator: (0, import_valibot2.optional)((0, import_valibot2.picklist)(["/", "-", "_"]), "/")
|
|
416
|
-
}),
|
|
417
|
-
{}
|
|
418
|
-
),
|
|
419
|
-
branch_description: (0, import_valibot2.optional)(
|
|
420
|
-
(0, import_valibot2.object)({
|
|
421
|
-
max_length: (0, import_valibot2.optional)((0, import_valibot2.number)([(0, import_valibot2.minValue)(1)]), 70),
|
|
422
|
-
separator: (0, import_valibot2.optional)((0, import_valibot2.picklist)(["", "/", "-", "_"]), "")
|
|
423
|
-
}),
|
|
424
|
-
{}
|
|
425
|
-
),
|
|
426
|
-
branch_action_default: (0, import_valibot2.optional)(V_BRANCH_ACTIONS, "branch"),
|
|
427
|
-
branch_order: (0, import_valibot2.optional)((0, import_valibot2.array)(V_BRANCH_FIELDS), BRANCH_ORDER_DEFAULTS),
|
|
428
|
-
enable_worktrees: (0, import_valibot2.optional)((0, import_valibot2.boolean)(), true),
|
|
429
|
-
overrides: (0, import_valibot2.optional)(
|
|
430
|
-
(0, import_valibot2.object)({
|
|
431
|
-
shell: (0, import_valibot2.optional)((0, import_valibot2.string)())
|
|
432
|
-
}),
|
|
433
|
-
{}
|
|
434
|
-
)
|
|
435
|
-
});
|
|
436
|
-
var CommitState = (0, import_valibot2.optional)(
|
|
437
|
-
(0, import_valibot2.object)({
|
|
438
|
-
type: (0, import_valibot2.optional)((0, import_valibot2.string)(), ""),
|
|
439
|
-
scope: (0, import_valibot2.optional)((0, import_valibot2.string)(), ""),
|
|
440
|
-
title: (0, import_valibot2.optional)((0, import_valibot2.string)(), ""),
|
|
441
|
-
body: (0, import_valibot2.optional)((0, import_valibot2.string)(), ""),
|
|
442
|
-
closes: (0, import_valibot2.optional)((0, import_valibot2.string)(), ""),
|
|
443
|
-
ticket: (0, import_valibot2.optional)((0, import_valibot2.string)(), ""),
|
|
444
|
-
breaking_title: (0, import_valibot2.optional)((0, import_valibot2.string)(), ""),
|
|
445
|
-
breaking_body: (0, import_valibot2.optional)((0, import_valibot2.string)(), ""),
|
|
446
|
-
deprecates: (0, import_valibot2.optional)((0, import_valibot2.string)(), ""),
|
|
447
|
-
deprecates_title: (0, import_valibot2.optional)((0, import_valibot2.string)(), ""),
|
|
448
|
-
deprecates_body: (0, import_valibot2.optional)((0, import_valibot2.string)(), ""),
|
|
449
|
-
custom_footer: (0, import_valibot2.optional)((0, import_valibot2.string)(), ""),
|
|
450
|
-
trailer: (0, import_valibot2.optional)((0, import_valibot2.string)(), "")
|
|
451
|
-
}),
|
|
452
|
-
{}
|
|
453
|
-
);
|
|
454
|
-
var BranchState = (0, import_valibot2.optional)(
|
|
455
|
-
(0, import_valibot2.object)({
|
|
456
|
-
user: (0, import_valibot2.optional)((0, import_valibot2.string)(), ""),
|
|
457
|
-
type: (0, import_valibot2.optional)((0, import_valibot2.string)(), ""),
|
|
458
|
-
ticket: (0, import_valibot2.optional)((0, import_valibot2.string)(), ""),
|
|
459
|
-
description: (0, import_valibot2.optional)((0, import_valibot2.string)(), ""),
|
|
460
|
-
version: (0, import_valibot2.optional)((0, import_valibot2.string)(), "")
|
|
461
|
-
}),
|
|
462
|
-
{}
|
|
463
|
-
);
|
|
464
|
-
|
|
465
|
-
// src/branch.ts
|
|
466
|
-
main(load_setup(" better-branch "));
|
|
467
|
-
async function main(config) {
|
|
468
|
-
const branch_state = (0, import_valibot3.parse)(BranchState, {});
|
|
469
|
-
let checkout_type = "branch";
|
|
470
|
-
if (config.enable_worktrees) {
|
|
471
|
-
const branch_or_worktree = await p2.select({
|
|
472
|
-
message: `Checkout a branch or create a worktree?`,
|
|
473
|
-
initialValue: config.branch_action_default,
|
|
474
|
-
options: BRANCH_ACTION_OPTIONS
|
|
475
|
-
});
|
|
476
|
-
if (p2.isCancel(branch_or_worktree))
|
|
477
|
-
process.exit();
|
|
478
|
-
checkout_type = branch_or_worktree;
|
|
479
|
-
}
|
|
480
|
-
if (config.branch_user.enable) {
|
|
481
|
-
const cache_user_name = get_user_from_cache();
|
|
482
|
-
const user_name_required = config.branch_user.required;
|
|
483
|
-
const user_name = await p2.text({
|
|
484
|
-
message: `Type your git username ${user_name_required ? "" : OPTIONAL_PROMPT} ${CACHE_PROMPT}`.trim(),
|
|
485
|
-
placeholder: "",
|
|
486
|
-
initialValue: cache_user_name,
|
|
487
|
-
validate: (val) => {
|
|
488
|
-
if (user_name_required && !val)
|
|
489
|
-
return "Please enter a username";
|
|
490
|
-
}
|
|
491
|
-
});
|
|
492
|
-
if (p2.isCancel(user_name))
|
|
493
|
-
process.exit(0);
|
|
494
|
-
branch_state.user = user_name?.replace(/\s+/g, "-")?.toLowerCase() ?? "";
|
|
495
|
-
set_user_cache(branch_state.user);
|
|
496
|
-
}
|
|
497
|
-
if (config.branch_type.enable) {
|
|
498
|
-
let initial_value = config.commit_type.initial_value;
|
|
499
|
-
const commit_type = await p2.select({
|
|
500
|
-
message: `Select a branch type`,
|
|
501
|
-
initialValue: initial_value,
|
|
502
|
-
options: config.commit_type.options
|
|
503
|
-
});
|
|
504
|
-
if (p2.isCancel(commit_type))
|
|
505
|
-
process.exit(0);
|
|
506
|
-
branch_state.type = commit_type;
|
|
507
|
-
}
|
|
508
|
-
if (config.branch_ticket.enable) {
|
|
509
|
-
const ticked_required = config.branch_ticket.required;
|
|
510
|
-
const ticket = await p2.text({
|
|
511
|
-
message: `Type ticket / issue number ${ticked_required ? "" : OPTIONAL_PROMPT}`.trim(),
|
|
512
|
-
placeholder: "",
|
|
513
|
-
validate: (val) => {
|
|
514
|
-
if (ticked_required && !val)
|
|
515
|
-
return "Please enter a ticket / issue";
|
|
516
|
-
}
|
|
517
|
-
});
|
|
518
|
-
if (p2.isCancel(ticket))
|
|
519
|
-
process.exit(0);
|
|
520
|
-
branch_state.ticket = ticket;
|
|
521
|
-
}
|
|
522
|
-
if (config.branch_version.enable) {
|
|
523
|
-
const version_required = config.branch_version.required;
|
|
524
|
-
const version = await p2.text({
|
|
525
|
-
message: `Type version number ${version_required ? "" : OPTIONAL_PROMPT}`.trim(),
|
|
526
|
-
placeholder: "",
|
|
527
|
-
validate: (val) => {
|
|
528
|
-
if (version_required && !val)
|
|
529
|
-
return "Please enter a version";
|
|
530
|
-
}
|
|
531
|
-
});
|
|
532
|
-
if (p2.isCancel(version))
|
|
533
|
-
process.exit(0);
|
|
534
|
-
branch_state.version = version;
|
|
535
|
-
}
|
|
536
|
-
const description_max_length = config.branch_description.max_length;
|
|
537
|
-
const description = await p2.text({
|
|
538
|
-
message: "Type a short description",
|
|
539
|
-
placeholder: "",
|
|
540
|
-
validate: (value) => {
|
|
541
|
-
if (!value)
|
|
542
|
-
return "Please enter a description";
|
|
543
|
-
if (value.length > description_max_length)
|
|
544
|
-
return `Exceeded max length. Description max [${description_max_length}]`;
|
|
545
|
-
}
|
|
546
|
-
});
|
|
547
|
-
if (p2.isCancel(description))
|
|
548
|
-
process.exit(0);
|
|
549
|
-
branch_state.description = description?.replace(/\s+/g, "-")?.toLowerCase() ?? "";
|
|
550
|
-
const pre_commands = checkout_type === "worktree" ? config.worktree_pre_commands : config.branch_pre_commands;
|
|
551
|
-
pre_commands.forEach((command) => {
|
|
552
|
-
try {
|
|
553
|
-
(0, import_child_process2.execSync)(command, { stdio: "inherit" });
|
|
554
|
-
} catch (err) {
|
|
555
|
-
p2.log.error("Something went wrong when executing pre-commands: " + err);
|
|
556
|
-
process.exit(0);
|
|
557
|
-
}
|
|
558
|
-
});
|
|
559
|
-
const branch_name = build_branch(branch_state, config);
|
|
560
|
-
const branch_flag = verify_branch_name(branch_name);
|
|
561
|
-
if (checkout_type === "branch") {
|
|
562
|
-
try {
|
|
563
|
-
(0, import_child_process2.execSync)(`git checkout ${branch_flag} ${branch_name}`, {
|
|
564
|
-
stdio: "inherit"
|
|
565
|
-
});
|
|
566
|
-
p2.log.info(
|
|
567
|
-
`Switched to a new branch '${import_picocolors2.default.bgGreen(
|
|
568
|
-
" " + import_picocolors2.default.black(branch_name) + " "
|
|
569
|
-
)}'`
|
|
570
|
-
);
|
|
571
|
-
} catch (err) {
|
|
572
|
-
process.exit(0);
|
|
573
|
-
}
|
|
574
|
-
} else {
|
|
575
|
-
try {
|
|
576
|
-
const ticket = branch_state.ticket ? `${branch_state.ticket}-` : "";
|
|
577
|
-
const worktree_name = `${ticket}${branch_state.description}`;
|
|
578
|
-
(0, import_child_process2.execSync)(
|
|
579
|
-
`git worktree add ${worktree_name} ${branch_flag} ${branch_name}`,
|
|
580
|
-
{
|
|
581
|
-
stdio: "inherit"
|
|
582
|
-
}
|
|
583
|
-
);
|
|
584
|
-
p2.log.info(
|
|
585
|
-
`Created a new worktree ${import_picocolors2.default.bgGreen(
|
|
586
|
-
+" " + import_picocolors2.default.black(worktree_name) + " "
|
|
587
|
-
)}, checked out branch ${import_picocolors2.default.bgGreen(
|
|
588
|
-
" " + import_picocolors2.default.black(branch_name) + " "
|
|
589
|
-
)}`
|
|
590
|
-
);
|
|
591
|
-
p2.log.info(
|
|
592
|
-
import_picocolors2.default.bgMagenta(import_picocolors2.default.black(` cd ${worktree_name} `)) + " to navigate to your new worktree"
|
|
593
|
-
);
|
|
594
|
-
(0, import_process.chdir)(worktree_name);
|
|
595
|
-
} catch (err) {
|
|
596
|
-
process.exit(0);
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
const post_commands = checkout_type === "worktree" ? config.worktree_post_commands : config.branch_post_commands;
|
|
600
|
-
post_commands.forEach((command) => {
|
|
601
|
-
try {
|
|
602
|
-
(0, import_child_process2.execSync)(command, { stdio: "inherit" });
|
|
603
|
-
} catch (err) {
|
|
604
|
-
p2.log.error("Something went wrong when executing post-commands: " + err);
|
|
605
|
-
process.exit(0);
|
|
606
|
-
}
|
|
607
|
-
});
|
|
608
|
-
}
|
|
609
|
-
function build_branch(branch, config) {
|
|
610
|
-
let res = "";
|
|
611
|
-
config.branch_order.forEach((b) => {
|
|
612
|
-
const config_key = `branch_${b}`;
|
|
613
|
-
if (branch[b])
|
|
614
|
-
res += branch[b] + config[config_key].separator;
|
|
615
|
-
});
|
|
616
|
-
if (res.endsWith("-") || res.endsWith("/") || res.endsWith("_")) {
|
|
617
|
-
return res.slice(0, -1).trim();
|
|
618
|
-
}
|
|
619
|
-
return res.trim();
|
|
620
|
-
}
|
|
621
|
-
function get_user_from_cache() {
|
|
622
|
-
try {
|
|
623
|
-
const config_store = new import_configstore.default("better-commits");
|
|
624
|
-
return config_store.get("username") ?? "";
|
|
625
|
-
} catch (err) {
|
|
626
|
-
p2.log.warn(
|
|
627
|
-
'There was an issue accessing username from cache. Check that the folder "~/.config" exists'
|
|
628
|
-
);
|
|
629
|
-
}
|
|
630
|
-
return "";
|
|
631
|
-
}
|
|
632
|
-
function verify_branch_name(branch_name) {
|
|
633
|
-
let branch_flag = "";
|
|
634
|
-
try {
|
|
635
|
-
(0, import_child_process2.execSync)(`git show-ref ${branch_name}`, { encoding: "utf-8" });
|
|
636
|
-
p2.log.warning(
|
|
637
|
-
import_picocolors2.default.yellow(
|
|
638
|
-
`${branch_name} already exists! Checking out existing branch.`
|
|
639
|
-
)
|
|
640
|
-
);
|
|
641
|
-
} catch (err) {
|
|
642
|
-
branch_flag = "-b";
|
|
643
|
-
}
|
|
644
|
-
return branch_flag;
|
|
645
|
-
}
|
|
646
|
-
function set_user_cache(val) {
|
|
647
|
-
try {
|
|
648
|
-
const config_store = new import_configstore.default("better-commits");
|
|
649
|
-
config_store.set("username", val);
|
|
650
|
-
} catch (err) {
|
|
651
|
-
}
|
|
652
|
-
}
|
|
2
|
+
import{d as u,g as h,h as d,p as f,q as b}from"./chunk-KFU55MTN.js";import*as t from"@clack/prompts";import{execSync as m}from"child_process";import g from"configstore";import a from"picocolors";import{chdir as k}from"process";import{parse as y}from"valibot";C(b(" better-branch "));async function C(e){let i=y(u,{}),o="branch";if(e.enable_worktrees){let r=await t.select({message:"Checkout a branch or create a worktree?",initialValue:e.branch_action_default,options:f});t.isCancel(r)&&process.exit(),o=r}if(e.branch_user.enable){let r=$(),n=e.branch_user.required,c=await t.text({message:`Type your git username ${n?"":h} ${d}`.trim(),placeholder:"",initialValue:r,validate:w=>{if(n&&!w)return"Please enter a username"}});t.isCancel(c)&&process.exit(0),i.user=c?.replace(/\s+/g,"-")?.toLowerCase()??"",v(i.user)}if(e.branch_type.enable){let r=e.commit_type.initial_value,n=await t.select({message:"Select a branch type",initialValue:r,options:e.commit_type.options});t.isCancel(n)&&process.exit(0),i.type=n}if(e.branch_ticket.enable){let r=e.branch_ticket.required,n=await t.text({message:`Type ticket / issue number ${r?"":h}`.trim(),placeholder:"",validate:c=>{if(r&&!c)return"Please enter a ticket / issue"}});t.isCancel(n)&&process.exit(0),i.ticket=n}if(e.branch_version.enable){let r=e.branch_version.required,n=await t.text({message:`Type version number ${r?"":h}`.trim(),placeholder:"",validate:c=>{if(r&&!c)return"Please enter a version"}});t.isCancel(n)&&process.exit(0),i.version=n}let s=e.branch_description.max_length,_=await t.text({message:"Type a short description",placeholder:"",validate:r=>{if(!r)return"Please enter a description";if(r.length>s)return`Exceeded max length. Description max [${s}]`}});t.isCancel(_)&&process.exit(0),i.description=_?.replace(/\s+/g,"-")?.toLowerCase()??"",(o==="worktree"?e.worktree_pre_commands:e.branch_pre_commands).forEach(r=>{try{m(r,{stdio:"inherit"})}catch(n){t.log.error("Something went wrong when executing pre-commands: "+n),process.exit(0)}});let p=x(i,e),l=O(p);if(o==="branch")try{m(`git checkout ${l} ${p}`,{stdio:"inherit"}),t.log.info(`Switched to a new branch '${a.bgGreen(" "+a.black(p)+" ")}'`)}catch{process.exit(0)}else try{let n=`${i.ticket?`${i.ticket}-`:""}${i.description}`;m(`git worktree add ${n} ${l} ${p}`,{stdio:"inherit"}),t.log.info(`Created a new worktree ${a.bgGreen(+" "+a.black(n)+" ")}, checked out branch ${a.bgGreen(" "+a.black(p)+" ")}`),t.log.info(a.bgMagenta(a.black(` cd ${n} `))+" to navigate to your new worktree"),k(n)}catch{process.exit(0)}(o==="worktree"?e.worktree_post_commands:e.branch_post_commands).forEach(r=>{try{m(r,{stdio:"inherit"})}catch(n){t.log.error("Something went wrong when executing post-commands: "+n),process.exit(0)}})}function x(e,i){let o="";return i.branch_order.forEach(s=>{let _=`branch_${s}`;e[s]&&(o+=e[s]+i[_].separator)}),o.endsWith("-")||o.endsWith("/")||o.endsWith("_")?o.slice(0,-1).trim():o.trim()}function $(){try{return new g("better-commits").get("username")??""}catch{t.log.warn('There was an issue accessing username from cache. Check that the folder "~/.config" exists')}return""}function O(e){let i="";try{m(`git show-ref ${e}`,{encoding:"utf-8"}),t.log.warning(a.yellow(`${e} already exists! Checking out existing branch.`))}catch{i="-b"}return i}function v(e){try{new g("better-commits").set("username",e)}catch{}}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import*as p from"valibot";var v="custom",b=["closes","trailer","breaking-change","deprecated","custom"],m=p.picklist(["branch","worktree"]),u=p.picklist(["closes","trailer","breaking-change","deprecated","custom"]),d=p.picklist(["user","version","type","ticket","description"]),w=p.picklist(["branch_user","branch_version","branch_type","branch_ticket","branch_description"]),f=["user","version","type","ticket","description"],h=[{value:"app",label:"app"},{value:"shared",label:"shared"},{value:"server",label:"server"},{value:"tools",label:"tools"},{value:"",label:"none"}],O=[{value:"feat",label:"feat",hint:"A new feature",emoji:"\u2728",trailer:"Changelog: feature"},{value:"fix",label:"fix",hint:"A bug fix",emoji:"\u{1F41B}",trailer:"Changelog: fix"},{value:"docs",label:"docs",hint:"Documentation only changes",emoji:"\u{1F4DA}",trailer:"Changelog: documentation"},{value:"refactor",label:"refactor",hint:"A code change that neither fixes a bug nor adds a feature",emoji:"\u{1F528}",trailer:"Changelog: refactor"},{value:"perf",label:"perf",hint:"A code change that improves performance",emoji:"\u{1F680}",trailer:"Changelog: performance"},{value:"test",label:"test",hint:"Adding missing tests or correcting existing tests",emoji:"\u{1F6A8}",trailer:"Changelog: test"},{value:"build",label:"build",hint:"Changes that affect the build system or external dependencies",emoji:"\u{1F6A7}",trailer:"Changelog: build"},{value:"ci",label:"ci",hint:"Changes to our CI configuration files and scripts",emoji:"\u{1F916}",trailer:"Changelog: ci"},{value:"chore",label:"chore",hint:"Other changes that do not modify src or test files",emoji:"\u{1F9F9}",trailer:"Changelog: chore"},{value:"",label:"none"}];import*as t from"valibot";var g=t.object({check_status:t.optional(t.boolean(),!0),commit_type:t.transform(t.optional(t.object({enable:t.optional(t.boolean(),!0),initial_value:t.optional(t.string(),"feat"),infer_type_from_branch:t.optional(t.boolean(),!0),append_emoji_to_label:t.optional(t.boolean(),!1),append_emoji_to_commit:t.optional(t.boolean(),!1),options:t.optional(t.array(t.object({value:t.string(),label:t.optional(t.string()),hint:t.optional(t.string()),emoji:t.optional(t.string([t.emoji()]),void 0),trailer:t.optional(t.string())})),O)},[t.custom(o=>o.options.map(e=>e.value).includes(o.initial_value),o=>`Type: initial_value "${o.input.initial_value}" must exist in options`)]),{}),o=>{let e=o.options.map(n=>({...n,label:n.emoji&&o.append_emoji_to_label?`${n.emoji} ${n.label}`:n.label}))??[];return{...o,options:e}}),commit_scope:t.transform(t.optional(t.object({enable:t.optional(t.boolean(),!0),custom_scope:t.optional(t.boolean(),!1),initial_value:t.optional(t.string(),"app"),options:t.optional(t.array(t.object({value:t.string(),label:t.optional(t.string()),hint:t.optional(t.string())})),h)},[t.custom(o=>o.options.map(n=>n.value).includes(o.initial_value),o=>`Scope: initial_value "${o.input.initial_value}" must exist in options`)]),{}),o=>{let e=o.options.map(n=>n.value);return o.custom_scope&&!e.includes(v)?{...o,options:[...o.options,{label:v,value:v,hint:"Write a custom scope"}]}:o}),check_ticket:t.optional(t.object({infer_ticket:t.optional(t.boolean(),!0),confirm_ticket:t.optional(t.boolean(),!0),add_to_title:t.optional(t.boolean(),!0),append_hashtag:t.optional(t.boolean(),!1),prepend_hashtag:t.optional(t.picklist(["Never","Always","Prompt"]),"Never"),surround:t.optional(t.picklist(["","()","[]","{}"]),""),title_position:t.optional(t.picklist(["start","end","before-colon","beginning"]),"start")}),{}),commit_title:t.optional(t.object({max_size:t.optional(t.number([t.minValue(1)]),70)}),{}),commit_body:t.optional(t.object({enable:t.optional(t.boolean(),!0),required:t.optional(t.boolean(),!1)}),{}),commit_footer:t.optional(t.object({enable:t.optional(t.boolean(),!0),initial_value:t.optional(t.array(u),[]),options:t.optional(t.array(u),b)}),{}),breaking_change:t.optional(t.object({add_exclamation_to_title:t.optional(t.boolean(),!1)}),{}),confirm_with_editor:t.optional(t.boolean(),!1),confirm_commit:t.optional(t.boolean(),!0),print_commit_output:t.optional(t.boolean(),!0),branch_pre_commands:t.optional(t.array(t.string()),[]),branch_post_commands:t.optional(t.array(t.string()),[]),worktree_pre_commands:t.optional(t.array(t.string()),[]),worktree_post_commands:t.optional(t.array(t.string()),[]),branch_user:t.optional(t.object({enable:t.optional(t.boolean(),!0),required:t.optional(t.boolean(),!1),separator:t.optional(t.picklist(["/","-","_"]),"/")}),{}),branch_type:t.optional(t.object({enable:t.optional(t.boolean(),!0),separator:t.optional(t.picklist(["/","-","_"]),"/")}),{}),branch_version:t.optional(t.object({enable:t.optional(t.boolean(),!1),required:t.optional(t.boolean(),!1),separator:t.optional(t.picklist(["/","-","_"]),"/")}),{}),branch_ticket:t.optional(t.object({enable:t.optional(t.boolean(),!0),required:t.optional(t.boolean(),!1),separator:t.optional(t.picklist(["/","-","_"]),"/")}),{}),branch_description:t.optional(t.object({max_length:t.optional(t.number([t.minValue(1)]),70),separator:t.optional(t.picklist(["","/","-","_"]),"")}),{}),branch_action_default:t.optional(m,"branch"),branch_order:t.optional(t.array(d),f),enable_worktrees:t.optional(t.boolean(),!0),overrides:t.optional(t.object({shell:t.optional(t.string())}),{})}),P=t.optional(t.object({type:t.optional(t.string(),""),scope:t.optional(t.string(),""),title:t.optional(t.string(),""),body:t.optional(t.string(),""),closes:t.optional(t.string(),""),ticket:t.optional(t.string(),""),breaking_title:t.optional(t.string(),""),breaking_body:t.optional(t.string(),""),deprecates:t.optional(t.string(),""),deprecates_title:t.optional(t.string(),""),deprecates_body:t.optional(t.string(),""),custom_footer:t.optional(t.string(),""),trailer:t.optional(t.string(),"")}),{}),L=t.optional(t.object({user:t.optional(t.string(),""),type:t.optional(t.string(),""),ticket:t.optional(t.string(),""),description:t.optional(t.string(),""),version:t.optional(t.string(),"")}),{});import*as i from"@clack/prompts";import{execSync as E}from"child_process";import _ from"fs";import{homedir as y}from"os";import a from"picocolors";import{ValiError as T,parse as A}from"valibot";var C=".better-commits.json",X=`${a.dim("(<space> to select)")}`,q=`${a.dim("(<space> to select, <a> to select all)")}`,Y=`${a.dim("(optional)")}`,Z=`${a.dim("(value will be saved)")}`,z=new RegExp(/\/(\w+-\d+)/),J=new RegExp(/^(\w+-\d+)/),W=new RegExp(/^([A-Z]+-[\[a-zA-Z\]\d]+)_/),K=new RegExp(/\/([A-Z]+-[\[a-zA-Z\]\d]+)_/),Q=new RegExp(/\/(\d+)/),tt=new RegExp(/^(\d+)/),ot=[{value:"closes",label:"closes <issue/ticket>",hint:"Attempts to infer ticket from branch"},{value:"trailer",label:"trailer",hint:"Appends trailer based on commit type"},{value:"breaking-change",label:"breaking change",hint:"Add breaking change"},{value:"deprecated",label:"deprecated",hint:"Add deprecated change"},{value:"custom",label:"custom",hint:"Add a custom footer"}],et=[{value:"branch",label:"Branch"},{value:"worktree",label:"Worktree"}];function nt(o=" better-commits "){console.clear(),i.intro(`${a.bgCyan(a.black(o))}`);let e=null,n=N();_.existsSync(n)&&(i.log.step("Found global config"),e=x(n));let l=`${k()}/${C}`;if(_.existsSync(l)){i.log.step("Found repository config");let s=x(l);return e?{...s,overrides:e.overrides.shell?e.overrides:s.overrides,confirm_with_editor:e.confirm_with_editor}:s}if(e)return e;let c=A(g,{});return i.log.step("Config not found. Generating default .better-commit.json at $HOME"),_.writeFileSync(n,JSON.stringify(c,null,4)),c}function x(o){let e=null;try{e=JSON.parse(_.readFileSync(o,"utf8"))}catch(n){i.log.error(`Invalid JSON file. Exiting.
|
|
2
|
+
`+n),process.exit(0)}return R(e)}function R(o){try{return A(g,o)}catch(e){if(e instanceof T){let r=(e.issues[0].path??[]).map(l=>l.key).join(".");i.log.error(`Invalid Configuration: ${a.red(r)}
|
|
3
|
+
`+e.message)}process.exit(0)}}function it(o){let e="";try{e=E("git branch --show-current",{stdio:"pipe"}).toString()}catch{return""}return o.find(r=>{let l=new RegExp(`^${r}-`),c=new RegExp(`-${r}-`),s=new RegExp(`${r}/`);return[e.match(l),e.match(c),e.match(s)].filter(S=>S!=null)?.length})??""}function k(){let o=".";try{o=E("git rev-parse --show-toplevel").toString().trim()}catch{i.log.warn("Could not find git root. If in a --bare repository, ignore this warning.")}return o}function N(){return y()+"/"+C}function rt(o,e){return e===o.length-1?"":`
|
|
4
|
+
`}function at(o){let e=o.trim();return e.endsWith(".")?e.substring(0,e.length-1).trim():o.trim()}export{v as a,g as b,P as c,L as d,C as e,X as f,Y as g,Z as h,z as i,J as j,W as k,K as l,Q as m,tt as n,ot as o,et as p,nt as q,it as r,k as s,rt as t,at as u};
|