git-er-done 0.1.19 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "git-er-done",
3
- "version": "0.1.19",
3
+ "version": "0.1.22",
4
4
  "description": "Utility for dealing with modified, created, deleted files since a git commit",
5
5
  "main": "src/index.js",
6
6
  "types": "types/index.d.ts",
@@ -9,6 +9,10 @@ module.exports.diffToGitJSONDSL = (diff, commits) => {
9
9
  const fileDiffs = parseDiff(diff)
10
10
  const addedDiffs = fileDiffs.filter(diff => diff['new'])
11
11
  const removedDiffs = fileDiffs.filter(diff => diff['deleted'])
12
+ // Renames have both from and to, but no new/deleted flag, and paths differ
13
+ const renamedDiffs = fileDiffs.filter(
14
+ diff => diff.from && diff.to && !diff['new'] && !diff['deleted'] && diff.from !== diff.to
15
+ )
12
16
  const modifiedDiffs = fileDiffs.filter(
13
17
  diff => !includes(addedDiffs, diff) && !includes(removedDiffs, diff)
14
18
  )
@@ -19,6 +23,8 @@ module.exports.diffToGitJSONDSL = (diff, commits) => {
19
23
  ),
20
24
  created_files: addedDiffs.map(d => d.to),
21
25
  deleted_files: removedDiffs.map(d => d.from),
26
+ // Renamed files with old and new paths
27
+ renamed_files: renamedDiffs.map(d => ({ from: d.from, to: d.to })),
22
28
  commits: commits
23
29
  }
24
30
  }
@@ -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
- * @returns {Promise<string | null>} Formatted diff string or null if no diff
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
- return formatted.split('\n').map(line => margin + line).join('\n')
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)
@@ -223,6 +223,7 @@ module.exports.gitJSONToGitDSL = (gitJSONRep, config) => {
223
223
  modifiedFiles: gitJSONRep.modified_files,
224
224
  createdFiles: gitJSONRep.created_files,
225
225
  deletedFiles: gitJSONRep.deleted_files,
226
+ renamedFiles: gitJSONRep.renamed_files || [],
226
227
  commits: gitJSONRep.commits,
227
228
  lastCommit: gitJSONRep.commits && gitJSONRep.commits[0] && gitJSONRep.commits[0].sha,
228
229
  dir: config.repo,
package/src/types.js CHANGED
@@ -35,12 +35,19 @@
35
35
  * @property {function(): Object<string, string[]>} getKeyedPaths - Returns an object with keys (modified, created, deleted, edited) mapped to their matching file arrays
36
36
  */
37
37
 
38
+ /**
39
+ * @typedef {Object} RenamedFile
40
+ * @property {string} from - Original file path before rename
41
+ * @property {string} to - New file path after rename
42
+ */
43
+
38
44
  /**
39
45
  * @typedef {Object} GitDetails
40
46
  * @property {function(...(string|string[])): FileMatchResult} fileMatch - Function to match files by glob pattern(s). Accepts multiple strings, arrays of strings, or a mix using rest parameters. Supports negation patterns with '!' prefix
41
47
  * @property {string[]} modifiedFiles - Array of modified file paths
42
48
  * @property {string[]} createdFiles - Array of created file paths
43
49
  * @property {string[]} deletedFiles - Array of deleted file paths
50
+ * @property {RenamedFile[]} renamedFiles - Array of renamed files with from/to paths
44
51
  * @property {CommitInfo[]} commits - Array of commits between base and head
45
52
  * @property {string} lastCommit - SHA of the last commit
46
53
  * @property {string} dir - Root path of the git repository
@@ -2,5 +2,9 @@ export function diffToGitJSONDSL(diff: any, commits: any): {
2
2
  modified_files: string[];
3
3
  created_files: string[];
4
4
  deleted_files: string[];
5
+ renamed_files: {
6
+ from: string;
7
+ to: string;
8
+ }[];
5
9
  commits: any;
6
10
  };
@@ -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
- * @returns {Promise<string | null>} Formatted diff string or null if no diff
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
- }): Promise<string | null>;
39
+ returnRaw?: boolean;
40
+ }): Promise<string | FormattedDiffResult | null>;
@@ -3,6 +3,7 @@ export function gitJSONToGitDSL(gitJSONRep: any, config: any): {
3
3
  modifiedFiles: any;
4
4
  createdFiles: any;
5
5
  deletedFiles: any;
6
+ renamedFiles: any;
6
7
  commits: any;
7
8
  lastCommit: any;
8
9
  dir: any;
package/types/types.d.ts CHANGED
@@ -92,6 +92,16 @@ export type FileMatchResult = {
92
92
  [x: string]: string[];
93
93
  };
94
94
  };
95
+ export type RenamedFile = {
96
+ /**
97
+ * - Original file path before rename
98
+ */
99
+ from: string;
100
+ /**
101
+ * - New file path after rename
102
+ */
103
+ to: string;
104
+ };
95
105
  export type GitDetails = {
96
106
  /**
97
107
  * - Function to match files by glob pattern(s). Accepts multiple strings, arrays of strings, or a mix using rest parameters. Supports negation patterns with '!' prefix
@@ -109,6 +119,10 @@ export type GitDetails = {
109
119
  * - Array of deleted file paths
110
120
  */
111
121
  deletedFiles: string[];
122
+ /**
123
+ * - Array of renamed files with from/to paths
124
+ */
125
+ renamedFiles: RenamedFile[];
112
126
  /**
113
127
  * - Array of commits between base and head
114
128
  */