github-search-cli 9.4.1 → 9.4.3

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 (55) hide show
  1. package/CHANGELOG.md +65 -1
  2. package/README.md +268 -237
  3. package/bin/ghfind.js +98 -89
  4. package/completions/ghfind.bash +1 -1
  5. package/completions/ghfind.fish +3 -1
  6. package/completions/ghfind.zsh +6 -0
  7. package/dist/{chunk-IVUU2KGR.js → chunk-GYIL4S5X.js} +4 -1
  8. package/dist/cli.js +1179 -403
  9. package/dist/{config-GNZOQRTH.js → config-OCIPF2IF.js} +1 -1
  10. package/package.json +16 -5
  11. package/release-notes/9.3.0.md +32 -29
  12. package/scripts/build.ts +34 -19
  13. package/scripts/generate-svg-demo.js +218 -168
  14. package/scripts/postinstall.js +176 -176
  15. package/src/bookmarks.ts +69 -69
  16. package/src/cli.ts +650 -566
  17. package/src/compare.ts +69 -47
  18. package/src/config.ts +70 -65
  19. package/src/deepdive.ts +149 -118
  20. package/src/doctor.ts +287 -287
  21. package/src/error-report.ts +8 -12
  22. package/src/errors.ts +62 -59
  23. package/src/explore.ts +34 -29
  24. package/src/export.ts +73 -63
  25. package/src/help.ts +157 -157
  26. package/src/history.ts +69 -55
  27. package/src/init.ts +60 -55
  28. package/src/landing.ts +106 -104
  29. package/src/login.ts +186 -0
  30. package/src/markdown-render.ts +1 -6
  31. package/src/notifications.ts +75 -59
  32. package/src/open-url.ts +16 -16
  33. package/src/org.ts +299 -0
  34. package/src/output.ts +153 -137
  35. package/src/package-browser.ts +317 -305
  36. package/src/package.ts +149 -137
  37. package/src/pipe.ts +60 -54
  38. package/src/releases.ts +182 -144
  39. package/src/saved-searches.ts +72 -50
  40. package/src/search-state.ts +283 -229
  41. package/src/search.ts +678 -653
  42. package/src/session.ts +26 -24
  43. package/src/share.ts +61 -54
  44. package/src/status.ts +68 -61
  45. package/src/storage.ts +136 -106
  46. package/src/themes.ts +259 -116
  47. package/src/tips.ts +42 -42
  48. package/src/toast.ts +70 -69
  49. package/src/trending-parser.ts +104 -0
  50. package/src/trending.ts +481 -462
  51. package/src/tui.ts +3015 -2867
  52. package/src/types.ts +160 -158
  53. package/src/update-check.ts +231 -215
  54. package/src/version.ts +33 -0
  55. package/src/watch.ts +95 -74
