git-viewer 13.0.0 → 15.0.0
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/entry.bundled.js +777 -242
- package/dist/server.js +200 -1
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -9033,6 +9033,112 @@ function formatDate(date) {
|
|
|
9033
9033
|
minute: "2-digit"
|
|
9034
9034
|
});
|
|
9035
9035
|
}
|
|
9036
|
+
async function getStatus() {
|
|
9037
|
+
let output = await git("status --porcelain=v1");
|
|
9038
|
+
let lines = output ? output.split("\n").filter(Boolean) : [];
|
|
9039
|
+
let staged = [];
|
|
9040
|
+
let unstaged = [];
|
|
9041
|
+
for (let line of lines) {
|
|
9042
|
+
let indexStatus = line[0];
|
|
9043
|
+
let workTreeStatus = line[1];
|
|
9044
|
+
let path4 = line.slice(3);
|
|
9045
|
+
if (path4.includes(" -> ")) {
|
|
9046
|
+
path4 = path4.split(" -> ")[1];
|
|
9047
|
+
}
|
|
9048
|
+
if (indexStatus !== " " && indexStatus !== "?") {
|
|
9049
|
+
staged.push({ path: path4, status: indexStatus });
|
|
9050
|
+
}
|
|
9051
|
+
if (workTreeStatus !== " ") {
|
|
9052
|
+
let status = workTreeStatus === "?" ? "?" : workTreeStatus;
|
|
9053
|
+
unstaged.push({ path: path4, status });
|
|
9054
|
+
}
|
|
9055
|
+
}
|
|
9056
|
+
return { staged, unstaged };
|
|
9057
|
+
}
|
|
9058
|
+
async function stageFiles(paths) {
|
|
9059
|
+
if (paths.length === 0) return;
|
|
9060
|
+
let escaped = paths.map((p) => `"${p}"`).join(" ");
|
|
9061
|
+
await git(`add ${escaped}`);
|
|
9062
|
+
}
|
|
9063
|
+
async function unstageFiles(paths) {
|
|
9064
|
+
if (paths.length === 0) return;
|
|
9065
|
+
let escaped = paths.map((p) => `"${p}"`).join(" ");
|
|
9066
|
+
await git(`restore --staged ${escaped}`);
|
|
9067
|
+
}
|
|
9068
|
+
async function commitChanges(message, amend) {
|
|
9069
|
+
let escapedMessage = message.replace(/"/g, '\\"');
|
|
9070
|
+
let args = `commit -m "${escapedMessage}"`;
|
|
9071
|
+
if (amend) {
|
|
9072
|
+
args += " --amend";
|
|
9073
|
+
}
|
|
9074
|
+
await git(args);
|
|
9075
|
+
}
|
|
9076
|
+
async function getLastCommit() {
|
|
9077
|
+
let format = "%H%x1f%h%x1f%s%x1f%b";
|
|
9078
|
+
let metaOutput = await git(`log -1 --format="${format}"`);
|
|
9079
|
+
let [sha, shortSha, subject, body] = metaOutput.split("");
|
|
9080
|
+
let filesOutput = await git("diff-tree --no-commit-id --name-status -r HEAD");
|
|
9081
|
+
let files = [];
|
|
9082
|
+
if (filesOutput) {
|
|
9083
|
+
for (let line of filesOutput.split("\n").filter(Boolean)) {
|
|
9084
|
+
let [status, ...pathParts] = line.split(" ");
|
|
9085
|
+
let path4 = pathParts.join(" ");
|
|
9086
|
+
if (pathParts.length > 1) {
|
|
9087
|
+
path4 = pathParts[1];
|
|
9088
|
+
}
|
|
9089
|
+
files.push({ path: path4, status: status[0] });
|
|
9090
|
+
}
|
|
9091
|
+
}
|
|
9092
|
+
return {
|
|
9093
|
+
sha,
|
|
9094
|
+
shortSha,
|
|
9095
|
+
subject,
|
|
9096
|
+
body: body ? body.trimEnd() : "",
|
|
9097
|
+
files
|
|
9098
|
+
};
|
|
9099
|
+
}
|
|
9100
|
+
async function getWorkingDiff(filePath) {
|
|
9101
|
+
let output = await git(`diff -- "${filePath}"`);
|
|
9102
|
+
if (output) {
|
|
9103
|
+
return output;
|
|
9104
|
+
}
|
|
9105
|
+
try {
|
|
9106
|
+
let fileContent = fs2.readFileSync(path3.join(repoDir, filePath), "utf-8");
|
|
9107
|
+
let lines = fileContent.split("\n");
|
|
9108
|
+
let diffLines = [
|
|
9109
|
+
`diff --git a/${filePath} b/${filePath}`,
|
|
9110
|
+
`new file mode 100644`,
|
|
9111
|
+
`--- /dev/null`,
|
|
9112
|
+
`+++ b/${filePath}`,
|
|
9113
|
+
`@@ -0,0 +1,${lines.length} @@`,
|
|
9114
|
+
...lines.map((line) => `+${line}`)
|
|
9115
|
+
];
|
|
9116
|
+
return diffLines.join("\n");
|
|
9117
|
+
} catch {
|
|
9118
|
+
return "";
|
|
9119
|
+
}
|
|
9120
|
+
}
|
|
9121
|
+
async function getStagedDiff(filePath) {
|
|
9122
|
+
let output = await git(`diff --cached -- "${filePath}"`);
|
|
9123
|
+
if (output) {
|
|
9124
|
+
return output;
|
|
9125
|
+
}
|
|
9126
|
+
try {
|
|
9127
|
+
let fileContent = await git(`show :${filePath}`);
|
|
9128
|
+
let lines = fileContent.split("\n");
|
|
9129
|
+
let diffLines = [
|
|
9130
|
+
`diff --git a/${filePath} b/${filePath}`,
|
|
9131
|
+
`new file mode 100644`,
|
|
9132
|
+
`--- /dev/null`,
|
|
9133
|
+
`+++ b/${filePath}`,
|
|
9134
|
+
`@@ -0,0 +1,${lines.length} @@`,
|
|
9135
|
+
...lines.map((line) => `+${line}`)
|
|
9136
|
+
];
|
|
9137
|
+
return diffLines.join("\n");
|
|
9138
|
+
} catch {
|
|
9139
|
+
return "";
|
|
9140
|
+
}
|
|
9141
|
+
}
|
|
9036
9142
|
async function getDiff(sha) {
|
|
9037
9143
|
let format = "%H%x1f%h%x1f%s%x1f%b%x1f%an%x1f%ai%x1f%P";
|
|
9038
9144
|
let metaOutput = await git(`show -z --format="${format}" -s ${sha}`);
|
|
@@ -9102,9 +9208,102 @@ router.get("/api/diff/:sha", async ({ params }) => {
|
|
|
9102
9208
|
return Response.json({ error: "Failed to get diff" }, { status: 500 });
|
|
9103
9209
|
}
|
|
9104
9210
|
});
|
|
9211
|
+
router.get("/api/status", async () => {
|
|
9212
|
+
try {
|
|
9213
|
+
let status = await getStatus();
|
|
9214
|
+
return Response.json(status);
|
|
9215
|
+
} catch (error) {
|
|
9216
|
+
console.error("Error getting status:", error);
|
|
9217
|
+
return Response.json({ error: "Failed to get status" }, { status: 500 });
|
|
9218
|
+
}
|
|
9219
|
+
});
|
|
9220
|
+
router.post("/api/stage", async ({ request }) => {
|
|
9221
|
+
try {
|
|
9222
|
+
let { paths } = await request.json();
|
|
9223
|
+
await stageFiles(paths);
|
|
9224
|
+
return Response.json({ success: true });
|
|
9225
|
+
} catch (error) {
|
|
9226
|
+
console.error("Error staging files:", error);
|
|
9227
|
+
return Response.json({ error: "Failed to stage files" }, { status: 500 });
|
|
9228
|
+
}
|
|
9229
|
+
});
|
|
9230
|
+
router.post("/api/unstage", async ({ request }) => {
|
|
9231
|
+
try {
|
|
9232
|
+
let { paths } = await request.json();
|
|
9233
|
+
await unstageFiles(paths);
|
|
9234
|
+
return Response.json({ success: true });
|
|
9235
|
+
} catch (error) {
|
|
9236
|
+
console.error("Error unstaging files:", error);
|
|
9237
|
+
return Response.json({ error: "Failed to unstage files" }, { status: 500 });
|
|
9238
|
+
}
|
|
9239
|
+
});
|
|
9240
|
+
router.post("/api/commit", async ({ request }) => {
|
|
9241
|
+
try {
|
|
9242
|
+
let { message, amend } = await request.json();
|
|
9243
|
+
await commitChanges(message, amend || false);
|
|
9244
|
+
return Response.json({ success: true });
|
|
9245
|
+
} catch (error) {
|
|
9246
|
+
console.error("Error committing:", error);
|
|
9247
|
+
return Response.json({ error: "Failed to commit" }, { status: 500 });
|
|
9248
|
+
}
|
|
9249
|
+
});
|
|
9250
|
+
router.get("/api/last-commit", async () => {
|
|
9251
|
+
try {
|
|
9252
|
+
let lastCommit = await getLastCommit();
|
|
9253
|
+
return Response.json(lastCommit);
|
|
9254
|
+
} catch (error) {
|
|
9255
|
+
console.error("Error getting last commit:", error);
|
|
9256
|
+
return Response.json({ error: "Failed to get last commit" }, { status: 500 });
|
|
9257
|
+
}
|
|
9258
|
+
});
|
|
9259
|
+
router.get("/api/working-diff", async ({ url }) => {
|
|
9260
|
+
try {
|
|
9261
|
+
let filePath = url.searchParams.get("path");
|
|
9262
|
+
if (!filePath) {
|
|
9263
|
+
return Response.json({ error: "Missing path parameter" }, { status: 400 });
|
|
9264
|
+
}
|
|
9265
|
+
let diffOutput = await getWorkingDiff(filePath);
|
|
9266
|
+
let parsedDiff = (0, import_diff2html.parse)(diffOutput);
|
|
9267
|
+
let diffHtml = (0, import_diff2html.html)(parsedDiff, {
|
|
9268
|
+
drawFileList: false,
|
|
9269
|
+
outputFormat: "line-by-line",
|
|
9270
|
+
matching: "lines"
|
|
9271
|
+
});
|
|
9272
|
+
return Response.json({ diffHtml });
|
|
9273
|
+
} catch (error) {
|
|
9274
|
+
console.error("Error getting working diff:", error);
|
|
9275
|
+
return Response.json({ error: "Failed to get working diff" }, { status: 500 });
|
|
9276
|
+
}
|
|
9277
|
+
});
|
|
9278
|
+
router.get("/api/staged-diff", async ({ url }) => {
|
|
9279
|
+
try {
|
|
9280
|
+
let filePath = url.searchParams.get("path");
|
|
9281
|
+
if (!filePath) {
|
|
9282
|
+
return Response.json({ error: "Missing path parameter" }, { status: 400 });
|
|
9283
|
+
}
|
|
9284
|
+
let diffOutput = await getStagedDiff(filePath);
|
|
9285
|
+
let parsedDiff = (0, import_diff2html.parse)(diffOutput);
|
|
9286
|
+
let diffHtml = (0, import_diff2html.html)(parsedDiff, {
|
|
9287
|
+
drawFileList: false,
|
|
9288
|
+
outputFormat: "line-by-line",
|
|
9289
|
+
matching: "lines"
|
|
9290
|
+
});
|
|
9291
|
+
return Response.json({ diffHtml });
|
|
9292
|
+
} catch (error) {
|
|
9293
|
+
console.error("Error getting staged diff:", error);
|
|
9294
|
+
return Response.json({ error: "Failed to get staged diff" }, { status: 500 });
|
|
9295
|
+
}
|
|
9296
|
+
});
|
|
9105
9297
|
var server = http.createServer(
|
|
9106
9298
|
createRequestListener(async (request) => {
|
|
9107
|
-
|
|
9299
|
+
let response = await router.fetch(request);
|
|
9300
|
+
let headers = new Headers(response.headers);
|
|
9301
|
+
headers.set("Cache-Control", "no-store");
|
|
9302
|
+
return new Response(response.body, {
|
|
9303
|
+
status: response.status,
|
|
9304
|
+
statusText: response.statusText,
|
|
9305
|
+
headers
|
|
9306
|
+
});
|
|
9108
9307
|
})
|
|
9109
9308
|
);
|
|
9110
9309
|
var startPort = 44100;
|