better-commits 1.5.2 → 1.7.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 +167 -32
- package/dist/index.js +117 -33
- package/dist/init.js +94 -27
- package/dist/utils.js +123 -32
- package/dist/zod-state.js +94 -27
- package/package.json +1 -1
- package/readme.md +122 -28
- package/src/branch.ts +74 -6
- package/src/index.ts +2 -1
- package/src/utils.ts +154 -79
- package/src/zod-state.ts +179 -115
package/dist/branch.js
CHANGED
|
@@ -47,13 +47,48 @@ var REGEX_SLASH_UND = new RegExp(/\/([A-Z]+-[\[a-zA-Z\]\d]+)_/);
|
|
|
47
47
|
var DEFAULT_TYPE_OPTIONS = [
|
|
48
48
|
{ value: "feat", label: "feat", hint: "A new feature", emoji: "\u2728" },
|
|
49
49
|
{ value: "fix", label: "fix", hint: "A bug fix", emoji: "\u{1F41B}" },
|
|
50
|
-
{
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
{
|
|
50
|
+
{
|
|
51
|
+
value: "docs",
|
|
52
|
+
label: "docs",
|
|
53
|
+
hint: "Documentation only changes",
|
|
54
|
+
emoji: "\u{1F4DA}"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
value: "refactor",
|
|
58
|
+
label: "refactor",
|
|
59
|
+
hint: "A code change that neither fixes a bug nor adds a feature",
|
|
60
|
+
emoji: "\u{1F528}"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
value: "perf",
|
|
64
|
+
label: "perf",
|
|
65
|
+
hint: "A code change that improves performance",
|
|
66
|
+
emoji: "\u{1F680}"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
value: "test",
|
|
70
|
+
label: "test",
|
|
71
|
+
hint: "Adding missing tests or correcting existing tests",
|
|
72
|
+
emoji: "\u{1F6A8}"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
value: "build",
|
|
76
|
+
label: "build",
|
|
77
|
+
hint: "Changes that affect the build system or external dependencies",
|
|
78
|
+
emoji: "\u{1F6A7}"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
value: "ci",
|
|
82
|
+
label: "ci",
|
|
83
|
+
hint: "Changes to our CI configuration files and scripts",
|
|
84
|
+
emoji: "\u{1F916}"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
value: "chore",
|
|
88
|
+
label: "chore",
|
|
89
|
+
hint: "Other changes that do not modify src or test files",
|
|
90
|
+
emoji: "\u{1F9F9}"
|
|
91
|
+
},
|
|
57
92
|
{ value: "", label: "none" }
|
|
58
93
|
];
|
|
59
94
|
var DEFAULT_SCOPE_OPTIONS = [
|
|
@@ -64,8 +99,23 @@ var DEFAULT_SCOPE_OPTIONS = [
|
|
|
64
99
|
{ value: "", label: "none" }
|
|
65
100
|
];
|
|
66
101
|
var CUSTOM_SCOPE_KEY = "custom";
|
|
67
|
-
var Z_FOOTER_OPTIONS = import_zod.z.enum([
|
|
68
|
-
|
|
102
|
+
var Z_FOOTER_OPTIONS = import_zod.z.enum([
|
|
103
|
+
"closes",
|
|
104
|
+
"breaking-change",
|
|
105
|
+
"deprecated",
|
|
106
|
+
"custom"
|
|
107
|
+
]);
|
|
108
|
+
var Z_BRANCH_ACTIONS = import_zod.z.enum(["branch", "worktree"]);
|
|
109
|
+
var FOOTER_OPTION_VALUES = [
|
|
110
|
+
"closes",
|
|
111
|
+
"breaking-change",
|
|
112
|
+
"deprecated",
|
|
113
|
+
"custom"
|
|
114
|
+
];
|
|
115
|
+
var BRANCH_ACTION_OPTIONS = [
|
|
116
|
+
{ value: "branch", label: "Branch" },
|
|
117
|
+
{ value: "worktree", label: "Worktree" }
|
|
118
|
+
];
|
|
69
119
|
function load_setup(cli_name = " better-commits ") {
|
|
70
120
|
console.clear();
|
|
71
121
|
p.intro(`${import_picocolors.default.bgCyan(import_picocolors.default.black(cli_name))}`);
|
|
@@ -81,7 +131,9 @@ function load_setup(cli_name = " better-commits ") {
|
|
|
81
131
|
return read_config_from_path(home_path);
|
|
82
132
|
}
|
|
83
133
|
const default_config = Config.parse({});
|
|
84
|
-
p.log.step(
|
|
134
|
+
p.log.step(
|
|
135
|
+
"Config not found. Generating default .better-commit.json at $HOME"
|
|
136
|
+
);
|
|
85
137
|
import_fs.default.writeFileSync(home_path, JSON.stringify(default_config, null, 4));
|
|
86
138
|
return default_config;
|
|
87
139
|
}
|
|
@@ -119,12 +171,14 @@ var Config = import_zod2.z.object({
|
|
|
119
171
|
infer_type_from_branch: import_zod2.z.boolean().default(true),
|
|
120
172
|
append_emoji_to_label: import_zod2.z.boolean().default(false),
|
|
121
173
|
append_emoji_to_commit: import_zod2.z.boolean().default(false),
|
|
122
|
-
options: import_zod2.z.array(
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
174
|
+
options: import_zod2.z.array(
|
|
175
|
+
import_zod2.z.object({
|
|
176
|
+
value: import_zod2.z.string(),
|
|
177
|
+
label: import_zod2.z.string().optional(),
|
|
178
|
+
hint: import_zod2.z.string().optional(),
|
|
179
|
+
emoji: import_zod2.z.string().emoji().optional()
|
|
180
|
+
})
|
|
181
|
+
).default(DEFAULT_TYPE_OPTIONS)
|
|
128
182
|
}).default({}).transform((val) => {
|
|
129
183
|
const options = val.options.map((v) => ({
|
|
130
184
|
...v,
|
|
@@ -133,30 +187,46 @@ var Config = import_zod2.z.object({
|
|
|
133
187
|
return { ...val, options };
|
|
134
188
|
}).refine(
|
|
135
189
|
(val) => val.options.map((v) => v.value).includes(val.initial_value),
|
|
136
|
-
(val) => ({
|
|
190
|
+
(val) => ({
|
|
191
|
+
message: `Type: initial_value "${val.initial_value}" must exist in options`
|
|
192
|
+
})
|
|
137
193
|
),
|
|
138
194
|
commit_scope: import_zod2.z.object({
|
|
139
195
|
enable: import_zod2.z.boolean().default(true),
|
|
140
196
|
custom_scope: import_zod2.z.boolean().default(false),
|
|
141
197
|
initial_value: import_zod2.z.string().default("app"),
|
|
142
|
-
options: import_zod2.z.array(
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
198
|
+
options: import_zod2.z.array(
|
|
199
|
+
import_zod2.z.object({
|
|
200
|
+
value: import_zod2.z.string(),
|
|
201
|
+
label: import_zod2.z.string().optional(),
|
|
202
|
+
hint: import_zod2.z.string().optional()
|
|
203
|
+
})
|
|
204
|
+
).default(DEFAULT_SCOPE_OPTIONS)
|
|
147
205
|
}).default({}).transform((val) => {
|
|
148
206
|
const options = val.options.map((v) => v.value);
|
|
149
207
|
if (val.custom_scope && !options.includes(CUSTOM_SCOPE_KEY)) {
|
|
150
208
|
return {
|
|
151
209
|
...val,
|
|
152
|
-
options: [
|
|
210
|
+
options: [
|
|
211
|
+
...val.options,
|
|
212
|
+
{
|
|
213
|
+
label: CUSTOM_SCOPE_KEY,
|
|
214
|
+
value: CUSTOM_SCOPE_KEY,
|
|
215
|
+
hint: "Write a custom scope"
|
|
216
|
+
}
|
|
217
|
+
]
|
|
153
218
|
};
|
|
154
219
|
}
|
|
155
220
|
return val;
|
|
156
|
-
}).refine(
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
221
|
+
}).refine(
|
|
222
|
+
(val) => {
|
|
223
|
+
const options = val.options.map((v) => v.value);
|
|
224
|
+
return options.includes(val.initial_value);
|
|
225
|
+
},
|
|
226
|
+
(val) => ({
|
|
227
|
+
message: `Scope: initial_value "${val.initial_value}" must exist in options`
|
|
228
|
+
})
|
|
229
|
+
),
|
|
160
230
|
check_ticket: import_zod2.z.object({
|
|
161
231
|
infer_ticket: import_zod2.z.boolean().default(true),
|
|
162
232
|
confirm_ticket: import_zod2.z.boolean().default(true),
|
|
@@ -199,7 +269,10 @@ var Config = import_zod2.z.object({
|
|
|
199
269
|
}).default({}),
|
|
200
270
|
branch_description: import_zod2.z.object({
|
|
201
271
|
max_length: import_zod2.z.number().positive().default(70)
|
|
202
|
-
}).default({})
|
|
272
|
+
}).default({}),
|
|
273
|
+
branch_action_default: Z_BRANCH_ACTIONS.default("branch"),
|
|
274
|
+
enable_worktrees: import_zod2.z.boolean().default(true),
|
|
275
|
+
overrides: import_zod2.z.object({ shell: import_zod2.z.string().optional() }).default({})
|
|
203
276
|
}).default({});
|
|
204
277
|
var CommitState = import_zod2.z.object({
|
|
205
278
|
type: import_zod2.z.string().default(""),
|
|
@@ -223,13 +296,25 @@ var BranchState = import_zod2.z.object({
|
|
|
223
296
|
}).default({});
|
|
224
297
|
|
|
225
298
|
// src/branch.ts
|
|
226
|
-
var import_simple_git = __toESM(require("simple-git"));
|
|
227
299
|
var p2 = __toESM(require("@clack/prompts"));
|
|
228
300
|
var import_configstore = __toESM(require("configstore"));
|
|
229
301
|
var import_child_process2 = require("child_process");
|
|
302
|
+
var import_picocolors2 = __toESM(require("picocolors"));
|
|
303
|
+
var import_process = require("process");
|
|
230
304
|
main(load_setup(" better-branch "));
|
|
231
305
|
async function main(config) {
|
|
232
306
|
const branch_state = BranchState.parse({});
|
|
307
|
+
let checkout_type = "branch";
|
|
308
|
+
if (config.enable_worktrees) {
|
|
309
|
+
const branch_or_worktree = await p2.select({
|
|
310
|
+
message: `Checkout a branch or create a worktree?`,
|
|
311
|
+
initialValue: config.branch_action_default,
|
|
312
|
+
options: BRANCH_ACTION_OPTIONS
|
|
313
|
+
});
|
|
314
|
+
if (p2.isCancel(branch_or_worktree))
|
|
315
|
+
process.exit();
|
|
316
|
+
checkout_type = branch_or_worktree;
|
|
317
|
+
}
|
|
233
318
|
if (config.branch_user.enable) {
|
|
234
319
|
const cache_user_name = get_user_from_cache();
|
|
235
320
|
const user_name_required = config.branch_user.required;
|
|
@@ -295,9 +380,45 @@ async function main(config) {
|
|
|
295
380
|
}
|
|
296
381
|
});
|
|
297
382
|
const branch_name = build_branch(branch_state, config);
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
|
|
383
|
+
const branch_flag = verify_branch_name(branch_name);
|
|
384
|
+
if (checkout_type === "branch") {
|
|
385
|
+
try {
|
|
386
|
+
(0, import_child_process2.execSync)(`git checkout ${branch_flag} ${branch_name}`, {
|
|
387
|
+
stdio: "inherit"
|
|
388
|
+
});
|
|
389
|
+
p2.log.info(
|
|
390
|
+
`Switched to a new branch '${import_picocolors2.default.bgGreen(
|
|
391
|
+
" " + import_picocolors2.default.black(branch_name) + " "
|
|
392
|
+
)}'`
|
|
393
|
+
);
|
|
394
|
+
} catch (err) {
|
|
395
|
+
process.exit(0);
|
|
396
|
+
}
|
|
397
|
+
} else {
|
|
398
|
+
try {
|
|
399
|
+
const ticket = branch_state.ticket ? `${branch_state.ticket}-` : "";
|
|
400
|
+
const worktree_name = `${ticket}${branch_state.description}`;
|
|
401
|
+
(0, import_child_process2.execSync)(
|
|
402
|
+
`git worktree add ${worktree_name} ${branch_flag} ${branch_name}`,
|
|
403
|
+
{
|
|
404
|
+
stdio: "inherit"
|
|
405
|
+
}
|
|
406
|
+
);
|
|
407
|
+
p2.log.info(
|
|
408
|
+
`Created a new worktree ${import_picocolors2.default.bgGreen(
|
|
409
|
+
+" " + import_picocolors2.default.black(worktree_name) + " "
|
|
410
|
+
)}, checked out branch ${import_picocolors2.default.bgGreen(
|
|
411
|
+
" " + import_picocolors2.default.black(branch_name) + " "
|
|
412
|
+
)}`
|
|
413
|
+
);
|
|
414
|
+
p2.log.info(
|
|
415
|
+
import_picocolors2.default.bgMagenta(import_picocolors2.default.black(` cd ${worktree_name} `)) + " to navigate to your new worktree"
|
|
416
|
+
);
|
|
417
|
+
(0, import_process.chdir)(worktree_name);
|
|
418
|
+
} catch (err) {
|
|
419
|
+
process.exit(0);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
301
422
|
config.branch_post_commands.forEach((command) => {
|
|
302
423
|
try {
|
|
303
424
|
(0, import_child_process2.execSync)(command, { stdio: "inherit" });
|
|
@@ -330,6 +451,20 @@ function get_user_from_cache() {
|
|
|
330
451
|
}
|
|
331
452
|
return "";
|
|
332
453
|
}
|
|
454
|
+
function verify_branch_name(branch_name) {
|
|
455
|
+
let branch_flag = "";
|
|
456
|
+
try {
|
|
457
|
+
(0, import_child_process2.execSync)(`git show-ref ${branch_name}`, { encoding: "utf-8" });
|
|
458
|
+
p2.log.warning(
|
|
459
|
+
import_picocolors2.default.yellow(
|
|
460
|
+
`${branch_name} already exists! Checking out existing branch.`
|
|
461
|
+
)
|
|
462
|
+
);
|
|
463
|
+
} catch (err) {
|
|
464
|
+
branch_flag = "-b";
|
|
465
|
+
}
|
|
466
|
+
return branch_flag;
|
|
467
|
+
}
|
|
333
468
|
function set_user_cache(val) {
|
|
334
469
|
try {
|
|
335
470
|
const config_store = new import_configstore.default("better-commits");
|
package/dist/index.js
CHANGED
|
@@ -63,13 +63,48 @@ var REGEX_SLASH_UND = new RegExp(/\/([A-Z]+-[\[a-zA-Z\]\d]+)_/);
|
|
|
63
63
|
var DEFAULT_TYPE_OPTIONS = [
|
|
64
64
|
{ value: "feat", label: "feat", hint: "A new feature", emoji: "\u2728" },
|
|
65
65
|
{ value: "fix", label: "fix", hint: "A bug fix", emoji: "\u{1F41B}" },
|
|
66
|
-
{
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
{
|
|
66
|
+
{
|
|
67
|
+
value: "docs",
|
|
68
|
+
label: "docs",
|
|
69
|
+
hint: "Documentation only changes",
|
|
70
|
+
emoji: "\u{1F4DA}"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
value: "refactor",
|
|
74
|
+
label: "refactor",
|
|
75
|
+
hint: "A code change that neither fixes a bug nor adds a feature",
|
|
76
|
+
emoji: "\u{1F528}"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
value: "perf",
|
|
80
|
+
label: "perf",
|
|
81
|
+
hint: "A code change that improves performance",
|
|
82
|
+
emoji: "\u{1F680}"
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
value: "test",
|
|
86
|
+
label: "test",
|
|
87
|
+
hint: "Adding missing tests or correcting existing tests",
|
|
88
|
+
emoji: "\u{1F6A8}"
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
value: "build",
|
|
92
|
+
label: "build",
|
|
93
|
+
hint: "Changes that affect the build system or external dependencies",
|
|
94
|
+
emoji: "\u{1F6A7}"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
value: "ci",
|
|
98
|
+
label: "ci",
|
|
99
|
+
hint: "Changes to our CI configuration files and scripts",
|
|
100
|
+
emoji: "\u{1F916}"
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
value: "chore",
|
|
104
|
+
label: "chore",
|
|
105
|
+
hint: "Other changes that do not modify src or test files",
|
|
106
|
+
emoji: "\u{1F9F9}"
|
|
107
|
+
},
|
|
73
108
|
{ value: "", label: "none" }
|
|
74
109
|
];
|
|
75
110
|
var DEFAULT_SCOPE_OPTIONS = [
|
|
@@ -80,14 +115,33 @@ var DEFAULT_SCOPE_OPTIONS = [
|
|
|
80
115
|
{ value: "", label: "none" }
|
|
81
116
|
];
|
|
82
117
|
var COMMIT_FOOTER_OPTIONS = [
|
|
83
|
-
{
|
|
84
|
-
|
|
118
|
+
{
|
|
119
|
+
value: "closes",
|
|
120
|
+
label: "closes <issue/ticket>",
|
|
121
|
+
hint: "Attempts to infer ticket from branch"
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
value: "breaking-change",
|
|
125
|
+
label: "breaking change",
|
|
126
|
+
hint: "Add breaking change"
|
|
127
|
+
},
|
|
85
128
|
{ value: "deprecated", label: "deprecated", hint: "Add deprecated change" },
|
|
86
129
|
{ value: "custom", label: "custom", hint: "Add a custom footer" }
|
|
87
130
|
];
|
|
88
131
|
var CUSTOM_SCOPE_KEY = "custom";
|
|
89
|
-
var Z_FOOTER_OPTIONS = import_zod.z.enum([
|
|
90
|
-
|
|
132
|
+
var Z_FOOTER_OPTIONS = import_zod.z.enum([
|
|
133
|
+
"closes",
|
|
134
|
+
"breaking-change",
|
|
135
|
+
"deprecated",
|
|
136
|
+
"custom"
|
|
137
|
+
]);
|
|
138
|
+
var Z_BRANCH_ACTIONS = import_zod.z.enum(["branch", "worktree"]);
|
|
139
|
+
var FOOTER_OPTION_VALUES = [
|
|
140
|
+
"closes",
|
|
141
|
+
"breaking-change",
|
|
142
|
+
"deprecated",
|
|
143
|
+
"custom"
|
|
144
|
+
];
|
|
91
145
|
function load_setup(cli_name = " better-commits ") {
|
|
92
146
|
console.clear();
|
|
93
147
|
p.intro(`${import_picocolors.default.bgCyan(import_picocolors.default.black(cli_name))}`);
|
|
@@ -103,7 +157,9 @@ function load_setup(cli_name = " better-commits ") {
|
|
|
103
157
|
return read_config_from_path(home_path);
|
|
104
158
|
}
|
|
105
159
|
const default_config = Config.parse({});
|
|
106
|
-
p.log.step(
|
|
160
|
+
p.log.step(
|
|
161
|
+
"Config not found. Generating default .better-commit.json at $HOME"
|
|
162
|
+
);
|
|
107
163
|
import_fs.default.writeFileSync(home_path, JSON.stringify(default_config, null, 4));
|
|
108
164
|
return default_config;
|
|
109
165
|
}
|
|
@@ -128,7 +184,9 @@ function validate_config(config) {
|
|
|
128
184
|
function infer_type_from_branch(types) {
|
|
129
185
|
let branch = "";
|
|
130
186
|
try {
|
|
131
|
-
branch = (0, import_child_process.execSync)("git branch --show-current", {
|
|
187
|
+
branch = (0, import_child_process.execSync)("git branch --show-current", {
|
|
188
|
+
stdio: "pipe"
|
|
189
|
+
}).toString();
|
|
132
190
|
} catch (err) {
|
|
133
191
|
return "";
|
|
134
192
|
}
|
|
@@ -136,7 +194,11 @@ function infer_type_from_branch(types) {
|
|
|
136
194
|
const start_dash = new RegExp(`^${t}-`);
|
|
137
195
|
const between_dash = new RegExp(`-${t}-`);
|
|
138
196
|
const before_slash = new RegExp(`${t}/`);
|
|
139
|
-
const re = [
|
|
197
|
+
const re = [
|
|
198
|
+
branch.match(start_dash),
|
|
199
|
+
branch.match(between_dash),
|
|
200
|
+
branch.match(before_slash)
|
|
201
|
+
].filter((v) => v != null);
|
|
140
202
|
return re?.length;
|
|
141
203
|
});
|
|
142
204
|
return found ?? "";
|
|
@@ -171,12 +233,14 @@ var Config = import_zod2.z.object({
|
|
|
171
233
|
infer_type_from_branch: import_zod2.z.boolean().default(true),
|
|
172
234
|
append_emoji_to_label: import_zod2.z.boolean().default(false),
|
|
173
235
|
append_emoji_to_commit: import_zod2.z.boolean().default(false),
|
|
174
|
-
options: import_zod2.z.array(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
236
|
+
options: import_zod2.z.array(
|
|
237
|
+
import_zod2.z.object({
|
|
238
|
+
value: import_zod2.z.string(),
|
|
239
|
+
label: import_zod2.z.string().optional(),
|
|
240
|
+
hint: import_zod2.z.string().optional(),
|
|
241
|
+
emoji: import_zod2.z.string().emoji().optional()
|
|
242
|
+
})
|
|
243
|
+
).default(DEFAULT_TYPE_OPTIONS)
|
|
180
244
|
}).default({}).transform((val) => {
|
|
181
245
|
const options = val.options.map((v) => ({
|
|
182
246
|
...v,
|
|
@@ -185,30 +249,46 @@ var Config = import_zod2.z.object({
|
|
|
185
249
|
return { ...val, options };
|
|
186
250
|
}).refine(
|
|
187
251
|
(val) => val.options.map((v) => v.value).includes(val.initial_value),
|
|
188
|
-
(val) => ({
|
|
252
|
+
(val) => ({
|
|
253
|
+
message: `Type: initial_value "${val.initial_value}" must exist in options`
|
|
254
|
+
})
|
|
189
255
|
),
|
|
190
256
|
commit_scope: import_zod2.z.object({
|
|
191
257
|
enable: import_zod2.z.boolean().default(true),
|
|
192
258
|
custom_scope: import_zod2.z.boolean().default(false),
|
|
193
259
|
initial_value: import_zod2.z.string().default("app"),
|
|
194
|
-
options: import_zod2.z.array(
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
260
|
+
options: import_zod2.z.array(
|
|
261
|
+
import_zod2.z.object({
|
|
262
|
+
value: import_zod2.z.string(),
|
|
263
|
+
label: import_zod2.z.string().optional(),
|
|
264
|
+
hint: import_zod2.z.string().optional()
|
|
265
|
+
})
|
|
266
|
+
).default(DEFAULT_SCOPE_OPTIONS)
|
|
199
267
|
}).default({}).transform((val) => {
|
|
200
268
|
const options = val.options.map((v) => v.value);
|
|
201
269
|
if (val.custom_scope && !options.includes(CUSTOM_SCOPE_KEY)) {
|
|
202
270
|
return {
|
|
203
271
|
...val,
|
|
204
|
-
options: [
|
|
272
|
+
options: [
|
|
273
|
+
...val.options,
|
|
274
|
+
{
|
|
275
|
+
label: CUSTOM_SCOPE_KEY,
|
|
276
|
+
value: CUSTOM_SCOPE_KEY,
|
|
277
|
+
hint: "Write a custom scope"
|
|
278
|
+
}
|
|
279
|
+
]
|
|
205
280
|
};
|
|
206
281
|
}
|
|
207
282
|
return val;
|
|
208
|
-
}).refine(
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
283
|
+
}).refine(
|
|
284
|
+
(val) => {
|
|
285
|
+
const options = val.options.map((v) => v.value);
|
|
286
|
+
return options.includes(val.initial_value);
|
|
287
|
+
},
|
|
288
|
+
(val) => ({
|
|
289
|
+
message: `Scope: initial_value "${val.initial_value}" must exist in options`
|
|
290
|
+
})
|
|
291
|
+
),
|
|
212
292
|
check_ticket: import_zod2.z.object({
|
|
213
293
|
infer_ticket: import_zod2.z.boolean().default(true),
|
|
214
294
|
confirm_ticket: import_zod2.z.boolean().default(true),
|
|
@@ -251,7 +331,10 @@ var Config = import_zod2.z.object({
|
|
|
251
331
|
}).default({}),
|
|
252
332
|
branch_description: import_zod2.z.object({
|
|
253
333
|
max_length: import_zod2.z.number().positive().default(70)
|
|
254
|
-
}).default({})
|
|
334
|
+
}).default({}),
|
|
335
|
+
branch_action_default: Z_BRANCH_ACTIONS.default("branch"),
|
|
336
|
+
enable_worktrees: import_zod2.z.boolean().default(true),
|
|
337
|
+
overrides: import_zod2.z.object({ shell: import_zod2.z.string().optional() }).default({})
|
|
255
338
|
}).default({});
|
|
256
339
|
var CommitState = import_zod2.z.object({
|
|
257
340
|
type: import_zod2.z.string().default(""),
|
|
@@ -482,7 +565,8 @@ async function main(config) {
|
|
|
482
565
|
process.exit(0);
|
|
483
566
|
}
|
|
484
567
|
try {
|
|
485
|
-
const
|
|
568
|
+
const options = config.overrides.shell ? { shell: config.overrides.shell } : {};
|
|
569
|
+
const output = (0, import_child_process2.execSync)(`git commit -m "${build_commit_string(commit_state, config, false)}"`, options).toString().trim();
|
|
486
570
|
if (config.print_commit_output)
|
|
487
571
|
p2.log.info(output);
|
|
488
572
|
} catch (err) {
|
package/dist/init.js
CHANGED
|
@@ -45,13 +45,48 @@ var REGEX_SLASH_UND = new RegExp(/\/([A-Z]+-[\[a-zA-Z\]\d]+)_/);
|
|
|
45
45
|
var DEFAULT_TYPE_OPTIONS = [
|
|
46
46
|
{ value: "feat", label: "feat", hint: "A new feature", emoji: "\u2728" },
|
|
47
47
|
{ value: "fix", label: "fix", hint: "A bug fix", emoji: "\u{1F41B}" },
|
|
48
|
-
{
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
{
|
|
48
|
+
{
|
|
49
|
+
value: "docs",
|
|
50
|
+
label: "docs",
|
|
51
|
+
hint: "Documentation only changes",
|
|
52
|
+
emoji: "\u{1F4DA}"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
value: "refactor",
|
|
56
|
+
label: "refactor",
|
|
57
|
+
hint: "A code change that neither fixes a bug nor adds a feature",
|
|
58
|
+
emoji: "\u{1F528}"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
value: "perf",
|
|
62
|
+
label: "perf",
|
|
63
|
+
hint: "A code change that improves performance",
|
|
64
|
+
emoji: "\u{1F680}"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
value: "test",
|
|
68
|
+
label: "test",
|
|
69
|
+
hint: "Adding missing tests or correcting existing tests",
|
|
70
|
+
emoji: "\u{1F6A8}"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
value: "build",
|
|
74
|
+
label: "build",
|
|
75
|
+
hint: "Changes that affect the build system or external dependencies",
|
|
76
|
+
emoji: "\u{1F6A7}"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
value: "ci",
|
|
80
|
+
label: "ci",
|
|
81
|
+
hint: "Changes to our CI configuration files and scripts",
|
|
82
|
+
emoji: "\u{1F916}"
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
value: "chore",
|
|
86
|
+
label: "chore",
|
|
87
|
+
hint: "Other changes that do not modify src or test files",
|
|
88
|
+
emoji: "\u{1F9F9}"
|
|
89
|
+
},
|
|
55
90
|
{ value: "", label: "none" }
|
|
56
91
|
];
|
|
57
92
|
var DEFAULT_SCOPE_OPTIONS = [
|
|
@@ -62,8 +97,19 @@ var DEFAULT_SCOPE_OPTIONS = [
|
|
|
62
97
|
{ value: "", label: "none" }
|
|
63
98
|
];
|
|
64
99
|
var CUSTOM_SCOPE_KEY = "custom";
|
|
65
|
-
var Z_FOOTER_OPTIONS = import_zod.z.enum([
|
|
66
|
-
|
|
100
|
+
var Z_FOOTER_OPTIONS = import_zod.z.enum([
|
|
101
|
+
"closes",
|
|
102
|
+
"breaking-change",
|
|
103
|
+
"deprecated",
|
|
104
|
+
"custom"
|
|
105
|
+
]);
|
|
106
|
+
var Z_BRANCH_ACTIONS = import_zod.z.enum(["branch", "worktree"]);
|
|
107
|
+
var FOOTER_OPTION_VALUES = [
|
|
108
|
+
"closes",
|
|
109
|
+
"breaking-change",
|
|
110
|
+
"deprecated",
|
|
111
|
+
"custom"
|
|
112
|
+
];
|
|
67
113
|
function get_git_root() {
|
|
68
114
|
return (0, import_child_process.execSync)("git rev-parse --show-toplevel").toString().trim();
|
|
69
115
|
}
|
|
@@ -77,12 +123,14 @@ var Config = import_zod2.z.object({
|
|
|
77
123
|
infer_type_from_branch: import_zod2.z.boolean().default(true),
|
|
78
124
|
append_emoji_to_label: import_zod2.z.boolean().default(false),
|
|
79
125
|
append_emoji_to_commit: import_zod2.z.boolean().default(false),
|
|
80
|
-
options: import_zod2.z.array(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
126
|
+
options: import_zod2.z.array(
|
|
127
|
+
import_zod2.z.object({
|
|
128
|
+
value: import_zod2.z.string(),
|
|
129
|
+
label: import_zod2.z.string().optional(),
|
|
130
|
+
hint: import_zod2.z.string().optional(),
|
|
131
|
+
emoji: import_zod2.z.string().emoji().optional()
|
|
132
|
+
})
|
|
133
|
+
).default(DEFAULT_TYPE_OPTIONS)
|
|
86
134
|
}).default({}).transform((val) => {
|
|
87
135
|
const options = val.options.map((v) => ({
|
|
88
136
|
...v,
|
|
@@ -91,30 +139,46 @@ var Config = import_zod2.z.object({
|
|
|
91
139
|
return { ...val, options };
|
|
92
140
|
}).refine(
|
|
93
141
|
(val) => val.options.map((v) => v.value).includes(val.initial_value),
|
|
94
|
-
(val) => ({
|
|
142
|
+
(val) => ({
|
|
143
|
+
message: `Type: initial_value "${val.initial_value}" must exist in options`
|
|
144
|
+
})
|
|
95
145
|
),
|
|
96
146
|
commit_scope: import_zod2.z.object({
|
|
97
147
|
enable: import_zod2.z.boolean().default(true),
|
|
98
148
|
custom_scope: import_zod2.z.boolean().default(false),
|
|
99
149
|
initial_value: import_zod2.z.string().default("app"),
|
|
100
|
-
options: import_zod2.z.array(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
150
|
+
options: import_zod2.z.array(
|
|
151
|
+
import_zod2.z.object({
|
|
152
|
+
value: import_zod2.z.string(),
|
|
153
|
+
label: import_zod2.z.string().optional(),
|
|
154
|
+
hint: import_zod2.z.string().optional()
|
|
155
|
+
})
|
|
156
|
+
).default(DEFAULT_SCOPE_OPTIONS)
|
|
105
157
|
}).default({}).transform((val) => {
|
|
106
158
|
const options = val.options.map((v) => v.value);
|
|
107
159
|
if (val.custom_scope && !options.includes(CUSTOM_SCOPE_KEY)) {
|
|
108
160
|
return {
|
|
109
161
|
...val,
|
|
110
|
-
options: [
|
|
162
|
+
options: [
|
|
163
|
+
...val.options,
|
|
164
|
+
{
|
|
165
|
+
label: CUSTOM_SCOPE_KEY,
|
|
166
|
+
value: CUSTOM_SCOPE_KEY,
|
|
167
|
+
hint: "Write a custom scope"
|
|
168
|
+
}
|
|
169
|
+
]
|
|
111
170
|
};
|
|
112
171
|
}
|
|
113
172
|
return val;
|
|
114
|
-
}).refine(
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
173
|
+
}).refine(
|
|
174
|
+
(val) => {
|
|
175
|
+
const options = val.options.map((v) => v.value);
|
|
176
|
+
return options.includes(val.initial_value);
|
|
177
|
+
},
|
|
178
|
+
(val) => ({
|
|
179
|
+
message: `Scope: initial_value "${val.initial_value}" must exist in options`
|
|
180
|
+
})
|
|
181
|
+
),
|
|
118
182
|
check_ticket: import_zod2.z.object({
|
|
119
183
|
infer_ticket: import_zod2.z.boolean().default(true),
|
|
120
184
|
confirm_ticket: import_zod2.z.boolean().default(true),
|
|
@@ -157,7 +221,10 @@ var Config = import_zod2.z.object({
|
|
|
157
221
|
}).default({}),
|
|
158
222
|
branch_description: import_zod2.z.object({
|
|
159
223
|
max_length: import_zod2.z.number().positive().default(70)
|
|
160
|
-
}).default({})
|
|
224
|
+
}).default({}),
|
|
225
|
+
branch_action_default: Z_BRANCH_ACTIONS.default("branch"),
|
|
226
|
+
enable_worktrees: import_zod2.z.boolean().default(true),
|
|
227
|
+
overrides: import_zod2.z.object({ shell: import_zod2.z.string().optional() }).default({})
|
|
161
228
|
}).default({});
|
|
162
229
|
var CommitState = import_zod2.z.object({
|
|
163
230
|
type: import_zod2.z.string().default(""),
|