better-commits 1.23.2 → 1.23.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/branch.js +628 -19
- package/dist/chunk-GAAS3VS3.js +922 -0
- package/dist/chunk-H5CLUQIL.js +313 -0
- package/dist/index.js +1122 -41
- package/dist/init.js +44 -1
- package/package.json +12 -4
- package/readme.md +4 -2
- package/.better-commits.json +0 -52
- package/.github/workflows/publish.yml +0 -34
- package/.github/workflows/test.yml +0 -27
- package/.prettierignore +0 -5
- package/.prettierrc +0 -1
- package/dist/chunk-43H72S6V.js +0 -1
- package/dist/chunk-B7AGSPP3.js +0 -261
- package/src/args.test.ts +0 -128
- package/src/args.ts +0 -125
- package/src/branch-args.test.ts +0 -75
- package/src/branch-args.ts +0 -107
- package/src/branch-help.ts +0 -125
- package/src/branch.ts +0 -97
- package/src/default-config-template.ts +0 -258
- package/src/git.test.ts +0 -64
- package/src/git.ts +0 -72
- package/src/help.ts +0 -138
- package/src/index.test.ts +0 -7
- package/src/index.ts +0 -101
- package/src/init.test.ts +0 -123
- package/src/init.ts +0 -46
- package/src/prompts/autocomplete-multiselect.test.ts +0 -129
- package/src/prompts/autocomplete-multiselect.ts +0 -249
- package/src/prompts/branch-checkout.prompt.ts +0 -36
- package/src/prompts/branch-confirm.prompt.test.ts +0 -89
- package/src/prompts/branch-confirm.prompt.ts +0 -149
- package/src/prompts/branch-description.prompt.ts +0 -37
- package/src/prompts/branch-runnable.ts +0 -13
- package/src/prompts/branch-scope.prompt.ts +0 -59
- package/src/prompts/branch-ticket.prompt.ts +0 -41
- package/src/prompts/branch-type.prompt.ts +0 -46
- package/src/prompts/branch-user.prompt.ts +0 -50
- package/src/prompts/branch-version.prompt.ts +0 -41
- package/src/prompts/commit-body.prompt.ts +0 -51
- package/src/prompts/commit-confirm.prompt.ts +0 -123
- package/src/prompts/commit-footer.prompt.ts +0 -195
- package/src/prompts/commit-scope.prompt.ts +0 -91
- package/src/prompts/commit-status.prompt.ts +0 -66
- package/src/prompts/commit-ticket.prompt.ts +0 -82
- package/src/prompts/commit-title.prompt.ts +0 -98
- package/src/prompts/commit-type.prompt.ts +0 -96
- package/src/prompts/runnable.ts +0 -13
- package/src/utils/build-branch.test.ts +0 -159
- package/src/utils/build-branch.ts +0 -48
- package/src/utils/build-commit-string.test.ts +0 -273
- package/src/utils/build-commit-string.ts +0 -163
- package/src/utils/commit-title-size.ts +0 -24
- package/src/utils/infer.test.ts +0 -174
- package/src/utils/infer.ts +0 -160
- package/src/utils/messages.ts +0 -25
- package/src/utils/no-interactive-branch-validation.test.ts +0 -193
- package/src/utils/no-interactive-validation.test.ts +0 -174
- package/src/utils/no-interactive-validation.ts +0 -213
- package/src/utils.test.ts +0 -164
- package/src/utils.ts +0 -235
- package/src/valibot-consts.ts +0 -117
- package/src/valibot-state.test.ts +0 -57
- package/src/valibot-state.ts +0 -276
- package/tsconfig.json +0 -15
- package/tsup.config.ts +0 -12
- package/vitest.config.ts +0 -8
package/src/args.ts
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { parse } from "@bomb.sh/args";
|
|
2
|
-
import { InferOutput } from "valibot";
|
|
3
|
-
import { CommitState } from "./valibot-state";
|
|
4
|
-
|
|
5
|
-
type CommitStateRuntime = InferOutput<typeof CommitState>;
|
|
6
|
-
|
|
7
|
-
type ParsedRuntimeFlags = {
|
|
8
|
-
help: boolean;
|
|
9
|
-
version: boolean;
|
|
10
|
-
git_args: string;
|
|
11
|
-
no_interactive: boolean;
|
|
12
|
-
dry_run: boolean;
|
|
13
|
-
commit_state: Partial<CommitStateRuntime>;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const COMMIT_OPTIONS = [
|
|
17
|
-
"type",
|
|
18
|
-
"scope",
|
|
19
|
-
"title",
|
|
20
|
-
"body",
|
|
21
|
-
"ticket",
|
|
22
|
-
"closes",
|
|
23
|
-
"trailer",
|
|
24
|
-
"breaking-title",
|
|
25
|
-
"breaking-body",
|
|
26
|
-
"deprecates-title",
|
|
27
|
-
"deprecates-body",
|
|
28
|
-
"custom-footer",
|
|
29
|
-
] as const;
|
|
30
|
-
|
|
31
|
-
export const GIT_OPTIONS = ["git-dir", "work-tree"] as const;
|
|
32
|
-
|
|
33
|
-
export const BOOLEAN_FLAGS = [
|
|
34
|
-
"interactive",
|
|
35
|
-
"dry-run",
|
|
36
|
-
"help",
|
|
37
|
-
"version",
|
|
38
|
-
] as const;
|
|
39
|
-
|
|
40
|
-
class Flags {
|
|
41
|
-
#runtime: ParsedRuntimeFlags;
|
|
42
|
-
|
|
43
|
-
constructor(runtime: ParsedRuntimeFlags) {
|
|
44
|
-
this.#runtime = runtime;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
get git_args(): string {
|
|
48
|
-
return this.#runtime.git_args;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
get interactive(): boolean {
|
|
52
|
-
return !this.#runtime.no_interactive;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
get dry_run(): boolean {
|
|
56
|
-
return this.#runtime.dry_run;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
get help(): boolean {
|
|
60
|
-
return this.#runtime.help;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
get version(): boolean {
|
|
64
|
-
return this.#runtime.version;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
get commit_state(): Partial<CommitStateRuntime> {
|
|
68
|
-
return this.#runtime.commit_state;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export const flags = new Flags(parse_runtime_flags(process.argv.slice(2)));
|
|
73
|
-
|
|
74
|
-
export function parse_runtime_flags(argv: string[]): ParsedRuntimeFlags {
|
|
75
|
-
const parsed = parse(argv, {
|
|
76
|
-
alias: { h: "help", v: "version" },
|
|
77
|
-
boolean: BOOLEAN_FLAGS,
|
|
78
|
-
string: [...COMMIT_OPTIONS, ...GIT_OPTIONS],
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
const commit_state: Partial<CommitStateRuntime> = {};
|
|
82
|
-
COMMIT_OPTIONS.forEach((value) => {
|
|
83
|
-
const cli_value = parsed[value];
|
|
84
|
-
const normalized_value = normalize_commit_flag(value, cli_value);
|
|
85
|
-
if (normalized_value !== undefined) {
|
|
86
|
-
const str = value.replace("-", "_") as keyof CommitStateRuntime;
|
|
87
|
-
commit_state[str] = normalized_value;
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
return {
|
|
92
|
-
help: parsed["help"] === true,
|
|
93
|
-
version: parsed["version"] === true,
|
|
94
|
-
git_args: get_git_args(parsed["git-dir"], parsed["work-tree"]),
|
|
95
|
-
no_interactive: parsed.interactive === false,
|
|
96
|
-
dry_run: parsed["dry-run"] === true,
|
|
97
|
-
commit_state,
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function normalize_commit_flag(
|
|
102
|
-
option: (typeof COMMIT_OPTIONS)[number],
|
|
103
|
-
value: string | undefined,
|
|
104
|
-
): string | undefined {
|
|
105
|
-
if (value === undefined) return undefined;
|
|
106
|
-
if (option !== "closes") return value;
|
|
107
|
-
|
|
108
|
-
const normalized = value.trim().toLowerCase();
|
|
109
|
-
if (normalized === "false") {
|
|
110
|
-
return undefined;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (value === "" || normalized) {
|
|
114
|
-
return "Closes:";
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return undefined;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function get_git_args(
|
|
121
|
-
git_dir: string | undefined,
|
|
122
|
-
work_tree: string | undefined,
|
|
123
|
-
): string {
|
|
124
|
-
return `${git_dir ? `--git-dir=${git_dir}` : ""} ${work_tree ? `--work-tree=${work_tree}` : ""}`.trim();
|
|
125
|
-
}
|
package/src/branch-args.test.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { parse_branch_runtime_flags } from "./branch-args";
|
|
3
|
-
|
|
4
|
-
describe("parse_branch_runtime_flags", () => {
|
|
5
|
-
it("maps branch flags into branch_state keys", () => {
|
|
6
|
-
const parsed = parse_branch_runtime_flags([
|
|
7
|
-
"--user",
|
|
8
|
-
"erik",
|
|
9
|
-
"--type",
|
|
10
|
-
"feat",
|
|
11
|
-
"--scope",
|
|
12
|
-
"cli",
|
|
13
|
-
"--ticket",
|
|
14
|
-
"ABC-123",
|
|
15
|
-
"--description",
|
|
16
|
-
"add-parser",
|
|
17
|
-
"--branch-version",
|
|
18
|
-
"1.2.0",
|
|
19
|
-
]);
|
|
20
|
-
|
|
21
|
-
expect(parsed.branch_state).toEqual({
|
|
22
|
-
user: "erik",
|
|
23
|
-
type: "feat",
|
|
24
|
-
scope: "cli",
|
|
25
|
-
ticket: "ABC-123",
|
|
26
|
-
description: "add-parser",
|
|
27
|
-
version: "1.2.0",
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it("maps --checkout into checkout", () => {
|
|
32
|
-
const parsed = parse_branch_runtime_flags(["--checkout", "worktree"]);
|
|
33
|
-
|
|
34
|
-
expect(parsed.branch_state).toEqual({
|
|
35
|
-
checkout: "worktree",
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("does not set checkout when --checkout is omitted", () => {
|
|
40
|
-
const parsed = parse_branch_runtime_flags([
|
|
41
|
-
"--type",
|
|
42
|
-
"feat",
|
|
43
|
-
"--description",
|
|
44
|
-
"add-parser",
|
|
45
|
-
]);
|
|
46
|
-
|
|
47
|
-
expect(parsed.branch_state).toEqual({
|
|
48
|
-
type: "feat",
|
|
49
|
-
description: "add-parser",
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it("honors interactive flag semantics", () => {
|
|
54
|
-
const default_flags = parse_branch_runtime_flags([]);
|
|
55
|
-
const explicit_interactive = parse_branch_runtime_flags(["--interactive"]);
|
|
56
|
-
const no_interactive = parse_branch_runtime_flags(["--no-interactive"]);
|
|
57
|
-
|
|
58
|
-
expect(default_flags.no_interactive).toBe(false);
|
|
59
|
-
expect(explicit_interactive.no_interactive).toBe(false);
|
|
60
|
-
expect(no_interactive.no_interactive).toBe(true);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("parses git-dir and work-tree into git_args", () => {
|
|
64
|
-
const parsed = parse_branch_runtime_flags([
|
|
65
|
-
"--git-dir",
|
|
66
|
-
"/tmp/repo/.git",
|
|
67
|
-
"--work-tree",
|
|
68
|
-
"/tmp/repo",
|
|
69
|
-
]);
|
|
70
|
-
|
|
71
|
-
expect(parsed.git_args).toBe(
|
|
72
|
-
"--git-dir=/tmp/repo/.git --work-tree=/tmp/repo",
|
|
73
|
-
);
|
|
74
|
-
});
|
|
75
|
-
});
|
package/src/branch-args.ts
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { parse } from "@bomb.sh/args";
|
|
2
|
-
import { InferOutput } from "valibot";
|
|
3
|
-
import { BranchState } from "./valibot-state";
|
|
4
|
-
|
|
5
|
-
type BranchStateRuntime = InferOutput<typeof BranchState>;
|
|
6
|
-
|
|
7
|
-
type ParsedRuntimeFlags = {
|
|
8
|
-
help: boolean;
|
|
9
|
-
version: boolean;
|
|
10
|
-
git_args: string;
|
|
11
|
-
no_interactive: boolean;
|
|
12
|
-
dry_run: boolean;
|
|
13
|
-
branch_state: Partial<BranchStateRuntime>;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const BRANCH_OPTIONS = [
|
|
17
|
-
"user",
|
|
18
|
-
"type",
|
|
19
|
-
"scope",
|
|
20
|
-
"description",
|
|
21
|
-
"ticket",
|
|
22
|
-
"branch-version",
|
|
23
|
-
"checkout",
|
|
24
|
-
] as const;
|
|
25
|
-
|
|
26
|
-
export const GIT_OPTIONS = ["git-dir", "work-tree"] as const;
|
|
27
|
-
|
|
28
|
-
export const BOOLEAN_FLAGS = [
|
|
29
|
-
"interactive",
|
|
30
|
-
"dry-run",
|
|
31
|
-
"help",
|
|
32
|
-
"version",
|
|
33
|
-
] as const;
|
|
34
|
-
|
|
35
|
-
class BranchFlags {
|
|
36
|
-
#runtime: ParsedRuntimeFlags;
|
|
37
|
-
|
|
38
|
-
constructor(runtime: ParsedRuntimeFlags) {
|
|
39
|
-
this.#runtime = runtime;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
get interactive(): boolean {
|
|
43
|
-
return !this.#runtime.no_interactive;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
get dry_run(): boolean {
|
|
47
|
-
return this.#runtime.dry_run;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
get help(): boolean {
|
|
51
|
-
return this.#runtime.help;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
get version(): boolean {
|
|
55
|
-
return this.#runtime.version;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
get git_args(): string {
|
|
59
|
-
return this.#runtime.git_args;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
get branch_state(): Partial<BranchStateRuntime> {
|
|
63
|
-
return this.#runtime.branch_state;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export const branch_flags = new BranchFlags(
|
|
68
|
-
parse_branch_runtime_flags(process.argv.slice(2)),
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
export function parse_branch_runtime_flags(argv: string[]): ParsedRuntimeFlags {
|
|
72
|
-
const parsed = parse(argv, {
|
|
73
|
-
alias: { h: "help", v: "version" },
|
|
74
|
-
boolean: BOOLEAN_FLAGS,
|
|
75
|
-
string: [...BRANCH_OPTIONS, ...GIT_OPTIONS],
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
const branch_state: Partial<BranchStateRuntime> = {};
|
|
79
|
-
BRANCH_OPTIONS.forEach((value) => {
|
|
80
|
-
const cli_value = parsed[value];
|
|
81
|
-
if (cli_value) {
|
|
82
|
-
const str = (
|
|
83
|
-
value === "branch-version" ? "version" : value.replace("-", "_")
|
|
84
|
-
) as keyof BranchStateRuntime;
|
|
85
|
-
if (str === "checkout")
|
|
86
|
-
branch_state[str] =
|
|
87
|
-
(cli_value as "worktree" | "branch" | undefined) ?? "branch";
|
|
88
|
-
else branch_state[str] = cli_value;
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
return {
|
|
93
|
-
help: parsed["help"] === true,
|
|
94
|
-
version: parsed["version"] === true,
|
|
95
|
-
git_args: get_git_args(parsed["git-dir"], parsed["work-tree"]),
|
|
96
|
-
no_interactive: parsed["interactive"] === false,
|
|
97
|
-
dry_run: parsed["dry-run"] === true,
|
|
98
|
-
branch_state: branch_state,
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function get_git_args(
|
|
103
|
-
git_dir: string | undefined,
|
|
104
|
-
work_tree: string | undefined,
|
|
105
|
-
): string {
|
|
106
|
-
return `${git_dir ? `--git-dir=${git_dir}` : ""} ${work_tree ? `--work-tree=${work_tree}` : ""}`.trim();
|
|
107
|
-
}
|
package/src/branch-help.ts
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { execSync } from "child_process";
|
|
2
|
-
import { InferOutput } from "valibot";
|
|
3
|
-
import { branch_flags } from "./branch-args";
|
|
4
|
-
import { get_package_version } from "./utils";
|
|
5
|
-
import {
|
|
6
|
-
infer_scope_from_git,
|
|
7
|
-
infer_ticket_from_git,
|
|
8
|
-
infer_type_from_git,
|
|
9
|
-
} from "./utils/infer";
|
|
10
|
-
import { Config } from "./valibot-state";
|
|
11
|
-
import color from "picocolors";
|
|
12
|
-
|
|
13
|
-
const CLI_FLAG_DEFINITIONS: Record<string, string> = {
|
|
14
|
-
"--interactive": "Run in interactive prompt mode (default behavior).",
|
|
15
|
-
"--dry-run": "Print branch commands without creating a branch or worktree.",
|
|
16
|
-
"--help": "Show help information and exit.",
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const BRANCH_FLAG_DEFINITIONS: Record<string, string> = {
|
|
20
|
-
"--user": "Set branch username segment.",
|
|
21
|
-
"--type": "Set branch type (for example feat, fix, docs).",
|
|
22
|
-
"--scope": "Set branch scope segment.",
|
|
23
|
-
"--description": "Set branch description segment.",
|
|
24
|
-
"--ticket": "Set branch ticket/issue segment.",
|
|
25
|
-
"--branch-version": "Set branch version segment.",
|
|
26
|
-
"--checkout": "Choose branch or worktree checkout mode.",
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const GIT_FLAG_DEFINITIONS: Record<string, string> = {
|
|
30
|
-
"--git-dir": "Set the path to the .git directory.",
|
|
31
|
-
"--work-tree": "Set the path to the working tree root.",
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
function to_definition_lines(definitions: Record<string, string>): string {
|
|
35
|
-
const description_column = 26;
|
|
36
|
-
const minimum_spacing = 2;
|
|
37
|
-
const indent = " ";
|
|
38
|
-
|
|
39
|
-
return Object.entries(definitions)
|
|
40
|
-
.map(([name, description]) => {
|
|
41
|
-
const spaces = Math.max(
|
|
42
|
-
minimum_spacing,
|
|
43
|
-
description_column - name.length,
|
|
44
|
-
);
|
|
45
|
-
return `${indent}${name}${" ".repeat(spaces)}${description}`;
|
|
46
|
-
})
|
|
47
|
-
.join("\n");
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function print_help_text(
|
|
51
|
-
config: InferOutput<typeof Config>,
|
|
52
|
-
config_source: "repository" | "global" | "none",
|
|
53
|
-
) {
|
|
54
|
-
const version = get_package_version();
|
|
55
|
-
|
|
56
|
-
let branch = "(none)";
|
|
57
|
-
try {
|
|
58
|
-
branch =
|
|
59
|
-
execSync(`git ${branch_flags.git_args} branch --show-current`, {
|
|
60
|
-
stdio: "pipe",
|
|
61
|
-
})
|
|
62
|
-
.toString()
|
|
63
|
-
.trim() || "(none)";
|
|
64
|
-
} catch {
|
|
65
|
-
// noop
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const inferred_type =
|
|
69
|
-
infer_type_from_git(config.commit_type.options, branch_flags.git_args) ||
|
|
70
|
-
"Unknown";
|
|
71
|
-
const inferred_ticket = config.check_ticket.infer_ticket
|
|
72
|
-
? infer_ticket_from_git(
|
|
73
|
-
{
|
|
74
|
-
append_hashtag: config.check_ticket.append_hashtag,
|
|
75
|
-
prepend_hashtag: config.check_ticket.prepend_hashtag,
|
|
76
|
-
},
|
|
77
|
-
branch_flags.git_args,
|
|
78
|
-
) || "Unknown"
|
|
79
|
-
: "Infer Disabled";
|
|
80
|
-
const inferred_scope = config.commit_scope.infer_scope_from_branch
|
|
81
|
-
? infer_scope_from_git(
|
|
82
|
-
config.commit_scope.options,
|
|
83
|
-
branch_flags.git_args,
|
|
84
|
-
) || "Unknown"
|
|
85
|
-
: "Infer Disabled";
|
|
86
|
-
|
|
87
|
-
const types = config.commit_type.options
|
|
88
|
-
.map((option) => option.value)
|
|
89
|
-
.join(", ")
|
|
90
|
-
.trim();
|
|
91
|
-
const scopes = config.commit_scope.options
|
|
92
|
-
.map((option) => option.value)
|
|
93
|
-
.join(", ")
|
|
94
|
-
.trim();
|
|
95
|
-
const cli_flags = to_definition_lines(CLI_FLAG_DEFINITIONS);
|
|
96
|
-
const git_flags = to_definition_lines(GIT_FLAG_DEFINITIONS);
|
|
97
|
-
const branch_flags_help = to_definition_lines(BRANCH_FLAG_DEFINITIONS);
|
|
98
|
-
|
|
99
|
-
console.log(`
|
|
100
|
-
${color.green(" better-branch")} ${color.gray("v" + version)}
|
|
101
|
-
|
|
102
|
-
${color.gray("BRANCH")}
|
|
103
|
-
${branch}
|
|
104
|
-
${color.gray("Type")} ${color.blue(inferred_type)} ${color.gray("·")} ${color.gray("Scope")} ${color.cyan(inferred_scope)} ${color.gray("·")} ${color.gray("Ticket")} ${color.magenta(inferred_ticket)}
|
|
105
|
-
|
|
106
|
-
${color.gray("CONFIGURATION")}
|
|
107
|
-
${config_source}
|
|
108
|
-
|
|
109
|
-
${color.gray("Types")}
|
|
110
|
-
${types}
|
|
111
|
-
|
|
112
|
-
${color.gray("Scopes")}
|
|
113
|
-
${scopes}
|
|
114
|
-
|
|
115
|
-
${color.gray("CLI FLAGS")}
|
|
116
|
-
${cli_flags}
|
|
117
|
-
|
|
118
|
-
${color.gray("Branch Flags")}
|
|
119
|
-
${branch_flags_help}
|
|
120
|
-
|
|
121
|
-
${color.gray("Git Flags (Advanced)")}
|
|
122
|
-
${git_flags}
|
|
123
|
-
|
|
124
|
-
`);
|
|
125
|
-
}
|
package/src/branch.ts
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import Configstore from "configstore";
|
|
4
|
-
import { chdir } from "process";
|
|
5
|
-
import { InferOutput, ValiError, parse } from "valibot";
|
|
6
|
-
import { BranchState, CommitState, Config } from "./valibot-state";
|
|
7
|
-
import {
|
|
8
|
-
load_setup,
|
|
9
|
-
get_git_root,
|
|
10
|
-
NOOP_PROMPT_CACHE,
|
|
11
|
-
ConfigSource,
|
|
12
|
-
} from "./utils";
|
|
13
|
-
import { BranchRunnable } from "./prompts/branch-runnable";
|
|
14
|
-
import { BranchCheckoutPrompt } from "./prompts/branch-checkout.prompt";
|
|
15
|
-
import { BranchUserPrompt } from "./prompts/branch-user.prompt";
|
|
16
|
-
import { BranchTypePrompt } from "./prompts/branch-type.prompt";
|
|
17
|
-
import { BranchScopePrompt } from "./prompts/branch-scope.prompt";
|
|
18
|
-
import { BranchTicketPrompt } from "./prompts/branch-ticket.prompt";
|
|
19
|
-
import { BranchVersionPrompt } from "./prompts/branch-version.prompt";
|
|
20
|
-
import { BranchDescriptionPrompt } from "./prompts/branch-description.prompt";
|
|
21
|
-
import { BranchConfirmPrompt } from "./prompts/branch-confirm.prompt";
|
|
22
|
-
import { branch_flags } from "./branch-args";
|
|
23
|
-
import { print_help_text } from "./branch-help";
|
|
24
|
-
import { create_strict_branch_state } from "./utils/no-interactive-validation";
|
|
25
|
-
import { get_package_version } from "./utils";
|
|
26
|
-
import * as p from "@clack/prompts";
|
|
27
|
-
|
|
28
|
-
type PromptCtor = new (
|
|
29
|
-
config: InferOutput<typeof Config>,
|
|
30
|
-
commit_state: InferOutput<typeof BranchState>,
|
|
31
|
-
prompt_cache: Configstore,
|
|
32
|
-
) => BranchRunnable;
|
|
33
|
-
|
|
34
|
-
const promptCtors: PromptCtor[] = [
|
|
35
|
-
BranchCheckoutPrompt,
|
|
36
|
-
BranchUserPrompt,
|
|
37
|
-
BranchTypePrompt,
|
|
38
|
-
BranchTicketPrompt,
|
|
39
|
-
BranchScopePrompt,
|
|
40
|
-
BranchVersionPrompt,
|
|
41
|
-
BranchDescriptionPrompt,
|
|
42
|
-
BranchConfirmPrompt,
|
|
43
|
-
];
|
|
44
|
-
|
|
45
|
-
const { config, config_source } = load_setup(
|
|
46
|
-
" better-branch ",
|
|
47
|
-
branch_flags.git_args,
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
main(config, config_source);
|
|
51
|
-
|
|
52
|
-
async function main(
|
|
53
|
-
config: InferOutput<typeof Config>,
|
|
54
|
-
config_source: ConfigSource,
|
|
55
|
-
) {
|
|
56
|
-
chdir(get_git_root(branch_flags.git_args));
|
|
57
|
-
|
|
58
|
-
if (branch_flags.version) {
|
|
59
|
-
const version = get_package_version();
|
|
60
|
-
p.log.step("Better Commits v" + version);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (branch_flags.help) {
|
|
65
|
-
print_help_text(config, config_source);
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const branch_state = parse(BranchState, branch_flags.branch_state);
|
|
70
|
-
|
|
71
|
-
if (!branch_flags.interactive) {
|
|
72
|
-
try {
|
|
73
|
-
parse(create_strict_branch_state(config), branch_state);
|
|
74
|
-
} catch (err) {
|
|
75
|
-
if (err instanceof ValiError) {
|
|
76
|
-
p.log.error(`Invalid branch input: ${err.message}`);
|
|
77
|
-
} else {
|
|
78
|
-
p.log.error(`Failed to validate branch input: ${err}`);
|
|
79
|
-
}
|
|
80
|
-
process.exit(0);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const prompt_cache = config.cache_last_value
|
|
85
|
-
? new Configstore("better-commits")
|
|
86
|
-
: NOOP_PROMPT_CACHE;
|
|
87
|
-
const prompts_to_run = branch_flags.interactive
|
|
88
|
-
? promptCtors
|
|
89
|
-
: [BranchConfirmPrompt];
|
|
90
|
-
for (const Prompt of prompts_to_run) {
|
|
91
|
-
await new Prompt(config, branch_state, prompt_cache).run();
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// TODO: No idea what's happening here
|
|
96
|
-
// If you don't use CommitState, (even in unreachable code), parse fails on Config
|
|
97
|
-
CommitState;
|