You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+28-17Lines changed: 28 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,20 +33,18 @@ grunt.initConfig({
33
33
// Target-specific options go here
34
34
},
35
35
// Hook definitions go there
36
-
'pre-commit':'jshint',
37
-
'post-merge': {
38
-
'taskNames':'bower:install'
39
-
}
40
36
}
41
-
},
42
37
},
43
38
})
44
39
```
45
40
46
41
#### Defining a few hooks
47
42
48
-
Hooks are listed as keys of your target configuration. *Any other key than `option`* in your target will be considered the name of a hook you want to create. The simplest way to define a hook is to provide a *space-separated list of the tasks* you want the hook to run as the value*. For example:
43
+
Hooks are listed as keys of your target configuration.
44
+
**Any key other than `option`** is considered the name of a hook you want to create.
45
+
The simplest way to define a hook is to provide a **space-separated list of the tasks you want the hook to run as the value**.
49
46
47
+
For example:
50
48
```js
51
49
grunt.initConfig({
52
50
githooks: {
@@ -56,12 +54,16 @@ grunt.initConfig({
56
54
}
57
55
}
58
56
});
57
+
```
59
58
60
-
The plugin warns you if the name matches one of the [hooks announced in the Git documentation](https://www.kernel.org/pub/software/scm/git/docs/githooks.html). It will still create the hook, though, in case Git introduces new hooks in the future.
59
+
The plugin warns you if the name matches one of the [hooks announced in the Git documentation](https://www.kernel.org/pub/software/scm/git/docs/githooks.html).
60
+
It will still create the hook, though, in case Git introduces new hooks in the future.
61
61
62
62
#### Hook specific options
63
63
64
-
If you need to override a few options for a given hook only, you can *use and Object instead of a String*. The`taskNames` property will then correspond to the tasks you want to run, and any other key will be merged into the options.
64
+
If you need to override a few options for a given hook only, you can *use and Object instead of a String*.
65
+
The `taskNames` property will then correspond to the tasks you want to run.
66
+
Any other key will be merged into the options.
65
67
66
68
```js
67
69
grunt.initConfig({
@@ -83,10 +85,12 @@ grunt.initConfig({
83
85
}
84
86
}
85
87
})
88
+
```
86
89
87
90
#### Working with existing hooks
88
91
89
-
If you happen to have existing hooks in your hook folder, the plugin will *append the code running Grunt* at the end of your hooks. You can also insert marker comments in your hooks to specify exactly where you want them inserted.
92
+
If you happen to have existing hooks in your hook folder, the plugin *appends the code launching Grunt* at the end of your hooks.
93
+
You can also insert marker comments in your hooks to specify exactly where you want them inserted.
90
94
Your existing hook would look something like this:
91
95
92
96
```js
@@ -97,13 +101,15 @@ Your existing hook would look something like this:
97
101
// Some code run after Grunt starts
98
102
```
99
103
100
-
The markers get automatically inserted when the plugin appends code, so the hooks get updated cleanly the next time you run `grunt githooks`.
104
+
The markers get automatically inserted when the plugin appends code, so hooks get updated cleanly the next time you run `grunt githooks`.
101
105
102
106
#### Customising hook output
103
107
104
-
By default, the plugin generate NodeJS scripts for the hooks. Reasonning behind this is that creating Shell scripts won't work well for people using Windows and NodeJS is already installed as Grunt kinda need is. However, you're not tied to it and you can customise pretty much everything.
108
+
By default, the plugin generate NodeJS scripts for the hooks.
109
+
Reasonning behind this is that creating Shell scripts won't work well for people using Windows.
110
+
Plus, NodeJS is already installed as Grunt kinda needs it.
111
+
However, you're not tied to it and you can customise the generated script entirely. In case of a Shell script:
105
112
106
-
So say you want a Shell script rather than the default NodeJS ones:
107
113
```js
108
114
grunt.initConfig({
109
115
githooks: {
@@ -124,7 +130,9 @@ grunt.initConfig({
124
130
125
131
#### Extending the plugin
126
132
127
-
Pretty annoying when you're using a library that's missing the exact extension point you need to tweak its functionalities? `grunt-githooks` is based on a lot of small functions and most of them are exposed so you can override them. If you need feel free to tinker with the internals (at your own risk though ;)). Could be something along:
133
+
Pretty annoying when you're using a library that's missing the exact extension point you need to tweak its functionalities?
134
+
`grunt-githooks` is based on a lot of small functions and most of them are exposed so you can override them.
135
+
If you need feel, free to tinker with the internals (at your own risk though ;)). Could be something along:
128
136
129
137
```js
130
138
var gruntGithooks =require('grunt-githooks/tasks/githooks');
@@ -136,7 +144,6 @@ gruntGithooks.internals.Hook.prototype.getHookContent = function () {
136
144
};
137
145
```
138
146
139
-
140
147
### Options
141
148
142
149
#### hashbang
@@ -151,7 +158,8 @@ code in it (to avoid inserting Node code in a Python hook for example).
151
158
Type: `String`
152
159
153
160
Path to the Handlebars template used to generate the code that will run Grunt
154
-
in the hook. Default template is the `node.js.hb` file located in the `templates` folder of the plugin. It also contains a `shell.hb` file with the template for a shell script hook.
161
+
in the hook. Default template is the `node.js.hb` file located in the `templates` folder of the plugin.
162
+
It also contains a `shell.hb` file with the template for a shell script hook.
`startMarker` and `endMarker` are markers the plugin use to know where to insert code if a hook already exist. If the existing hook doesn't have these markers, the code will simply be appended.
172
+
`startMarker` and `endMarker` are markers the plugin use to know where to insert code if a hook already exist.
173
+
If the existing hook doesn't have these markers, the code will simply be appended.
165
174
166
175
#### preventExit
167
176
Type: `Boolean`
168
177
Default `false`
169
178
170
-
By default, the inserted code will exit the process after Grunt has run, using a -1 exit code if the task(s) failed. If you're inserting the code running Grunt in the middle of an existing hook, you'll probably want to disable this so any code after what was inserted by the plugin runs.
179
+
By default, the inserted code will exit the process after Grunt has run, using a -1 exit code if the task(s) failed.
180
+
If you're inserting the code running Grunt in the middle of an existing hook,
181
+
you might want to disable this so any code after what was inserted by the plugin runs.
0 commit comments