@nemo-cli/git 0.1.4 → 0.1.5
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/README.md +48 -7
- package/dist/chunk-Ba_voAlZ.js +32 -0
- package/dist/devtools-DiPu_Fyh.js +3589 -0
- package/dist/devtools-DiPu_Fyh.js.map +1 -0
- package/dist/index.js +47 -60
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { addFiles, colors, createCheckbox, createCommand, createConfirm, createHelpExample, createInput, createNote, createOptions, createSelect, createSpinner, exit, getCurrentBranch, getGitStatus, intro, isEmpty, isString, loadConfig, log, outro, readPackage, safeAwait, x, xASync } from "@nemo-cli/shared";
|
|
2
|
-
import { BigText, ErrorMessage, Message, renderHistViewer, renderStashList, renderStatusViewer } from "@nemo-cli/ui";
|
|
2
|
+
import { BigText, ErrorMessage, Message, renderBranchViewer, renderCommitDetail, renderCommitViewer, renderDiffViewer, renderHistViewer, renderStashList, renderStatusViewer } from "@nemo-cli/ui";
|
|
3
3
|
import path, { dirname, join } from "node:path";
|
|
4
4
|
import readline from "node:readline";
|
|
5
5
|
import { spawn } from "node:child_process";
|
|
@@ -220,7 +220,8 @@ const HELP_MESSAGE$1 = {
|
|
|
220
220
|
main: createHelpExample("ng --version", "ng --help", "ng <command> [option]"),
|
|
221
221
|
branch: createHelpExample("ng branch --version", "ng branch --help", "ng branch <command> [option]"),
|
|
222
222
|
branchDelete: createHelpExample("ng branch delete --version", "ng branch delete --help", "ng branch delete <command> [option]"),
|
|
223
|
-
branchClean: createHelpExample("ng branch clean --version", "ng branch clean --help")
|
|
223
|
+
branchClean: createHelpExample("ng branch clean --version", "ng branch clean --help"),
|
|
224
|
+
branchList: createHelpExample("ng branch list --version", "ng branch list --help", "ng branch list [option]")
|
|
224
225
|
};
|
|
225
226
|
|
|
226
227
|
//#endregion
|
|
@@ -367,7 +368,7 @@ const getRemoteBranches = async () => {
|
|
|
367
368
|
])).stdout.split("\n").filter((line) => line.trim() && !line.includes("->")).map((line) => line.trim().replace(remotePrefix, "")) };
|
|
368
369
|
};
|
|
369
370
|
const currentBranchPrefix = /^\* /;
|
|
370
|
-
const formatBranch$1 = (branch) => branch
|
|
371
|
+
const formatBranch$1 = (branch) => branch.trim().replace(currentBranchPrefix, "");
|
|
371
372
|
const getLocalBranches = async () => {
|
|
372
373
|
const list = (await x("git", ["branch", "--sort=-committerdate"])).stdout.split("\n");
|
|
373
374
|
const currentBranch = list.find((line) => line.includes("*"));
|
|
@@ -549,7 +550,7 @@ const handleGitStash = async (message, options) => {
|
|
|
549
550
|
const { branch = void 0, operation = "manual" } = options || {};
|
|
550
551
|
const now = /* @__PURE__ */ new Date();
|
|
551
552
|
let stashName;
|
|
552
|
-
if (message
|
|
553
|
+
if (message?.trim()) stashName = message.trim();
|
|
553
554
|
else stashName = `${operation}:${currentBranch}@${now.toISOString().replace(/[:.]/g, "-").slice(0, 19)}`;
|
|
554
555
|
const internalId = `${Date.now()}_${operation}_${currentBranch.replace(/[/]/g, "_")}`;
|
|
555
556
|
const [error, result] = await xASync("git", [
|
|
@@ -799,6 +800,29 @@ function branchCommand(command) {
|
|
|
799
800
|
}, { isRemote: options.remote ?? false })));
|
|
800
801
|
Message({ text: "Successfully deleted branches" });
|
|
801
802
|
});
|
|
803
|
+
subCommand.command("list").alias("ls").description("List git branches").addHelpText("after", HELP_MESSAGE$1.branchList).option("-l, --local", "List local branches").option("-r, --remote", "List remote branches").option("-a, --all", "List all branches", true).option("-n, --number <count>", "Limit number of branches to show").action(async (options) => {
|
|
804
|
+
if (options.all || !options.local && !options.remote) {
|
|
805
|
+
await renderBranchViewer(options.number ? Number.parseInt(options.number, 10) : void 0);
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
if (options.local) {
|
|
809
|
+
const { branches } = await getLocalBranches();
|
|
810
|
+
if (!branches || branches.length === 0) {
|
|
811
|
+
log.error("No local branches found. Please check your git repository.");
|
|
812
|
+
return;
|
|
813
|
+
}
|
|
814
|
+
log.info(`Found ${branches.length} local branches:`);
|
|
815
|
+
for (const branch of branches) log.info(branch);
|
|
816
|
+
} else {
|
|
817
|
+
const { branches } = await getRemoteBranches();
|
|
818
|
+
if (!branches || branches.length === 0) {
|
|
819
|
+
log.error("No remote branches found. Please check your git repository.");
|
|
820
|
+
return;
|
|
821
|
+
}
|
|
822
|
+
log.info(`Found ${branches.length} remote branches:`);
|
|
823
|
+
for (const branch of branches) log.info(branch);
|
|
824
|
+
}
|
|
825
|
+
});
|
|
802
826
|
}
|
|
803
827
|
|
|
804
828
|
//#endregion
|
|
@@ -1712,25 +1736,18 @@ const configCommand = (command) => {
|
|
|
1712
1736
|
//#endregion
|
|
1713
1737
|
//#region src/commands/diff.ts
|
|
1714
1738
|
const handleDiff = async (branch, { isLocal }) => {
|
|
1715
|
-
console.log("🚀 : handleDiff : branch:", branch, isLocal);
|
|
1716
1739
|
const currentBranch = await getCurrentBranch();
|
|
1717
1740
|
if (!currentBranch) {
|
|
1718
1741
|
log.error("Could not determine current branch");
|
|
1719
1742
|
return;
|
|
1720
1743
|
}
|
|
1721
|
-
const
|
|
1744
|
+
const targetBranch = branch === currentBranch ? void 0 : branch;
|
|
1722
1745
|
log.show(`Showing diff between ${branch === currentBranch ? "working directory and HEAD" : `${branch} and ${currentBranch}`}`);
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
log.show(line);
|
|
1746
|
+
try {
|
|
1747
|
+
await renderDiffViewer(targetBranch);
|
|
1748
|
+
} catch (error) {
|
|
1749
|
+
log.error(`Failed to display diff viewer: ${error instanceof Error ? error.message : "Unknown error"}${targetBranch ? ` (branch: ${targetBranch})` : ""}`);
|
|
1728
1750
|
}
|
|
1729
|
-
const { exitCode, stderr } = await process;
|
|
1730
|
-
if (exitCode) {
|
|
1731
|
-
log.error(`Failed to diff. Command exited with code ${exitCode}.`);
|
|
1732
|
-
if (stderr) log.error(stderr);
|
|
1733
|
-
} else if (!hasOutput) log.show("No differences found.", { type: "info" });
|
|
1734
1751
|
};
|
|
1735
1752
|
function diffCommand(command) {
|
|
1736
1753
|
command.command("diff").alias("di").description("Show differences between branches or working directory").option("-l, --local", "Diff local branch", true).option("-r, --remote", "Diff remote branch").action(async (options) => {
|
|
@@ -1760,49 +1777,6 @@ const histCommand = (command) => {
|
|
|
1760
1777
|
return command;
|
|
1761
1778
|
};
|
|
1762
1779
|
|
|
1763
|
-
//#endregion
|
|
1764
|
-
//#region src/commands/list.ts
|
|
1765
|
-
function listCommand(command) {
|
|
1766
|
-
command.command("list").alias("ls").description("List git branches").option("-l, --local", "List local branches").option("-r, --remote", "List remote branches").option("-a, --all", "List all branches", true).action(async (options) => {
|
|
1767
|
-
if (options.all) {
|
|
1768
|
-
const { branches: localBranches, currentBranch } = await getLocalBranches();
|
|
1769
|
-
const { branches: remoteBranches } = await getRemoteBranches();
|
|
1770
|
-
if (!localBranches.length && !remoteBranches.length) {
|
|
1771
|
-
log.error("No branches found. Please check your git repository.");
|
|
1772
|
-
return;
|
|
1773
|
-
}
|
|
1774
|
-
log.show(`Local ${localBranches.length} branches`, {
|
|
1775
|
-
symbol: "🔖",
|
|
1776
|
-
colors: colors.bgGreen
|
|
1777
|
-
});
|
|
1778
|
-
for (const branch of localBranches) if (branch === currentBranch) log.show(`${branch} (current)`, { type: "info" });
|
|
1779
|
-
else log.show(branch, { type: "step" });
|
|
1780
|
-
log.show(`Remote ${remoteBranches.length} branches`, {
|
|
1781
|
-
symbol: "🔖",
|
|
1782
|
-
colors: colors.bgYellow
|
|
1783
|
-
});
|
|
1784
|
-
for (const branch of remoteBranches) if (branch === currentBranch) log.show(`${branch} (current)`, { type: "info" });
|
|
1785
|
-
else log.show(branch, { type: "step" });
|
|
1786
|
-
} else if (options.local) {
|
|
1787
|
-
const { branches } = await getLocalBranches();
|
|
1788
|
-
if (!branches || branches.length === 0) {
|
|
1789
|
-
log.error("No local branches found. Please check your git repository.");
|
|
1790
|
-
return;
|
|
1791
|
-
}
|
|
1792
|
-
log.info(`Found ${branches.length} local branches:`);
|
|
1793
|
-
for (const branch of branches) log.info(branch);
|
|
1794
|
-
} else {
|
|
1795
|
-
const { branches } = await getRemoteBranches();
|
|
1796
|
-
if (!branches || branches.length === 0) {
|
|
1797
|
-
log.error("No remote branches found. Please check your git repository.");
|
|
1798
|
-
return;
|
|
1799
|
-
}
|
|
1800
|
-
log.info(`Found ${branches.length} remote branches:`);
|
|
1801
|
-
for (const branch of branches) log.info(branch);
|
|
1802
|
-
}
|
|
1803
|
-
});
|
|
1804
|
-
}
|
|
1805
|
-
|
|
1806
1780
|
//#endregion
|
|
1807
1781
|
//#region src/commands/merge.ts
|
|
1808
1782
|
const handleMerge = async (branch) => {
|
|
@@ -1953,6 +1927,19 @@ function pullCommand(command) {
|
|
|
1953
1927
|
});
|
|
1954
1928
|
}
|
|
1955
1929
|
|
|
1930
|
+
//#endregion
|
|
1931
|
+
//#region src/commands/show.ts
|
|
1932
|
+
const showCommand = (command) => {
|
|
1933
|
+
command.command("show [hash]").description("Show commit details (interactive viewer)").option("-n, --number <count>", "Limit number of commits to show in selector").action(async (hash, options) => {
|
|
1934
|
+
if (hash) await renderCommitDetail(hash);
|
|
1935
|
+
else {
|
|
1936
|
+
const selectedHash = await renderCommitViewer(options.number ? Number.parseInt(options.number, 10) : void 0);
|
|
1937
|
+
if (selectedHash) await renderCommitDetail(selectedHash);
|
|
1938
|
+
}
|
|
1939
|
+
});
|
|
1940
|
+
return command;
|
|
1941
|
+
};
|
|
1942
|
+
|
|
1956
1943
|
//#endregion
|
|
1957
1944
|
//#region src/constants/stash.ts
|
|
1958
1945
|
const HELP_MESSAGE = {
|
|
@@ -2194,7 +2181,6 @@ const pkg = readPackage(import.meta, "..");
|
|
|
2194
2181
|
const init = () => {
|
|
2195
2182
|
const command = createCommand("ng").version(pkg.version).description(`${pkg.name} CLI helper for git`).addHelpText("after", HELP_MESSAGE$1.main);
|
|
2196
2183
|
pullCommand(command);
|
|
2197
|
-
listCommand(command);
|
|
2198
2184
|
pushCommand(command);
|
|
2199
2185
|
checkoutCommand(command);
|
|
2200
2186
|
branchCommand(command);
|
|
@@ -2205,6 +2191,7 @@ const init = () => {
|
|
|
2205
2191
|
commitCommand(command);
|
|
2206
2192
|
statusCommand(command);
|
|
2207
2193
|
histCommand(command);
|
|
2194
|
+
showCommand(command);
|
|
2208
2195
|
configCommand(command);
|
|
2209
2196
|
return command;
|
|
2210
2197
|
};
|