git-diff-view 0.0.8 → 0.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/dist/cli.js +35 -0
- package/index.ts +2 -0
- package/package.json +3 -3
package/dist/cli.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
// @bun
|
|
3
|
+
var{$:o}=globalThis.Bun;import{join as a,dirname as w}from"path";var d=import.meta.path,m=async()=>{if(process.platform!=="darwin")return!0;try{return(await o`defaults read -g AppleInterfaceStyle`.quiet()).text().trim()==="Dark"}catch{return!1}},y=async(e)=>{try{let t=Bun.spawn(["git","diff",...e],{stdout:"pipe",stderr:"pipe"}),s=await new Response(t.stdout).text(),n=await new Response(t.stderr).text(),i=await t.exited;if(i!==0){if(n.includes("Not a git repository"))console.error("Error: Not a git repository"),process.exit(1);console.error(n),process.exit(i)}return s}catch(t){throw t}},v=async()=>{let e=`!${d} run`;await o`git config --global alias.dv ${e}`,console.log("\u2713 Installed git alias 'dv'"),console.log(" Usage: git dv [options]")},b=async()=>{try{await o`git config --global --unset alias.dv`.quiet(),console.log("\u2713 Uninstalled git alias 'dv'")}catch{console.log("Alias 'dv' was not installed")}},x=async(e)=>{let t=await y(e);if(!t.trim())console.log("No diff to display"),process.exit(0);let s=await m(),i=JSON.stringify({patch:t,theme:s?"pierre-dark":"pierre-light"}),f=w(d).replace("file://",""),r=a(f,"dist"),p=Bun.file(a(r,"frontend.js")),g=Bun.file(a(r,"styles.css")),u=`<!DOCTYPE html>
|
|
4
|
+
<html>
|
|
5
|
+
<head>
|
|
6
|
+
<meta charset="utf-8">
|
|
7
|
+
<title>Git Diff</title>
|
|
8
|
+
<link rel="stylesheet" href="/styles.css">
|
|
9
|
+
<style>body { background: ${s?"#1a1a1a":"#ffffff"}; }</style>
|
|
10
|
+
</head>
|
|
11
|
+
<body>
|
|
12
|
+
<div id="diff"></div>
|
|
13
|
+
<script type="module" src="/frontend.js"></script>
|
|
14
|
+
</body>
|
|
15
|
+
</html>`,l=Bun.serve({port:0,development:!1,routes:{"/":new Response(u,{headers:{"Content-Type":"text/html"}}),"/frontend.js":new Response(p,{headers:{"Content-Type":"application/javascript"}}),"/styles.css":new Response(g,{headers:{"Content-Type":"text/css"}}),"/api/diff":new Response(i,{headers:{"Content-Type":"application/json"}})}}),h=`http://localhost:${l.port}`;await o`open ${h}`.quiet(),await Bun.sleep(3000),l.stop(),process.exit(0)},c=()=>{console.log(`git-diff-view - Beautiful git diffs in your browser
|
|
16
|
+
|
|
17
|
+
Usage:
|
|
18
|
+
git-diff-view <command> [options]
|
|
19
|
+
|
|
20
|
+
Commands:
|
|
21
|
+
install Install the 'git dv' alias globally
|
|
22
|
+
uninstall Remove the 'git dv' alias
|
|
23
|
+
run View diff in browser (used by the alias)
|
|
24
|
+
|
|
25
|
+
Examples:
|
|
26
|
+
git-diff-view install
|
|
27
|
+
git-diff-view run
|
|
28
|
+
git-diff-view run --staged
|
|
29
|
+
git-diff-view run HEAD~3
|
|
30
|
+
|
|
31
|
+
After installing, use:
|
|
32
|
+
git dv # unstaged changes
|
|
33
|
+
git dv --staged # staged changes
|
|
34
|
+
git dv HEAD~3 # last 3 commits
|
|
35
|
+
`)},k=async()=>{let e=process.argv.slice(2),t=e[0];switch(t){case"install":await v();break;case"uninstall":await b();break;case"run":await x(e.slice(1));break;case"--help":case"-h":c();break;default:if(!t)c();else console.error(`Unknown command: ${t}`),console.error("Run 'git-diff-view --help' for usage"),process.exit(1)}};k();
|
package/index.ts
CHANGED
|
@@ -73,12 +73,14 @@ const run = async (args: string[]) => {
|
|
|
73
73
|
const jsFile = Bun.file(join(distDir, "frontend.js"));
|
|
74
74
|
const cssFile = Bun.file(join(distDir, "styles.css"));
|
|
75
75
|
|
|
76
|
+
const bgColor = dark ? "#1a1a1a" : "#ffffff";
|
|
76
77
|
const html = `<!DOCTYPE html>
|
|
77
78
|
<html>
|
|
78
79
|
<head>
|
|
79
80
|
<meta charset="utf-8">
|
|
80
81
|
<title>Git Diff</title>
|
|
81
82
|
<link rel="stylesheet" href="/styles.css">
|
|
83
|
+
<style>body { background: ${bgColor}; }</style>
|
|
82
84
|
</head>
|
|
83
85
|
<body>
|
|
84
86
|
<div id="diff"></div>
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "git-diff-view",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"module": "index.ts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
|
-
"git-diff-view": "./
|
|
7
|
+
"git-diff-view": "./dist/cli.js"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"start": "bun run index.ts",
|
|
11
|
-
"build": "bun build ./frontend.tsx --outdir ./dist --minify && bun build ./styles.css --outdir ./dist --minify",
|
|
11
|
+
"build": "bun build ./index.ts --outfile ./dist/cli.js --target node --minify && bun build ./frontend.tsx --outdir ./dist --minify && bun build ./styles.css --outdir ./dist --minify",
|
|
12
12
|
"prepublishOnly": "bun run build"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|