forked from kimmobrunfeldt/progressbar.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
180 lines (162 loc) · 4.67 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
var fs = require('fs');
var _ = require('lodash');
// Split array to smaller arrays containing n elements at max
function groupToElements(array, n) {
var lists = _.groupBy(array, function(element, index){
return Math.floor(index / n);
});
return _.toArray(lists);
}
function endsWith(str, suffix) {
return str.indexOf(suffix, str.length - suffix.length) !== -1;
}
// Setup karma configuration dynamically to run browsers sequentially
// https://github.com/karma-runner/karma-sauce-launcher/issues/8
var MAXIMUM_CONCURRENT_SAUCE = 3;
var sauceBrowsers = require('./saucelabs-browsers');
var browserGroups = groupToElements(Object.keys(sauceBrowsers), MAXIMUM_CONCURRENT_SAUCE);
var karmaConfig = {
options: {
configFile: 'karma.conf.js'
}
};
_.each(browserGroups, function(group, index) {
karmaConfig['sauce' + index] = {
browsers: group
}
});
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
files: ['src/*.js', 'test/**/*.js'],
options: {
globals: {
jQuery: true,
module: true
}
}
},
shell: {
stageMinified: {
options: {
stdout: true,
// If minified files do not change on release,
// git command fails
failOnError: false
},
command: 'git add dist/progressbar.js dist/progressbar.min.js dist/progressbar.min.js.map'
},
browserifyDevelopment: {
options: {
stdout: true
},
command: 'browserify src/main.js -o dist/progressbar.js --standalone ProgressBar'
},
browserifyMinified: {
options: {
stdout: true
},
// The output file is minified by uglifyjs later.
command: 'browserify src/main.js -o dist/progressbar.min.js --standalone ProgressBar'
},
watchifyLocalDev: {
options: {
stdout: true
},
command: 'watchify local-dev/main.js -o local-dev/bundle.js --debug --verbose'
},
release: {
options: {
stdout: true
},
command: function(bump) {
bump = bump || 'patch';
return './tools/release.js ' + bump;
}
},
karma: {
options: {
stdout: true
},
// This will run tests in Sauce Lab
command: './node_modules/karma/bin/karma start'
},
testem: {
options: {
stdout: true
},
// This will run tests in all local browsers available/detected
command: 'testem ci -R dot -l chrome'
}
},
// Uglify must be run after browserify
uglify: {
progressbar: {
options: {
sourceMap: true
},
files: {
'dist/progressbar.min.js': ['dist/progressbar.min.js']
}
}
},
// Calculated dynamically above
karma: karmaConfig
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-karma');
grunt.registerTask('watch', function() {
grunt.task.run(['shell:watchifyLocalDev']);
});
grunt.registerTask('stageMinified', function() {
grunt.task.run(['shell:stageMinified']);
});
// Build distributables to dist folder
grunt.registerTask('build', [
'shell:browserifyDevelopment',
'shell:browserifyMinified',
'uglify:progressbar'
]);
grunt.registerTask('test', ['shell:testem']);
// Run multiple tests serially, but continue if one of them fails.
// Adapted from http://stackoverflow.com/questions/16487681/gruntfile-getting-error-codes-from-programs-serially
grunt.registerTask('sauce', function() {
var done = this.async();
var tasks = {};
_.each(browserGroups, function(group, index) {
tasks['karma:sauce' + index] = 0;
});
var success = true;
grunt.util.async.forEachSeries(Object.keys(tasks), function(task, next) {
grunt.util.spawn({
// Use grunt to spawn
grunt: true,
args: [task],
// Print to the same stdout
opts: { stdio: 'inherit' }
}, function(err, result, code) {
tasks[task] = code;
if (code !== 0) {
success = false;
}
next();
});
}, function() {
done(success);
});
});
// Test, build, and release library to public
grunt.registerTask('release', function(bump) {
bump = bump || 'patch';
grunt.task.run([
'jshint',
'test',
'build',
'stageMinified',
'shell:release:' + bump
]);
});
};