git-er-done 0.1.20 → 0.1.22
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/package.json
CHANGED
|
@@ -51,6 +51,12 @@ function getLongestLineLength(diff) {
|
|
|
51
51
|
return maxLength
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
/**
|
|
55
|
+
* @typedef {Object} FormattedDiffResult
|
|
56
|
+
* @property {string} formatted - Terminal-formatted diff with colors
|
|
57
|
+
* @property {string} raw - Raw unified diff from git
|
|
58
|
+
*/
|
|
59
|
+
|
|
54
60
|
/**
|
|
55
61
|
* Get formatted diff for a specific file
|
|
56
62
|
* @param {Object} options - Options for getting formatted diff
|
|
@@ -62,7 +68,8 @@ function getLongestLineLength(diff) {
|
|
|
62
68
|
* @param {number} [options.leftMargin=0] - Number of spaces to add to the left of each line
|
|
63
69
|
* @param {number} [options.width=140] - Width of the diff output (ignored if shrinkToLongestLine is true)
|
|
64
70
|
* @param {boolean} [options.hideHeader=false] - Remove the file path header from the diff
|
|
65
|
-
* @
|
|
71
|
+
* @param {boolean} [options.returnRaw=false] - Return both formatted and raw diff
|
|
72
|
+
* @returns {Promise<string | FormattedDiffResult | null>} Formatted diff string, or {formatted, raw} if returnRaw, or null if no diff
|
|
66
73
|
*/
|
|
67
74
|
async function getFormattedDiff({
|
|
68
75
|
filePath,
|
|
@@ -72,7 +79,8 @@ async function getFormattedDiff({
|
|
|
72
79
|
shrinkToLongestLine = false,
|
|
73
80
|
leftMargin = 0,
|
|
74
81
|
width = 140,
|
|
75
|
-
hideHeader = false
|
|
82
|
+
hideHeader = false,
|
|
83
|
+
returnRaw = false
|
|
76
84
|
}) {
|
|
77
85
|
try {
|
|
78
86
|
const { formatDiff } = await import('@davidwells/git-split-diffs')
|
|
@@ -130,9 +138,12 @@ async function getFormattedDiff({
|
|
|
130
138
|
// Add left margin if specified
|
|
131
139
|
if (leftMargin > 0) {
|
|
132
140
|
const margin = ' '.repeat(leftMargin)
|
|
133
|
-
|
|
141
|
+
formatted = formatted.split('\n').map(line => margin + line).join('\n')
|
|
134
142
|
}
|
|
135
143
|
|
|
144
|
+
if (returnRaw) {
|
|
145
|
+
return { formatted, raw: diff }
|
|
146
|
+
}
|
|
136
147
|
return formatted
|
|
137
148
|
} catch (err) {
|
|
138
149
|
console.error(`Error formatting diff for ${filePath}:`, err.message)
|
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
export type FormattedDiffResult = {
|
|
2
|
+
/**
|
|
3
|
+
* - Terminal-formatted diff with colors
|
|
4
|
+
*/
|
|
5
|
+
formatted: string;
|
|
6
|
+
/**
|
|
7
|
+
* - Raw unified diff from git
|
|
8
|
+
*/
|
|
9
|
+
raw: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {Object} FormattedDiffResult
|
|
13
|
+
* @property {string} formatted - Terminal-formatted diff with colors
|
|
14
|
+
* @property {string} raw - Raw unified diff from git
|
|
15
|
+
*/
|
|
1
16
|
/**
|
|
2
17
|
* Get formatted diff for a specific file
|
|
3
18
|
* @param {Object} options - Options for getting formatted diff
|
|
@@ -9,9 +24,10 @@
|
|
|
9
24
|
* @param {number} [options.leftMargin=0] - Number of spaces to add to the left of each line
|
|
10
25
|
* @param {number} [options.width=140] - Width of the diff output (ignored if shrinkToLongestLine is true)
|
|
11
26
|
* @param {boolean} [options.hideHeader=false] - Remove the file path header from the diff
|
|
12
|
-
* @
|
|
27
|
+
* @param {boolean} [options.returnRaw=false] - Return both formatted and raw diff
|
|
28
|
+
* @returns {Promise<string | FormattedDiffResult | null>} Formatted diff string, or {formatted, raw} if returnRaw, or null if no diff
|
|
13
29
|
*/
|
|
14
|
-
export function getFormattedDiff({ filePath, gitRootDir, cwd, baseBranch, shrinkToLongestLine, leftMargin, width, hideHeader }: {
|
|
30
|
+
export function getFormattedDiff({ filePath, gitRootDir, cwd, baseBranch, shrinkToLongestLine, leftMargin, width, hideHeader, returnRaw }: {
|
|
15
31
|
filePath: string;
|
|
16
32
|
gitRootDir?: string;
|
|
17
33
|
cwd?: string;
|
|
@@ -20,4 +36,5 @@ export function getFormattedDiff({ filePath, gitRootDir, cwd, baseBranch, shrink
|
|
|
20
36
|
leftMargin?: number;
|
|
21
37
|
width?: number;
|
|
22
38
|
hideHeader?: boolean;
|
|
23
|
-
|
|
39
|
+
returnRaw?: boolean;
|
|
40
|
+
}): Promise<string | FormattedDiffResult | null>;
|