git-diff-view 0.0.10 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bun
2
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>
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
4
  <html>
5
5
  <head>
6
6
  <meta charset="utf-8">
@@ -12,7 +12,7 @@ var{$:o}=globalThis.Bun;import{join as a,dirname as w}from"path";var d=import.me
12
12
  <div id="diff"></div>
13
13
  <script type="module" src="/frontend.js"></script>
14
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
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
16
 
17
17
  Usage:
18
18
  git-diff-view <command> [options]
@@ -32,4 +32,4 @@ After installing, use:
32
32
  git dv # unstaged changes
33
33
  git dv --staged # staged changes
34
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();
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,6 +1,6 @@
1
1
  {
2
2
  "name": "git-diff-view",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {
@@ -8,7 +8,7 @@
8
8
  },
9
9
  "scripts": {
10
10
  "start": "bun run index.ts",
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",
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": {