-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathGruntfile.js
167 lines (160 loc) · 6.03 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
module.exports = function(grunt) {
'use strict';
grunt.initConfig({
jshint: {
options: {
jshintrc: '.jshintrc'
},
src: ['Gruntfile.js', 'src/**/*.js']
},
connect: {
test: {
options: {
port: 8080
}
}
},
jasmine: {
taskName: {
src: 'amd/**/*.js',
options: {
specs: 'test/web/*_test.js',
host: 'http://127.0.0.1:8080/',
template: require('grunt-template-jasmine-requirejs'),
templateOptions: {
requireConfig: {
}
}
}
}
},
complexity: {
generic: {
src: ['src/o2/*/*.js'],
options: {
errorsOnly: false,
/**
* Different resources recommend different values for
* cyclomatic complexity.
*
* For instance http://www.amazon.com/dp/1842651765/
* recommends a value of 10 and says even 15 may be
* acceptable.
* On the other hand, http://bit.ly/cyclomatic regards a
* number below 10 as "reliable".
* Also McCabe (1996) discusses about limiting cyclomatic
* complexity to 10.
*
* Keeping this at "5", a reasonably strict value: This
* overly-conservative choice will also force splitting
* longer methods into smaller sub-methods.
*/
cyclomatic: 5,
/**
* There does not appear a common consensus for this metric
* either.
*
* o2.js code uses "15" to err on the conservative side.
* This value might adjust itself as the library evolves.
*
* Here are some interesting findings:
*
* http://www.amazon.com/dp/0471887137 suggests 50 to 100
* lines of code, less than 10 cyclomatic complexity, and
* less than 10 Halstead difficulty per method.
*
* Some other resources recommend a Halstead "volume" of
* at least 20, and not more than 1000 per method.
*
* http://www.mccabe.com/pdf/McCabe%20IQ%20Metrics.pdf
* suggests a threshold of 30 for Halstead difficulty index.
*
* There even are sources that take numbers as high as 50
* as a difficulty thresholds for methods
* (e.g., http://bit.ly/halstead50).
*
* And some sources even argue that using Halstead
* difficulty does not prove much value, since there are
* simpler methods (such as counting lines of code) that
* provide adequate information.
* See, for example, http://bit.ly/simplerIsBetter which
* shows high correlation between SLOC and Halstead
* difficulty;
* meaning: simply counting lines of code gives mostly the
* same information as doing a more complex Halstead
* analysis.
*/
halstead: 15,
/**
* 65 is considered to be a real warning sign.
* 85 and more is recommended.
* ref: http://bit.ly/complexityMetrics
*
* Keeping it at 100 to be conservative.
*/
maintainability: 100
}
}
},
exec: {
examples: {
command: 'sh bin/examples.sh',
stdout: true,
stderr: true
},
clean: {
command: 'sh bin/clean.sh',
stdout: true,
stderr: true
},
install: {
command:'sh bin/install.sh',
stdout: true,
stderr: true
},
amdify: {
command: 'r.js -convert src/o2 amd/o2;',
stdout: true,
stderr: true
},
'test': {
command: 'npm test',
stdout: true,
stderr: true
}
},
pkg: grunt.file.readJSON('package.json'),
yuidoc: {
compile: {
name: '<%= pkg.name %>',
description: '<%= pkg.description %>',
version: '<%= pkg.version %>',
url: '<%= pkg.homepage %>',
logo: '../assets/logo.png',
options: {
paths: 'src/o2',
outdir: 'documentation'
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-jasmine');
grunt.loadNpmTasks('grunt-complexity');
grunt.loadNpmTasks('grunt-exec');
grunt.loadNpmTasks('grunt-contrib-yuidoc');
grunt.registerTask('default', ['jshint']);
grunt.registerTask('lint', ['jshint']);
grunt.registerTask('test', ['connect:test', 'jasmine']);
grunt.registerTask('publish', [
'exec:clean',
'exec:install',
'exec:amdify',
'lint',
'complexity'
]);
grunt.registerTask('minify-examples', ['exec:examples']);
grunt.registerTask('testAll', ['exec:test', 'test']);
grunt.registerTask('doc', ['yuidoc']);
};