forked from telefonicaid/lwm2m-node-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
304 lines (274 loc) · 9.42 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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
/*
* Copyright 2014 Telefonica Investigación y Desarrollo, S.A.U
*
* This file is part of iotagent-lwm2m-lib
*
* iotagent-lwm2m-lib is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* iotagent-lwm2m-lib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with iotagent-lwm2m-lib.
* If not, seehttp://www.gnu.org/licenses/.
*
* For those usages not covered by the GNU Affero General Public License
* please contact with::[[email protected]]
*/
'use strict';
/**
* Grunt tasks definitions
*
* @param {Object} grunt
*/
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkgFile: 'package.json',
pkg: grunt.file.readJSON('package.json'),
clean: {
reportTest: ['report/test'],
reportLint: ['report/lint'],
reportCoverage: ['report/coverage'],
siteCoverage: ['site/coverage'],
siteDoc: ['site/doc'],
siteReport: ['site/report']
},
mkdir: {
reportTest: {
options: {
create: ['<%= clean.reportTest[0] %>']
}
},
reportLint: {
options: {
create: ['<%= clean.reportLint[0] %>']
}
},
reportCoverage: {
options: {
create: ['<%= clean.reportCoverage[0] %>']
}
},
siteCoverage: {
options: {
create: ['<%= clean.siteCoverage[0] %>']
}
},
siteDoc: {
options: {
create: ['<%= clean.siteDoc[0] %>']
}
},
siteReport: {
options: {
create: ['<%= clean.siteReport[0] %>']
}
}
},
jshint: {
gruntfile: {
src: 'Gruntfile.js',
options: {
jshintrc: '.jshintrc'
}
},
lib: {
src: ['lib/**/*.js'],
options: {
jshintrc: '.jshintrc'
}
},
test: {
src: ['test/**/*.js'],
options: {
jshintrc: 'test/.jshintrc'
}
},
reportGruntfile: {
src: 'Gruntfile.js',
options: {
reporter: 'checkstyle',
reporterOutput: '<%= clean.reportLint[0] %>/jshint-gruntfile.xml',
jshintrc: '.jshintrc'
}
},
reportLib: {
src: 'lib/**/*.js',
options: {
reporter: 'checkstyle',
reporterOutput: '<%= clean.reportLint[0] %>/jshint-lib.xml',
jshintrc: 'lib/.jshintrc'
}
},
reportTest: {
src: 'test/**/*.js',
options: {
reporter: 'checkstyle',
reporterOutput: '<%= clean.reportLint[0] %>/jshint-test.xml',
jshintrc: 'test/.jshintrc'
}
}
},
watch: {
gruntfile: {
files: '<%= jshint.gruntfile.src %>',
tasks: ['jshint:gruntfile']
},
lib: {
files: '<%= jshint.lib.src %>',
tasks: ['jshint:lib', 'test']
},
test: {
files: '<%= jshint.test.src %>',
tasks: ['jshint:test', 'test']
}
},
mochaTest: {
unit: {
options: {
ui: 'bdd',
reporter: 'spec',
timeout: 2000
},
src: [
'tools/mocha-globals.js',
'<%= jshint.test.src %>'
]
},
unitReport: {
options: {
ui: 'bdd',
reporter: 'tap',
quiet: true,
captureFile: '<%= clean.reportTest[0] %>/unit_tests.tap'
},
src: [
'tools/mocha-globals.js',
'<%= jshint.test.src %>'
]
}
},
githubPages: {
target: {
options: {
commitMessage: 'UPDATE Doc'
},
src: 'site'
}
},
dox: {
options: {
title: 'iotagent-lwm2m-lib documentation'
},
files: {
src: ['<%= jshint.lib.src %>'],
dest: '<%= clean.siteDoc[0] %>'
}
},
exec: {
istanbul: {
cmd:
'bash -c "./node_modules/.bin/istanbul cover --root lib/ --dir <%= clean.siteCoverage[0] %> -- ' +
'\\"`npm root -g`/grunt-cli/bin/grunt\\" test && ' +
'./node_modules/.bin/istanbul report --dir <%= clean.siteCoverage[0] %> text-summary"'
},
istanbulCobertura: {
cmd:
'bash -c "./node_modules/.bin/istanbul report --dir <%= clean.siteCoverage[0] %> cobertura && ' +
'mv <%= clean.siteCoverage[0] %>/cobertura-coverage.xml <%= clean.reportCoverage[0] %>"'
},
githubPagesInit: {
cmd: 'bash tools/github-pages.sh'
}
},
plato: {
options: {
jshint: grunt.file.readJSON('.jshintrc')
},
lib: {
files: {
'<%= clean.siteReport[0] %>': '<%= jshint.lib.src %>'
}
}
},
githooks: {
all: {
'pre-commit': 'lint test'
}
},
gjslint: {
options: {
reporter: {
name: 'console'
},
flags: [
'--flagfile .gjslintrc' //use flag file'
],
force: false
},
gruntfile: {
src: '<%= jshint.gruntfile.src %>'
},
lib: {
src: '<%= jshint.lib.src %>'
},
test: {
src: '<%= jshint.test.src %>'
},
report: {
options: {
reporter: {
name: 'gjslint_xml',
dest: '<%= clean.reportLint[0] %>/gjslint.xml'
},
flags: [
'--flagfile .gjslintrc'
],
force: false
},
src: ['<%= jshint.gruntfile.src %>', '<%= jshint.lib.src %>', '<%= jshint.test.src %>']
}
}
});
// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-github-pages');
grunt.loadNpmTasks('grunt-exec');
grunt.loadNpmTasks('grunt-plato');
grunt.loadNpmTasks('grunt-gjslint');
grunt.loadNpmTasks('grunt-dox');
grunt.loadNpmTasks('grunt-mkdir');
grunt.loadNpmTasks('grunt-githooks');
grunt.loadTasks('tools/tasks');
grunt.registerTask('init-pages', ['exec:githubPagesInit']);
grunt.registerTask('test', 'Run tests', ['mochaTest:unit']);
grunt.registerTask('test-report', 'Generate tests reports',
['clean:reportTest', 'mkdir:reportTest', 'mochaTest:unitReport']);
grunt.registerTask('coverage', 'Print coverage report',
['clean:siteCoverage', 'exec:istanbul']);
grunt.registerTask('coverage-report', 'Generate Cobertura report',
['clean:reportCoverage', 'mkdir:reportCoverage', 'coverage', 'exec:istanbulCobertura']);
grunt.registerTask('complexity', 'Generate code complexity reports', ['plato']);
grunt.registerTask('doc', 'Generate source code JSDoc', ['dox']);
grunt.registerTask('lint-jshint', 'Check source code style with JsHint',
['jshint:gruntfile', 'jshint:lib', 'jshint:test']);
grunt.registerTask('lint-gjslint', 'Check source code style with Google Closure Linter',
['gjslint:gruntfile', 'gjslint:lib', 'gjslint:test']);
grunt.registerTask('lint', 'Check source code style', ['lint-jshint', 'lint-gjslint']);
grunt.registerTask('lint-report', 'Generate checkstyle reports',
['clean:reportLint', 'mkdir:reportLint', 'jshint:reportGruntfile', 'jshint:reportLib',
'jshint:reportTest', 'gjslint:report']);
grunt.registerTask('site', ['doc', 'coverage', 'complexity', 'githubPages']);
grunt.registerTask('init-dev-env', ['githooks']);
// Default task.
grunt.registerTask('default', ['lint-jshint', 'test']);
};