-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathGruntfile.js
234 lines (228 loc) · 8.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
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
module.exports = function(grunt){
var defaultOptsTmpl = {
requireConfigFile: 'RequireConfig.js'
};
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
meta:{
bin:{
coverage: 'bin/coverage'
},
port:{
coverage: 8082
}
},
connect: {
test: {
port: 8000,
base: '.'
},
coverage:{
options:{
port: '<%= meta.port.coverage %>',
middleware: function(connect, options){
var src = [];
var adjustMethod = function(file){
src.push('/'+file);
};
grunt.file.expand(grunt.config.get("jasmine.coverage.src")).forEach(adjustMethod);
var staticConnection = connect.static(options.base);
return [
function(request, response, next){
if(src.indexOf(request.url) > -1){
request.url = "/.grunt/grunt-contrib-jasmine"+request.url;
}
return staticConnection.apply(this, arguments);
}
];
}
}
}
},
//compress
uglify: {
production:{
files: {
'build/yoson-min.js':['dist/yoson.js']
},
options:{
preserveComments: false,
sourceMap: "dist/yoson.min.map",
sourceMappingURL: "yoson.min.map",
report: "min",
beautify:{
ascii_only: true
},
banner: "/*! FrontendLabs comunity | yOSONJS v<%=pkg.version%> | " +
"(c) 2014, <%=grunt.template.today('yyyy')%> FrontendLabs comunity */",
compress: {
hoist_funs: false,
loops: false,
unused: false
}
}
}
},
//for validation
jshint: {
options: {
jshintrc: '.jshintrc'
},
all: ['src/**/*.js', 'spec/**/*.js', '!src/yoson.js']
},
//for execute shell commands
exec: {
cleanDist: {
command: 'rm -fr dist'
},
cleanBuild: {
command: 'rm -fr build'
}
},
jasmine:{
requirejs:{
src: 'src/**/*.js',
options: {
specs: 'test/spec/Spec*.js',
helpers: 'test/helper/Helper*.js',
host: 'http://127.0.0.1:<%= connect.test.port %>/',
template: require('grunt-template-jasmine-requirejs'),
templateOptions: defaultOptsTmpl
}
},
coverage:{
src: 'src/**/*.js',
options: {
specs: 'test/spec/Spec*.js',
host: 'http://127.0.0.1:<%= meta.port.coverage %>/',
template: require('grunt-template-jasmine-istanbul'),
templateOptions: {
coverage: '<%= meta.bin.coverage%>/coverage.json',
report: [
{
type: "html",
options: {
dir: "<%= meta.bin.coverage%>/html"
}
},
{
type: "text-summary"
},
{
type: "lcov",
options: {
dir: "reports/lcov"
}
}
],
replace: false,
template: require("grunt-template-jasmine-requirejs"),
templateOptions:defaultOptsTmpl
}
}
}
},
//for documentation
yuidoc:{
all: {
name: '<%= pkg.name %>',
description: '<%= pkg.description %>',
version: '<%= pkg.version %>',
url: '<%= pkg.homepage %>',
options:{
paths: ['src'],
outdir: './docs/'
}
}
},
//for complexity
complexity: {
generic: {
src: ["src/**/*.js"],
options:{
"jsLintXML": "report/jslint.xml",
"checkstyleXML":"report/checkstyle.xml",
"cyclomatic": 3,
"halstead": 8,
"maintainability": 100,
"broadcast": false
}
}
},
//for changelog
conventionalChangelog: {
options: {
changelogOpts: {
// conventional-changelog options go here
preset: 'angular'
},
context: {
// context goes here
},
gitRawCommitsOpts: {
// git-raw-commits options go here
},
parserOpts: {
// conventional-commits-parser options go here
},
writerOpts: {
// conventional-changelog-writer options go here
}
},
release: {
src: 'CHANGELOG.md'
}
},
//for coveralls service
coveralls:{
options:{
//src: 'coverage-results/lcov.info',
force: false
},
main_target:{
src: 'reports/lcov/lcov.info'
}
},
//for bump
bump:{
options: {
}
}
});
//load package for task of requirejs
grunt.loadNpmTasks('grunt-contrib-requirejs');
//load package for task of jshint
grunt.loadNpmTasks('grunt-contrib-jshint');
//load package for task of jshint
grunt.loadNpmTasks('grunt-complexity');
//módulo para emular la conexión por consola de los tests
grunt.loadNpmTasks('grunt-contrib-connect');
//load package for task of uglify compress
grunt.loadNpmTasks('grunt-contrib-uglify');
//load package for task of shell
grunt.loadNpmTasks('grunt-exec');
//Load the plugin that provides the jasmine test
grunt.loadNpmTasks('grunt-contrib-jasmine');
//Load the plugin that provides the yuidoc
grunt.loadNpmTasks('grunt-contrib-yuidoc');
//Load the plugin that provides the generator of changelog file
grunt.loadNpmTasks('grunt-conventional-changelog');
//Load the plugin that provides the bump actions
grunt.loadNpmTasks('grunt-bump');
//Load the plugin for generate the report to coveralls service
grunt.loadNpmTasks('grunt-coveralls');
//Load the tasks
grunt.loadTasks('tasks');
//log the tasks
grunt.log.write("running grunt for yoson");
//enroll tasks
grunt.registerTask('hint', ['jshint', 'complexity']);
grunt.registerTask('spec', ['connect', 'jasmine:requirejs']);
grunt.registerTask('coverage', ['connect:coverage', 'jasmine:coverage', 'coveralls']);
grunt.registerTask('dist', ['exec:cleanDist', 'generateDist']);
grunt.registerTask('build', ['exec:cleanBuild', 'uglify']);
grunt.registerTask('changelog', ['conventionalChangelog']);
grunt.registerTask('doc', ['yuidoc']);
grunt.registerTask('default', ['spec', 'dist', 'build', 'doc']);
//grunt.registerTask('default', ['spec']);
};