binary-collections 2.0.9 → 2.0.10
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/binaries/binary-executor.cjs +43 -0
- package/{bin → binaries}/clean-nodemodule +0 -0
- package/binaries/clean-nodemodule.cjs +43 -0
- package/binaries/clean-nodemodule.cmd +4 -0
- package/{bin → binaries}/clean-nodemodules +0 -0
- package/binaries/clean-nodemodules.cjs +43 -0
- package/binaries/clean-nodemodules.cmd +5 -0
- package/{bin → binaries}/dev +0 -0
- package/binaries/dev.cjs +43 -0
- package/{bin → binaries}/empty +0 -0
- package/binaries/empty.cjs +43 -0
- package/{bin → binaries}/git-reduce-size +0 -0
- package/binaries/git-reduce-size.cjs +43 -0
- package/binaries/javakill.cjs +43 -0
- package/{bin → binaries}/javakill.cmd +0 -0
- package/{bin → binaries}/kill-process +0 -0
- package/binaries/kill-process.cjs +43 -0
- package/binaries/nodekill.cjs +43 -0
- package/{bin → binaries}/nodekill.ps1 +0 -0
- package/{bin → binaries}/prod +0 -0
- package/binaries/prod.cjs +43 -0
- package/{bin → binaries}/rmfind +0 -0
- package/binaries/rmfind.cjs +43 -0
- package/{bin → binaries}/rmx +0 -0
- package/binaries/rmx.cjs +43 -0
- package/{bin → binaries}/submodule-token +0 -0
- package/binaries/submodule-token.cjs +43 -0
- package/docs-src/clean-github-actions-caches.md +26 -0
- package/docs-src/free-chatgpt.md +26 -0
- package/lib/binary-collections-config.cjs +3 -2
- package/lib/binary-collections-config.mjs +2 -2
- package/lib/binary-collections.cjs +452 -105
- package/lib/binary-collections.mjs +131 -84
- package/lib/changelog.cjs +3 -3
- package/lib/changelog.mjs +177 -171
- package/lib/chunk-4EWQC6GZ.mjs +382 -0
- package/lib/chunk-4ZI7BQKQ.mjs +381 -0
- package/lib/chunk-5J2BEPY5.mjs +83 -0
- package/lib/{chunk-4BYBVEYC.mjs → chunk-66PAU5PS.mjs} +5 -4
- package/lib/chunk-6HHJRKFB.mjs +59 -0
- package/lib/chunk-6S4NXESK.mjs +26 -0
- package/lib/{chunk-ZYAQRPUL.mjs → chunk-7YD7IPFF.mjs} +2 -2
- package/lib/{chunk-SH3L6HHV.mjs → chunk-A2JQXI5Z.mjs} +2 -2
- package/lib/{chunk-EGSSKVDH.mjs → chunk-A3VUZEJK.mjs} +1 -1
- package/lib/chunk-AGZYRDC2.mjs +323 -0
- package/lib/{chunk-VVEZVNIV.mjs → chunk-AI4CVPJ7.mjs} +6 -6
- package/lib/chunk-BDCHCWHD.mjs +136 -0
- package/lib/chunk-BEZKJ25G.mjs +140 -0
- package/lib/chunk-DI5MDPSN.mjs +386 -0
- package/lib/{chunk-ONIBBBQ3.mjs → chunk-E6FDDAOO.mjs} +4 -3
- package/lib/chunk-FKI7IEB5.mjs +172 -0
- package/lib/chunk-GJTGHXRA.mjs +356 -0
- package/lib/{chunk-YV7DO3YV.mjs → chunk-HLGOWBEO.mjs} +1 -1
- package/lib/chunk-HMRMTYZM.mjs +40 -0
- package/lib/chunk-HN52G2YL.mjs +305 -0
- package/lib/chunk-HO6GHCOB.mjs +385 -0
- package/lib/chunk-LEM5OMRP.mjs +384 -0
- package/lib/{chunk-YX5U7XDR.mjs → chunk-M3YIYRHT.mjs} +6 -5
- package/lib/chunk-O6SWBEOQ.mjs +81 -0
- package/lib/{chunk-JGR2NW6D.mjs → chunk-PDSXF5HY.mjs} +3 -3
- package/lib/{chunk-AASHBCRW.mjs → chunk-QQ4A6DLD.mjs} +8 -0
- package/lib/chunk-RCP7DHVY.mjs +190 -0
- package/lib/chunk-SBNDSKG5.mjs +136 -0
- package/lib/chunk-U6SO4QEV.mjs +320 -0
- package/lib/{chunk-APBWENF6.mjs → chunk-V3N3JEUF.mjs} +3 -3
- package/lib/chunk-XD6BJK6Q.mjs +351 -0
- package/lib/chunk-XVBFFVCJ.mjs +209 -0
- package/lib/chunk-YXSFGA2D.mjs +383 -0
- package/lib/clean-github-actions-caches.cjs +243 -148
- package/lib/clean-github-actions-caches.mjs +3 -2
- package/lib/del-gradle.cjs +2 -2
- package/lib/del-gradle.js +1 -1
- package/lib/del-gradle.mjs +2 -2
- package/lib/del-node-modules.cjs +2 -2
- package/lib/del-node-modules.js +1 -1
- package/lib/del-node-modules.mjs +2 -2
- package/lib/del-ps.cjs +29 -8
- package/lib/del-ps.js +2 -2
- package/lib/del-ps.mjs +7 -5
- package/lib/del-yarn-caches.cjs +26 -5
- package/lib/del-yarn-caches.js +38 -3
- package/lib/del-yarn-caches.mjs +6 -6
- package/lib/find-node-modules-cli.cjs +5 -4
- package/lib/find-node-modules-cli.js +1 -1
- package/lib/find-node-modules-cli.mjs +2 -2
- package/lib/find-node-modules.cjs +4 -3
- package/lib/{find-node-modules.d.ts → find-node-modules.d.cts} +1 -1
- package/lib/find-node-modules.mjs +2 -2
- package/lib/free-chatgpt.cjs +548 -0
- package/lib/free-chatgpt.js +51 -0
- package/lib/free-chatgpt.mjs +50 -0
- package/lib/git/gitattributes.cjs +1 -1
- package/lib/git/{gitattributes.d.mts → gitattributes.d.cts} +5 -7
- package/lib/git/gitattributes.mjs +2 -2
- package/lib/git/line-endings.cjs +297 -64
- package/lib/git/line-endings.mjs +4 -4
- package/lib/git/normalize.cjs +26 -36
- package/lib/git/normalize.mjs +2 -2
- package/lib/git/permissions.cjs +77 -11
- package/lib/git/permissions.mjs +3 -3
- package/lib/git/pull-strategy.cjs +76 -9
- package/lib/git/pull-strategy.mjs +3 -3
- package/lib/git/user-config.cjs +266 -83
- package/lib/git/user-config.mjs +4 -4
- package/lib/git/utils.cjs +40 -60
- package/lib/git/utils.mjs +2 -2
- package/lib/git-diff-cli.cjs +651 -0
- package/lib/git-diff-cli.d.ts +1 -0
- package/lib/git-diff-cli.js +15 -0
- package/lib/git-diff-cli.mjs +16 -0
- package/lib/git-diff.cjs +657 -58
- package/lib/git-diff.d.ts +38 -83
- package/lib/git-diff.js +152 -0
- package/lib/git-diff.mjs +23 -85
- package/lib/git-fix.cjs +685 -97
- package/lib/git-fix.mjs +14 -13
- package/lib/git-purge.cjs +3 -3
- package/lib/git-purge.d.cts +1 -0
- package/lib/git-purge.mjs +43 -37
- package/lib/index.cjs +7 -6
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -5
- package/lib/index.mjs +4 -4
- package/lib/npm-run-series.cjs +3 -3
- package/lib/npm-run-series.mjs +42 -36
- package/lib/package-resolutions-updater.cjs +5 -5
- package/lib/package-resolutions-updater.mjs +266 -309
- package/lib/print-directory-tree.cjs +275 -210
- package/lib/print-directory-tree.mjs +2 -2
- package/lib/ps/connected-domain.cjs +25 -2
- package/lib/ps/connected-domain.d.ts +10 -2
- package/lib/ps/connected-domain.js +5 -2
- package/lib/ps/connected-domain.mjs +8 -4
- package/lib/ps/index.cjs +345 -322
- package/lib/ps/index.d.mjs +1 -1
- package/lib/ps/index.js +1 -1
- package/lib/ps/index.mjs +179 -182
- package/lib/ps/isWin.cjs +24 -1
- package/lib/ps/isWin.d.ts +1 -1
- package/lib/ps/isWin.js +3 -1
- package/lib/ps/isWin.mjs +8 -4
- package/lib/ps/table-parser.cjs +167 -159
- package/lib/ps/table-parser.d.ts +5 -0
- package/lib/ps/table-parser.js +10 -4
- package/lib/ps/table-parser.mjs +9 -5
- package/lib/remove-module.cjs +262 -0
- package/lib/remove-module.d.mts +1 -0
- package/lib/remove-module.mjs +111 -0
- package/lib/rmpath.cjs +274 -0
- package/lib/rmpath.d.mts +3 -0
- package/lib/rmpath.mjs +108 -0
- package/lib/submodule-install.cjs +264 -86
- package/lib/submodule-install.mjs +51 -3
- package/lib/submodule-remove-cli.cjs +103 -0
- package/lib/submodule-remove-cli.d.ts +1 -0
- package/lib/submodule-remove-cli.js +31 -0
- package/lib/submodule-remove-cli.mjs +28 -0
- package/lib/submodule-remove.cjs +43 -0
- package/lib/submodule-remove.d.cts +2 -0
- package/lib/submodule-remove.mjs +6 -0
- package/lib/utils/chatgpt.cjs +383 -0
- package/lib/utils/chatgpt.d.ts +31 -0
- package/lib/utils/chatgpt.js +541 -0
- package/lib/utils/chatgpt.mjs +8 -0
- package/lib/{utils.cjs → utils/index.cjs} +1 -1
- package/lib/{utils.mjs → utils/index.mjs} +2 -2
- package/lib/yarn-reinstall.cjs +172 -38
- package/lib/yarn-reinstall.mjs +2 -2
- package/package.json +91 -71
- package/readme.md +43 -69
- package/releases/readme.md +36 -0
- package/test/README.md +101 -0
- package/test/package.json +2 -1
- package/test-project/readme.md +26 -0
- package/tmp/test-repo/README.md +35 -0
- package/tmp/test-repo/package.json +1 -1
- package/tmp/typedoc/readme.md +320 -0
- package/bin/bash-dummy +0 -56
- package/bin/bash-dummy.cmd +0 -25
- package/bin/dir-tree.cmd +0 -7
- package/bin/git-diff +0 -4
- package/bin/git-diff.cmd +0 -7
- package/bin/git-fix +0 -36
- package/bin/git-fix.cmd +0 -7
- package/bin/rmpath +0 -70
- package/bin/submodule-install.txt +0 -118
- package/bin/submodule-remove +0 -46
- package/bin/submodule.txt +0 -172
- package/lib/binary-collections-config.d.mts +0 -18
- package/lib/binary-collections-config.js +0 -39
- package/lib/binary-collections.d.mts +0 -137
- package/lib/binary-collections.d.ts +0 -137
- package/lib/changelog.d.mts +0 -2
- package/lib/changelog.js +0 -226
- package/lib/chunk-DPKAJKFO.mjs +0 -171
- package/lib/chunk-G3THLIDT.mjs +0 -200
- package/lib/chunk-W3ENOM53.mjs +0 -18
- package/lib/clean-github-actions-caches.d.mts +0 -169
- package/lib/clean-github-actions-caches.d.ts +0 -169
- package/lib/del-gradle.d.mts +0 -2
- package/lib/del-node-modules.d.mts +0 -2
- package/lib/del-ps.d.mts +0 -2
- package/lib/del-yarn-caches.d.mts +0 -2
- package/lib/find-node-modules-cli.d.mts +0 -1
- package/lib/find-node-modules.d.mts +0 -13
- package/lib/find-node-modules.js +0 -53
- package/lib/git/line-endings.d.mts +0 -83
- package/lib/git/line-endings.d.ts +0 -83
- package/lib/git/normalize.d.mts +0 -43
- package/lib/git/normalize.d.ts +0 -43
- package/lib/git/permissions.d.mts +0 -17
- package/lib/git/permissions.d.ts +0 -17
- package/lib/git/pull-strategy.d.mts +0 -15
- package/lib/git/pull-strategy.d.ts +0 -15
- package/lib/git/user-config.d.mts +0 -105
- package/lib/git/user-config.d.ts +0 -105
- package/lib/git/utils.d.mts +0 -69
- package/lib/git/utils.d.ts +0 -69
- package/lib/git-diff.d.mts +0 -84
- package/lib/git-fix.d.mts +0 -141
- package/lib/git-fix.d.ts +0 -141
- package/lib/git-purge.d.mts +0 -2
- package/lib/git-purge.js +0 -59
- package/lib/index.d.mts +0 -1
- package/lib/npm-run-series.d.mts +0 -1
- package/lib/npm-run-series.d.ts +0 -2
- package/lib/npm-run-series.js +0 -86
- package/lib/package-resolutions-updater.d.ts +0 -352
- package/lib/print-directory-tree.d.mts +0 -234
- package/lib/print-directory-tree.d.ts +0 -234
- package/lib/ps/connected-domain.d.mts +0 -3
- package/lib/ps/index.d.d.mts +0 -26
- package/lib/ps/index.d.d.ts +0 -26
- package/lib/ps/index.d.mts +0 -26
- package/lib/ps/isWin.d.mts +0 -3
- package/lib/ps/table-parser.d.mts +0 -3
- package/lib/submodule-install.d.mts +0 -121
- package/lib/submodule-install.d.ts +0 -121
- package/lib/utils.d.mts +0 -40
- package/lib/utils.js +0 -181
- package/lib/yarn-reinstall.d.mts +0 -49
- package/lib/yarn-reinstall.d.ts +0 -49
- package/src/package-resolutions-updater.mjs +0 -350
- package/src/print-directory-tree.cjs +0 -234
- package/src/ps/index.js +0 -286
- package/src/yarn-reinstall.cjs +0 -49
- /package/{bin → binaries}/nodekill +0 -0
- /package/{bin → binaries}/nodekill.cmd +0 -0
- /package/lib/{binary-collections-config.d.ts → binary-collections-config.d.cts} +0 -0
- /package/lib/{changelog.d.ts → changelog.d.cts} +0 -0
- /package/lib/{git-purge.d.ts → free-chatgpt.d.ts} +0 -0
- /package/lib/{git-diff.d.cts → npm-run-series.d.cts} +0 -0
- /package/lib/{utils.d.ts → utils/index.d.cts} +0 -0
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
__require,
|
|
4
|
+
init_esm_shims
|
|
5
|
+
} from "./chunk-QQ4A6DLD.mjs";
|
|
6
|
+
|
|
7
|
+
// src/utils/chatgpt.js
|
|
8
|
+
init_esm_shims();
|
|
9
|
+
import fs from "fs-extra";
|
|
10
|
+
import puppeteer from "puppeteer-extra";
|
|
11
|
+
import StealthPlugin from "puppeteer-extra-plugin-stealth";
|
|
12
|
+
import path from "upath";
|
|
13
|
+
import { pathToFileURL } from "url";
|
|
14
|
+
var COOKIE_DIR = path.join(process.cwd(), "tmp", "cookies");
|
|
15
|
+
var DEFAULT_COOKIE_PATH = path.join(COOKIE_DIR, "cookies.json");
|
|
16
|
+
fs.ensureDirSync(COOKIE_DIR);
|
|
17
|
+
async function saveCookies(page, path2 = DEFAULT_COOKIE_PATH) {
|
|
18
|
+
const cookies = await page.cookies();
|
|
19
|
+
fs.writeFileSync(path2, JSON.stringify(cookies, null, 2));
|
|
20
|
+
}
|
|
21
|
+
function getCookiePathForUrl(url) {
|
|
22
|
+
try {
|
|
23
|
+
const { hostname } = new URL(url);
|
|
24
|
+
return path.join(COOKIE_DIR, `cookies_${hostname}.json`);
|
|
25
|
+
} catch {
|
|
26
|
+
return DEFAULT_COOKIE_PATH;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async function navigatePage(page, url) {
|
|
30
|
+
const cookiePath = getCookiePathForUrl(url);
|
|
31
|
+
const cookies = loadCookies(cookiePath);
|
|
32
|
+
if (cookies) {
|
|
33
|
+
await page.setCookie(...cookies);
|
|
34
|
+
}
|
|
35
|
+
await page.goto(url, { waitUntil: "networkidle0" });
|
|
36
|
+
await page.evaluate(() => {
|
|
37
|
+
window.__domStillUpdating = true;
|
|
38
|
+
if (window.__domObserver) {
|
|
39
|
+
window.__domObserver.disconnect();
|
|
40
|
+
}
|
|
41
|
+
window.__domObserver = new MutationObserver(() => {
|
|
42
|
+
window.__lastDomMutation = Date.now();
|
|
43
|
+
});
|
|
44
|
+
window.__lastDomMutation = Date.now();
|
|
45
|
+
window.__domObserver.observe(document.body, {
|
|
46
|
+
childList: true,
|
|
47
|
+
subtree: true,
|
|
48
|
+
attributes: true,
|
|
49
|
+
characterData: true
|
|
50
|
+
});
|
|
51
|
+
setTimeout(() => {
|
|
52
|
+
window.__domStillUpdating = false;
|
|
53
|
+
window.__domObserver.disconnect();
|
|
54
|
+
}, 3e4);
|
|
55
|
+
});
|
|
56
|
+
const waitForDomIdle = async (idleMs = 1e3, timeout = 1e4) => {
|
|
57
|
+
const start = Date.now();
|
|
58
|
+
while (Date.now() - start < timeout) {
|
|
59
|
+
const lastMutation = await page.evaluate(() => window.__lastDomMutation);
|
|
60
|
+
const idle = Date.now() - lastMutation;
|
|
61
|
+
if (idle >= idleMs) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
65
|
+
}
|
|
66
|
+
throw new Error("DOM did not stabilize within timeout");
|
|
67
|
+
};
|
|
68
|
+
return { waitForDomIdle };
|
|
69
|
+
}
|
|
70
|
+
function loadCookies(cookieFilePath = DEFAULT_COOKIE_PATH) {
|
|
71
|
+
if (!fs.existsSync(cookieFilePath)) return null;
|
|
72
|
+
return JSON.parse(fs.readFileSync(cookieFilePath));
|
|
73
|
+
}
|
|
74
|
+
async function writeQuestion(page, question) {
|
|
75
|
+
const questions = question.split("\n");
|
|
76
|
+
const promptTextarea = await page.waitForSelector("#prompt-textarea", { timeout: 3e4 });
|
|
77
|
+
if (!promptTextarea) {
|
|
78
|
+
console.log(
|
|
79
|
+
"Cannot find the prompt input on the webpage. Please check whether you have access to chat.openai.com without logging in via your browser."
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
await page.evaluate(() => {
|
|
83
|
+
document.querySelector("#prompt-textarea").innerHTML = `<p></p>`;
|
|
84
|
+
});
|
|
85
|
+
if (questions.length === 1) {
|
|
86
|
+
await page.type("#prompt-textarea", questions[0], { delay: 100 });
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
for (const q of questions) {
|
|
90
|
+
await page.type("#prompt-textarea", q, { delay: 100 });
|
|
91
|
+
if (q !== questions[questions.length - 1]) {
|
|
92
|
+
await page.keyboard.down("Shift");
|
|
93
|
+
await page.keyboard.press("Enter");
|
|
94
|
+
await page.keyboard.up("Shift");
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
async function clickSubmitButton(page) {
|
|
99
|
+
try {
|
|
100
|
+
const fruitjuiceSendButton = await page.evaluate(() => {
|
|
101
|
+
return document.querySelector('[data-testid="fruitjuice-send-button"]') !== null;
|
|
102
|
+
});
|
|
103
|
+
const sendButton = await page.evaluate(() => {
|
|
104
|
+
return document.querySelector('[data-testid="send-button"]') !== null;
|
|
105
|
+
});
|
|
106
|
+
if (fruitjuiceSendButton) {
|
|
107
|
+
await page.click('[data-testid="fruitjuice-send-button"]');
|
|
108
|
+
} else if (sendButton) {
|
|
109
|
+
await page.click('[data-testid="send-button"]');
|
|
110
|
+
} else {
|
|
111
|
+
console.log("Neither send button is present");
|
|
112
|
+
}
|
|
113
|
+
} catch (e) {
|
|
114
|
+
console.log(`Failed to click the send button: ${e}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
var lastMessageId = null;
|
|
118
|
+
var messageCount = 0;
|
|
119
|
+
var is_streaming = false;
|
|
120
|
+
function sleep(ms) {
|
|
121
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
122
|
+
}
|
|
123
|
+
async function waitForInitialResponse(page, timeout = 3e4) {
|
|
124
|
+
const startTime = Date.now();
|
|
125
|
+
while (Date.now() - startTime < timeout) {
|
|
126
|
+
const assistantMessages = await page.$$('[data-message-author-role="assistant"]');
|
|
127
|
+
const currentMessageCount = assistantMessages.length;
|
|
128
|
+
if (currentMessageCount > messageCount) {
|
|
129
|
+
const lastMessage = assistantMessages[assistantMessages.length - 1];
|
|
130
|
+
const isThinking = await lastMessage.$(".result-thinking");
|
|
131
|
+
if (!isThinking) {
|
|
132
|
+
lastMessageId = await page.evaluate((element) => element.getAttribute("data-message-id"), lastMessage);
|
|
133
|
+
messageCount = currentMessageCount;
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
await sleep(100);
|
|
138
|
+
}
|
|
139
|
+
console.log("Timed out waiting for the initial response.");
|
|
140
|
+
}
|
|
141
|
+
async function handleStreamingResponse(page, outputFile = path.join(process.cwd(), "tmp/response.txt")) {
|
|
142
|
+
let previousText = "";
|
|
143
|
+
let completeResponse = "";
|
|
144
|
+
let newContentDetected = false;
|
|
145
|
+
while (!newContentDetected) {
|
|
146
|
+
const assistantMessages = await page.$$('[data-message-author-role="assistant"]');
|
|
147
|
+
if (assistantMessages.length > 0) {
|
|
148
|
+
const lastMessage = assistantMessages[assistantMessages.length - 1];
|
|
149
|
+
const currentMessageId = await page.evaluate((element) => element.getAttribute("data-message-id"), lastMessage);
|
|
150
|
+
if (currentMessageId === lastMessageId) {
|
|
151
|
+
const currentText = await page.evaluate((element) => element.textContent, lastMessage);
|
|
152
|
+
console.log(`Current text: ${currentText}`);
|
|
153
|
+
if (currentText !== previousText) {
|
|
154
|
+
if (is_streaming) {
|
|
155
|
+
process.stdout.write(currentText.slice(previousText.length));
|
|
156
|
+
} else {
|
|
157
|
+
completeResponse += currentText.slice(previousText.length);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
previousText = currentText;
|
|
161
|
+
const isStreaming = await lastMessage.$(".result-streaming");
|
|
162
|
+
if (!isStreaming) {
|
|
163
|
+
newContentDetected = true;
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
lastMessageId = currentMessageId;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
await sleep(100);
|
|
170
|
+
}
|
|
171
|
+
if (!is_streaming) {
|
|
172
|
+
console.log(completeResponse.trim());
|
|
173
|
+
console.log("\n\n");
|
|
174
|
+
fs.ensureDirSync(path.dirname(outputFile));
|
|
175
|
+
fs.writeFileSync(outputFile, completeResponse.trim());
|
|
176
|
+
console.log(`Response saved to ${outputFile}`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
async function isLoggedIn(page) {
|
|
180
|
+
const result = await page.evaluate(() => {
|
|
181
|
+
const loginButton = document.querySelector('[data-testid="login-button"]');
|
|
182
|
+
return !(loginButton && loginButton.offsetParent !== null);
|
|
183
|
+
});
|
|
184
|
+
return result === true;
|
|
185
|
+
}
|
|
186
|
+
async function createBrowser(browserOptions = {}) {
|
|
187
|
+
return await puppeteer.use(StealthPlugin()).launch({ headless: false, userDataDir: path.join(process.cwd(), "tmp/puppeteer-profile"), ...browserOptions });
|
|
188
|
+
}
|
|
189
|
+
async function loginToChatGpt() {
|
|
190
|
+
const browser = await createBrowser({ headless: false });
|
|
191
|
+
const page = (await browser.pages()).length > 0 ? (await browser.pages())[0] : await browser.newPage();
|
|
192
|
+
const url = "https://chat.openai.com";
|
|
193
|
+
const navigate = await navigatePage(page, url);
|
|
194
|
+
await navigate.waitForDomIdle(2e3, 1e4);
|
|
195
|
+
const loginButtonExists = await page.evaluate(() => {
|
|
196
|
+
return document.querySelector('[data-testid="login-button"]') !== null;
|
|
197
|
+
});
|
|
198
|
+
if (loginButtonExists) {
|
|
199
|
+
console.log("Login button found, clicking to log in...");
|
|
200
|
+
await page.click('[data-testid="login-button"]');
|
|
201
|
+
await page.waitForNavigation({ waitUntil: "networkidle0" });
|
|
202
|
+
console.log("Login process completed.");
|
|
203
|
+
} else {
|
|
204
|
+
console.log("No login required - user appears to be already logged in.");
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
async function runChatGpt(chatgptOptions = {}) {
|
|
208
|
+
const headless = chatgptOptions.headless !== void 0 ? chatgptOptions.headless : true;
|
|
209
|
+
const questionFile = chatgptOptions.questionFile;
|
|
210
|
+
let question = chatgptOptions.question;
|
|
211
|
+
const responseFile = chatgptOptions.responseFile || path.join(process.cwd(), "tmp", "response.txt");
|
|
212
|
+
const noInputProvided = !question && !questionFile;
|
|
213
|
+
const questionIsEmpty = question && question.trim().length === 0;
|
|
214
|
+
const questionFileIsEmpty = questionFile && questionFile.trim().length === 0;
|
|
215
|
+
if (noInputProvided || questionIsEmpty || questionFileIsEmpty) {
|
|
216
|
+
throw new Error("You must provide a question or a question file.");
|
|
217
|
+
}
|
|
218
|
+
const browser = await createBrowser({ headless });
|
|
219
|
+
const page = (await browser.pages()).length > 0 ? (await browser.pages())[0] : await browser.newPage();
|
|
220
|
+
const url = "https://chat.openai.com";
|
|
221
|
+
const navigate = await navigatePage(page, url);
|
|
222
|
+
await navigate.waitForDomIdle(2e3, 15e3);
|
|
223
|
+
try {
|
|
224
|
+
const tempChatButton = await page.$('button[aria-label="Turn on temporary chat"]');
|
|
225
|
+
if (tempChatButton) {
|
|
226
|
+
await page.evaluate((el) => el.click(), tempChatButton);
|
|
227
|
+
console.log("Successfully clicked temporary chat button");
|
|
228
|
+
await navigate.waitForDomIdle(1e3, 1e4);
|
|
229
|
+
} else {
|
|
230
|
+
console.log("Temporary chat button not found, proceeding without it.");
|
|
231
|
+
}
|
|
232
|
+
} catch (error) {
|
|
233
|
+
console.log(`Failed to click temporary chat button: ${error.message}`);
|
|
234
|
+
}
|
|
235
|
+
if (question) {
|
|
236
|
+
await writeQuestion(page, question);
|
|
237
|
+
await clickSubmitButton(page);
|
|
238
|
+
await navigate.waitForDomIdle(1e3, 3e4);
|
|
239
|
+
await waitForInitialResponse(page);
|
|
240
|
+
await handleStreamingResponse(page, responseFile);
|
|
241
|
+
await saveCookies(page, getCookiePathForUrl(url));
|
|
242
|
+
} else if (questionFile) {
|
|
243
|
+
await navigate.waitForDomIdle(2e3, 1e4);
|
|
244
|
+
const isUserLoggedIn = await isLoggedIn(page);
|
|
245
|
+
console.log(`Login status: ${isUserLoggedIn ? "Logged in" : "Not logged in"}`);
|
|
246
|
+
if (!isUserLoggedIn) {
|
|
247
|
+
console.log(
|
|
248
|
+
"Not logged in. Please log in to ChatGPT in the browser window, then close it and run the command again."
|
|
249
|
+
);
|
|
250
|
+
return loginToChatGpt();
|
|
251
|
+
}
|
|
252
|
+
const plusButtonExists = await page.evaluate(() => {
|
|
253
|
+
const button = document.querySelector('[data-testid="composer-plus-btn"]');
|
|
254
|
+
return button !== null;
|
|
255
|
+
});
|
|
256
|
+
if (plusButtonExists) {
|
|
257
|
+
await page.click('[data-testid="composer-plus-btn"]');
|
|
258
|
+
await sleep(500);
|
|
259
|
+
const menuItems = await page.$$('[role="menuitem"]');
|
|
260
|
+
let clicked = false;
|
|
261
|
+
for (const item of menuItems) {
|
|
262
|
+
const text = await page.evaluate((el) => el.innerText, item);
|
|
263
|
+
if (text && text.includes("Add photos") && text.includes("files")) {
|
|
264
|
+
await item.hover();
|
|
265
|
+
clicked = true;
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
if (!clicked) {
|
|
270
|
+
console.log('Could not find the "Add photos & files" menu item.');
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
try {
|
|
274
|
+
await sleep(1e3);
|
|
275
|
+
const fileInput = await page.waitForSelector('input[type="file"]', { timeout: 1e4 });
|
|
276
|
+
if (fileInput) {
|
|
277
|
+
console.log(`Uploading file: ${questionFile}`);
|
|
278
|
+
await fileInput.uploadFile(questionFile);
|
|
279
|
+
await navigate.waitForDomIdle(2e3, 15e3);
|
|
280
|
+
console.log("File uploaded successfully");
|
|
281
|
+
await clickSubmitButton(page);
|
|
282
|
+
await navigate.waitForDomIdle(1e3, 3e4);
|
|
283
|
+
await waitForInitialResponse(page);
|
|
284
|
+
await handleStreamingResponse(page, responseFile);
|
|
285
|
+
} else {
|
|
286
|
+
console.log("Could not find file input element");
|
|
287
|
+
}
|
|
288
|
+
} catch (error) {
|
|
289
|
+
console.log(`Error uploading file: ${error.message}`);
|
|
290
|
+
}
|
|
291
|
+
} else {
|
|
292
|
+
console.log('Could not find the [data-testid="composer-plus-btn"] button.');
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
await browser.close();
|
|
296
|
+
}
|
|
297
|
+
var isMain = false;
|
|
298
|
+
try {
|
|
299
|
+
if (typeof __require !== "undefined" && typeof module !== "undefined" && __require.main === module) {
|
|
300
|
+
isMain = true;
|
|
301
|
+
}
|
|
302
|
+
} catch (_e) {
|
|
303
|
+
}
|
|
304
|
+
try {
|
|
305
|
+
const mainArg = process.argv[1] && path.resolve(process.argv[1]);
|
|
306
|
+
if (mainArg && import.meta.url === pathToFileURL(mainArg).href) {
|
|
307
|
+
isMain = true;
|
|
308
|
+
}
|
|
309
|
+
} catch (_e) {
|
|
310
|
+
}
|
|
311
|
+
if (isMain) {
|
|
312
|
+
(async () => {
|
|
313
|
+
try {
|
|
314
|
+
await runChatGpt({ headless: false, questionFile: path.join(process.cwd(), "tmp/gpt-question.txt") });
|
|
315
|
+
} catch (error) {
|
|
316
|
+
console.error("Error running ChatGPT:", error);
|
|
317
|
+
}
|
|
318
|
+
})();
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export {
|
|
322
|
+
runChatGpt
|
|
323
|
+
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
require_gitattributes
|
|
4
|
-
} from "./chunk-JGR2NW6D.mjs";
|
|
5
2
|
import {
|
|
6
3
|
require_utils
|
|
7
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-A3VUZEJK.mjs";
|
|
5
|
+
import {
|
|
6
|
+
require_gitattributes
|
|
7
|
+
} from "./chunk-PDSXF5HY.mjs";
|
|
8
8
|
import {
|
|
9
9
|
__commonJS,
|
|
10
10
|
__require,
|
|
11
11
|
init_esm_shims
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-QQ4A6DLD.mjs";
|
|
13
13
|
|
|
14
14
|
// src/git/line-endings.cjs
|
|
15
15
|
var require_line_endings = __commonJS({
|
|
@@ -18,7 +18,7 @@ var require_line_endings = __commonJS({
|
|
|
18
18
|
var path = __require("upath");
|
|
19
19
|
var fs = __require("fs");
|
|
20
20
|
var { runGitCommand } = require_utils();
|
|
21
|
-
var { updateGitAttributes } = require_gitattributes();
|
|
21
|
+
var { updateGitAttributes } = require_gitattributes().default;
|
|
22
22
|
function forceLfLineEndings() {
|
|
23
23
|
console.log("\n=== Configuring LF Line Endings ===");
|
|
24
24
|
runGitCommand(["config", "core.autocrlf", "false"], "Disable automatic CRLF conversion");
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
runChatGpt
|
|
4
|
+
} from "./chunk-GJTGHXRA.mjs";
|
|
5
|
+
import {
|
|
6
|
+
require_binary_collections_config
|
|
7
|
+
} from "./chunk-66PAU5PS.mjs";
|
|
8
|
+
import {
|
|
9
|
+
require_utils
|
|
10
|
+
} from "./chunk-V3N3JEUF.mjs";
|
|
11
|
+
import {
|
|
12
|
+
__toESM,
|
|
13
|
+
init_esm_shims
|
|
14
|
+
} from "./chunk-QQ4A6DLD.mjs";
|
|
15
|
+
|
|
16
|
+
// src/git-diff.js
|
|
17
|
+
init_esm_shims();
|
|
18
|
+
var import_binary_collections_config = __toESM(require_binary_collections_config(), 1);
|
|
19
|
+
import { execSync } from "child_process";
|
|
20
|
+
import fs from "fs";
|
|
21
|
+
import path from "path";
|
|
22
|
+
import { fileURLToPath } from "url";
|
|
23
|
+
var import_utils = __toESM(require_utils(), 1);
|
|
24
|
+
var __filename = fileURLToPath(import.meta.url);
|
|
25
|
+
var __dirname = path.dirname(__filename);
|
|
26
|
+
var DIFF_OUTPUT = (0, import_binary_collections_config.getTempPath)("git-diff.txt");
|
|
27
|
+
var GPT_DIFF_OUTPUT = (0, import_binary_collections_config.getTempPath)("gpt-question.txt");
|
|
28
|
+
var CACHE_DIR = path.dirname(DIFF_OUTPUT);
|
|
29
|
+
var DIFF_OUTPUT_RELATIVE = path.relative(process.cwd(), DIFF_OUTPUT);
|
|
30
|
+
var GPT_DIFF_OUTPUT_RELATIVE = path.relative(process.cwd(), GPT_DIFF_OUTPUT);
|
|
31
|
+
if (!fs.existsSync(CACHE_DIR)) {
|
|
32
|
+
fs.mkdirSync(CACHE_DIR, { recursive: true });
|
|
33
|
+
}
|
|
34
|
+
function showHelp() {
|
|
35
|
+
console.log("\u{1F4DD} Git Diff Helper");
|
|
36
|
+
console.log("\u{1F4C4} Usage:");
|
|
37
|
+
console.log(" \u{1F4C2} git-diff FILE Show staged diff of specified file");
|
|
38
|
+
console.log(" \u{1F4C2} git-diff --staged-only Show staged diff of all files");
|
|
39
|
+
console.log(" \u{1F4C2} git-diff -s | -S Same as --staged-only");
|
|
40
|
+
console.log(" \u{1F4C2} git-diff --ai Run ChatGPT automation for commit message");
|
|
41
|
+
console.log(" \u{1F4C2} git-diff --help | -h Show this help message");
|
|
42
|
+
console.log("");
|
|
43
|
+
console.log(`\u{1F4BE} Output is saved to: ${DIFF_OUTPUT_RELATIVE}`);
|
|
44
|
+
console.log(`\u{1F916} GPT prompt is saved to: ${GPT_DIFF_OUTPUT_RELATIVE}`);
|
|
45
|
+
process.exit(0);
|
|
46
|
+
}
|
|
47
|
+
function runGitDiff(command, successMessage, errorMessage) {
|
|
48
|
+
try {
|
|
49
|
+
console.log(`\u{1F50D} [i] Running command: ${command}`);
|
|
50
|
+
const result = execSync(command, {
|
|
51
|
+
encoding: "utf8",
|
|
52
|
+
maxBuffer: 1024 * 1024 * 10
|
|
53
|
+
// 10MB buffer to handle large diffs
|
|
54
|
+
});
|
|
55
|
+
if (!result || result.trim() === "") {
|
|
56
|
+
console.log(`\u2139\uFE0F [i] No changes found for the specified criteria`);
|
|
57
|
+
fs.writeFileSync(DIFF_OUTPUT, "# No changes found\n");
|
|
58
|
+
console.log(`\u2705 Empty diff saved to "${DIFF_OUTPUT_RELATIVE}"`);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
fs.writeFileSync(DIFF_OUTPUT, result);
|
|
62
|
+
fs.writeFileSync(
|
|
63
|
+
GPT_DIFF_OUTPUT,
|
|
64
|
+
`Hello, ChatGPT!
|
|
65
|
+
Can you create a conventional commit message by diff content below:
|
|
66
|
+
|
|
67
|
+
\`\`\`${result}
|
|
68
|
+
\`\`\`
|
|
69
|
+
|
|
70
|
+
Give me result as codeblock with language "text" only.
|
|
71
|
+
|
|
72
|
+
Thank you!`
|
|
73
|
+
);
|
|
74
|
+
console.log(`\u2705 ${successMessage}`);
|
|
75
|
+
console.log(`\u{1F4BE} GPT diff prompt saved to "${GPT_DIFF_OUTPUT_RELATIVE}"`);
|
|
76
|
+
} catch (error) {
|
|
77
|
+
console.error(`\u274C ${errorMessage}`);
|
|
78
|
+
console.error(`\u{1F4DD} Command: ${command}`);
|
|
79
|
+
console.error(`\u26A0\uFE0F Error: ${error.message}`);
|
|
80
|
+
if (error.message.includes("not a git repository")) {
|
|
81
|
+
console.error("\u{1F6A7} Make sure you are in a git repository");
|
|
82
|
+
}
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async function mainGitDiff() {
|
|
87
|
+
const args = (0, import_utils.getArgs)();
|
|
88
|
+
const positional = args._ || [];
|
|
89
|
+
if (args.help || args.h) {
|
|
90
|
+
showHelp();
|
|
91
|
+
}
|
|
92
|
+
if (args["staged-only"] || args.s || args.S) {
|
|
93
|
+
runGitDiff(
|
|
94
|
+
"git --no-pager diff --staged",
|
|
95
|
+
`Full staged diff saved to "${DIFF_OUTPUT_RELATIVE}"`,
|
|
96
|
+
"Failed to save staged diff"
|
|
97
|
+
);
|
|
98
|
+
} else {
|
|
99
|
+
const file = positional[0];
|
|
100
|
+
if (!file) {
|
|
101
|
+
runGitDiff(
|
|
102
|
+
"git --no-pager diff",
|
|
103
|
+
`Full staged diff saved to "${DIFF_OUTPUT_RELATIVE}"`,
|
|
104
|
+
"Failed to save all diff's"
|
|
105
|
+
);
|
|
106
|
+
} else {
|
|
107
|
+
runGitDiff(
|
|
108
|
+
`git --no-pager diff --cached -- "${file}"`,
|
|
109
|
+
`Staged diff of "${file}" saved to "${DIFF_OUTPUT_RELATIVE}"`,
|
|
110
|
+
`Failed to generate diff for "${file}"`
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (args.ai) {
|
|
115
|
+
try {
|
|
116
|
+
await runChatGpt({ headless: true, questionFile: GPT_DIFF_OUTPUT });
|
|
117
|
+
} catch (error) {
|
|
118
|
+
console.error("\u274C Error running ChatGPT:", error.message);
|
|
119
|
+
console.error("\u{1F4A1} Try running with visible browser mode or check if Chrome is installed");
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
console.log("\u{1F4A1} Tip: Use --ai flag to generate commit message with ChatGPT");
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
var git_diff_default = runGitDiff;
|
|
126
|
+
|
|
127
|
+
export {
|
|
128
|
+
DIFF_OUTPUT,
|
|
129
|
+
GPT_DIFF_OUTPUT,
|
|
130
|
+
CACHE_DIR,
|
|
131
|
+
DIFF_OUTPUT_RELATIVE,
|
|
132
|
+
GPT_DIFF_OUTPUT_RELATIVE,
|
|
133
|
+
runGitDiff,
|
|
134
|
+
mainGitDiff,
|
|
135
|
+
git_diff_default
|
|
136
|
+
};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
runChatGpt
|
|
4
|
+
} from "./chunk-GJTGHXRA.mjs";
|
|
5
|
+
import {
|
|
6
|
+
require_binary_collections_config
|
|
7
|
+
} from "./chunk-66PAU5PS.mjs";
|
|
8
|
+
import {
|
|
9
|
+
require_utils
|
|
10
|
+
} from "./chunk-V3N3JEUF.mjs";
|
|
11
|
+
import {
|
|
12
|
+
__toESM,
|
|
13
|
+
init_esm_shims
|
|
14
|
+
} from "./chunk-QQ4A6DLD.mjs";
|
|
15
|
+
|
|
16
|
+
// src/git-diff.js
|
|
17
|
+
init_esm_shims();
|
|
18
|
+
var import_binary_collections_config = __toESM(require_binary_collections_config(), 1);
|
|
19
|
+
import { execSync } from "child_process";
|
|
20
|
+
import fs from "fs";
|
|
21
|
+
import path from "path";
|
|
22
|
+
import { fileURLToPath } from "url";
|
|
23
|
+
var import_utils = __toESM(require_utils(), 1);
|
|
24
|
+
var __filename = fileURLToPath(import.meta.url);
|
|
25
|
+
var __dirname = path.dirname(__filename);
|
|
26
|
+
var DIFF_OUTPUT = (0, import_binary_collections_config.getTempPath)("git-diff.txt");
|
|
27
|
+
var GPT_DIFF_OUTPUT = (0, import_binary_collections_config.getTempPath)("gpt-question.txt");
|
|
28
|
+
var CACHE_DIR = path.dirname(DIFF_OUTPUT);
|
|
29
|
+
var DIFF_OUTPUT_RELATIVE = path.relative(process.cwd(), DIFF_OUTPUT);
|
|
30
|
+
var GPT_DIFF_OUTPUT_RELATIVE = path.relative(process.cwd(), GPT_DIFF_OUTPUT);
|
|
31
|
+
if (!fs.existsSync(CACHE_DIR)) {
|
|
32
|
+
fs.mkdirSync(CACHE_DIR, { recursive: true });
|
|
33
|
+
}
|
|
34
|
+
function showHelp() {
|
|
35
|
+
console.log("\u{1F4DD} Git Diff Helper");
|
|
36
|
+
console.log("\u{1F4C4} Usage:");
|
|
37
|
+
console.log(" \u{1F4C2} git-diff FILE Show staged diff of specified file");
|
|
38
|
+
console.log(" \u{1F4C2} git-diff --staged-only Show staged diff of all files");
|
|
39
|
+
console.log(" \u{1F4C2} git-diff -s | -S Same as --staged-only");
|
|
40
|
+
console.log(" \u{1F4C2} git-diff --ai Run ChatGPT automation for commit message");
|
|
41
|
+
console.log(" \u{1F4C2} git-diff --help | -h Show this help message");
|
|
42
|
+
console.log("");
|
|
43
|
+
console.log(`\u{1F4BE} Output is saved to: ${DIFF_OUTPUT_RELATIVE}`);
|
|
44
|
+
console.log(`\u{1F916} GPT prompt is saved to: ${GPT_DIFF_OUTPUT_RELATIVE}`);
|
|
45
|
+
process.exit(0);
|
|
46
|
+
}
|
|
47
|
+
function runGitDiff(command, successMessage, errorMessage) {
|
|
48
|
+
try {
|
|
49
|
+
console.log(`\u{1F50D} [i] Running command: ${command}`);
|
|
50
|
+
const result = execSync(command, {
|
|
51
|
+
encoding: "utf8",
|
|
52
|
+
maxBuffer: 1024 * 1024 * 10
|
|
53
|
+
// 10MB buffer to handle large diffs
|
|
54
|
+
});
|
|
55
|
+
if (!result || result.trim() === "") {
|
|
56
|
+
console.log(`\u2139\uFE0F [i] No changes found for the specified criteria`);
|
|
57
|
+
fs.writeFileSync(DIFF_OUTPUT, "# No changes found\n");
|
|
58
|
+
console.log(`\u2705 Empty diff saved to "${DIFF_OUTPUT_RELATIVE}"`);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
fs.writeFileSync(DIFF_OUTPUT, result);
|
|
62
|
+
fs.writeFileSync(
|
|
63
|
+
GPT_DIFF_OUTPUT,
|
|
64
|
+
`Hello, ChatGPT!
|
|
65
|
+
Can you create a conventional commit message by diff content below:
|
|
66
|
+
|
|
67
|
+
\`\`\`${result}
|
|
68
|
+
\`\`\`
|
|
69
|
+
|
|
70
|
+
Give me result as codeblock with language "text" only.
|
|
71
|
+
|
|
72
|
+
Thank you!`
|
|
73
|
+
);
|
|
74
|
+
console.log(`\u2705 ${successMessage}`);
|
|
75
|
+
console.log(`\u{1F4BE} GPT diff prompt saved to "${GPT_DIFF_OUTPUT_RELATIVE}"`);
|
|
76
|
+
} catch (error) {
|
|
77
|
+
console.error(`\u274C ${errorMessage}`);
|
|
78
|
+
console.error(`\u{1F4DD} Command: ${command}`);
|
|
79
|
+
console.error(`\u26A0\uFE0F Error: ${error.message}`);
|
|
80
|
+
if (error.message.includes("not a git repository")) {
|
|
81
|
+
console.error("\u{1F6A7} Make sure you are in a git repository");
|
|
82
|
+
}
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async function mainGitDiff() {
|
|
87
|
+
const args = (0, import_utils.getArgs)();
|
|
88
|
+
const positional = args._ || [];
|
|
89
|
+
if (args.help || args.h) {
|
|
90
|
+
showHelp();
|
|
91
|
+
}
|
|
92
|
+
if (args["staged-only"] || args.s || args.S) {
|
|
93
|
+
runGitDiff(
|
|
94
|
+
"git --no-pager diff --staged",
|
|
95
|
+
`Full staged diff saved to "${DIFF_OUTPUT_RELATIVE}"`,
|
|
96
|
+
"Failed to save staged diff"
|
|
97
|
+
);
|
|
98
|
+
} else {
|
|
99
|
+
const file = positional[0];
|
|
100
|
+
if (!file) {
|
|
101
|
+
runGitDiff(
|
|
102
|
+
"git --no-pager diff",
|
|
103
|
+
`Full staged diff saved to "${DIFF_OUTPUT_RELATIVE}"`,
|
|
104
|
+
"Failed to save all diff's"
|
|
105
|
+
);
|
|
106
|
+
} else {
|
|
107
|
+
runGitDiff(
|
|
108
|
+
`git --no-pager diff --cached -- "${file}"`,
|
|
109
|
+
`Staged diff of "${file}" saved to "${DIFF_OUTPUT_RELATIVE}"`,
|
|
110
|
+
`Failed to generate diff for "${file}"`
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (args.ai) {
|
|
115
|
+
try {
|
|
116
|
+
await runChatGpt({ headless: true, questionFile: GPT_DIFF_OUTPUT });
|
|
117
|
+
} catch (error) {
|
|
118
|
+
console.error("\u274C Error running ChatGPT:", error.message);
|
|
119
|
+
console.error("\u{1F4A1} Try running with visible browser mode or check if Chrome is installed");
|
|
120
|
+
console.error(`\u{1F4C1} The diff has been saved to: ${DIFF_OUTPUT_RELATIVE}`);
|
|
121
|
+
console.error(`\u{1F4C1} GPT prompt saved to: ${GPT_DIFF_OUTPUT_RELATIVE}`);
|
|
122
|
+
}
|
|
123
|
+
} else {
|
|
124
|
+
console.log("\u{1F4A1} Tip: Use --ai flag to generate commit message with ChatGPT");
|
|
125
|
+
console.log(`\u{1F4C1} Diff saved to: ${DIFF_OUTPUT_RELATIVE}`);
|
|
126
|
+
console.log(`\u{1F4C1} GPT prompt saved to: ${GPT_DIFF_OUTPUT_RELATIVE}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
var git_diff_default = runGitDiff;
|
|
130
|
+
|
|
131
|
+
export {
|
|
132
|
+
DIFF_OUTPUT,
|
|
133
|
+
GPT_DIFF_OUTPUT,
|
|
134
|
+
CACHE_DIR,
|
|
135
|
+
DIFF_OUTPUT_RELATIVE,
|
|
136
|
+
GPT_DIFF_OUTPUT_RELATIVE,
|
|
137
|
+
runGitDiff,
|
|
138
|
+
mainGitDiff,
|
|
139
|
+
git_diff_default
|
|
140
|
+
};
|