git-diff-view 0.0.10 → 0.0.13
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 +3 -3
- package/dist/frontend.js +83 -66
- package/dist/styles.css +1 -0
- package/index.ts +32 -16
- package/package.json +7 -7
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
var{$:
|
|
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>`,
|
|
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
|
-
`)},
|
|
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();
|