-
Notifications
You must be signed in to change notification settings - Fork 22
/
Gruntfile.js
201 lines (183 loc) · 4.92 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
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
project: {
lib: 'lib',
test: 'test',
dist: 'dist',
doc: 'doc',
apidoc: '<%= project.doc %>/api',
name: 'jmap-client'
},
uglify: {
dist: {
files: [
{
dest: '<%= project.dist %>/<%= project.name %>.min.js',
src: ['<%= project.dist %>/<%= project.name %>.js']
}
]
}
},
eslint: {
all: {
src: ['Gruntfile.js', 'lib/**/*.js', 'test/**/**/*.js']
},
options: {
quiet: true
}
},
lint_pattern: {
options: {
rules: [
{ pattern: /(describe|it)\.only/, message: 'Must not use .only in tests' }
]
},
all: {
src: ['<%= eslint.all.src %>']
}
},
mocha_istanbul: {
coverage: {
src: [
'<%= project.test %>/common/',
'<%= project.test %>/backend/'
],
options: {
require: ['chai'],
reporter: 'spec',
reportFormats: ['lcov', 'text-summary'],
timeout: 3000,
coverageFolder: 'coverage/backend',
mask: '**/*.js',
root: 'dist/'
}
}
},
lcovMerge: {
options: {
emitters: ['file'],
outputFile: 'coverage/lcov-merged.info'
},
src: [
'coverage/backend/lcov.info',
'coverage/frontend/lcov.info'
]
},
coveralls: {
options: {
force: false // When true, grunt-coveralls will only print a warning rather than an error
},
publish: {
src: 'coverage/lcov-merged.info'
}
},
watch: {
files: ['<%= eslint.all.src %>'],
tasks: ['test']
},
// Empties folders to start fresh
clean: {
dist: {
files: [{
dot: true,
src: [
'<%= project.dist %>/*',
'!<%= project.dist %>/.git*'
]
}]
},
apidoc: {
files: [{
src: ['<%= project.apidoc %>/**/*']
}]
}
},
browserify: {
dist: {
options: {
transform: [
'browserify-versionify',
[
'babelify',
{
presets: ['es2015'],
plugins: [
['transform-builtin-extend', { globals: ['Error'], approximate: true }],
'transform-object-assign',
'add-module-exports']
}
]
],
browserifyOptions: {
standalone: 'jmap'
},
external: [
'request',
'q'
]
},
files: {
'<%= project.dist %>/jmap-client.js': ['<%= project.lib %>/API.js']
}
}
},
karma: {
unit: {
configFile: '<%= project.test %>/config/karma.conf.js'
}
},
jsdoc: {
dist: {
src: ['<%= project.lib %>/'],
jsdoc: 'node_modules/jsdoc/jsdoc.js',
options: {
recurse: true,
destination: '<%= project.apidoc %>',
configure: '.jsdocrc'
}
}
},
release: {
options: {
file: 'package.json',
additionalFiles: ['bower.json'],
commitMessage: 'Bumped version to <%= version %>',
tagName: 'v<%= version %>',
tagMessage: 'Version <%= version %>',
afterBump: ['exec:gitcheckout_ReleaseBranch', 'test', 'apidoc'],
beforeRelease: ['exec:gitadd_DistAndAPIDoc', 'exec:gitcommit_DistAndAPIDoc'],
afterRelease: ['exec:gitcheckout_master']
}
},
exec: {
gitcheckout_ReleaseBranch: {
cmd: function() {
return 'git checkout -b release-' + this.file.readJSON('package.json').version;
}
},
gitcheckout_master: {
cmd: 'git checkout master'
},
gitadd_DistAndAPIDoc: {
cmd: 'git add -f dist/ doc/api/'
},
gitcommit_DistAndAPIDoc: {
cmd: function() {
return 'git commit -m"Added distribution and API documentation for release."';
}
}
}
});
require('load-grunt-tasks')(grunt);
grunt.loadNpmTasks('grunt-mocha-istanbul');
grunt.loadNpmTasks('grunt-coveralls');
grunt.loadNpmTasks('grunt-eslint');
grunt.registerTask('compile', 'Compile from ES6 to ES5', ['clean:dist', 'browserify', 'uglify']);
grunt.registerTask('coverage', ['test', 'lcovMerge', 'coveralls:publish']);
grunt.registerTask('linters', 'Check code for lint', ['eslint:all', 'lint_pattern:all']);
grunt.registerTask('test', 'Lint, compile and launch test suite', ['linters', 'compile', 'mocha_istanbul:coverage', 'karma']);
grunt.registerTask('dev', 'Launch tests then for each changes relaunch it', ['test', 'watch']);
grunt.registerTask('apidoc', 'Generates API documentation', ['clean:apidoc', 'jsdoc']);
grunt.registerTask('default', ['test']);
};