@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.
Files changed (3) hide show
  1. package/README.md +52 -56
  2. package/package.json +1 -1
  3. 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
- module.exports = {
13
- onPreBuild: ({ utils }) => {
14
- const { git } = utils
15
-
16
- /* Do stuff if files modified */
17
- if (git.modifiedFiles.length !== 0) {
18
- console.log('Modified files:', git.modifiedFiles)
19
- }
20
-
21
- /* Do stuff only if html code edited */
22
- const htmlFiles = git.fileMatch('**/*.html')
23
- console.log('html files git info:', htmlFiles)
24
-
25
- if (htmlFiles.edited.length !== 0) {
26
- console.log('>> Run thing because HTML has changed\n')
27
- }
28
- //
29
- /* Do stuff only if markdown files edited */
30
- const markdownFiles = git.fileMatch('**/*.md')
31
- console.log('markdown files git info:', markdownFiles)
32
-
33
- if (markdownFiles.modified.length !== 0) {
34
- console.log('>> Run thing because Markdown files have been created/changed/deleted\n')
35
- }
36
-
37
- /* Do stuff only if css files edited */
38
- const cssFiles = git.fileMatch('**/*.css')
39
- if (cssFiles.deleted.length !== 0) {
40
- console.log('>> Run thing because css files have been deleted\n')
41
- console.log(cssFiles)
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
- module.exports = {
53
- onPreBuild: ({ utils }) => {
54
- console.log(utils.git)
55
- // {
56
- // fileMatch: [Function], <-- Lookup function. See below
57
- // modifiedFiles: [ Array of all modified files ],
58
- // createdFiles: [ Array of all created files ],
59
- // deletedFiles: [ Array of all deleted files ],
60
- // commits: [ Array of commits with details ],
61
- // linesOfCode: [AsyncFunction: linesOfCode] <-- how many lines of code have changed
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 cssFiles = git.fileMatch('**/*.css')
74
- console.log('cssFiles', cssFiles)
75
- // {
76
- // modified: [ 'just-changed.css', 'just-changed-two.css' ],
77
- // created: [ 'just-added.css' ],
78
- // deleted: [ 'just-deleted.css' ],
79
- // edited: [ 'just-changed.css', 'just-changed-two.css', 'just-added.css', 'just-deleted.css' ]
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/git-utils",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "description": "Utility for dealing with modified, created, deleted files since a git commit",
5
5
  "type": "module",
6
6
  "exports": "./src/main.js",
package/src/exec.js CHANGED
@@ -38,7 +38,7 @@ const getCwdValue = function (cwd) {
38
38
 
39
39
  try {
40
40
  return process.cwd()
41
- } catch (error) {
41
+ } catch {
42
42
  throw new Error('Current directory does not exist')
43
43
  }
44
44
  }