This repository was archived by the owner on Jul 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGruntfile.js
More file actions
147 lines (131 loc) · 4.97 KB
/
Gruntfile.js
File metadata and controls
147 lines (131 loc) · 4.97 KB
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
/*jshint node:true, maxstatements:false, maxlen:false */
var versionSync = require("local-version").sync;
var semver = require("semver");
module.exports = function(grunt) {
"use strict";
// These plugins provide necessary tasks.
grunt.loadNpmTasks("grunt-contrib-jshint");
grunt.loadNpmTasks("grunt-contrib-concat");
grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks("grunt-karma");
// Project configuration.
grunt.initConfig({
// Metadata.
pkg: grunt.file.readJSON("package.json"),
banner: "/*!\n" +
" * <%= pkg.title || pkg.name %>\n" +
" * <%= pkg.description %>\n" +
" * Copyright (c) <%= grunt.template.today('yyyy') %> <%= pkg.author.name %>\n" +
" * Licensed <%= _.pluck(pkg.licenses, 'type').join(', ') %>\n" +
"<%= pkg.homepage ? ' * ' + pkg.homepage + '\\n' : '' %>" +
" * v<%= pkg.version %>\n" +
" */\n",
// Task configuration.
jshint: {
options: {
jshintrc: true
},
gruntfile: ["Gruntfile.js"],
karma: ["karma.conf*.js"],
js: ["src/**/*.js", "!src/start.js", "!src/end.js"],
test: ["test/**/*.js"],
dist: ["dist/*.js", "!dist/*.min.js"]
},
concat: {
options: {
banner: "<%= banner %>",
stripBanners: true
},
dist: {
src: ["src/start.js", "src/main.js", "src/end.js"],
dest: "dist/<%= pkg.title %>.js"
}
},
uglify: {
options: {
report: "min",
preserveComments: "some"
},
dist: {
src: ["<%= concat.dist.dest %>"],
dest: "dist/<%= pkg.title %>.min.js"
}
},
karma: (function() {
var taskConfig = {
local: {
configFile: "karma.conf.js",
autoWatch: false,
singleRun: true
},
ci: {
configFile: "karma.conf-ci.js"
}
};
// Support for `conf.concurrency` was added in `karma@0.13.12`
var karmaVersion = versionSync("karma");
if (semver.gte(karmaVersion, "0.13.12")) {
// Just use the built-in mechanism in Karma >= 0.13.12
grunt.registerTask("karma-ci-chain", ["karma:ci"]);
}
else {
var maxConcurrency = 1;
var karmaConfCi = require("./" + taskConfig.ci.configFile);
var karmaCiTaskChain = [];
karmaConfCi(
{
set: function(conf) {
if (typeof conf.concurrency === "number") {
maxConcurrency = conf.concurrency;
}
if (conf.browsers && conf.browsers.length > 0) {
var i, len, target, targetName,
ie6Regex = /_ie_6\.0$/;
// Workaround for IE6 issue requires it to use the "jsonp-polling" transport:
// https://github.com/karma-runner/karma/issues/983
var ie6Browsers = conf.browsers.filter(function(browserId) {
return ie6Regex.test(browserId);
});
for (i = 0, len = ie6Browsers.length; i < len; i += maxConcurrency) {
target = {
configFile: taskConfig.ci.configFile
};
target.browsers = ie6Browsers.slice(i, i + maxConcurrency);
target.transports = ["jsonp-polling"];
targetName = maxConcurrency === 1 || len === 1 ? target.browsers[0] : "ci_ie6_" + ((i / maxConcurrency) + 1);
taskConfig[targetName] = target;
karmaCiTaskChain.push("karma:" + targetName);
}
var otherBrowsers = conf.browsers.filter(function(browserId) {
return !ie6Regex.test(browserId);
});
for (i = 0, len = otherBrowsers.length; i < len; i += maxConcurrency) {
target = {
configFile: taskConfig.ci.configFile
};
target.browsers = otherBrowsers.slice(i, i + maxConcurrency);
targetName = maxConcurrency === 1 || len === 1 ? target.browsers[0] : "ci_" + ((i / maxConcurrency) + 1);
taskConfig[targetName] = target;
karmaCiTaskChain.push("karma:" + targetName);
}
}
}
},
true
);
// `grunt-karma` does not correctly honor buffering launcher
// requests to the limit of maxConcurrency of a SauceLabs
// account, which usually results in lots of errors
grunt.registerTask("karma-ci-chain", karmaCiTaskChain);
}
return taskConfig;
})()
});
// Helper tasks
grunt.registerTask("jshint-prebuild", ["jshint:gruntfile", "jshint:karma", "jshint:js", "jshint:test"]);
grunt.registerTask("jshint-postbuild", ["jshint:dist"]);
// Default task.
grunt.registerTask("default", ["jshint-prebuild", "concat", "uglify", "jshint-postbuild", "karma:local"]);
// TravisCI task.
grunt.registerTask("travis", ["jshint-prebuild", "concat", "jshint-postbuild", "karma-ci-chain"]);
};