@hallaxius/forge 0.1.3 → 0.1.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.
Files changed (45) hide show
  1. package/README.md +160 -158
  2. package/bin/forge.js +2 -2
  3. package/dist/cli.js +12764 -13800
  4. package/package.json +75 -75
  5. package/src/cli.ts +80 -78
  6. package/src/commands/account.ts +80 -0
  7. package/src/commands/alias.ts +66 -66
  8. package/src/commands/branch.ts +46 -46
  9. package/src/commands/ci.ts +28 -28
  10. package/src/commands/clone.ts +100 -100
  11. package/src/commands/commit.ts +88 -88
  12. package/src/commands/config.ts +47 -48
  13. package/src/commands/diff.ts +26 -26
  14. package/src/commands/fetch.ts +20 -20
  15. package/src/commands/help.ts +58 -58
  16. package/src/commands/init.ts +32 -33
  17. package/src/commands/issue.ts +63 -63
  18. package/src/commands/log.ts +29 -29
  19. package/src/commands/merge.ts +37 -37
  20. package/src/commands/pr.ts +65 -65
  21. package/src/commands/push.ts +35 -35
  22. package/src/commands/release.ts +26 -26
  23. package/src/commands/remote.ts +107 -107
  24. package/src/commands/reset.ts +30 -30
  25. package/src/commands/setup.ts +93 -94
  26. package/src/commands/stash.ts +44 -44
  27. package/src/commands/status.ts +74 -74
  28. package/src/commands/sync.ts +20 -20
  29. package/src/commands/tag.ts +41 -41
  30. package/src/commands/undo.ts +27 -27
  31. package/src/commands/version.ts +12 -12
  32. package/src/constants/colors.ts +7 -7
  33. package/src/constants/commit-types.ts +24 -24
  34. package/src/constants/messages.ts +13 -23
  35. package/src/lib/auth.ts +172 -172
  36. package/src/lib/config.ts +108 -108
  37. package/src/lib/git.ts +543 -543
  38. package/src/lib/github.ts +202 -160
  39. package/src/lib/logger.ts +18 -31
  40. package/src/lib/ui.ts +122 -156
  41. package/src/lib/validators.ts +16 -16
  42. package/src/templates/commit-types.json +9 -9
  43. package/src/utils/files.ts +21 -21
  44. package/src/utils/strings.ts +19 -19
  45. package/src/version.const.ts +1 -1
