@gogd-core/ggd 0.1.1 → 0.1.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/main.js CHANGED
@@ -24,7 +24,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  ));
25
25
 
26
26
  // apps/ggd/src/main.ts
27
- var import_commander4 = require("commander");
27
+ var import_commander6 = require("commander");
28
28
 
29
29
  // apps/ggd/src/commands/env.ts
30
30
  var import_commander = require("commander");
@@ -81,8 +81,156 @@ function createRunCommand() {
81
81
  return run;
82
82
  }
83
83
 
84
- // apps/ggd/src/commands/completion.ts
84
+ // apps/ggd/src/commands/rsh.ts
85
85
  var import_commander3 = require("commander");
86
+ var import_execa2 = __toESM(require("execa"));
87
+ var readline = __toESM(require("readline"));
88
+ async function getCurrentBranch() {
89
+ const { stdout } = await (0, import_execa2.default)("git", ["symbolic-ref", "--short", "HEAD"]);
90
+ return stdout.trim();
91
+ }
92
+ async function getUncommittedChangeCount() {
93
+ const { stdout } = await (0, import_execa2.default)("git", ["status", "--porcelain"]);
94
+ if (!stdout.trim())
95
+ return 0;
96
+ return stdout.trim().split("\n").length;
97
+ }
98
+ function confirm(message) {
99
+ const rl = readline.createInterface({
100
+ input: process.stdin,
101
+ output: process.stderr
102
+ });
103
+ return new Promise((resolve) => {
104
+ rl.question(message, (answer) => {
105
+ rl.close();
106
+ const normalized = (answer || "Y").trim().toLowerCase();
107
+ resolve(normalized === "y" || normalized === "yes");
108
+ });
109
+ });
110
+ }
111
+ async function resetHard(branch) {
112
+ try {
113
+ await (0, import_execa2.default)("git", ["fetch", "origin", branch], { stdio: "inherit" });
114
+ await (0, import_execa2.default)("git", ["reset", "--hard", `origin/${branch}`], { stdio: "inherit" });
115
+ return 0;
116
+ } catch {
117
+ return 1;
118
+ }
119
+ }
120
+ function createRshCommand() {
121
+ const rsh = new import_commander3.Command("rsh").description("Reset current branch to origin (git reset --hard)").option("-y, --yes", "Skip confirmation prompt").action(async (opts) => {
122
+ try {
123
+ const branch = await getCurrentBranch();
124
+ const changeCount = await getUncommittedChangeCount();
125
+ console.error(`\x1B[36mBranch:\x1B[0m ${branch}`);
126
+ if (changeCount > 0) {
127
+ console.error(`\x1B[33mUncommitted changes: ${changeCount} file(s) will be lost\x1B[0m`);
128
+ }
129
+ console.error(`\x1B[31mTarget: git reset --hard origin/${branch}\x1B[0m`);
130
+ if (!opts.yes) {
131
+ const ok = await confirm("\nProceed? (Y/n): ");
132
+ if (!ok) {
133
+ console.error("Reset aborted.");
134
+ return;
135
+ }
136
+ }
137
+ const exitCode = await resetHard(branch);
138
+ if (exitCode !== 0) {
139
+ process.exitCode = exitCode;
140
+ }
141
+ } catch (error) {
142
+ const message = error instanceof Error ? error.message : String(error);
143
+ console.error(`\x1B[31mError: ${message}\x1B[0m`);
144
+ process.exitCode = 1;
145
+ }
146
+ });
147
+ return rsh;
148
+ }
149
+
150
+ // apps/ggd/src/commands/mt.ts
151
+ var import_commander4 = require("commander");
152
+ var import_execa3 = __toESM(require("execa"));
153
+ async function localBranchExists(branch) {
154
+ try {
155
+ await (0, import_execa3.default)("git", ["show-ref", "--verify", "--quiet", `refs/heads/${branch}`]);
156
+ return true;
157
+ } catch {
158
+ return false;
159
+ }
160
+ }
161
+ async function deleteLocalBranch(branch) {
162
+ await (0, import_execa3.default)("git", ["branch", "-D", branch], { stdio: "inherit" });
163
+ }
164
+ async function switchBranch(branch) {
165
+ await (0, import_execa3.default)("git", ["switch", branch], { stdio: "inherit" });
166
+ }
167
+ async function mergeBranch(source) {
168
+ try {
169
+ await (0, import_execa3.default)("git", ["merge", source], { stdio: "inherit" });
170
+ return 0;
171
+ } catch {
172
+ return 1;
173
+ }
174
+ }
175
+ async function pushBranch(branch) {
176
+ try {
177
+ await (0, import_execa3.default)("git", ["push", "origin", branch], { stdio: "inherit" });
178
+ return 0;
179
+ } catch {
180
+ return 1;
181
+ }
182
+ }
183
+ function createMtCommand() {
184
+ const mt = new import_commander4.Command("mt").description("Merge current branch into target branch").argument("<branch>", "Target branch to merge into").option("-y, --yes", "Skip confirmation prompt").action(async (targetBranch, opts) => {
185
+ try {
186
+ const sourceBranch = await getCurrentBranch();
187
+ if (sourceBranch === targetBranch) {
188
+ console.error("\x1B[31mError: Cannot merge a branch into itself\x1B[0m");
189
+ process.exitCode = 1;
190
+ return;
191
+ }
192
+ console.error(`\x1B[36mSource:\x1B[0m ${sourceBranch}`);
193
+ console.error(`\x1B[36mTarget:\x1B[0m ${targetBranch}`);
194
+ console.error(`\x1B[33mWill: delete local ${targetBranch} (if exists), switch to it, merge ${sourceBranch}\x1B[0m`);
195
+ if (!opts.yes) {
196
+ const ok = await confirm(`
197
+ Merge ${sourceBranch} into ${targetBranch}? (Y/n): `);
198
+ if (!ok) {
199
+ console.error("Merge aborted.");
200
+ return;
201
+ }
202
+ }
203
+ if (await localBranchExists(targetBranch)) {
204
+ console.error(`\x1B[33mDeleting local ${targetBranch}...\x1B[0m`);
205
+ await deleteLocalBranch(targetBranch);
206
+ }
207
+ await switchBranch(targetBranch);
208
+ const exitCode = await mergeBranch(sourceBranch);
209
+ if (exitCode !== 0) {
210
+ console.error(`\x1B[31mMerge failed. You are now on ${targetBranch}.\x1B[0m`);
211
+ process.exitCode = exitCode;
212
+ return;
213
+ }
214
+ console.error(`\x1B[32mMerge successful!\x1B[0m`);
215
+ const shouldPush = await confirm(`Push ${targetBranch} to origin? (Y/n): `);
216
+ if (shouldPush) {
217
+ const pushExit = await pushBranch(targetBranch);
218
+ if (pushExit !== 0) {
219
+ console.error(`\x1B[31mPush failed.\x1B[0m`);
220
+ process.exitCode = pushExit;
221
+ }
222
+ }
223
+ } catch (error) {
224
+ const message = error instanceof Error ? error.message : String(error);
225
+ console.error(`\x1B[31mError: ${message}\x1B[0m`);
226
+ process.exitCode = 1;
227
+ }
228
+ });
229
+ return mt;
230
+ }
231
+
232
+ // apps/ggd/src/commands/completion.ts
233
+ var import_commander5 = require("commander");
86
234
  function detectShell() {
87
235
  const shell = process.env["SHELL"] || "";
88
236
  if (shell.includes("zsh"))
@@ -152,7 +300,7 @@ function getCompletions(program2, args) {
152
300
  }
153
301
  var VALID_SHELLS = ["bash", "zsh", "powershell"];
154
302
  function createCompletionCommand() {
155
- const completion = new import_commander3.Command("completion").description("Output shell completion script").argument("[shell]", "Shell type: bash, zsh, powershell (auto-detected if omitted)").action((shell) => {
303
+ const completion = new import_commander5.Command("completion").description("Output shell completion script").argument("[shell]", "Shell type: bash, zsh, powershell (auto-detected if omitted)").action((shell) => {
156
304
  const resolved = shell ? validateShell(shell) : detectShell();
157
305
  console.log(getCompletionScript(resolved));
158
306
  });
@@ -168,10 +316,12 @@ function validateShell(shell) {
168
316
  }
169
317
 
170
318
  // apps/ggd/src/main.ts
171
- var program = new import_commander4.Command();
172
- program.name("ggd").description("GoGoodDev workspace CLI").version("0.1.0");
319
+ var program = new import_commander6.Command();
320
+ program.name("ggd").description("GoGoodDev workspace CLI").version("0.1.3");
173
321
  program.addCommand(createEnvCommand());
174
322
  program.addCommand(createRunCommand());
323
+ program.addCommand(createRshCommand());
324
+ program.addCommand(createMtCommand());
175
325
  program.addCommand(createCompletionCommand());
176
326
  if (process.argv.includes("--get-completions")) {
177
327
  const args = process.argv.slice(process.argv.indexOf("--get-completions") + 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gogd-core/ggd",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "dependencies": {
5
5
  "commander": "12.1.0",
6
6
  "execa": "5.1.1"
@@ -1,3 +1,5 @@
1
1
  export { createEnvCommand } from './env';
2
2
  export { createRunCommand } from './run';
3
+ export { createRshCommand } from './rsh';
4
+ export { createMtCommand } from './mt';
3
5
  export { createCompletionCommand, getCompletions } from './completion';
@@ -0,0 +1,32 @@
1
+ /**
2
+ * `ggd mt` command — merge current branch into a target branch.
3
+ *
4
+ * Switches to target branch (re-creating from origin if it exists locally),
5
+ * then merges the source branch into it with confirmation.
6
+ */
7
+ import { Command } from 'commander';
8
+ /**
9
+ * Checks if a local branch exists.
10
+ */
11
+ export declare function localBranchExists(branch: string): Promise<boolean>;
12
+ /**
13
+ * Deletes a local branch.
14
+ */
15
+ export declare function deleteLocalBranch(branch: string): Promise<void>;
16
+ /**
17
+ * Switches to a branch.
18
+ */
19
+ export declare function switchBranch(branch: string): Promise<void>;
20
+ /**
21
+ * Merges a source branch into the current branch.
22
+ */
23
+ export declare function mergeBranch(source: string): Promise<number>;
24
+ /**
25
+ * Pushes the current branch to origin.
26
+ */
27
+ export declare function pushBranch(branch: string): Promise<number>;
28
+ /**
29
+ * Creates the `mt` command.
30
+ * Merges current branch into a target branch with confirmation.
31
+ */
32
+ export declare function createMtCommand(): Command;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * `ggd rsh` command — safe git reset --hard to origin/<current-branch>.
3
+ *
4
+ * Shows branch name and uncommitted change count before prompting for confirmation.
5
+ */
6
+ import { Command } from 'commander';
7
+ /**
8
+ * Returns the current git branch name.
9
+ */
10
+ export declare function getCurrentBranch(): Promise<string>;
11
+ /**
12
+ * Returns the number of uncommitted changes (staged + unstaged + untracked).
13
+ */
14
+ export declare function getUncommittedChangeCount(): Promise<number>;
15
+ /**
16
+ * Prompts the user with a yes/no question. Returns true for yes.
17
+ */
18
+ export declare function confirm(message: string): Promise<boolean>;
19
+ /**
20
+ * Executes git reset --hard origin/<branch>.
21
+ */
22
+ export declare function resetHard(branch: string): Promise<number>;
23
+ /**
24
+ * Creates the `rsh` command.
25
+ * Resets current branch to origin/<branch> with confirmation.
26
+ */
27
+ export declare function createRshCommand(): Command;