git-truck 0.8.2 → 0.8.6-experimental

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.
Files changed (42) hide show
  1. package/.github/workflows/bump-version.yml +1 -1
  2. package/README.md +17 -13
  3. package/cli.js +2 -0
  4. package/dev.js +4 -2
  5. package/package.json +4 -4
  6. package/server.ts +13 -8
  7. package/src/analyzer/analyze.server.ts +43 -76
  8. package/src/analyzer/analyze.test.ts +30 -30
  9. package/src/analyzer/args.server.ts +20 -6
  10. package/src/analyzer/constants.ts +1 -1
  11. package/src/analyzer/git-caller.server.ts +290 -0
  12. package/src/analyzer/hydrate.server.ts +1 -1
  13. package/src/analyzer/model.ts +13 -2
  14. package/src/analyzer/{util.ts → util.server.ts} +27 -33
  15. package/src/analyzer/util.test.ts +1 -1
  16. package/src/components/AnalyzingIndicator.tsx +55 -0
  17. package/src/components/Animations.ts +14 -0
  18. package/src/components/Chart.tsx +29 -8
  19. package/src/components/Details.tsx +8 -7
  20. package/src/components/GlobalInfo.tsx +19 -8
  21. package/src/components/HiddenFiles.tsx +3 -3
  22. package/src/components/Legend.tsx +1 -1
  23. package/src/components/LegendOther.tsx +42 -42
  24. package/src/components/Main.tsx +1 -1
  25. package/src/components/SearchBar.tsx +1 -6
  26. package/src/components/util.tsx +19 -10
  27. package/src/const.ts +6 -6
  28. package/src/contexts/ClickedContext.ts +17 -17
  29. package/src/contexts/DataContext.ts +12 -12
  30. package/src/contexts/MetricContext.ts +12 -12
  31. package/src/contexts/OptionsContext.ts +51 -51
  32. package/src/contexts/SearchContext.ts +19 -19
  33. package/src/lang-map.d.ts +3 -3
  34. package/src/metrics.ts +3 -2
  35. package/src/root.tsx +44 -1
  36. package/src/routes/{repo.tsx → $repo.tsx} +59 -15
  37. package/src/routes/index.tsx +156 -46
  38. package/build/index.js +0 -6836
  39. package/post-build.js +0 -14
  40. package/public/favicon.ico +0 -0
  41. package/src/analyzer/git-caller.ts +0 -117
  42. package/src/analyzer/index.ts +0 -4
package/post-build.js DELETED
@@ -1,14 +0,0 @@
1
- const fs = require("fs")
2
-
3
- const shebang = "#!/usr/bin/env node\n"
4
- const buildPath = "./build/index.js"
5
-
6
- const data = fs.readFileSync(buildPath)
7
- const fd = fs.openSync(buildPath, "w+")
8
- const insert = Buffer.from(shebang)
9
- fs.writeSync(fd, insert, 0, insert.length, 0)
10
- fs.writeSync(fd, data, 0, data.length, insert.length)
11
- fs.close(fd, (err) => {
12
- if (err) throw err
13
- })
14
- fs.chmodSync(buildPath, "755")
Binary file
@@ -1,117 +0,0 @@
1
- import { runProcess } from "./util"
2
-
3
- export type RawGitObjectType = "blob" | "tree" | "commit" | "tag"
4
- export type RawGitObject = {
5
- hash: string
6
- type: RawGitObjectType
7
- idk: string
8
- value: string
9
- }
10
-
11
- export class GitCaller {
12
- private useCache = true
13
- private repo: string
14
- private catFileCache: Map<string, string> = new Map()
15
- private diffNumStatCache: Map<string, string> = new Map()
16
- private blameCache: Map<string, string> = new Map()
17
-
18
- private static instance: GitCaller | null = null
19
-
20
- static initInstance(repo: string) {
21
- if (!GitCaller.instance || GitCaller.instance.repo !== repo) {
22
- GitCaller.instance = new GitCaller(repo)
23
- }
24
- }
25
-
26
- static destroyInstance() {
27
- GitCaller.instance = null
28
- }
29
-
30
- static getInstance(): GitCaller {
31
- if (!GitCaller.instance) {
32
- throw Error("ObjectDeflator not initialized")
33
- }
34
- return GitCaller.instance
35
- }
36
-
37
- private constructor(repo: string) {
38
- this.repo = repo
39
- }
40
-
41
- setUseCache(useCache: boolean) {
42
- this.useCache = useCache
43
- }
44
-
45
- private async catFile(hash: string) {
46
- const result = await runProcess(this.repo, "git", ["cat-file", "-p", hash])
47
- return result as string
48
- }
49
-
50
- async catFileCached(hash: string): Promise<string> {
51
- if (!this.useCache) {
52
- const cachedValue = this.catFileCache.get(hash)
53
- if (cachedValue) {
54
- return cachedValue
55
- }
56
- }
57
- const result = await this.catFile(hash)
58
- this.catFileCache.set(hash, result)
59
-
60
- return result
61
- }
62
-
63
- private async blame(path: string) {
64
- const result = await runProcess(this.repo, "git", ["blame", path])
65
- return result as string
66
- }
67
-
68
- async blameCached(path: string): Promise<string> {
69
- if (!this.useCache) {
70
- const cachedValue = this.blameCache.get(path)
71
- if (cachedValue) {
72
- return cachedValue
73
- }
74
- }
75
- const result = await this.blame(path)
76
- this.blameCache.set(path, result)
77
-
78
- return result
79
- }
80
-
81
- async parseBlame(path: string) {
82
- const cutString = path.slice(path.indexOf("/") + 1)
83
- const blame = await this.blameCached(cutString)
84
- const blameRegex = /\((?<author>.*?)\s+\d{4}-\d{2}-\d{2}/gm
85
- const matches = blame.match(blameRegex)
86
- const blameAuthors: Record<string, number> = {}
87
- matches?.forEach((match) => {
88
- const author = match
89
- .slice(1)
90
- .slice(0, match.length - 11)
91
- .trim()
92
- if (author !== "Not Committed Yet") {
93
- const currentValue = blameAuthors[author] ?? 0
94
- blameAuthors[author] = currentValue + 1
95
- }
96
- })
97
- return blameAuthors
98
- }
99
-
100
- async gitDiffNumStatCached(a: string, b: string) {
101
- const key = a + b
102
- if (this.useCache) {
103
- const cachedValue = this.diffNumStatCache.get(key)
104
- if (cachedValue) {
105
- return cachedValue
106
- }
107
- }
108
- const result = await this.gitDiffNumStat(a, b)
109
- this.diffNumStatCache.set(key, result)
110
- return result
111
- }
112
-
113
- private async gitDiffNumStat(a: string, b: string) {
114
- const result = await runProcess(this.repo, "git", ["diff", "--numstat", a, b])
115
- return result as string
116
- }
117
- }
@@ -1,4 +0,0 @@
1
- import "dotenv/config"
2
- import { analyze } from "./analyze.server"
3
-
4
- analyze()