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
+66-29Lines changed: 66 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,15 +7,20 @@
7
7
> A Grunt plugin to help bind Grunt tasks to Git hooks
8
8
9
9
## Getting Started
10
-
This plugin requires Grunt `~0.4.1`
10
+
This plugin requires at least Grunt `~0.4.1`
11
11
12
-
If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
12
+
If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the
13
+
[Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to
14
+
create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and
15
+
use Grunt plugins. Once you're familiar with that process, you may install this
16
+
plugin with this command:
13
17
14
18
```shell
15
19
npm install grunt-githooks --save-dev
16
20
```
17
21
18
-
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
22
+
Once the plugin has been installed, it may be enabled inside your
In your project's Gruntfile, add a section named `githooks` to the data object passed into `grunt.initConfig()`.
32
+
In your project's Gruntfile, add a section named `githooks` to the data
33
+
object passed into `grunt.initConfig()`.
28
34
29
35
```js
30
36
grunt.initConfig({
@@ -44,9 +50,10 @@ grunt.initConfig({
44
50
45
51
#### Defining a few hooks
46
52
47
-
Hooks are listed as keys of your target configuration.
48
-
**Any key other than `option`** is considered the name of a hook you want to create.
49
-
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**.
53
+
Hooks are listed as keys of your target configuration. **Any key other than
54
+
`option`** is considered the name of a hook you want to create. The simplest way
55
+
to define a hook is to provide a **space-separated list of the tasks you want
56
+
the hook to run as the value**.
50
57
51
58
For example:
52
59
```js
@@ -60,12 +67,15 @@ grunt.initConfig({
60
67
});
61
68
```
62
69
63
-
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).
64
-
It will still create the hook, though, in case Git introduces new hooks in the future.
70
+
The plugin warns you if the name matches one of the
71
+
[hooks announced in the Git documentation](https://www.kernel.org/pub/software/scm/git/docs/githooks.html).
72
+
It will still create the hook, though, in case Git introduces new hooks
73
+
in the future.
65
74
66
75
#### Hook specific options
67
76
68
-
If you need to override a few options for a given hook only, you can *use an Object instead of a String*.
77
+
If you need to override a few options for a given hook only, you can *use an
78
+
Object instead of a String*.
69
79
The `taskNames` property will then correspond to the tasks you want to run.
70
80
Any other key will be merged into the options.
71
81
@@ -93,9 +103,10 @@ grunt.initConfig({
93
103
94
104
#### Working with existing hooks
95
105
96
-
If you happen to have existing hooks in your hook folder, the plugin *appends the code launching Grunt* at the end of your hooks.
97
-
You can also insert marker comments in your hooks to specify exactly where you want them inserted.
98
-
Your existing hook would look something like this:
106
+
If you happen to have existing hooks in your hook folder, the plugin *appends
107
+
the code launching Grunt* at the end of your hooks. You can also insert marker
108
+
comments in your hooks to specify exactly where you want them inserted. Your
109
+
existing hook would look something like this:
99
110
100
111
```js
101
112
// Some code run before Grunt starts
@@ -105,14 +116,16 @@ Your existing hook would look something like this:
105
116
// Some code run after Grunt starts
106
117
```
107
118
108
-
The markers get automatically inserted when the plugin appends code, so hooks get updated cleanly the next time you run `grunt githooks`.
119
+
The markers get automatically inserted when the plugin appends code, so hooks
120
+
get updated cleanly the next time you run `grunt githooks`.
109
121
110
122
#### Customising hook output
111
123
112
-
By default, the plugin generate NodeJS scripts for the hooks.
113
-
Reasonning behind this is that creating Shell scripts won't work well for people using Windows.
114
-
Plus, NodeJS is already installed as Grunt kinda needs it.
115
-
However, you're not tied to it and you can customise the generated script entirely. In case of a Shell script:
124
+
By default, the plugin generate NodeJS scripts for the hooks. Reasoning behind
125
+
this is that creating Shell scripts won't work well for people using Windows.
126
+
Plus, NodeJS is already installed as Grunt kinda needs it. However, you're not
127
+
tied to it and you can customise the generated script entirely. In case of
128
+
a Shell script:
116
129
117
130
```js
118
131
grunt.initConfig({
@@ -144,9 +157,11 @@ In the template, you've got access to the following variables:
144
157
145
158
#### Extending the plugin
146
159
147
-
Pretty annoying when you're using a library that's missing the exact extension point you need to tweak its functionalities?
148
-
`grunt-githooks` is based on a lot of small functions and most of them are exposed so you can override them.
149
-
If you need feel, free to tinker with the internals (at your own risk though ;)). Could be something along:
160
+
Pretty annoying when you're using a library that's missing the exact extension
161
+
point you need to tweak its functionalities? `grunt-githooks` is based on a lot
162
+
of small functions and most of them are exposed so you can override them. If you
163
+
need feel, free to tinker with the internals (at your own risk though ;)).
164
+
Could be something along:
150
165
151
166
```js
152
167
var gruntGithooks =require('grunt-githooks/tasks/githooks');
@@ -190,8 +205,9 @@ code in it (to avoid inserting Node code in a Python hook for example).
190
205
Type: `String`
191
206
192
207
Path to the Handlebars template used to generate the code that will run Grunt
193
-
in the hook. Default template is the `node.js.hb` file located in the `templates` folder of the plugin.
194
-
It also contains a `shell.hb` file with the template for a shell script hook.
208
+
in the hook. Default template is the `node.js.hb` file located in the `templates`
209
+
folder of the plugin. It also contains a `shell.hb` file with the template for a
210
+
shell script hook.
195
211
196
212
> **Note**: Handlebars escapes HTML special characters if you use only two curly braces to insert
197
213
> a variable in your template. Make sure you use three `{{{my_var}}}` if you need to insert variable
`startMarker` and `endMarker` are markers the plugin use to know where to insert code if a hook already exist.
209
-
If the existing hook doesn't have these markers, the code will simply be appended.
224
+
`startMarker` and `endMarker` are markers the plugin use to know where to insert
225
+
code if a hook already exist. If the existing hook doesn't have these markers,
226
+
the code will simply be appended.
210
227
211
228
#### preventExit
212
229
Type: `Boolean`
213
230
Default `false`
214
231
215
-
By default, the inserted code will exit the process after Grunt has run, using a -1 exit code if the task(s) failed.
216
-
If you're inserting the code running Grunt in the middle of an existing hook,
217
-
you might want to disable this so any code after what was inserted by the plugin runs.
232
+
By default, the inserted code will exit the process after Grunt has run, using
233
+
a -1 exit code if the task(s) failed. If you're inserting the code running Grunt
234
+
in the middle of an existing hook, you might want to disable this so any code
235
+
after what was inserted by the plugin runs.
218
236
219
237
#### dest
220
238
Type: `String`
@@ -226,8 +244,27 @@ Comes in handy if your Gruntfile is not at the root of your Git project.
226
244
227
245
## Contributing
228
246
229
-
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).
247
+
In lieu of a formal style-guide, take care to maintain the existing coding style.
248
+
Please file a Pull Request along your issues.
230
249
250
+
* Add unit tests for any new or changed functionality.
251
+
* Lint and test your code using [Grunt](http://gruntjs.com/).
252
+
* Keep the line length at 80-100 characters per line.
253
+
254
+
### File a Pull Request
255
+
256
+
The process actually is quite simple:
257
+
258
+
1. Please check out your changes on a separate branch named `issue-{$integer}` and commit against that one.
259
+
1. When your tests pass and are green, merge to `dev` using `--no-ff` so we have a separate commit for that merge.
260
+
1. After the review on `dev`, we can merge to `master`, again using `--no-ff`.
261
+
1. The merge to `master` will get tagged. We use the [SemVer standard](http://semver.org), so _no_ leading `v`.
262
+
263
+
If your PR is successful, you will get added as contributor to the repo. We
264
+
trust you after your first PR made it into the repo and you then have access
265
+
for further changes, handling issues, etc. So the *important* thing is to add
266
+
your name to the `package.json` array of `contributors` when changing or adding
267
+
some code for a PR. Please do that in a separate commit.
0 commit comments