Skip to content

Commit e63f308

Browse files
committed
feat: implement
1 parent d8b0d2d commit e63f308

34 files changed

+860
-16
lines changed

.github/workflows/main.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: CI
2+
on: [push, pull_request]
3+
jobs:
4+
build:
5+
name: Test
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v2
9+
- uses: borales/[email protected]
10+
with:
11+
cmd: install
12+
- uses: borales/[email protected]
13+
with:
14+
cmd: check:all

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
22
build
3+
coverage
File renamed without changes.

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
build
33
yarn.lock
4+
coverage

.prettierrc.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"trailingComma": "es5",
3+
"tabWidth": 2,
4+
"semi": true,
5+
"singleQuote": true
6+
}

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 YeonJuan
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+17
Original file line numberDiff line numberDiff line change
@@ -1 +1,18 @@
11
# parse-git-diff
2+
3+
## Installation
4+
5+
```bash
6+
npm install parse-git-diff
7+
```
8+
9+
## Usage
10+
11+
```js
12+
import parseGitDiff from 'parse-git-diff';
13+
parseGitDiff('...');
14+
```
15+
16+
## License
17+
18+
- [MIT](./LICENSE)

jest.config.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
22
module.exports = {
3-
preset: "ts-jest",
4-
testEnvironment: "node",
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
testMatch: ['<rootDir>/**/*.test.ts'],
56
};

package.json

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"name": "parse-git-diff",
3-
"version": "0.0.1",
4-
"description": "",
3+
"version": "0.0.4",
4+
"description": "Parse git diff",
55
"main": "build/index.js",
6+
"types": "build/index.d.ts",
67
"scripts": {
8+
"prepublish": "yarn build",
79
"build": "rimraf build && tsc",
810
"format": "prettier . --write",
911
"test": "jest",
10-
"postinstall": "yarn husky install",
1112
"check:all": "prettier --check . && tsc --noEmit && yarn test"
1213
},
1314
"repository": {
@@ -28,5 +29,16 @@
2829
"rimraf": "^3.0.2",
2930
"ts-jest": "^27.0.5",
3031
"typescript": "^4.4.3"
31-
}
32+
},
33+
"files": [
34+
"build",
35+
"tsconfig.json",
36+
"README.md",
37+
"yarn.lock",
38+
"package.json"
39+
],
40+
"keywords": [
41+
"git",
42+
"git diff"
43+
]
3244
}

src/__fixtures__/all

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
diff --git a/rename.md b/rename.md
2+
index 0e05564..aa39060 100644
3+
--- a/rename.md
4+
+++ b/rename.md
5+
@@ -1,2 +1 @@
6+
newfile
7+
-newline
8+
diff --git a/newfile.md b/newfile.md
9+
deleted file mode 100644
10+
index aa39060..0000000
11+
--- a/newfile.md
12+
+++ /dev/null
13+
@@ -1 +0,0 @@
14+
-newfile
15+
diff --git a/newfile.md b/newfile.md
16+
new file mode 100644
17+
index 0000000..aa39060
18+
--- /dev/null
19+
+++ b/newfile.md
20+
@@ -0,0 +1 @@
21+
+newfile
22+
diff --git a/rename.md b/rename.md
23+
index aa39060..0e05564 100644
24+
--- a/rename.md
25+
+++ b/rename.md
26+
@@ -1 +1,2 @@
27+
newfile
28+
+newline
29+
diff --git a/newfile.md b/rename.md
30+
similarity index 100%
31+
rename from newfile.md
32+
rename to rename.md

src/__fixtures__/deleted-file

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
diff --git a/newfile.md b/newfile.md
2+
deleted file mode 100644
3+
index aa39060..0000000
4+
--- a/newfile.md
5+
+++ /dev/null
6+
@@ -1 +0,0 @@
7+
-newfile

src/__fixtures__/deleted-line

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
diff --git a/rename.md b/rename.md
2+
index 0e05564..aa39060 100644
3+
--- a/rename.md
4+
+++ b/rename.md
5+
@@ -1,2 +1 @@
6+
newfile
7+
-newline

src/__fixtures__/new-file

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
diff --git a/newfile.md b/newfile.md
2+
new file mode 100644
3+
index 0000000..aa39060
4+
--- /dev/null
5+
+++ b/newfile.md
6+
@@ -0,0 +1 @@
7+
+newfile

src/__fixtures__/new-line

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
diff --git a/rename.md b/rename.md
2+
index aa39060..0e05564 100644
3+
--- a/rename.md
4+
+++ b/rename.md
5+
@@ -1 +1,2 @@
6+
newfile
7+
+newline

