@zjex/git-workflow 0.3.0 → 0.3.2
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/.husky/pre-commit +5 -2
- package/ROADMAP.md +275 -0
- package/dist/index.js +349 -88
- package/docs/features/git-wrapped.md +199 -0
- package/package.json +2 -1
- package/scripts/release.sh +61 -1
- package/src/ai-service.ts +8 -2
- package/src/commands/commit.ts +4 -0
- package/src/commands/log.ts +503 -0
- package/src/index.ts +37 -13
- package/src/utils.ts +10 -0
- package/tests/log.test.ts +106 -0
- package/src/commands/help.ts +0 -76
- package/tests/help.test.ts +0 -134
package/dist/index.js
CHANGED
|
@@ -59,9 +59,14 @@ var init_utils = __esm({
|
|
|
59
59
|
red: (s) => `\x1B[31m${s}\x1B[0m`,
|
|
60
60
|
green: (s) => `\x1B[32m${s}\x1B[0m`,
|
|
61
61
|
yellow: (s) => `\x1B[33m${s}\x1B[0m`,
|
|
62
|
+
blue: (s) => `\x1B[34m${s}\x1B[0m`,
|
|
62
63
|
cyan: (s) => `\x1B[36m${s}\x1B[0m`,
|
|
63
64
|
dim: (s) => `\x1B[2m${s}\x1B[0m`,
|
|
64
65
|
bold: (s) => `\x1B[1m${s}\x1B[0m`,
|
|
66
|
+
purple: (s) => `\x1B[35m${s}\x1B[0m`,
|
|
67
|
+
orange: (s) => `\x1B[38;5;208m${s}\x1B[0m`,
|
|
68
|
+
lightPurple: (s) => `\x1B[38;5;141m${s}\x1B[0m`,
|
|
69
|
+
white: (s) => `\x1B[37m${s}\x1B[0m`,
|
|
65
70
|
reset: "\x1B[0m"
|
|
66
71
|
};
|
|
67
72
|
TODAY = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10).replace(/-/g, "");
|
|
@@ -1993,7 +1998,9 @@ async function callOllamaAPI(prompt, model, maxTokens) {
|
|
|
1993
1998
|
}
|
|
1994
1999
|
}
|
|
1995
2000
|
function cleanAIResponse(response) {
|
|
1996
|
-
|
|
2001
|
+
let cleaned = response.replace(/^[.\s`~-]+/, "").trim();
|
|
2002
|
+
cleaned = cleaned.replace(/[.\s`~-]+$/, "").trim();
|
|
2003
|
+
const lines = cleaned.split("\n").map((line) => line.trim()).filter((line) => line);
|
|
1997
2004
|
const uniqueLines = [];
|
|
1998
2005
|
const seen = /* @__PURE__ */ new Set();
|
|
1999
2006
|
for (const line of lines) {
|
|
@@ -2253,6 +2260,7 @@ async function commit() {
|
|
|
2253
2260
|
spinner.succeed("\u63D0\u4EA4\u6210\u529F");
|
|
2254
2261
|
const commitHash = execOutput("git rev-parse --short HEAD");
|
|
2255
2262
|
console.log(colors.dim(`commit: ${commitHash}`));
|
|
2263
|
+
console.log("");
|
|
2256
2264
|
} catch (error) {
|
|
2257
2265
|
spinner.fail("\u63D0\u4EA4\u5931\u8D25");
|
|
2258
2266
|
console.log("");
|
|
@@ -2264,6 +2272,7 @@ async function commit() {
|
|
|
2264
2272
|
console.log(colors.yellow("\u4F60\u53EF\u4EE5\u624B\u52A8\u6267\u884C\u4EE5\u4E0B\u547D\u4EE4:"));
|
|
2265
2273
|
console.log(colors.cyan(` git commit -m "${message}"`));
|
|
2266
2274
|
console.log("");
|
|
2275
|
+
throw error;
|
|
2267
2276
|
}
|
|
2268
2277
|
}
|
|
2269
2278
|
async function buildManualCommitMessage(config2) {
|
|
@@ -2345,83 +2354,6 @@ ${issues}`;
|
|
|
2345
2354
|
return message;
|
|
2346
2355
|
}
|
|
2347
2356
|
|
|
2348
|
-
// src/commands/help.ts
|
|
2349
|
-
init_utils();
|
|
2350
|
-
function showHelp() {
|
|
2351
|
-
return `
|
|
2352
|
-
\u5206\u652F\u547D\u4EE4:
|
|
2353
|
-
gw feature [--base <branch>] \u521B\u5EFA feature \u5206\u652F
|
|
2354
|
-
gw feat [--base <branch>] \u540C\u4E0A (\u522B\u540D)
|
|
2355
|
-
gw f [--base <branch>] \u540C\u4E0A (\u522B\u540D)
|
|
2356
|
-
|
|
2357
|
-
gw hotfix [--base <branch>] \u521B\u5EFA hotfix \u5206\u652F
|
|
2358
|
-
gw fix [--base <branch>] \u540C\u4E0A (\u522B\u540D)
|
|
2359
|
-
gw h [--base <branch>] \u540C\u4E0A (\u522B\u540D)
|
|
2360
|
-
|
|
2361
|
-
gw delete [branch] \u5220\u9664\u672C\u5730/\u8FDC\u7A0B\u5206\u652F
|
|
2362
|
-
gw del [branch] \u540C\u4E0A (\u522B\u540D)
|
|
2363
|
-
gw d [branch] \u540C\u4E0A (\u522B\u540D)
|
|
2364
|
-
|
|
2365
|
-
Tag \u547D\u4EE4:
|
|
2366
|
-
gw tags [prefix] \u5217\u51FA\u6240\u6709 tag\uFF0C\u53EF\u6309\u524D\u7F00\u8FC7\u6EE4
|
|
2367
|
-
gw ts [prefix] \u540C\u4E0A (\u522B\u540D)
|
|
2368
|
-
|
|
2369
|
-
gw tag [prefix] \u4EA4\u4E92\u5F0F\u9009\u62E9\u7248\u672C\u7C7B\u578B\u5E76\u521B\u5EFA tag
|
|
2370
|
-
gw t [prefix] \u540C\u4E0A (\u522B\u540D)
|
|
2371
|
-
|
|
2372
|
-
gw tag:delete \u5220\u9664 tag
|
|
2373
|
-
gw td \u540C\u4E0A (\u522B\u540D)
|
|
2374
|
-
|
|
2375
|
-
gw tag:update \u91CD\u547D\u540D tag
|
|
2376
|
-
gw tu \u540C\u4E0A (\u522B\u540D)
|
|
2377
|
-
|
|
2378
|
-
\u53D1\u5E03\u547D\u4EE4:
|
|
2379
|
-
gw release \u4EA4\u4E92\u5F0F\u9009\u62E9\u7248\u672C\u53F7\u5E76\u66F4\u65B0 package.json
|
|
2380
|
-
gw r \u540C\u4E0A (\u522B\u540D)
|
|
2381
|
-
|
|
2382
|
-
\u914D\u7F6E\u547D\u4EE4:
|
|
2383
|
-
gw init \u521D\u59CB\u5316\u914D\u7F6E\u6587\u4EF6
|
|
2384
|
-
\u2022 \u5168\u5C40\u914D\u7F6E: ~/.gwrc.json (\u6240\u6709\u9879\u76EE\u751F\u6548)
|
|
2385
|
-
\u2022 \u9879\u76EE\u914D\u7F6E: .gwrc.json (\u4EC5\u5F53\u524D\u9879\u76EE)
|
|
2386
|
-
\u8FD0\u884C\u65F6\u53EF\u9009\u62E9\u914D\u7F6E\u8303\u56F4
|
|
2387
|
-
|
|
2388
|
-
\u66F4\u65B0\u547D\u4EE4:
|
|
2389
|
-
gw update \u68C0\u67E5\u5E76\u66F4\u65B0\u5230\u6700\u65B0\u7248\u672C
|
|
2390
|
-
gw upt \u540C\u4E0A (\u522B\u540D)
|
|
2391
|
-
|
|
2392
|
-
\u6E05\u7406\u547D\u4EE4:
|
|
2393
|
-
gw clean \u6E05\u7406\u7F13\u5B58\u6587\u4EF6
|
|
2394
|
-
|
|
2395
|
-
Stash \u547D\u4EE4:
|
|
2396
|
-
gw stash \u4EA4\u4E92\u5F0F\u7BA1\u7406 stash
|
|
2397
|
-
gw s \u540C\u4E0A (\u522B\u540D)
|
|
2398
|
-
gw st \u540C\u4E0A (\u522B\u540D)
|
|
2399
|
-
|
|
2400
|
-
Commit \u547D\u4EE4:
|
|
2401
|
-
gw commit \u4EA4\u4E92\u5F0F\u63D0\u4EA4 (Conventional Commits + Gitmoji)
|
|
2402
|
-
gw c \u540C\u4E0A (\u522B\u540D)
|
|
2403
|
-
gw cm \u540C\u4E0A (\u522B\u540D)
|
|
2404
|
-
|
|
2405
|
-
\u793A\u4F8B:
|
|
2406
|
-
gw f \u57FA\u4E8E main/master \u521B\u5EFA feature \u5206\u652F
|
|
2407
|
-
gw f --base develop \u57FA\u4E8E develop \u5206\u652F\u521B\u5EFA feature \u5206\u652F
|
|
2408
|
-
gw h --base release \u57FA\u4E8E release \u5206\u652F\u521B\u5EFA hotfix \u5206\u652F
|
|
2409
|
-
gw d \u4EA4\u4E92\u5F0F\u9009\u62E9\u5E76\u5220\u9664\u5206\u652F
|
|
2410
|
-
gw d feature/xxx \u76F4\u63A5\u5220\u9664\u6307\u5B9A\u5206\u652F
|
|
2411
|
-
gw ts v \u5217\u51FA\u6240\u6709 v \u5F00\u5934\u7684 tag
|
|
2412
|
-
gw t \u4EA4\u4E92\u5F0F\u521B\u5EFA tag
|
|
2413
|
-
gw td \u4EA4\u4E92\u5F0F\u5220\u9664 tag
|
|
2414
|
-
gw tu \u4EA4\u4E92\u5F0F\u4FEE\u6539 tag
|
|
2415
|
-
gw r \u4EA4\u4E92\u5F0F\u53D1\u5E03\u7248\u672C
|
|
2416
|
-
gw s \u4EA4\u4E92\u5F0F\u7BA1\u7406 stash
|
|
2417
|
-
gw c \u4EA4\u4E92\u5F0F\u63D0\u4EA4\u4EE3\u7801
|
|
2418
|
-
|
|
2419
|
-
\u5206\u652F\u547D\u540D\u683C\u5F0F:
|
|
2420
|
-
feature/${TODAY}-<Story ID>-<\u63CF\u8FF0>
|
|
2421
|
-
hotfix/${TODAY}-<Issue ID>-<\u63CF\u8FF0>
|
|
2422
|
-
`;
|
|
2423
|
-
}
|
|
2424
|
-
|
|
2425
2357
|
// src/index.ts
|
|
2426
2358
|
init_update_notifier();
|
|
2427
2359
|
|
|
@@ -2561,6 +2493,320 @@ async function update(currentVersion) {
|
|
|
2561
2493
|
}
|
|
2562
2494
|
}
|
|
2563
2495
|
|
|
2496
|
+
// src/commands/log.ts
|
|
2497
|
+
init_utils();
|
|
2498
|
+
import { execSync as execSync8 } from "child_process";
|
|
2499
|
+
import boxen3 from "boxen";
|
|
2500
|
+
import { spawn } from "child_process";
|
|
2501
|
+
function parseGitLog(output) {
|
|
2502
|
+
const commits = [];
|
|
2503
|
+
const lines = output.trim().split("\n");
|
|
2504
|
+
for (const line of lines) {
|
|
2505
|
+
if (!line.trim()) continue;
|
|
2506
|
+
const parts = line.split("|");
|
|
2507
|
+
if (parts.length >= 6) {
|
|
2508
|
+
commits.push({
|
|
2509
|
+
hash: parts[0],
|
|
2510
|
+
shortHash: parts[1],
|
|
2511
|
+
subject: parts[2],
|
|
2512
|
+
author: parts[3],
|
|
2513
|
+
date: parts[4],
|
|
2514
|
+
relativeDate: parts[5],
|
|
2515
|
+
refs: parts[6] || ""
|
|
2516
|
+
});
|
|
2517
|
+
}
|
|
2518
|
+
}
|
|
2519
|
+
return commits;
|
|
2520
|
+
}
|
|
2521
|
+
function getCommitTypeIcon(subject) {
|
|
2522
|
+
const lowerSubject = subject.toLowerCase();
|
|
2523
|
+
if (lowerSubject.includes("feat") || lowerSubject.includes("feature")) return "\u2728";
|
|
2524
|
+
if (lowerSubject.includes("fix") || lowerSubject.includes("bug")) return "\u{1F41B}";
|
|
2525
|
+
if (lowerSubject.includes("docs") || lowerSubject.includes("doc")) return "\u{1F4DA}";
|
|
2526
|
+
if (lowerSubject.includes("style")) return "\u{1F484}";
|
|
2527
|
+
if (lowerSubject.includes("refactor")) return "\u267B\uFE0F";
|
|
2528
|
+
if (lowerSubject.includes("test")) return "\u{1F9EA}";
|
|
2529
|
+
if (lowerSubject.includes("chore")) return "\u{1F527}";
|
|
2530
|
+
if (lowerSubject.includes("perf")) return "\u26A1";
|
|
2531
|
+
if (lowerSubject.includes("ci")) return "\u{1F477}";
|
|
2532
|
+
if (lowerSubject.includes("build")) return "\u{1F4E6}";
|
|
2533
|
+
if (lowerSubject.includes("revert")) return "\u23EA";
|
|
2534
|
+
if (lowerSubject.includes("merge")) return "\u{1F500}";
|
|
2535
|
+
if (lowerSubject.includes("release") || lowerSubject.includes("version")) return "\u{1F516}";
|
|
2536
|
+
return "\u{1F4DD}";
|
|
2537
|
+
}
|
|
2538
|
+
function groupCommitsByDate(commits) {
|
|
2539
|
+
const groups = /* @__PURE__ */ new Map();
|
|
2540
|
+
for (const commit2 of commits) {
|
|
2541
|
+
const date = commit2.date;
|
|
2542
|
+
if (!groups.has(date)) {
|
|
2543
|
+
groups.set(date, []);
|
|
2544
|
+
}
|
|
2545
|
+
groups.get(date).push(commit2);
|
|
2546
|
+
}
|
|
2547
|
+
return groups;
|
|
2548
|
+
}
|
|
2549
|
+
function formatRelativeTime(relativeDate) {
|
|
2550
|
+
let result = relativeDate;
|
|
2551
|
+
const timeMap = {
|
|
2552
|
+
"second": "\u79D2",
|
|
2553
|
+
"seconds": "\u79D2",
|
|
2554
|
+
"minute": "\u5206\u949F",
|
|
2555
|
+
"minutes": "\u5206\u949F",
|
|
2556
|
+
"hour": "\u5C0F\u65F6",
|
|
2557
|
+
"hours": "\u5C0F\u65F6",
|
|
2558
|
+
"day": "\u5929",
|
|
2559
|
+
"days": "\u5929",
|
|
2560
|
+
"week": "\u5468",
|
|
2561
|
+
"weeks": "\u5468",
|
|
2562
|
+
"month": "\u4E2A\u6708",
|
|
2563
|
+
"months": "\u4E2A\u6708",
|
|
2564
|
+
"year": "\u5E74",
|
|
2565
|
+
"years": "\u5E74",
|
|
2566
|
+
"ago": "\u524D"
|
|
2567
|
+
};
|
|
2568
|
+
for (const [en, zh] of Object.entries(timeMap)) {
|
|
2569
|
+
result = result.replace(new RegExp(`\\b${en}\\b`, "g"), zh);
|
|
2570
|
+
}
|
|
2571
|
+
result = result.replace(/(\d+)\s+(秒|分钟|小时|天|周|个月|年)\s+前/g, "$1$2\u524D");
|
|
2572
|
+
const match = result.match(/(\d+)(分钟|小时|天|周|个月|年)前/);
|
|
2573
|
+
if (match) {
|
|
2574
|
+
const num = parseInt(match[1]);
|
|
2575
|
+
const unit = match[2];
|
|
2576
|
+
if (unit === "\u5206\u949F" && num >= 60) {
|
|
2577
|
+
const hours = Math.floor(num / 60);
|
|
2578
|
+
return `${hours}\u5C0F\u65F6\u524D`;
|
|
2579
|
+
}
|
|
2580
|
+
if (unit === "\u5C0F\u65F6" && num >= 24) {
|
|
2581
|
+
const days = Math.floor(num / 24);
|
|
2582
|
+
return `${days}\u5929\u524D`;
|
|
2583
|
+
}
|
|
2584
|
+
if (unit === "\u5929" && num >= 7 && num < 30) {
|
|
2585
|
+
const weeks = Math.floor(num / 7);
|
|
2586
|
+
return `${weeks}\u5468\u524D`;
|
|
2587
|
+
}
|
|
2588
|
+
if (unit === "\u5929" && num >= 30) {
|
|
2589
|
+
const months = Math.floor(num / 30);
|
|
2590
|
+
return `${months}\u4E2A\u6708\u524D`;
|
|
2591
|
+
}
|
|
2592
|
+
if (unit === "\u5468" && num >= 4) {
|
|
2593
|
+
const months = Math.floor(num / 4);
|
|
2594
|
+
return `${months}\u4E2A\u6708\u524D`;
|
|
2595
|
+
}
|
|
2596
|
+
if (unit === "\u4E2A\u6708" && num >= 12) {
|
|
2597
|
+
const years = Math.floor(num / 12);
|
|
2598
|
+
return `${years}\u5E74\u524D`;
|
|
2599
|
+
}
|
|
2600
|
+
}
|
|
2601
|
+
return result;
|
|
2602
|
+
}
|
|
2603
|
+
function parseCommitSubject(subject) {
|
|
2604
|
+
if (subject.includes(" - ")) {
|
|
2605
|
+
const parts = subject.split(" - ");
|
|
2606
|
+
const title = parts[0].trim();
|
|
2607
|
+
const tasks = parts.slice(1).map((task) => task.trim()).filter((task) => task.length > 0);
|
|
2608
|
+
return { title, tasks };
|
|
2609
|
+
}
|
|
2610
|
+
return { title: subject, tasks: [] };
|
|
2611
|
+
}
|
|
2612
|
+
function supportsColor() {
|
|
2613
|
+
return true;
|
|
2614
|
+
}
|
|
2615
|
+
function formatTimelineStyle(commits) {
|
|
2616
|
+
const groupedCommits = groupCommitsByDate(commits);
|
|
2617
|
+
let output = "";
|
|
2618
|
+
const sortedDates = Array.from(groupedCommits.keys()).sort(
|
|
2619
|
+
(a, b) => new Date(b).getTime() - new Date(a).getTime()
|
|
2620
|
+
);
|
|
2621
|
+
const useColors = supportsColor() || process.env.FORCE_COLOR;
|
|
2622
|
+
for (let dateIndex = 0; dateIndex < sortedDates.length; dateIndex++) {
|
|
2623
|
+
const date = sortedDates[dateIndex];
|
|
2624
|
+
const dateCommits = groupedCommits.get(date);
|
|
2625
|
+
const dateTitle = `\u{1F4C5} Commits on ${date}`;
|
|
2626
|
+
if (useColors) {
|
|
2627
|
+
output += "\n" + colors.bold(colors.yellow(dateTitle)) + "\n\n";
|
|
2628
|
+
} else {
|
|
2629
|
+
output += "\n" + dateTitle + "\n\n";
|
|
2630
|
+
}
|
|
2631
|
+
for (let commitIndex = 0; commitIndex < dateCommits.length; commitIndex++) {
|
|
2632
|
+
const commit2 = dateCommits[commitIndex];
|
|
2633
|
+
const icon = getCommitTypeIcon(commit2.subject);
|
|
2634
|
+
const { title, tasks } = parseCommitSubject(commit2.subject);
|
|
2635
|
+
const commitContent = [];
|
|
2636
|
+
if (useColors) {
|
|
2637
|
+
commitContent.push(`${icon} ${colors.bold(colors.white(title))}`);
|
|
2638
|
+
} else {
|
|
2639
|
+
commitContent.push(`${icon} ${title}`);
|
|
2640
|
+
}
|
|
2641
|
+
if (tasks.length > 0) {
|
|
2642
|
+
commitContent.push("");
|
|
2643
|
+
tasks.forEach((task) => {
|
|
2644
|
+
if (useColors) {
|
|
2645
|
+
commitContent.push(` ${colors.dim("\u2013")} ${colors.dim(task)}`);
|
|
2646
|
+
} else {
|
|
2647
|
+
commitContent.push(` \u2013 ${task}`);
|
|
2648
|
+
}
|
|
2649
|
+
});
|
|
2650
|
+
}
|
|
2651
|
+
commitContent.push("");
|
|
2652
|
+
if (useColors) {
|
|
2653
|
+
commitContent.push(`${colors.dim("\u{1F464}")} ${colors.blue(commit2.author)} ${colors.dim("committed")} ${colors.green(formatRelativeTime(commit2.relativeDate))}`);
|
|
2654
|
+
commitContent.push(`${colors.dim("\u{1F517}")} ${colors.orange("#" + commit2.shortHash)}`);
|
|
2655
|
+
if (commit2.refs && commit2.refs.trim()) {
|
|
2656
|
+
const refs = commit2.refs.trim();
|
|
2657
|
+
const refParts = refs.split(", ");
|
|
2658
|
+
const branches = [];
|
|
2659
|
+
const tags = [];
|
|
2660
|
+
refParts.forEach((ref) => {
|
|
2661
|
+
if (ref.startsWith("tag: ")) {
|
|
2662
|
+
tags.push(ref.replace("tag: ", ""));
|
|
2663
|
+
} else if (ref.includes("/") || ref === "HEAD") {
|
|
2664
|
+
branches.push(ref);
|
|
2665
|
+
} else {
|
|
2666
|
+
branches.push(ref);
|
|
2667
|
+
}
|
|
2668
|
+
});
|
|
2669
|
+
if (branches.length > 0) {
|
|
2670
|
+
commitContent.push(`${colors.dim("\u{1F33F}")} ${colors.lightPurple(branches.join(", "))}`);
|
|
2671
|
+
}
|
|
2672
|
+
if (tags.length > 0) {
|
|
2673
|
+
const tagText = tags.map((tag) => `tag ${tag}`).join(", ");
|
|
2674
|
+
commitContent.push(`${colors.dim("\u{1F516}")} ${colors.yellow(tagText)}`);
|
|
2675
|
+
}
|
|
2676
|
+
}
|
|
2677
|
+
} else {
|
|
2678
|
+
commitContent.push(`\u{1F464} ${commit2.author} committed ${formatRelativeTime(commit2.relativeDate)}`);
|
|
2679
|
+
commitContent.push(`\u{1F517} #${commit2.shortHash}`);
|
|
2680
|
+
if (commit2.refs && commit2.refs.trim()) {
|
|
2681
|
+
const refs = commit2.refs.trim();
|
|
2682
|
+
const refParts = refs.split(", ");
|
|
2683
|
+
const branches = [];
|
|
2684
|
+
const tags = [];
|
|
2685
|
+
refParts.forEach((ref) => {
|
|
2686
|
+
if (ref.startsWith("tag: ")) {
|
|
2687
|
+
tags.push(ref.replace("tag: ", ""));
|
|
2688
|
+
} else if (ref.includes("/") || ref === "HEAD") {
|
|
2689
|
+
branches.push(ref);
|
|
2690
|
+
} else {
|
|
2691
|
+
branches.push(ref);
|
|
2692
|
+
}
|
|
2693
|
+
});
|
|
2694
|
+
if (branches.length > 0) {
|
|
2695
|
+
commitContent.push(`\u{1F33F} ${branches.join(", ")}`);
|
|
2696
|
+
}
|
|
2697
|
+
if (tags.length > 0) {
|
|
2698
|
+
const tagText = tags.map((tag) => `tag ${tag}`).join(", ");
|
|
2699
|
+
commitContent.push(`\u{1F516} ${tagText}`);
|
|
2700
|
+
}
|
|
2701
|
+
}
|
|
2702
|
+
}
|
|
2703
|
+
const commitBox = boxen3(commitContent.join("\n"), {
|
|
2704
|
+
padding: { top: 0, bottom: 0, left: 1, right: 1 },
|
|
2705
|
+
margin: { top: 0, bottom: 1, left: 0, right: 0 },
|
|
2706
|
+
borderStyle: "round",
|
|
2707
|
+
borderColor: "gray"
|
|
2708
|
+
});
|
|
2709
|
+
output += commitBox + "\n";
|
|
2710
|
+
}
|
|
2711
|
+
}
|
|
2712
|
+
return output;
|
|
2713
|
+
}
|
|
2714
|
+
function startInteractivePager(content) {
|
|
2715
|
+
const pager = process.env.PAGER || "less";
|
|
2716
|
+
try {
|
|
2717
|
+
const pagerProcess = spawn(pager, ["-R", "-S", "-F", "-X", "-i"], {
|
|
2718
|
+
stdio: ["pipe", "inherit", "inherit"],
|
|
2719
|
+
env: { ...process.env, LESS: "-R -S -F -X -i" }
|
|
2720
|
+
});
|
|
2721
|
+
pagerProcess.stdin.write(content);
|
|
2722
|
+
pagerProcess.stdin.end();
|
|
2723
|
+
pagerProcess.on("exit", () => {
|
|
2724
|
+
});
|
|
2725
|
+
pagerProcess.on("error", (err) => {
|
|
2726
|
+
console.log(content);
|
|
2727
|
+
});
|
|
2728
|
+
} catch (error) {
|
|
2729
|
+
console.log(content);
|
|
2730
|
+
}
|
|
2731
|
+
}
|
|
2732
|
+
function executeTimelineLog(options) {
|
|
2733
|
+
try {
|
|
2734
|
+
let cmd = 'git log --pretty=format:"%H|%h|%s|%an|%ad|%ar|%D" --date=short';
|
|
2735
|
+
if (options.limit && !options.interactive) cmd += ` -${options.limit}`;
|
|
2736
|
+
if (options.author) cmd += ` --author="${options.author}"`;
|
|
2737
|
+
if (options.since) cmd += ` --since="${options.since}"`;
|
|
2738
|
+
if (options.until) cmd += ` --until="${options.until}"`;
|
|
2739
|
+
if (options.grep) cmd += ` --grep="${options.grep}"`;
|
|
2740
|
+
if (options.all) cmd += ` --all`;
|
|
2741
|
+
if (options.interactive && !options.limit) {
|
|
2742
|
+
cmd += ` -50`;
|
|
2743
|
+
}
|
|
2744
|
+
const output = execSync8(cmd, {
|
|
2745
|
+
encoding: "utf8",
|
|
2746
|
+
stdio: "pipe",
|
|
2747
|
+
maxBuffer: 1024 * 1024 * 10
|
|
2748
|
+
});
|
|
2749
|
+
if (output.trim()) {
|
|
2750
|
+
const commits = parseGitLog(output);
|
|
2751
|
+
let fullOutput = "";
|
|
2752
|
+
const title = `\u{1F4CA} \u5171\u663E\u793A ${commits.length} \u4E2A\u63D0\u4EA4`;
|
|
2753
|
+
fullOutput += "\n" + boxen3(title, {
|
|
2754
|
+
padding: { top: 0, bottom: 0, left: 2, right: 2 },
|
|
2755
|
+
margin: { top: 0, bottom: 1, left: 0, right: 0 },
|
|
2756
|
+
borderStyle: "double",
|
|
2757
|
+
borderColor: "green",
|
|
2758
|
+
textAlignment: "center"
|
|
2759
|
+
}) + "\n";
|
|
2760
|
+
const timelineOutput = formatTimelineStyle(commits);
|
|
2761
|
+
fullOutput += timelineOutput;
|
|
2762
|
+
if (options.interactive) {
|
|
2763
|
+
startInteractivePager(fullOutput);
|
|
2764
|
+
} else {
|
|
2765
|
+
console.log(fullOutput);
|
|
2766
|
+
}
|
|
2767
|
+
} else {
|
|
2768
|
+
const noCommitsMsg = "\n" + boxen3("\u{1F4ED} \u6CA1\u6709\u627E\u5230\u5339\u914D\u7684\u63D0\u4EA4\u8BB0\u5F55", {
|
|
2769
|
+
padding: { top: 0, bottom: 0, left: 2, right: 2 },
|
|
2770
|
+
borderStyle: "round",
|
|
2771
|
+
borderColor: "yellow",
|
|
2772
|
+
textAlignment: "center"
|
|
2773
|
+
});
|
|
2774
|
+
if (options.interactive) {
|
|
2775
|
+
startInteractivePager(noCommitsMsg);
|
|
2776
|
+
} else {
|
|
2777
|
+
console.log(noCommitsMsg);
|
|
2778
|
+
}
|
|
2779
|
+
}
|
|
2780
|
+
} catch (error) {
|
|
2781
|
+
let errorMessage = "\u274C \u6267\u884C\u5931\u8D25";
|
|
2782
|
+
if (error.status === 128) {
|
|
2783
|
+
errorMessage = "\u274C Git\u4ED3\u5E93\u9519\u8BEF\u6216\u6CA1\u6709\u63D0\u4EA4\u8BB0\u5F55";
|
|
2784
|
+
} else {
|
|
2785
|
+
errorMessage = `\u274C \u6267\u884C\u5931\u8D25: ${error.message}`;
|
|
2786
|
+
}
|
|
2787
|
+
const errorBox = "\n" + boxen3(errorMessage, {
|
|
2788
|
+
padding: { top: 0, bottom: 0, left: 2, right: 2 },
|
|
2789
|
+
borderStyle: "round",
|
|
2790
|
+
borderColor: "red",
|
|
2791
|
+
textAlignment: "center"
|
|
2792
|
+
});
|
|
2793
|
+
if (options.interactive) {
|
|
2794
|
+
startInteractivePager(errorBox);
|
|
2795
|
+
} else {
|
|
2796
|
+
console.log(errorBox);
|
|
2797
|
+
}
|
|
2798
|
+
}
|
|
2799
|
+
}
|
|
2800
|
+
async function log(options = {}) {
|
|
2801
|
+
if (options.interactive === void 0) {
|
|
2802
|
+
options.interactive = true;
|
|
2803
|
+
}
|
|
2804
|
+
if (!options.interactive && !options.limit) {
|
|
2805
|
+
options.limit = 10;
|
|
2806
|
+
}
|
|
2807
|
+
executeTimelineLog(options);
|
|
2808
|
+
}
|
|
2809
|
+
|
|
2564
2810
|
// src/index.ts
|
|
2565
2811
|
process.on("uncaughtException", (err) => {
|
|
2566
2812
|
if (err instanceof ExitPromptError) {
|
|
@@ -2586,7 +2832,7 @@ process.on("SIGTERM", () => {
|
|
|
2586
2832
|
console.log("");
|
|
2587
2833
|
process.exit(0);
|
|
2588
2834
|
});
|
|
2589
|
-
var version = true ? "0.3.
|
|
2835
|
+
var version = true ? "0.3.2" : "0.0.0-dev";
|
|
2590
2836
|
async function mainMenu() {
|
|
2591
2837
|
console.log(
|
|
2592
2838
|
colors.green(`
|
|
@@ -2644,7 +2890,11 @@ async function mainMenu() {
|
|
|
2644
2890
|
value: "stash"
|
|
2645
2891
|
},
|
|
2646
2892
|
{
|
|
2647
|
-
name: `[b] \
|
|
2893
|
+
name: `[b] \u{1F4CA} \u67E5\u770B\u65E5\u5FD7 ${colors.dim("gw log")}`,
|
|
2894
|
+
value: "log"
|
|
2895
|
+
},
|
|
2896
|
+
{
|
|
2897
|
+
name: `[c] \u2699\uFE0F \u521D\u59CB\u5316\u914D\u7F6E ${colors.dim("gw init")}`,
|
|
2648
2898
|
value: "init"
|
|
2649
2899
|
},
|
|
2650
2900
|
{ name: "[0] \u2753 \u5E2E\u52A9", value: "help" },
|
|
@@ -2693,11 +2943,15 @@ async function mainMenu() {
|
|
|
2693
2943
|
checkGitRepo();
|
|
2694
2944
|
await stash();
|
|
2695
2945
|
break;
|
|
2946
|
+
case "log":
|
|
2947
|
+
checkGitRepo();
|
|
2948
|
+
await log();
|
|
2949
|
+
break;
|
|
2696
2950
|
case "init":
|
|
2697
2951
|
await init();
|
|
2698
2952
|
break;
|
|
2699
2953
|
case "help":
|
|
2700
|
-
|
|
2954
|
+
cli.outputHelp();
|
|
2701
2955
|
break;
|
|
2702
2956
|
case "exit":
|
|
2703
2957
|
break;
|
|
@@ -2764,6 +3018,13 @@ cli.command("commit", "\u4EA4\u4E92\u5F0F\u63D0\u4EA4 (Conventional Commits + Gi
|
|
|
2764
3018
|
cli.command("update", "\u68C0\u67E5\u5E76\u66F4\u65B0\u5230\u6700\u65B0\u7248\u672C").alias("upt").action(async () => {
|
|
2765
3019
|
return update(version);
|
|
2766
3020
|
});
|
|
3021
|
+
cli.command("log", "\u4EA4\u4E92\u5F0FGit\u65E5\u5FD7\u67E5\u770B (\u5206\u9875\u6A21\u5F0F)").alias("ls").alias("l").option("--limit <number>", "\u9650\u5236\u663E\u793A\u6570\u91CF").action(async (options) => {
|
|
3022
|
+
await checkForUpdates(version, "@zjex/git-workflow");
|
|
3023
|
+
checkGitRepo();
|
|
3024
|
+
const logOptions = { interactive: true };
|
|
3025
|
+
if (options.limit) logOptions.limit = parseInt(options.limit);
|
|
3026
|
+
return log(logOptions);
|
|
3027
|
+
});
|
|
2767
3028
|
cli.command("clean", "\u6E05\u7406\u7F13\u5B58\u6587\u4EF6").action(async () => {
|
|
2768
3029
|
const { clearUpdateCache: clearUpdateCache3 } = await Promise.resolve().then(() => (init_update_notifier(), update_notifier_exports));
|
|
2769
3030
|
clearUpdateCache3();
|
|
@@ -2771,15 +3032,15 @@ cli.command("clean", "\u6E05\u7406\u7F13\u5B58\u6587\u4EF6").action(async () =>
|
|
|
2771
3032
|
console.log(colors.green("\u2714 \u7F13\u5B58\u5DF2\u6E05\u7406"));
|
|
2772
3033
|
console.log("");
|
|
2773
3034
|
});
|
|
2774
|
-
cli.help((sections) => {
|
|
2775
|
-
sections.push({
|
|
2776
|
-
body: showHelp()
|
|
2777
|
-
});
|
|
2778
|
-
});
|
|
2779
3035
|
cli.option("-v, --version", "\u663E\u793A\u7248\u672C\u53F7");
|
|
2780
|
-
|
|
2781
|
-
|
|
3036
|
+
cli.option("-h, --help", "\u663E\u793A\u5E2E\u52A9\u4FE1\u606F");
|
|
3037
|
+
var processArgs = process.argv.slice(2);
|
|
3038
|
+
if (processArgs.includes("-v") || processArgs.includes("--version")) {
|
|
2782
3039
|
console.log(colors.yellow(`v${version}`));
|
|
2783
3040
|
process.exit(0);
|
|
2784
3041
|
}
|
|
3042
|
+
if (processArgs.includes("-h") || processArgs.includes("--help")) {
|
|
3043
|
+
cli.outputHelp();
|
|
3044
|
+
process.exit(0);
|
|
3045
|
+
}
|
|
2785
3046
|
cli.parse();
|