package/src/lib/ui.ts CHANGED
@@ -1,156 +1,122 @@
1
- import boxen from "boxen";
2
- import chalk from "chalk";
3
- import inquirer from "inquirer";
4
- import ora from "ora";
5
- import { colors } from "../constants/colors.js";
6
- import { formatting } from "../constants/messages.js";
7
-
8
- const { prompt } = inquirer;
9
-
10
- function stripAnsi(str: string): string {
11
- return str.replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "");
12
- }
13
-
14
- function padEnd(str: string, len: number): string {
15
- const visibleLen = stripAnsi(str).length;
16
- const diff = len - visibleLen;
17
- return diff > 0 ? str + " ".repeat(diff) : str;
18
- }
19
-
20
- export function showBox(
21
- title: string,
22
- content: string,
23
- options?: Record<string, unknown>,
24
- ): void {
25
- const boxContent = `${chalk.bold(title)}\n\n${content}`;
26
- console.log(
27
- boxen(boxContent, {
28
- padding: 1,
29
- borderColor: "cyan",
30
- borderStyle: "round",
31
- ...options,
32
- }),
33
- );
34
- }
35
-
36
- export function createTable(headers: string[], rows: string[][]): string {
37
- const _colCount = headers.length;
38
- const colWidths: number[] = headers.map((h, i) => {
39
- const maxRow = Math.max(...rows.map((r) => stripAnsi(r[i] || "").length));
40
- return Math.max(stripAnsi(h).length, maxRow);
41
- });
42
-
43
- const separator = `+${colWidths.map((w) => "-".repeat(w + 2)).join("+")}+`;
44
- const headerRow = `| ${headers.map((h, i) => padEnd(h, colWidths[i])).join(" | ")} |`;
45
- const dataRows = rows.map(
46
- (row) =>
47
- "| " +
48
- row.map((cell, i) => padEnd(cell, colWidths[i])).join(" | ") +
49
- " |",
50
- );
51
-
52
- return [separator, headerRow, separator, ...dataRows, separator].join("\n");
53
- }
54
-
55
- export async function withSpinner<T>(
56
- text: string,
57
- fn: () => Promise<T>,
58
- ): Promise<T> {
59
- const spinner = ora({
60
- text,
61
- color: "cyan",
62
- }).start();
63
-
64
- try {
65
- const result = await fn();
66
- spinner.succeed();
67
- return result;
68
- } catch (err) {
69
- spinner.fail();
70
- throw err;
71
- }
72
- }
73
-
74
- export function showHeader(text: string): void {
75
- console.log(chalk.hex(colors.highlight)(text));
76
- console.log(chalk.hex(colors.info)(formatting.header));
77
- }
78
-
79
- export function showSeparator(): void {
80
- console.log(chalk.dim(formatting.separator));
81
- }
82
-
83
- export async function confirm(
84
- msg: string,
85
- defaultValue: boolean = true,
86
- ): Promise<boolean> {
87
- const { value } = await prompt([
88
- {
89
- type: "confirm",
90
- name: "value",
91
- message: msg,
92
- default: defaultValue,
93
- },
94
- ]);
95
- return value;
96
- }
97
-
98
- export async function select<T>(
99
- message: string,
100
- choices: { name: string; value: T }[],
101
- ): Promise<T> {
102
- const { value } = await prompt([
103
- {
104
- type: "list",
105
- name: "value",
106
- message,
107
- choices,
108
- },
109
- ]);
110
- return value;
111
- }
112
-
113
- export async function input(
114
- message: string,
115
- defaultValue?: string,
116
- ): Promise<string> {
117
- const { value } = await prompt([
118
- {
119
- type: "input",
120
- name: "value",
121
- message,
122
- default: defaultValue,
123
- },
124
- ]);
125
- return value;
126
- }
127
-
128
- export async function password(
129
- message: string,
130
- mask: string = "*",
131
- ): Promise<string> {
132
- const { value } = await prompt([
133
- {
134
- type: "password",
135
- name: "value",
136
- message,
137
- mask,
138
- },
139
- ]);
140
- return value;
141
- }
142
-
143
- export async function checkbox(
144
- message: string,
145
- choices: { name: string; value: string; checked?: boolean }[],
146
- ): Promise<string[]> {
147
- const { value } = await prompt([
148
- {
149
- type: "checkbox",
150
- name: "value",
151
- message,
152
- choices,
153
- },
154
- ]);
155
- return value;
156
- }
1
+ import inquirer from "inquirer";
2
+ import ora from "ora";
3
+
4
+ const { prompt } = inquirer;
5
+
6
+ function stripAnsi(str: string): string {
7
+ return str.replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "");
8
+ }
9
+
10
+ function padEnd(str: string, len: number): string {
11
+ const visibleLen = stripAnsi(str).length;
12
+ const diff = len - visibleLen;
13
+ return diff > 0 ? str + " ".repeat(diff) : str;
14
+ }
15
+
16
+ export function createTable(headers: string[], rows: string[][]): string {
17
+ const colWidths: number[] = headers.map((h, i) => {
18
+ const maxRow = Math.max(...rows.map((r) => stripAnsi(r[i] || "").length));
19
+ return Math.max(stripAnsi(h).length, maxRow);
20
+ });
21
+
22
+ const headerRow = headers.map((h, i) => padEnd(h, colWidths[i])).join(" ");
23
+ const dataRows = rows.map((row) =>
24
+ row.map((cell, i) => padEnd(cell, colWidths[i])).join(" "),
25
+ );
26
+
27
+ return [headerRow, ...dataRows].join("\n");
28
+ }
29
+
30
+ export async function withSpinner<T>(
31
+ text: string,
32
+ fn: () => Promise<T>,
33
+ ): Promise<T> {
34
+ const spinner = ora({
35
+ text,
36
+ color: "cyan",
37
+ }).start();
38
+
39
+ try {
40
+ const result = await fn();
41
+ spinner.succeed();
42
+ return result;
43
+ } catch (err) {
44
+ spinner.fail();
45
+ throw err;
46
+ }
47
+ }
48
+
49
+ export async function confirm(
50
+ msg: string,
51
+ defaultValue: boolean = true,
52
+ ): Promise<boolean> {
53
+ const { value } = await prompt([
54
+ {
55
+ type: "confirm",
56
+ name: "value",
57
+ message: msg,
58
+ default: defaultValue,
59
+ },
60
+ ]);
61
+ return value;
62
+ }
63
+
64
+ export async function select<T>(
65
+ message: string,
66
+ choices: { name: string; value: T }[],
67
+ ): Promise<T> {
68
+ const { value } = await prompt([
69
+ {
70
+ type: "list",
71
+ name: "value",
72
+ message,
73
+ choices,
74
+ },
75
+ ]);
76
+ return value;
77
+ }
78
+
79
+ export async function input(
80
+ message: string,
81
+ defaultValue?: string,
82
+ ): Promise<string> {
83
+ const { value } = await prompt([
84
+ {
85
+ type: "input",
86
+ name: "value",
87
+ message,
88
+ default: defaultValue,
89
+ },
90
+ ]);
91
+ return value;
92
+ }
93
+
94
+ export async function password(
95
+ message: string,
96
+ mask: string = "*",
97
+ ): Promise<string> {
98
+ const { value } = await prompt([
99
+ {
100
+ type: "password",
101
+ name: "value",
102
+ message,
103
+ mask,
104
+ },
105
+ ]);
106
+ return value;
107
+ }
108
+
109
+ export async function checkbox(
110
+ message: string,
111
+ choices: { name: string; value: string; checked?: boolean }[],
112
+ ): Promise<string[]> {
113
+ const { value } = await prompt([
114
+ {
115
+ type: "checkbox",
116
+ name: "value",
117
+ message,
118
+ choices,
119
+ },
120
+ ]);
121
+ return value;
122
+ }
@@ -1,16 +1,16 @@
1
- export function validateEmail(email: string): boolean {
2
- const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
3
- return emailRegex.test(email);
4
- }
5
-
6
- export function validateGitHubToken(token: string): boolean {
7
- const tokenRegex = /^(ghp_|gho_|ghu_|ghs_|ghr_|github_pat_)[a-zA-Z0-9]{4,}$/;
8
- return tokenRegex.test(token);
9
- }
10
-
11
- export function validateNotEmpty(input: string): boolean | string {
12
- if (input.length === 0) {
13
- return "Value cannot be empty";
14
- }
15
- return true;
16
- }
1
+ export function validateEmail(email: string): boolean {
2
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
3
+ return emailRegex.test(email);
4
+ }
5
+
6
+ export function validateGitHubToken(token: string): boolean {
7
+ const tokenRegex = /^(ghp_|gho_|ghu_|ghs_|ghr_|github_pat_)[a-zA-Z0-9]{4,}$/;
8
+ return tokenRegex.test(token);
9
+ }
10
+
11
+ export function validateNotEmpty(input: string): boolean | string {
12
+ if (input.length === 0) {
13
+ return "Value cannot be empty";
14
+ }
15
+ return true;
16
+ }
@@ -1,9 +1,9 @@
1
- [
2
- { "value": "feat", "description": "A new feature" },
3
- { "value": "fix", "description": "A bug fix" },
4
- { "value": "docs", "description": "Documentation only changes" },
5
- { "value": "style", "description": "Code style changes (formatting, etc)" },
6
- { "value": "refactor", "description": "Code refactoring" },
7
- { "value": "test", "description": "Adding or fixing tests" },
8
- { "value": "chore", "description": "Build process or tool changes" }
9
- ]
1
+ [
2
+ { "value": "feat", "description": "A new feature" },
3
+ { "value": "fix", "description": "A bug fix" },
4
+ { "value": "docs", "description": "Documentation only changes" },
5
+ { "value": "style", "description": "Code style changes (formatting, etc)" },
6
+ { "value": "refactor", "description": "Code refactoring" },
7
+ { "value": "test", "description": "Adding or fixing tests" },
8
+ { "value": "chore", "description": "Build process or tool changes" }
9
+ ]
@@ -1,21 +1,21 @@
1
- import { existsSync } from "node:fs";
2
- import { mkdir, readFile, writeFile } from "node:fs/promises";
3
- import { dirname } from "node:path";
4
-
5
- export async function ensureDir(dirPath: string): Promise<void> {
6
- if (!existsSync(dirPath)) {
7
- await mkdir(dirPath, { recursive: true });
8
- }
9
- }
10
-
11
- export async function readJSON(path: string): Promise<any> {
12
- const content = await readFile(path, "utf-8");
13
- return JSON.parse(content);
14
- }
15
-
16
- export async function writeJSON(path: string, data: any): Promise<void> {
17
- const directory = dirname(path);
18
- await ensureDir(directory);
19
- const content = JSON.stringify(data, null, 2);
20
- await writeFile(path, content, "utf-8");
21
- }
1
+ import { existsSync } from "node:fs";
2
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
3
+ import { dirname } from "node:path";
4
+
5
+ export async function ensureDir(dirPath: string): Promise<void> {
6
+ if (!existsSync(dirPath)) {
7
+ await mkdir(dirPath, { recursive: true });
8
+ }
9
+ }
10
+
11
+ export async function readJSON(path: string): Promise<any> {
12
+ const content = await readFile(path, "utf-8");
13
+ return JSON.parse(content);
14
+ }
15
+
16
+ export async function writeJSON(path: string, data: any): Promise<void> {
17
+ const directory = dirname(path);
18
+ await ensureDir(directory);
19
+ const content = JSON.stringify(data, null, 2);
20
+ await writeFile(path, content, "utf-8");
21
+ }
@@ -1,19 +1,19 @@
1
- export function capitalize(str: string): string {
2
- if (str.length === 0) return str;
3
- return str.charAt(0).toUpperCase() + str.slice(1);
4
- }
5
-
6
- export function truncate(str: string, maxLength: number): string {
7
- if (str.length <= maxLength) return str;
8
- return `${str.slice(0, maxLength - 3)}...`;
9
- }
10
-
11
- export function formatTimestamp(date: Date): string {
12
- const year = date.getFullYear();
13
- const month = String(date.getMonth() + 1).padStart(2, "0");
14
- const day = String(date.getDate()).padStart(2, "0");
15
- const hours = String(date.getHours()).padStart(2, "0");
16
- const minutes = String(date.getMinutes()).padStart(2, "0");
17
- const seconds = String(date.getSeconds()).padStart(2, "0");
18
- return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
19
- }
1
+ export function capitalize(str: string): string {
2
+ if (str.length === 0) return str;
3
+ return str.charAt(0).toUpperCase() + str.slice(1);
4
+ }
5
+
6
+ export function truncate(str: string, maxLength: number): string {
7
+ if (str.length <= maxLength) return str;
8
+ return `${str.slice(0, maxLength - 3)}...`;
9
+ }
10
+
11
+ export function formatTimestamp(date: Date): string {
12
+ const year = date.getFullYear();
13
+ const month = String(date.getMonth() + 1).padStart(2, "0");
14
+ const day = String(date.getDate()).padStart(2, "0");
15
+ const hours = String(date.getHours()).padStart(2, "0");
16
+ const minutes = String(date.getMinutes()).padStart(2, "0");
17
+ const seconds = String(date.getSeconds()).padStart(2, "0");
18
+ return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
19
+ }
@@ -1,2 +1,2 @@
1
1
  // Auto-generated by build script. DO NOT EDIT.
2
- export const VERSION = "0.1.3";
2
+ export const VERSION = "0.1.4";