-
Notifications
You must be signed in to change notification settings - Fork 3
/
Gruntfile.js
258 lines (231 loc) · 7.05 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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
'use strict';
var path = require('path');
var grunt = require('grunt');
/**
* Gets the index.html file from the code coverage folder.
*
* @param {!string} folder The path to the code coverage folder.
* @returns {string} The path to the index.html file
*/
function getCoverageReport (folder) {
var reports = grunt.file.expand(folder + '*/index.html');
if (reports && reports.length > 0) {
return reports[0];
}
return '';
}
module.exports = function (grunt) {
// Load grunt tasks automatically
require('load-grunt-tasks')(grunt);
// Time how long tasks take. Can help when optimizing build times
require('time-grunt')(grunt);
grunt.initConfig({
// Set paths
src: {
reports: './build/reports',
test: './test',
api: './api',
lib: './lib',
server: './server',
lint: [
'api/**/*.js',
'lib/**/*.js',
'server/**/*.js',
'test/**/*.js',
'Gruntfile.js',
'baboon-backend.js',
'validate-commit-msg.js'
]
},
// Clean before build
clean: {
reports: {
src: ['<%= src.reports %>']
},
coverage: {
src: ['<%= src.reports %>/coverage']
}
},
// Make sure code styles are up to par and there are no obvious mistakes
eslint: {
all: {
src: '<%= src.lint %>'
},
jslint: {
options: {
format: 'jslint-xml',
outputFile: '<%= src.reports %>/lint/eslint.xml'
},
files: {
src: '<%= src.lint %>'
}
},
checkstyle: {
options: {
format: 'checkstyle',
outputFile: '<%= src.reports %>/lint/eslint_checkstyle.xml'
},
files: {
src: '<%= src.lint %>'
}
}
},
// open browser
open: {
coverage: {
path: function () {
return path.join(__dirname, getCoverageReport('build/reports/coverage/'));
}
}
},
// Use nodemon to run server in debug mode with an initial breakpoint
nodemon: {
dev: {
script: 'baboon-backend.js',
options: {
env: {
DEBUG: '*',
PORT: 8081,
HOST: 'localhost',
NODE_ENV: 'development'
},
callback: function (nodemon) {
nodemon.on('log', function (event) {
console.log(event.colour);
});
},
watch: ['api/**/*.js', 'lib/*.js', 'server/*.js', 'Gruntfile.js']
}
}
},
// Shell commands for jasmine, coverage, reports and tests
shell: {
coverage: {
command: 'node node_modules/istanbul/lib/cli.js cover --dir build/reports/coverage node_modules/jasmine-node/bin/jasmine-node -- test/ --forceexit',
options: {
async: false
}
},
cobertura: {
command: 'node node_modules/istanbul/lib/cli.js report --root build/reports/coverage --dir build/reports/coverage cobertura',
options: {
async: false
}
}
},
jasmine_node: {
options: {
forceExit: true,
match: '.',
matchall: false,
extensions: 'js',
specNameMatcher: 'spec'
},
unit: ['test/api/'],
regApi: ['test/regressions/'],
all: ['test/'],
ci: {
options: {
jUnit: {
report: true,
savePath: '<%= src.reports %>/jasmine/',
useDotNotation: true,
consolidate: true
}
},
src: ['test/']
}
},
conventionalChangelog: {
options: {
changelogOpts: {
preset: 'angular'
}
},
release: {
src: 'CHANGELOG.md'
}
},
bump: {
options: {
commitFiles: ['.'],
commitMessage: 'chore: release v%VERSION%',
files: ['package.json'],
push: false
}
}
});
/**
* Serve tasks
*
* Task serve start server and watch
*/
grunt.registerTask('serve', function () {
grunt.task.run(['nodemon:dev']);
});
/**
* Test tasks
*
* Task test start eslint and all jasmine tests
* Task test:eslint start only eslint tests
* Task test:unit start only unit tests
* Task test:regApi start only regression api tests
*/
grunt.registerTask('test', function (target) {
// Task test:eslint
if (target === 'eslint') {
return grunt.task.run(['eslint:all']);
}
// Task test:unit
if (target === 'unit') {
return grunt.task.run(['jasmine_node:unit']);
}
// Task test:unit
if (target === 'regApi') {
return grunt.task.run(['jasmine_node:regApi']);
}
// Task test
grunt.task.run(['eslint:all', 'jasmine_node:all']);
});
/**
* Coverage for tests
*/
grunt.registerTask('cover', [
'clean:coverage',
'shell:coverage',
'shell:cobertura',
'open:coverage'
]);
/**
* Task for continuous integration server process
* Reports save in build/reports
*/
grunt.registerTask('ci', [
'clean:reports',
'eslint:jslint',
'eslint:checkstyle',
'jasmine_node:ci',
'shell:coverage',
'shell:cobertura'
]);
/**
* Task for check git commit message format
*/
grunt.registerTask('git:commitHook', 'Install git commit hook', function () {
grunt.file.copy('validate-commit-msg.js', '.git/hooks/commit-msg');
require('fs').chmodSync('.git/hooks/commit-msg', '0755');
grunt.log.ok('Registered git hook: commit-msg');
});
/**
* Task for publish release
* Update version in package.json, update CHANGELOG.md, tag version and commit
*/
grunt.registerTask('release', 'Bump version, update changelog and tag version', function (version) {
grunt.task.run([
'bump:' + (version || 'patch') + ':bump-only',
'conventionalChangelog:release',
'bump-commit'
]);
});
grunt.registerTask('default', 'test');
};