@vexdo/cli 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.
- package/dist/index.js +46 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -801,12 +801,51 @@ async function exec(opts) {
|
|
|
801
801
|
// src/lib/gh.ts
|
|
802
802
|
import { execFile as execFileCb2 } from "child_process";
|
|
803
803
|
var GH_TIMEOUT_MS = 3e4;
|
|
804
|
+
var GIT_TIMEOUT_MS = 3e4;
|
|
804
805
|
var GhNotFoundError = class extends Error {
|
|
805
806
|
constructor() {
|
|
806
807
|
super("gh CLI not found. Install it: https://cli.github.com");
|
|
807
808
|
this.name = "GhNotFoundError";
|
|
808
809
|
}
|
|
809
810
|
};
|
|
811
|
+
var GitCommandError = class extends Error {
|
|
812
|
+
exitCode;
|
|
813
|
+
stderr;
|
|
814
|
+
constructor(args, exitCode, stderr) {
|
|
815
|
+
super(`git ${args.join(" ")} failed (exit ${String(exitCode)}): ${stderr}`);
|
|
816
|
+
this.name = "GitCommandError";
|
|
817
|
+
this.exitCode = exitCode;
|
|
818
|
+
this.stderr = stderr;
|
|
819
|
+
}
|
|
820
|
+
};
|
|
821
|
+
async function execGit(args, cwd) {
|
|
822
|
+
await new Promise((resolve, reject) => {
|
|
823
|
+
execFileCb2("git", args, { cwd, timeout: GIT_TIMEOUT_MS, encoding: "utf8" }, (error, _stdout, stderr) => {
|
|
824
|
+
if (error) {
|
|
825
|
+
const exitCode = typeof error.code === "number" ? error.code : -1;
|
|
826
|
+
reject(new GitCommandError(args, exitCode, (stderr || error.message).trim()));
|
|
827
|
+
return;
|
|
828
|
+
}
|
|
829
|
+
resolve();
|
|
830
|
+
});
|
|
831
|
+
});
|
|
832
|
+
}
|
|
833
|
+
function isNoUpstreamError(error) {
|
|
834
|
+
const text = error.stderr.toLowerCase();
|
|
835
|
+
return text.includes("no upstream configured for branch") || text.includes("has no upstream branch");
|
|
836
|
+
}
|
|
837
|
+
async function pushCurrentBranch(cwd) {
|
|
838
|
+
try {
|
|
839
|
+
await execGit(["rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}"], cwd);
|
|
840
|
+
await execGit(["push"], cwd);
|
|
841
|
+
} catch (error) {
|
|
842
|
+
if (error instanceof GitCommandError && isNoUpstreamError(error)) {
|
|
843
|
+
await execGit(["push", "--set-upstream", "origin", "HEAD"], cwd);
|
|
844
|
+
return;
|
|
845
|
+
}
|
|
846
|
+
throw error;
|
|
847
|
+
}
|
|
848
|
+
}
|
|
810
849
|
async function checkGhAvailable() {
|
|
811
850
|
await new Promise((resolve, reject) => {
|
|
812
851
|
execFileCb2("gh", ["--version"], { timeout: GH_TIMEOUT_MS, encoding: "utf8" }, (error) => {
|
|
@@ -820,6 +859,11 @@ async function checkGhAvailable() {
|
|
|
820
859
|
}
|
|
821
860
|
async function createPr(opts) {
|
|
822
861
|
const base = opts.base ?? "main";
|
|
862
|
+
try {
|
|
863
|
+
await pushCurrentBranch(opts.cwd);
|
|
864
|
+
} catch (error) {
|
|
865
|
+
throw new Error(`Failed to push current branch before creating PR: ${error instanceof Error ? error.message : String(error)}`);
|
|
866
|
+
}
|
|
823
867
|
return await new Promise((resolve, reject) => {
|
|
824
868
|
execFileCb2(
|
|
825
869
|
"gh",
|
|
@@ -853,7 +897,7 @@ import path5 from "path";
|
|
|
853
897
|
|
|
854
898
|
// src/lib/git.ts
|
|
855
899
|
import { execFile as execFileCb3 } from "child_process";
|
|
856
|
-
var
|
|
900
|
+
var GIT_TIMEOUT_MS2 = 3e4;
|
|
857
901
|
var GitError = class extends Error {
|
|
858
902
|
command;
|
|
859
903
|
exitCode;
|
|
@@ -868,7 +912,7 @@ var GitError = class extends Error {
|
|
|
868
912
|
};
|
|
869
913
|
async function exec2(args, cwd) {
|
|
870
914
|
return new Promise((resolve, reject) => {
|
|
871
|
-
execFileCb3("git", args, { cwd, timeout:
|
|
915
|
+
execFileCb3("git", args, { cwd, timeout: GIT_TIMEOUT_MS2, encoding: "utf8" }, (error, stdout, stderr) => {
|
|
872
916
|
if (error) {
|
|
873
917
|
const exitCode = typeof error.code === "number" ? error.code : -1;
|
|
874
918
|
reject(new GitError(args, exitCode, (stderr || error.message).trim()));
|