git-tm 0.4.1 → 1.0.1
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/LICENSE +21 -21
- package/README.md +176 -89
- package/package.json +40 -45
- package/src/cli.js +147 -235
- package/src/git.js +690 -213
- package/src/public/app.css +2628 -0
- package/src/public/index.html +78 -88
- package/src/public/js/compare.js +426 -0
- package/src/public/js/detail.js +269 -0
- package/src/public/js/diff.js +328 -0
- package/src/public/js/graph.js +110 -0
- package/src/public/js/history.js +386 -0
- package/src/public/js/insights.js +150 -0
- package/src/public/js/main.js +409 -0
- package/src/public/js/theme.js +5 -0
- package/src/public/js/ui.js +226 -0
- package/src/public/logo.svg +1 -0
- package/src/server.js +207 -103
- package/src/public/app.js +0 -960
- package/src/public/fonts/InterVariable.woff2 +0 -0
- package/src/public/images/logo.png +0 -0
- package/src/public/images/logo.svg +0 -9
- package/src/public/styles.css +0 -1259
package/src/cli.js
CHANGED
|
@@ -1,235 +1,147 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
)
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
)
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
borderColor: "cyan",
|
|
149
|
-
width: boxWidth,
|
|
150
|
-
textAlignment: "left",
|
|
151
|
-
float: "left",
|
|
152
|
-
...options,
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (process.argv.includes('-v') || process.argv.includes('--version')) {
|
|
157
|
-
console.log("\n"+chalk.hex("#e84d31")("git-tm") + ` version: ${chalk.cyan(VERSION)}`);
|
|
158
|
-
process.exit(0);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
program
|
|
162
|
-
.name("git-tm")
|
|
163
|
-
.description("Interactive Git repository visualization tool")
|
|
164
|
-
.version(VERSION, '-v, --version', 'Output the current version')
|
|
165
|
-
.argument("[repo-path]", "path to git repository")
|
|
166
|
-
.option(
|
|
167
|
-
"-p, --port <number>",
|
|
168
|
-
"port to run the server on",
|
|
169
|
-
DEFAULT_PORT.toString()
|
|
170
|
-
)
|
|
171
|
-
.helpOption(false)
|
|
172
|
-
.addOption(new program.Option("-h, --help", "display help").hideHelp())
|
|
173
|
-
.action(async (repoPath, options) => {
|
|
174
|
-
if (options.help) {
|
|
175
|
-
console.log(await getHelpText() + "\n");
|
|
176
|
-
process.exit(0);
|
|
177
|
-
}
|
|
178
|
-
if (!repoPath) {
|
|
179
|
-
console.log(await getHelpText() + '\n');
|
|
180
|
-
process.exit(0);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
await displayBanner();
|
|
184
|
-
console.log();
|
|
185
|
-
|
|
186
|
-
const fullPath = await validateGitRepo(repoPath);
|
|
187
|
-
process.chdir(fullPath);
|
|
188
|
-
|
|
189
|
-
const startingSpinner = createSpinner("Starting server...");
|
|
190
|
-
startingSpinner.start();
|
|
191
|
-
|
|
192
|
-
try {
|
|
193
|
-
const port = await startServer(parseInt(options.port));
|
|
194
|
-
startingSpinner.succeed(chalk.green("Server started successfully"));
|
|
195
|
-
|
|
196
|
-
console.log(
|
|
197
|
-
createBox(
|
|
198
|
-
[
|
|
199
|
-
chalk.cyan.bold("📂 Repository Information"),
|
|
200
|
-
`${chalk.white("Path:")} ${chalk.yellow(fullPath)}`,
|
|
201
|
-
"",
|
|
202
|
-
chalk.cyan.bold("🚀 Server Information"),
|
|
203
|
-
`${chalk.white("URL:")} ${chalk.green(
|
|
204
|
-
`http://localhost:${port}`
|
|
205
|
-
)}`,
|
|
206
|
-
`${chalk.white("Port:")} ${chalk.cyan(port)}`,
|
|
207
|
-
"",
|
|
208
|
-
chalk.dim("Press Ctrl+C to stop the server"),
|
|
209
|
-
].join("\n")
|
|
210
|
-
)
|
|
211
|
-
);
|
|
212
|
-
|
|
213
|
-
await sleep(5000);
|
|
214
|
-
|
|
215
|
-
process.on("SIGINT", async () => {
|
|
216
|
-
console.log(
|
|
217
|
-
centerAlign(chalk.cyan("\nThanks for using Git Time Machine! 👋\n"))
|
|
218
|
-
);
|
|
219
|
-
process.exit(0);
|
|
220
|
-
});
|
|
221
|
-
} catch (error) {
|
|
222
|
-
startingSpinner.fail(chalk.red("Failed to start server"));
|
|
223
|
-
console.log(chalk.red(`Error: ${error.message}\n`));
|
|
224
|
-
process.exit(1);
|
|
225
|
-
}
|
|
226
|
-
})
|
|
227
|
-
.exitOverride(async (err) => {
|
|
228
|
-
if (err.code === "commander.missingArgument") {
|
|
229
|
-
console.log(await getHelpText() + "\n");
|
|
230
|
-
process.exit(1);
|
|
231
|
-
}
|
|
232
|
-
throw err;
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
program.parse(process.argv);
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { parseArgs } from "node:util";
|
|
7
|
+
import { openRepo } from "./git.js";
|
|
8
|
+
import { createServer, listen } from "./server.js";
|
|
9
|
+
|
|
10
|
+
const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
11
|
+
|
|
12
|
+
const useColor = process.stdout.isTTY && !process.env.NO_COLOR && process.env.TERM !== "dumb";
|
|
13
|
+
const paint = (code) => (s) => (useColor ? `\x1b[${code}m${s}\x1b[0m` : String(s));
|
|
14
|
+
const c = {
|
|
15
|
+
bold: paint("1"),
|
|
16
|
+
dim: paint("2"),
|
|
17
|
+
red: paint("31"),
|
|
18
|
+
green: paint("32"),
|
|
19
|
+
cyan: paint("36"),
|
|
20
|
+
accent: (s) => (useColor ? `\x1b[38;2;240;81;51m${s}\x1b[0m` : String(s)),
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const HELP = `
|
|
24
|
+
${c.accent(c.bold("git-tm"))} ${c.dim(`v${pkg.version}`)} Explore a repository's history in your browser
|
|
25
|
+
|
|
26
|
+
${c.bold("Usage")}
|
|
27
|
+
git-tm [path] [options]
|
|
28
|
+
git tm [path] [options] ${c.dim("same thing, as a Git subcommand (use -h for help)")}
|
|
29
|
+
|
|
30
|
+
${c.bold("Options")}
|
|
31
|
+
-p, --port <number> Port to listen on ${c.dim("(default 7890, next free port is used if busy)")}
|
|
32
|
+
--host <address> Interface to bind ${c.dim("(default 127.0.0.1)")}
|
|
33
|
+
-o, --open Open the browser once the server is running
|
|
34
|
+
--no-avatars Do not load author avatars from GitHub / Gravatar
|
|
35
|
+
-v, --version Print the version
|
|
36
|
+
-h, --help Print this help
|
|
37
|
+
|
|
38
|
+
${c.bold("Examples")}
|
|
39
|
+
git-tm ${c.dim("current directory")}
|
|
40
|
+
git-tm ../other-repo ${c.dim("another repository")}
|
|
41
|
+
git-tm -p 8080 --open
|
|
42
|
+
|
|
43
|
+
${c.dim(pkg.homepage)}
|
|
44
|
+
`;
|
|
45
|
+
|
|
46
|
+
function fail(message) {
|
|
47
|
+
console.error(`${c.red("error")} ${message}`);
|
|
48
|
+
console.error(c.dim("Run git-tm --help for usage."));
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function parse() {
|
|
53
|
+
try {
|
|
54
|
+
return parseArgs({
|
|
55
|
+
allowPositionals: true,
|
|
56
|
+
options: {
|
|
57
|
+
port: { type: "string", short: "p", default: "7890" },
|
|
58
|
+
host: { type: "string", default: "127.0.0.1" },
|
|
59
|
+
open: { type: "boolean", short: "o", default: false },
|
|
60
|
+
"no-open": { type: "boolean", default: false }, // accepted for compatibility; opening is now opt-in
|
|
61
|
+
"no-avatars": { type: "boolean", default: false },
|
|
62
|
+
version: { type: "boolean", short: "v", default: false },
|
|
63
|
+
help: { type: "boolean", short: "h", default: false },
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
} catch (err) {
|
|
67
|
+
fail(err.message);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function openBrowser(url) {
|
|
72
|
+
const [cmd, args] =
|
|
73
|
+
process.platform === "darwin"
|
|
74
|
+
? ["open", [url]]
|
|
75
|
+
: process.platform === "win32"
|
|
76
|
+
? ["cmd", ["/c", "start", "", url]]
|
|
77
|
+
: ["xdg-open", [url]];
|
|
78
|
+
try {
|
|
79
|
+
const child = spawn(cmd, args, { stdio: "ignore", detached: true, windowsHide: true });
|
|
80
|
+
child.on("error", () => {});
|
|
81
|
+
child.unref();
|
|
82
|
+
} catch {
|
|
83
|
+
/* no browser available; the URL is printed anyway */
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function tildify(p) {
|
|
88
|
+
const home = os.homedir();
|
|
89
|
+
return p === home || p.startsWith(home + path.sep) ? "~" + p.slice(home.length) : p;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async function main() {
|
|
93
|
+
const { values, positionals } = parse();
|
|
94
|
+
if (values.help) return console.log(HELP);
|
|
95
|
+
if (values.version) return console.log(pkg.version);
|
|
96
|
+
if (positionals.length > 1) fail("Only one repository path can be given");
|
|
97
|
+
|
|
98
|
+
const port = Number(values.port);
|
|
99
|
+
if (!Number.isInteger(port) || port < 0 || port > 65535) fail(`Invalid port: ${values.port}`);
|
|
100
|
+
|
|
101
|
+
const target = path.resolve(positionals[0] ?? ".");
|
|
102
|
+
let repo;
|
|
103
|
+
try {
|
|
104
|
+
repo = await openRepo(target);
|
|
105
|
+
} catch (err) {
|
|
106
|
+
fail(err.message);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const server = createServer(repo, { avatars: !values["no-avatars"], host: values.host });
|
|
110
|
+
let actual;
|
|
111
|
+
try {
|
|
112
|
+
actual = await listen(server, port, values.host);
|
|
113
|
+
} catch (err) {
|
|
114
|
+
fail(`Could not start server: ${err.message}`);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const shownHost = ["127.0.0.1", "::1", "0.0.0.0", "::"].includes(values.host) ? "localhost" : values.host;
|
|
118
|
+
const url = `http://${shownHost}:${actual}`;
|
|
119
|
+
const info = await repo.info().catch(() => ({}));
|
|
120
|
+
const where = info.branch ?? (info.head ? info.head.slice(0, 7) : "no commits yet");
|
|
121
|
+
|
|
122
|
+
console.log();
|
|
123
|
+
console.log(` ${c.accent(c.bold("git-tm"))} ${c.dim(`v${pkg.version}`)}`);
|
|
124
|
+
console.log();
|
|
125
|
+
console.log(` ${c.dim("repo")} ${tildify(repo.root)} ${c.dim(`(${where})`)}`);
|
|
126
|
+
console.log(` ${c.dim("url ")} ${c.cyan(url)}`);
|
|
127
|
+
if (actual !== port && port !== 0) console.log(` ${c.dim(`port ${port} was busy, using ${actual}`)}`);
|
|
128
|
+
console.log();
|
|
129
|
+
console.log(c.dim(" Press Ctrl+C to stop"));
|
|
130
|
+
console.log();
|
|
131
|
+
|
|
132
|
+
if (values.open) openBrowser(url);
|
|
133
|
+
|
|
134
|
+
// Keep serving if something unexpected goes wrong; say what happened instead of dying silently.
|
|
135
|
+
const report = (err) => console.error(`${c.red("error")} ${err?.stack || err}`);
|
|
136
|
+
process.on("uncaughtException", report);
|
|
137
|
+
process.on("unhandledRejection", report);
|
|
138
|
+
|
|
139
|
+
const stop = () => {
|
|
140
|
+
server.close();
|
|
141
|
+
process.exit(0);
|
|
142
|
+
};
|
|
143
|
+
process.on("SIGINT", stop);
|
|
144
|
+
process.on("SIGTERM", stop);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
main();
|