@netlify/git-utils 4.0.0 → 4.1.0
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/README.md +52 -56
- package/package.json +1 -1
- package/src/exec.js +1 -1
package/README.md
CHANGED
|
@@ -9,38 +9,36 @@ Utility for dealing with modified, created, deleted files since a git commit.
|
|
|
9
9
|
|
|
10
10
|
```js
|
|
11
11
|
/* Export the Netlify Plugin */
|
|
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
|
-
},
|
|
12
|
+
export const onPreBuild = function ({ utils }) {
|
|
13
|
+
const { git } = utils
|
|
14
|
+
|
|
15
|
+
/* Do stuff if files modified */
|
|
16
|
+
if (git.modifiedFiles.length !== 0) {
|
|
17
|
+
console.log('Modified files:', git.modifiedFiles)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/* Do stuff only if html code edited */
|
|
21
|
+
const htmlFiles = git.fileMatch('**/*.html')
|
|
22
|
+
console.log('html files git info:', htmlFiles)
|
|
23
|
+
|
|
24
|
+
if (htmlFiles.edited.length !== 0) {
|
|
25
|
+
console.log('>> Run thing because HTML has changed\n')
|
|
26
|
+
}
|
|
27
|
+
//
|
|
28
|
+
/* Do stuff only if markdown files edited */
|
|
29
|
+
const markdownFiles = git.fileMatch('**/*.md')
|
|
30
|
+
console.log('markdown files git info:', markdownFiles)
|
|
31
|
+
|
|
32
|
+
if (markdownFiles.modified.length !== 0) {
|
|
33
|
+
console.log('>> Run thing because Markdown files have been created/changed/deleted\n')
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/* Do stuff only if css files edited */
|
|
37
|
+
const cssFiles = git.fileMatch('**/*.css')
|
|
38
|
+
if (cssFiles.deleted.length !== 0) {
|
|
39
|
+
console.log('>> Run thing because css files have been deleted\n')
|
|
40
|
+
console.log(cssFiles)
|
|
41
|
+
}
|
|
44
42
|
}
|
|
45
43
|
```
|
|
46
44
|
|
|
@@ -49,36 +47,34 @@ module.exports = {
|
|
|
49
47
|
The `git` util includes the following signature.
|
|
50
48
|
|
|
51
49
|
```js
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
//
|
|
64
|
-
},
|
|
50
|
+
export const onPreBuild = function ({ utils }) {
|
|
51
|
+
console.log(utils.git)
|
|
52
|
+
// {
|
|
53
|
+
// fileMatch: [Function], <-- Lookup function. See below
|
|
54
|
+
// modifiedFiles: [ Array of all modified files ],
|
|
55
|
+
// createdFiles: [ Array of all created files ],
|
|
56
|
+
// deletedFiles: [ Array of all deleted files ],
|
|
57
|
+
// commits: [ Array of commits with details ],
|
|
58
|
+
// linesOfCode: [AsyncFunction: linesOfCode] <-- how many lines of code have changed
|
|
59
|
+
// }
|
|
60
|
+
//
|
|
65
61
|
}
|
|
66
62
|
```
|
|
67
63
|
|
|
68
64
|
`git.fileMatch()` is a glob matcher function to detect the git status of a pattern of files.
|
|
69
65
|
|
|
70
|
-
Example:
|
|
71
|
-
|
|
72
66
|
```js
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
//
|
|
77
|
-
//
|
|
78
|
-
//
|
|
79
|
-
//
|
|
80
|
-
//
|
|
81
|
-
//
|
|
67
|
+
export const onPreBuild = function ({ utils }) {
|
|
68
|
+
const cssFiles = utils.git.fileMatch('**/*.css')
|
|
69
|
+
console.log('cssFiles', cssFiles)
|
|
70
|
+
// {
|
|
71
|
+
// modified: [ 'just-changed.css', 'just-changed-two.css' ],
|
|
72
|
+
// created: [ 'just-added.css' ],
|
|
73
|
+
// deleted: [ 'just-deleted.css' ],
|
|
74
|
+
// edited: [ 'just-changed.css', 'just-changed-two.css', 'just-added.css', 'just-deleted.css' ]
|
|
75
|
+
// }
|
|
76
|
+
//
|
|
77
|
+
}
|
|
82
78
|
```
|
|
83
79
|
|
|
84
80
|
## Prior art
|
package/package.json
CHANGED