package/src/output.ts CHANGED
@@ -1,137 +1,153 @@
1
- /**
2
- * Output module — unified formatting, export, and pipe execution.
3
- *
4
- * All format functions (JSON, CSV, Markdown, text, urls, names, ssh-urls,
5
- * clone-commands, ids) register in a single registry. One `format()` function
6
- * dispatches. `exportToFile` and `pipeExec` are methods on the same module.
7
- */
8
- import { writeFileSync } from "fs";
9
- import type { Repo } from "./types";
10
- import { openUrl } from "./open-url";
11
-
12
- export type Format =
13
- | "json" | "csv" | "markdown" | "text"
14
- | "urls" | "names" | "ssh-urls" | "clone-commands" | "ids";
15
-
16
- export type FormatFn = (repos: Repo[]) => string;
17
-
18
- /** Registry of all format functions. Adding a format = 1 line here. */
19
- const FORMATS: Map<Format, FormatFn> = new Map([
20
- // Export formats
21
- ["json", formatJson],
22
- ["csv", formatCsv],
23
- ["markdown", formatMarkdown],
24
- ["text", formatText],
25
- // Pipe formats
26
- ["urls", formatUrls],
27
- ["names", formatNames],
28
- ["ssh-urls", formatSshUrls],
29
- ["clone-commands", formatCloneCommands],
30
- ["ids", formatIds],
31
- ]);
32
-
33
- // ── Export format functions ────────────────────────────────────────────
34
-
35
- export function formatJson(repos: Repo[]): string {
36
- return JSON.stringify(repos, null, 2);
37
- }
38
-
39
- function csvEscape(val: unknown): string {
40
- const str = String(val ?? "");
41
- if (str.includes('"') || str.includes(",") || str.includes("\n")) {
42
- return `"${str.replace(/"/g, '""')}"`;
43
- }
44
- return str;
45
- }
46
-
47
- export function formatCsv(repos: Repo[]): string {
48
- const header = "rank,full_name,stars,forks,language,url";
49
- const rows = repos.map((r, i) =>
50
- `${i + 1},${csvEscape(r.fullName)},${r.stars},${r.forks},${csvEscape(r.language ?? "")},${csvEscape(r.url)}`,
51
- );
52
- return [header, ...rows].join("\n");
53
- }
54
-
55
- export function formatMarkdown(repos: Repo[]): string {
56
- const header = "| # | Repo | Stars | Forks | Language |";
57
- const sep = "|---|------|-------|-------|----------|";
58
- const rows = repos.map(
59
- (r, i) =>
60
- `| ${i + 1} | [${r.fullName}](${r.url}) | ${r.stars.toLocaleString()} | ${r.forks.toLocaleString()} | ${r.language ?? "—"} |`,
61
- );
62
- return [header, sep, ...rows].join("\n");
63
- }
64
-
65
- export function formatText(repos: Repo[]): string {
66
- return repos.map((r, i) => `${i + 1}. ${r.fullName} ★ ${r.stars.toLocaleString()} ${r.url}`).join("\n");
67
- }
68
-
69
- // ── Pipe format functions ──────────────────────────────────────────────
70
-
71
- export function formatUrls(repos: Repo[]): string {
72
- return repos.map((r) => r.url).join("\n");
73
- }
74
-
75
- export function formatNames(repos: Repo[]): string {
76
- return repos.map((r) => r.fullName).join("\n");
77
- }
78
-
79
- export function formatSshUrls(repos: Repo[]): string {
80
- return repos.map((r) => `git@github.com:${r.fullName}.git`).join("\n");
81
- }
82
-
83
- export function formatCloneCommands(repos: Repo[]): string {
84
- return repos.map((r) => `git clone git@github.com:${r.fullName}.git`).join("\n");
85
- }
86
-
87
- export function formatIds(repos: Repo[]): string {
88
- return repos.map((r) => String(r.id)).join("\n");
89
- }
90
-
91
- // ── Public API ─────────────────────────────────────────────────────────
92
-
93
- /** Format repos using the registered format function. */
94
- export function format(repos: Repo[], format: Format): string {
95
- const fn = FORMATS.get(format);
96
- if (!fn) throw new Error(`Unknown format: ${format}`);
97
- return fn(repos);
98
- }
99
-
100
- /** Export repos to a file. Returns the file path. */
101
- export function exportToFile(repos: Repo[], fmt: Format): string {
102
- const ext = fmt === "markdown" ? "md" : fmt;
103
- const ts = Date.now();
104
- const path = `./ghfind-export-${ts}.${ext}`;
105
- writeFileSync(path, format(repos, fmt), "utf-8");
106
- return path;
107
- }
108
-
109
- /** Execute a pipe target (clone, open) on repos. */
110
- export async function pipeExec(repos: Repo[], target: string): Promise<void> {
111
- for (const repo of repos) {
112
- const url = repo.url;
113
- switch (target) {
114
- case "open":
115
- await openUrl(url);
116
- break;
117
- case "clone":
118
- console.log(`git clone git@github.com:${repo.fullName}.git`);
119
- break;
120
- }
121
- }
122
- }
123
-
124
- // ─── Backward-compatible re-exports ─────────────────────────────────────
125
-
126
- export type ExportFormat = "json" | "csv" | "markdown" | "text";
127
- export type FormatLine = "urls" | "names" | "ssh-urls" | "clone-commands" | "ids";
128
-
129
- /** @deprecated Use `format()` instead. */
130
- export function formatRepos(repos: Repo[], fmt: ExportFormat): string {
131
- return format(repos, fmt);
132
- }
133
-
134
- /** @deprecated Use `format()` instead. */
135
- export function formatLines(repos: Repo[], fmt: FormatLine): string {
136
- return format(repos, fmt);
137
- }
1
+ /**
2
+ * Output module — unified formatting, export, and pipe execution.
3
+ *
4
+ * All format functions (JSON, CSV, Markdown, text, urls, names, ssh-urls,
5
+ * clone-commands, ids) register in a single registry. One `format()` function
6
+ * dispatches. `exportToFile` and `pipeExec` are methods on the same module.
7
+ */
8
+ import { writeFileSync } from "fs";
9
+ import type { Repo } from "./types";
10
+ import { openUrl } from "./open-url";
11
+
12
+ export type Format =
13
+ | "json"
14
+ | "csv"
15
+ | "markdown"
16
+ | "text"
17
+ | "urls"
18
+ | "names"
19
+ | "ssh-urls"
20
+ | "clone-commands"
21
+ | "ids";
22
+
23
+ export type FormatFn = (repos: Repo[]) => string;
24
+
25
+ /** Registry of all format functions. Adding a format = 1 line here. */
26
+ const FORMATS: Map<Format, FormatFn> = new Map([
27
+ // Export formats
28
+ ["json", formatJson],
29
+ ["csv", formatCsv],
30
+ ["markdown", formatMarkdown],
31
+ ["text", formatText],
32
+ // Pipe formats
33
+ ["urls", formatUrls],
34
+ ["names", formatNames],
35
+ ["ssh-urls", formatSshUrls],
36
+ ["clone-commands", formatCloneCommands],
37
+ ["ids", formatIds],
38
+ ]);
39
+
40
+ // ── Export format functions ────────────────────────────────────────────
41
+
42
+ export function formatJson(repos: Repo[]): string {
43
+ return JSON.stringify(repos, null, 2);
44
+ }
45
+
46
+ function csvEscape(val: unknown): string {
47
+ const str = String(val ?? "");
48
+ if (str.includes('"') || str.includes(",") || str.includes("\n")) {
49
+ return `"${str.replace(/"/g, '""')}"`;
50
+ }
51
+ return str;
52
+ }
53
+
54
+ export function formatCsv(repos: Repo[]): string {
55
+ const header = "rank,full_name,stars,forks,language,url";
56
+ const rows = repos.map(
57
+ (r, i) =>
58
+ `${i + 1},${csvEscape(r.fullName)},${r.stars},${r.forks},${csvEscape(r.language ?? "")},${csvEscape(r.url)}`,
59
+ );
60
+ return [header, ...rows].join("\n");
61
+ }
62
+
63
+ export function formatMarkdown(repos: Repo[]): string {
64
+ const header = "| # | Repo | Stars | Forks | Language |";
65
+ const sep = "|---|------|-------|-------|----------|";
66
+ const rows = repos.map(
67
+ (r, i) =>
68
+ `| ${i + 1} | [${r.fullName}](${r.url}) | ${r.stars.toLocaleString()} | ${r.forks.toLocaleString()} | ${r.language ?? "—"} |`,
69
+ );
70
+ return [header, sep, ...rows].join("\n");
71
+ }
72
+
73
+ export function formatText(repos: Repo[]): string {
74
+ return repos
75
+ .map(
76
+ (r, i) =>
77
+ `${i + 1}. ${r.fullName} ★ ${r.stars.toLocaleString()} ${r.url}`,
78
+ )
79
+ .join("\n");
80
+ }
81
+
82
+ // ── Pipe format functions ──────────────────────────────────────────────
83
+
84
+ export function formatUrls(repos: Repo[]): string {
85
+ return repos.map((r) => r.url).join("\n");
86
+ }
87
+
88
+ export function formatNames(repos: Repo[]): string {
89
+ return repos.map((r) => r.fullName).join("\n");
90
+ }
91
+
92
+ export function formatSshUrls(repos: Repo[]): string {
93
+ return repos.map((r) => `git@github.com:${r.fullName}.git`).join("\n");
94
+ }
95
+
96
+ export function formatCloneCommands(repos: Repo[]): string {
97
+ return repos
98
+ .map((r) => `git clone git@github.com:${r.fullName}.git`)
99
+ .join("\n");
100
+ }
101
+
102
+ export function formatIds(repos: Repo[]): string {
103
+ return repos.map((r) => String(r.id)).join("\n");
104
+ }
105
+
106
+ // ── Public API ─────────────────────────────────────────────────────────
107
+
108
+ /** Format repos using the registered format function. */
109
+ export function format(repos: Repo[], format: Format): string {
110
+ const fn = FORMATS.get(format);
111
+ if (!fn) throw new Error(`Unknown format: ${format}`);
112
+ return fn(repos);
113
+ }
114
+
115
+ /** Export repos to a file. Returns the file path. */
116
+ export function exportToFile(repos: Repo[], fmt: Format): string {
117
+ const ext = fmt === "markdown" ? "md" : fmt;
118
+ const ts = Date.now();
119
+ const path = `./ghfind-export-${ts}.${ext}`;
120
+ writeFileSync(path, format(repos, fmt), "utf-8");
121
+ return path;
122
+ }
123
+
124
+ /** Execute a pipe target (clone, open) on repos. */
125
+ export async function pipeExec(repos: Repo[], target: string): Promise<void> {
126
+ for (const repo of repos) {
127
+ const url = repo.url;
128
+ switch (target) {
129
+ case "open":
130
+ await openUrl(url);
131
+ break;
132
+ case "clone":
133
+ console.log(`git clone git@github.com:${repo.fullName}.git`);
134
+ break;
135
+ }
136
+ }
137
+ }
138
+
139
+ // ─── Backward-compatible re-exports ─────────────────────────────────────
140
+
141
+ export type ExportFormat = "json" | "csv" | "markdown" | "text";
142
+ export type FormatLine =
143
+ "urls" | "names" | "ssh-urls" | "clone-commands" | "ids";
144
+
145
+ /** @deprecated Use `format()` instead. */
146
+ export function formatRepos(repos: Repo[], fmt: ExportFormat): string {
147
+ return format(repos, fmt);
148
+ }
149
+
150
+ /** @deprecated Use `format()` instead. */
151
+ export function formatLines(repos: Repo[], fmt: FormatLine): string {
152
+ return format(repos, fmt);
153
+ }