-
Notifications
You must be signed in to change notification settings - Fork 1
/
Gruntfile.js
executable file
·182 lines (164 loc) · 3.99 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
'use strict';
module.exports = function (grunt) {
// Load grunt tasks automatically
require('load-grunt-tasks')(grunt);
// Define the configuration for all the tasks
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
// Concat files
concat: {
dist: {
src: [
'module.prefix',
'.tmp/main.js',
'.tmp/*.js',
'module.suffix'],
dest: 'dist/<%= pkg.name %>.js'
}
},
// Clean
clean: ['.tmp/', 'dist/', 'coverage/'],
// Remove 'use strict' repetition
replace: {
strict: {
src: ['src/**/*.js'],
dest: '.tmp/',
replacements: [{
from: '\'use strict\';\n\n',
to: ''
}]
}
},
// Minify
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> v<%= pkg.version %> */\n'
},
dist: {
files: {
'dist/<%= pkg.name %>.min.js': ['<%= concat.dist.dest %>']
}
}
},
// JShint
jshint: {
options: {
jshintrc: '.jshintrc',
reporter: require('jshint-stylish')
},
all: ['src/**/*.js'],
test: {
options: {
jshintrc: 'test/.jshintrc'
},
src: ['test/spec/**/*.js']
}
},
// JSCS
jscs: {
main: {
files: {
src: ['src/**/*.js', 'test/spec/**/*.js']
},
options: {
config: '.jscsrc'
}
}
},
// Test Server
connect: {
test: {
options: {
port: 9001,
base: [
'test',
'src'
]
}
},
coverage: {
options: {
port: 9090,
open: 'http://localhost:9090',
keepalive: true,
base: ['coverage/html']
}
}
},
// Test settings
karma: {
options: {
configFile: 'karma.conf.js'
},
test: {},
debug: {
singleRun: false
},
'ci-test': {
signleRun: true,
browsers: ['PhantomJS']
},
coverage: {
preprocessors: {
'src/**/*.js': 'coverage'
},
reporters: ['coverage'],
coverageReporter: {
reporters: [{
type: 'html',
subdir: 'html'
}, {
type: 'text',
subdir: 'text'
}]
}
},
'ci-coverage': {
browsers: ['PhantomJS'],
singleRun: true,
preprocessors: {
'src/**/*.js': 'coverage'
},
reporters: ['coverage'],
coverageReporter: {
reporters: [{
type: 'text-summary',
subdir: 'text-summary'
}, {
type: 'lcov',
subdir: 'lcov'
}]
}
}
},
bumpup: {
files: ['package.json', 'bower.json']
}
});
// Register tasks
grunt.registerTask('build', ['clean', 'jshint:all', 'jscs', 'replace:strict', 'concat', 'uglify']);
grunt.registerTask('test', ['clean', 'jshint:all', 'jscs', 'jshint:test', 'connect:test', 'karma:test', 'karma:coverage']);
grunt.registerTask('coverage', ['connect:test', 'karma:coverage', 'connect:coverage']);
grunt.registerTask('default', ['test', 'build']);
grunt.registerTask('debug', ['connect:test', 'karma:debug']);
grunt.registerTask('test-ci', ['clean', 'jshint:all', 'jshint:test', 'connect:test', 'karma:ci-test', 'karma:ci-coverage']);
// When version bump is occurring, test, bump version, build and update changelog
grunt.registerTask('bump', function (version) {
var tasks = [], type;
if (version === 'pre') {
type = 'prerelease';
} else if (version === 'bug') {
type = 'patch';
} else if (version === 'minor') {
type = 'minor';
} else if (version === 'major') {
type = 'major';
} else {
type = version;
}
tasks.push('test');
tasks.push('bumpup:' + type);
tasks.push('build');
grunt.task.run(tasks);
});
};