-
Notifications
You must be signed in to change notification settings - Fork 1
/
GruntFile.js
253 lines (252 loc) · 7.79 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
'use strict';
// # Grunt File for a11y-auditor APP
//
// Tasks performed :
// 1. Run JSHint to lint the files.
// 2. Run grunt-browserify task to convert the files to be front end compatible
// 3. Have watchify to watch over the files changing under lib/*.js
//
module.exports = function(grunt) {
// loading the npm task
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-jscs');
grunt.loadNpmTasks('grunt-jsonlint');
grunt.loadNpmTasks('grunt-docco-plus');
grunt.loadNpmTasks('grunt-gh-pages');
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-istanbul');
grunt.loadNpmTasks('grunt-coveralls');
grunt.loadNpmTasks('grunt-env');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-uglify');
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
//grunt-contrib-uglify tasks to minify the output from browserify
uglify: {
options: {
mangle: false
},
dist: {
files: {
'dist/a11y-auditor.min.js': ['dist/a11y-auditor.js'],
'dist/a11y-auditor.min.only.js': ['dist/a11y-auditor.src.js']
}
}
},
//grunt-contrib-clean tasks to clean folders on every document, test, coverage tasks
clean: {
docs: ['.docs', '.cache'],
testCoverage: ['.coverage', '.test', '.cache'],
postUglify: ['dist/a11y-auditor.js', 'dist/a11y-auditor.src.js']
},
//grunt-contrib-copy tasks copies the lib folder and places it inside .coverage/instrument/
copy: {
main: {
files: [
{
expand: true,
flatten: true,
src: ['lib'],
dest: '.coverage/instrument/'
}
]
}
},
// grunt-contrib-jshint tasks runs jshint across files mentioned in src
jshint: {
lib: {
src: [
'lib/**/*.js',
'*.js'
],
options: {
jshintrc: '.jshintrc'
}
}
},
//grunt-jscs tasks runs tests for code style errors
jscs: {
lib: {
src: [
'lib/**/*.js',
'*.js'
],
options: {
config: '.jscsrc'
}
}
},
//grunt-jsonlint tasks runs lint tests across .json files
jsonlint: {
lib: {
src: [
'lib/**/*.json',
'*.json'
]
}
},
// server side grunt-mocha-test task
mochaTest: {
test: {
options: {
reporter: 'spec',
timeout: 50000
},
src: [
'test/*.js'
]
}
},
//grunt-istanbul instrumentor - used to instrument files under .coverage/instrument/lib/*
instrument: {
files: [
'lib/**/*.js'
],
options: {
lazy: false,
basePath: '.coverage/instrument/'
}
},
//grunt-istanbul task to store coverage info under .coverage/json/
storeCoverage: {
options: {
dir: '.coverage/json/'
}
},
//grunt-istanbul task to make report from .json file into .lcov
makeReport: {
src: '.coverage/json/**/*.json',
options: {
type: 'lcov',
dir: '.coverage/reports/',
print: 'detail'
}
},
//grunt-env task to store coverage directory
env: {
coverage: {
APP_DIR_FOR_CODE_COVERAGE: '.coverage/instrument/'
}
},
//grunt-docco-plus task to generate documentation
'docco-plus': {
debug: {
src: [
'lib/**',
'test/**',
'*.js',
'*.md'
],
options: {
output: '.docs/'
}
}
},
//grunt-gh-pages to be used by travis to auto commit into gh-pages
'gh-pages': {
options: {
base: '.docs',
// GH_TOKEN is the environment variable holding the access token for the repository
repo: 'https://' + process.env.GH_TOKEN + '@github.com/' + process.env.TRAVIS_REPO_SLUG + '.git',
clone: '.gh_pages',
message: 'build #' + process.env.TRAVIS_BUILD_NUMBER + ' travis commit',
// This configuration will suppress logging and sanitize error messages.
silent: true,
user: {
name: 'travis',
email: '[email protected]'
}
},
src: [
'**'
]
},
//grunt-coveralls to use the .lcov file
coveralls: {
lcov: {
// LCOV coverage file relevant to every target
src: '.coverage/reports/lcov.info'
}
},
//grunt-browserify task to generate bundled file for browser env
browserify: {
main: {
src: 'index.js',
dest: 'dist/a11y-auditor.js',
options: {
ignore: ['glob'],
exclude: ['glob'],
browserifyOptions: {
standalone: 'auditRunner',
transform: ['require-globify']
}
}
},
srcOnly: {
src: 'index.js',
dest: 'dist/a11y-auditor.src.js',
options: {
ignore: ['glob', 'jquery', 'lodash/core'],
exclude: ['glob', 'jquery', 'lodash/core'],
browserifyOptions: {
standalone: 'auditRunner',
transform: ['require-globify']
}
}
}
},
//grunt-contrib-watch task to watch files that change and run build
watch: {
files: [
'lib/**/*.js',
'index.js'
],
tasks: ['default']
}
});
//register the grunt task for mocha tests on Jsdom
grunt.registerTask('test', [
'lint',
'clean:testCoverage',
'copy:main',
'env:coverage',
'instrument',
'mochaTest'
]);
//register the grunt task for linting
grunt.registerTask('lint', [
'jshint',
'jscs',
'jsonlint'
]);
//register the grunt task for browserify bundler
grunt.registerTask('build', [
'lint',
'browserify:main',
'browserify:srcOnly',
'uglify',
'clean:postUglify'
]);
//register the grunt task for coverage
grunt.registerTask('coverage', [
'test',
'storeCoverage',
'makeReport',
'coveralls:lcov'
]);
//register the grunt task for documentation
grunt.registerTask('document', [
'clean:docs',
'docco-plus'
]);
//register the default grunt tasks that need to be executed
grunt.registerTask('default', [
'test',
'build',
'watch'
]);
};