git-diff-view 0.0.9 → 0.0.12

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 ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env bun
2
+ // @bun
3
+ var{$:a}=globalThis.Bun;import{join as r,dirname as y}from"path";var l=import.meta.path,v=async()=>{if(process.platform!=="darwin")return!0;try{return(await a`defaults read -g AppleInterfaceStyle`.quiet()).text().trim()==="Dark"}catch{return!1}},b=async(e)=>{try{let t=Bun.spawn(["git","diff",...e],{stdout:"pipe",stderr:"pipe"}),s=await new Response(t.stdout).text(),o=await new Response(t.stderr).text(),n=await t.exited;if(n!==0){if(o.includes("Not a git repository"))console.error("Error: Not a git repository"),process.exit(1);console.error(o),process.exit(n)}return s}catch(t){throw t}},x=async()=>{let e=`!${l} run`;await a`git config --global alias.dv ${e}`,console.log("\u2713 Installed git alias 'dv'"),console.log(" Usage: git dv [options]")},k=async()=>{try{await a`git config --global --unset alias.dv`.quiet(),console.log("\u2713 Uninstalled git alias 'dv'")}catch{console.log("Alias 'dv' was not installed")}},R=async(e)=>{let t=await b(e);if(!t.trim())console.log("No diff to display"),process.exit(0);let s=await v(),n=JSON.stringify({patch:t,theme:s?"pierre-dark":"pierre-light"}),c=y(l).replace("file://",""),d=l.includes("/dist/")?c:r(c,"dist"),u=r(d,"frontend.js"),g=r(d,"styles.css"),h=`<!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>`,f=Bun.serve({port:0,development:!1,fetch(w){let i=new URL(w.url);if(i.pathname==="/")return new Response(h,{headers:{"Content-Type":"text/html"}});if(i.pathname==="/frontend.js")return new Response(Bun.file(u),{headers:{"Content-Type":"application/javascript"}});if(i.pathname==="/styles.css")return new Response(Bun.file(g),{headers:{"Content-Type":"text/css"}});if(i.pathname==="/api/diff")return new Response(n,{headers:{"Content-Type":"application/json"}});return new Response("Not Found",{status:404})}}),m=`http://localhost:${f.port}`;await a`open ${m}`.quiet(),await Bun.sleep(3000),f.stop(),process.exit(0)},p=()=>{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
+ `)},C=async()=>{let e=process.argv.slice(2),t=e[0];switch(t){case"install":await x();break;case"uninstall":await k();break;case"run":await R(e.slice(1));break;case"--help":case"-h":p();break;default:if(!t)p();else console.error(`Unknown command: ${t}`),console.error("Run 'git-diff-view --help' for usage"),process.exit(1)}};C();
@@ -0,0 +1 @@
1
+ :root{--buncss-light:initial;--buncss-dark: ;color-scheme:light dark}@media (prefers-color-scheme:dark){:root{--buncss-light: ;--buncss-dark:initial}}body{background:var(--bg-color,#fff);margin:0;padding:20px;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,sans-serif}@media (prefers-color-scheme:dark){body{background:#1a1a1a}}
package/index.ts CHANGED
@@ -68,10 +68,11 @@ const run = async (args: string[]) => {
68
68
  const diffData = JSON.stringify({ patch, theme });
69
69
 
70
70
  const scriptDir = dirname(SCRIPT_PATH).replace("file://", "");
71
- const distDir = join(scriptDir, "dist");
71
+ const isBundle = SCRIPT_PATH.includes("/dist/");
72
+ const distDir = isBundle ? scriptDir : join(scriptDir, "dist");
72
73
 
73
- const jsFile = Bun.file(join(distDir, "frontend.js"));
74
- const cssFile = Bun.file(join(distDir, "styles.css"));
74
+ const jsPath = join(distDir, "frontend.js");
75
+ const cssPath = join(distDir, "styles.css");
75
76
 
76
77
  const bgColor = dark ? "#1a1a1a" : "#ffffff";
77
78
  const html = `<!DOCTYPE html>
@@ -91,19 +92,34 @@ const run = async (args: string[]) => {
91
92
  const server = Bun.serve({
92
93
  port: 0,
93
94
  development: false,
94
- routes: {
95
- "/": new Response(html, {
96
- headers: { "Content-Type": "text/html" },
97
- }),
98
- "/frontend.js": new Response(jsFile, {
99
- headers: { "Content-Type": "application/javascript" },
100
- }),
101
- "/styles.css": new Response(cssFile, {
102
- headers: { "Content-Type": "text/css" },
103
- }),
104
- "/api/diff": new Response(diffData, {
105
- headers: { "Content-Type": "application/json" },
106
- }),
95
+ fetch(req) {
96
+ const url = new URL(req.url);
97
+
98
+ if (url.pathname === "/") {
99
+ return new Response(html, {
100
+ headers: { "Content-Type": "text/html" },
101
+ });
102
+ }
103
+
104
+ if (url.pathname === "/frontend.js") {
105
+ return new Response(Bun.file(jsPath), {
106
+ headers: { "Content-Type": "application/javascript" },
107
+ });
108
+ }
109
+
110
+ if (url.pathname === "/styles.css") {
111
+ return new Response(Bun.file(cssPath), {
112
+ headers: { "Content-Type": "text/css" },
113
+ });
114
+ }
115
+
116
+ if (url.pathname === "/api/diff") {
117
+ return new Response(diffData, {
118
+ headers: { "Content-Type": "application/json" },
119
+ });
120
+ }
121
+
122
+ return new Response("Not Found", { status: 404 });
107
123
  },
108
124
  });
109
125
 
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "git-diff-view",
3
- "version": "0.0.9",
3
+ "version": "0.0.12",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {
7
- "git-diff-view": "./index.ts"
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 bun --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": {