-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGruntfile.js
314 lines (292 loc) · 9.04 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
305
306
307
308
309
310
311
312
313
314
/**
* Gruntfile
*
* Handles the building of the application.
*
* @param grunt
*/
/* Node modules */
var semver = require("semver");
module.exports = function (grunt) {
"use strict";
/* Load all grunt tasks */
require("load-grunt-tasks")(grunt);
require("grunt-timer").init(grunt);
var pkg = grunt.file.readJSON("package.json");
grunt.initConfig({
config: {
build: "build",
coverage: "coverage",
docs: "doc",
src: "lib",
test: "test"
},
pkg: pkg,
clean: {
build: [
"./<%= config.build %>"
],
coverage: [
"./<%= config.coverage %>"
],
docs: [
"./<%= config.docs %>"
]
},
copy: {
src: {
cwd: "./<%= config.src %>",
dest: "./<%= config.build %>/",
expand: true,
src: "**/*.js"
}
},
codeclimate: {
options: {
file: "./<%= config.coverage %>/lcov.info",
token: "704eb25dd7e4075de3617c454ddce846548208c4ee0a204d36d234669497b67b"
}
},
coveralls: {
push: {
src: "./<%= config.coverage %>/lcov.info"
}
},
jscs: {
options: {
config: ".jscsrc"
},
src: {
files: {
src: [
"Gruntfile.js",
"./<%= config.src %>/**/*.js"
]
}
},
test: {
files: {
src: [
"./<%= config.test %>/**/*.js"
]
}
}
},
jsdoc: {
dist : {
src: [
"<%= config.src %>/**/*.js",
"<%= config.test %>/**/*.js"
],
options: {
destination: "<%= config.docs %>"
}
}
},
jshint: {
options: {
bitwise: true,
camelcase: true,
curly: true,
eqeqeq: true,
esnext: true,
globals: {
},
immed: true,
noarg: true,
node: true,
newcap: true,
quotmark: "double",
regexp: true,
strict: true,
trailing: true,
undef: true,
unused: false
},
src: {
files: {
src: [
"Gruntfile.js",
"./<%= config.src %>/**/*.js"
]
}
}
},
jsonlint: {
src: {
src: [
"./*.json",
"./<%= config.src %>/**/*.json",
"./<%= config.test %>/**/*.json"
]
}
},
"mocha_istanbul": {
checkCoverage: {
options: {
check: {
branches: 100,
functions: 100,
lines: 100,
statements: 100
},
coverage: true,
recursive: true,
root: "./<%= config.src %>"
},
src: "./<%= config.test %>/unit"
}
},
mochaTest: {
options: {
reporter: "spec",
ui: "bdd"
},
unittest: {
src: [
"./<%= config.test %>/**/*.test.js"
]
}
},
prompt: {
npmVersion: {
options: {
questions: [{
choices: [{
value: "build",
name: "Build: " + (pkg.version + "-?").yellow + " Unstable, betas, and release candidates."
}, {
value: "patch",
name: "Patch: " + semver.inc(pkg.version, "patch").yellow + " Backwards-compatible bug fixes."
}, {
value: "minor",
name: "Minor: " + semver.inc(pkg.version, "minor").yellow + " Add functionality in a backwards-compatible manner."
}, {
value: "major",
name: "Major: " + semver.inc(pkg.version, "major").yellow + " Incompatible API changes."
}, {
value: "custom",
name: "Custom: " + "?.?.?".yellow + " Specify version..."
}
],
config: "bump.increment",
message: "What sort of increment would you like?",
type: "list"
}, {
config: "bump.version",
message: "What specific version would you like",
type: "input",
when: function (answers) {
return answers["bump.increment"] === "custom";
},
validate: function (value) {
var valid = semver.valid(value) && true;
return valid || "Must be a valid semver, such as 1.2.3-rc1. See " +
"http://semver.org/".blue.underline + " for more details.";
}
}]
}
}
},
shell: {
addDocs: {
command: "git add --all -f <%= config.docs %>/"
},
gitPush: {
command: "git push"
},
gitPushTags: {
command: "git push origin --tags"
},
npmVersion: {
command: function () {
var bump = {
increment: grunt.config.get("bump.increment"),
version: grunt.config.get("bump.version")
};
var script = bump.increment;
if (script === "custom") {
script = bump.version;
}
return "npm version " + script;
}
}
},
watch: {
options: {
atBegin: true,
dateFormat: function (time) {
grunt.log.writeln("The task finished in " + time + "ms");
grunt.log.writeln("Waiting for more changes…");
}
},
coverage: {
files: [
"Gruntfile.js",
"<%= config.src %>/**/*.js",
"<%= config.src %>/**/*.json",
"<%= config.test %>/**/*.js",
"<%= config.test %>/**/*.json"
],
tasks: [
"mocha_istanbul"
]
},
test: {
files: [
"Gruntfile.js",
"<%= config.src %>/**/*.js",
"<%= config.src %>/**/*.json",
"<%= config.test %>/**/*.js",
"<%= config.test %>/**/*.json"
],
tasks: [
"test"
]
}
}
});
grunt.registerTask("build", "Build the package", [
"clean",
"test",
"dist"
]);
grunt.registerTask("ci", "Runs the continuous integration tests", [
"test",
"coverage"
]);
grunt.registerTask("coverage", "Runs the coverage tests", [
"mocha_istanbul:checkCoverage"
]);
grunt.registerTask("default", [
"build"
]);
grunt.registerTask("dist", "Create the distributable files", [
"copy:src"
]);
grunt.registerTask("lint", "Run the lint tests", [
"jshint:src",
"jsonlint:src",
"jscs:src",
"jscs:test" /* Run JSCS on tests to ensure readability */
]);
grunt.registerTask("tag", "Tag a new release", [
"prompt:npmVersion",
"shell:npmVersion",
"shell:gitPush",
"shell:gitPushTags"
]);
grunt.registerTask("test", "Perform tests on the codebase", [
"lint",
"unittest"
]);
grunt.registerTask("unittest", "Run the unit tests", [
"mochaTest:unittest"
]);
grunt.registerTask("watchcoverage", "Runs the coverage tests and watch for changes", [
"watch:coverage"
]);
grunt.registerTask("watchtest", "Perform tests on the codebase and watch for changes", [
"watch:test"
]);
};