src/__fixtures__/renamed-file

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
diff --git a/newfile.md b/rename.md
2+
similarity index 100%
3+
rename from newfile.md
4+
rename to rename.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`aa parse \`all\` 1`] = `
4+
Object {
5+
"files": Array [
6+
Object {
7+
"chunks": Array [
8+
Object {
9+
"changes": Array [
10+
Object {
11+
"content": "newfile",
12+
"lineAfter": 1,
13+
"lineBefore": 1,
14+
"type": "UnchangedLine",
15+
},
16+
Object {
17+
"content": "newline",
18+
"lineBefore": 2,
19+
"type": "DeletedLine",
20+
},
21+
],
22+
"rangeAfter": Object {
23+
"lines": 1,
24+
"start": 1,
25+
},
26+
"rangeBefore": Object {
27+
"lines": 2,
28+
"start": 1,
29+
},
30+
"type": "Chunk",
31+
},
32+
],
33+
"path": "rename.md",
34+
"type": "ChangedFile",
35+
},
36+
Object {
37+
"chunks": Array [
38+
Object {
39+
"changes": Array [
40+
Object {
41+
"content": "newfile",
42+
"lineBefore": 1,
43+
"type": "DeletedLine",
44+
},
45+
],
46+
"rangeAfter": Object {
47+
"lines": 0,
48+
"start": 0,
49+
},
50+
"rangeBefore": Object {
51+
"lines": 1,
52+
"start": 1,
53+
},
54+
"type": "Chunk",
55+
},
56+
],
57+
"path": "newfile.md",
58+
"type": "DeletedFile",
59+
},
60+
Object {
61+
"chunks": Array [
62+
Object {
63+
"changes": Array [
64+
Object {
65+
"content": "newfile",
66+
"lineAfter": 1,
67+
"type": "AddedLine",
68+
},
69+
],
70+
"rangeAfter": Object {
71+
"lines": 1,
72+
"start": 1,
73+
},
74+
"rangeBefore": Object {
75+
"lines": 0,
76+
"start": 0,
77+
},
78+
"type": "Chunk",
79+
},
80+
],
81+
"path": "newfile.md",
82+
"type": "AddedFile",
83+
},
84+
Object {
85+
"chunks": Array [
86+
Object {
87+
"changes": Array [
88+
Object {
89+
"content": "newfile",
90+
"lineAfter": 1,
91+
"lineBefore": 1,
92+
"type": "UnchangedLine",
93+
},
94+
Object {
95+
"content": "newline",
96+
"lineAfter": 2,
97+
"type": "AddedLine",
98+
},
99+
],
100+
"rangeAfter": Object {
101+
"lines": 2,
102+
"start": 1,
103+
},
104+
"rangeBefore": Object {
105+
"lines": 1,
106+
"start": 1,
107+
},
108+
"type": "Chunk",
109+
},
110+
],
111+
"path": "rename.md",
112+
"type": "ChangedFile",
113+
},
114+
Object {
115+
"chunks": Array [],
116+
"pathAfter": "rename.md",
117+
"pathBefore": "newfile.md",
118+
"type": "RenamedFile",
119+
},
120+
],
121+
"type": "GitDiff",
122+
}
123+
`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`deleted-file parse \`deleted-file\` 1`] = `
4+
Object {
5+
"files": Array [
6+
Object {
7+
"chunks": Array [
8+
Object {
9+
"changes": Array [
10+
Object {
11+
"content": "newfile",
12+
"lineBefore": 1,
13+
"type": "DeletedLine",
14+
},
15+
],
16+
"rangeAfter": Object {
17+
"lines": 0,
18+
"start": 0,
19+
},
20+
"rangeBefore": Object {
21+
"lines": 1,
22+
"start": 1,
23+
},
24+
"type": "Chunk",
25+
},
26+
],
27+
"path": "newfile.md",
28+
"type": "DeletedFile",
29+
},
30+
],
31+
"type": "GitDiff",
32+
}
33+
`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`deleted-line parse \`deleted-line\` 1`] = `
4+
Object {
5+
"files": Array [
6+
Object {
7+
"chunks": Array [
8+
Object {
9+
"changes": Array [
10+
Object {
11+
"content": "newfile",
12+
"lineAfter": 1,
13+
"lineBefore": 1,
14+
"type": "UnchangedLine",
15+
},
16+
Object {
17+
"content": "newline",
18+
"lineBefore": 2,
19+
"type": "DeletedLine",
20+
},
21+
],
22+
"rangeAfter": Object {
23+
"lines": 1,
24+
"start": 1,
25+
},
26+
"rangeBefore": Object {
27+
"lines": 2,
28+
"start": 1,
29+
},
30+
"type": "Chunk",
31+
},
32+
],
33+
"path": "rename.md",
34+
"type": "ChangedFile",
35+
},
36+
],
37+
"type": "GitDiff",
38+
}
39+
`;

0 commit comments

Comments
 (0)