-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathGruntfile.js
244 lines (206 loc) · 5.35 KB
/
Gruntfile.js
1
2
3
4
5
6
7
8
9
10
11
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/*
* grunt-githooks
* https://github.com/rhumaric/grunt-githooks
*
* Copyright (c) 2013 Romaric Pascal
* Licensed under the MIT license.
*/
'use strict';
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
jshint: {
all: [
'Gruntfile.js',
'tasks/*.js',
'lib/*.js',
'<%= nodeunit.tests %>',
],
options: {
jshintrc: '.jshintrc',
},
},
// Before generating any new files, remove any previously-created files.
clean: {
tests: ['tmp'],
},
copy: {
tests: {
files: [
{cwd: 'test/fixtures', src: '**', dest: 'tmp', expand: true}
]
}
},
// Configuration to be run (and then tested).
githooks: {
// Actual target used to bind hooks for project development
'dev': {
'pre-commit': 'jshint'
},
// Test targets
// Default hook creation
'test.default': {
options: {
dest: 'tmp/default',
},
'pre-commit': 'aTask'
},
// Binding multiple tasks
'test.multiple_tasks': {
options: {
dest: 'tmp/multiple_tasks',
},
'pre-commit': 'aTask anotherTask'
},
'test.multipleHooks': {
options: {
dest: 'tmp/multipleHooks'
},
'pre-commit': 'aTask',
'commit-msg': 'anotherTask'
},
// Appending binding to and existing hook
'test.append': {
options: {
dest: 'tmp/append'
},
'pre-commit': 'aTask'
},
'test.customTemplate': {
options: {
dest: 'tmp/customTemplate',
template: 'test/fixtures/custom-template.js.hb'
},
'pre-commit': 'aTask'
},
'test.insert': {
options: {
dest: 'tmp/insert',
preventExit: true
},
'pre-commit': 'aTask'
},
'test.customHashbang': {
options: {
dest: 'tmp/customHashbang',
hashbang: '#!/usr/bin/node'
},
'pre-commit': 'aTask'
},
'test.withArguments': {
options: {
dest: 'tmp/withArguments',
args: "--test myargument"
},
'pre-commit': 'aTask'
},
'test.withQuotedArguments': {
options: {
dest: 'tmp/withQuotedArguments',
args: '--test "foo \'bar baz\'"'
},
'pre-commit': 'aTask'
},
'test.hookSpecificOptions': {
options: {
dest: 'tmp/hookSpecificOptions',
hashbang: '#!/usr/bin/node'
},
'pre-commit': {
taskNames: 'aTask',
template: 'test/fixtures/custom-template.js.hb'
}
},
'test.shellScript': {
options: {
dest: 'tmp/shellScript',
hashbang: '#!/bin/sh',
template: 'templates/shell.hb',
startMarker: '## GRUNT-GITHOOKS START',
endMarker: '## GRUNT-GITHOOKS END'
},
'pre-commit':'jshint'
},
'test.command': {
options: {
dest: 'tmp/command'
},
'pre-commit': {
command: '/usr/bin/grunt',
taskNames: 'aTask'
}
},
'test.noTaskNames': {
options: {
dest: 'tmp/noTaskNames'
},
'pre-commit': {
preventExit: true
}
},
// Test targets for logging validation
// Logs which tasks get bound to which hook
'logs.defaultLogging': {
options: {
dest: 'tmp/defaultLogging',
},
'pre-commit': 'aTask'
},
// Logs if the hook name does not correspond to a Git hook
'logs.warnIfNotValidHook': {
options: {
dest: 'tmp/warnIfNotValidHook',
},
'definitelyNotTheNameOfAGitHook': 'jshint'
},
// Fail if the existing hook does not have the appropriate scripting
// language
'fails.invalidScriptingLanguage': {
options: {
dest: 'tmp/invalidScriptingLanguage',
},
'pre-commit': 'jshint'
},
'fails.customHashbangInvalidScriptingLanguage': {
options: {
dest: 'tmp/customHashbangInvalidScriptingLanguage',
hashbang: '#!/usr/bin/node'
},
'pre-commit': 'jshint'
}
},
// Unit tests.
nodeunit: {
tests: ['test/*_test.js'],
},
});
// Actually load this plugin's task(s).
grunt.loadTasks('tasks');
// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-nodeunit');
// Whenever the "test" task is run, first clean the "tmp" dir, then run this
// plugin's test task(s), then test the result.
grunt.registerTask('test', (function () {
var tasks = [
'clean',
'copy'
];
for (var target in grunt.config.data.githooks) {
if(/^test\./.test(target)){
tasks.push('githooks:'+target);
}
}
tasks.push('nodeunit');
return tasks;
}()));
// By default, lint and run all tests.
grunt.registerTask('default', ['jshint', 'test']);
// Dummy tasks used for testing
grunt.registerTask('aTask', function () {
console.log('Boom! Running a task!');
});
grunt.registerTask('anotherTask', function () {});
};