forked from jquery/jquery-color
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grunt.js
203 lines (169 loc) · 4.62 KB
/
grunt.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
/*jshint node: true */
module.exports = function( grunt ) {
"use strict";
var max = [ "dist/jquery.color.js", "dist/jquery.color.svg-names.js" ],
min = [ "dist/jquery.color.min.js", "dist/jquery.color.svg-names.min.js", "dist/jquery.color.plus-names.min.js"],
combined = "dist/jquery.color.plus-names.js",
minify = {},
concat = {};
minify[ min[0] ] = [ "<banner>", max[0] ];
minify[ min[1] ] = [ "<banner:meta.bannerSvg>", max[1] ];
minify[ min[2] ] = [ "<banner:meta.bannerCombined>", combined ];
concat[ combined ] = [ max[0], max[1] ];
grunt.loadNpmTasks( "grunt-compare-size" );
grunt.loadNpmTasks( "grunt-git-authors" );
grunt.initConfig({
pkg: "<json:package.json>",
meta: {
banner: "/*! jQuery Color v@<%= pkg.version %> http://github.com/jquery/jquery-color | jquery.org/license */",
bannerSvg: "/*! jQuery Color v@<%= pkg.version %> SVG Color Names http://github.com/jquery/jquery-color | jquery.org/license */",
bannerCombined: "/*! jQuery Color v@<%= pkg.version %> with SVG Color Names http://github.com/jquery/jquery-color | jquery.org/license */"
},
lint: {
src: [ "jquery.color.js", "jquery.color.svg-names.js" ],
grunt: "grunt.js",
test: "test/unit/**"
},
jshint: (function() {
function parserc( path ) {
var rc = grunt.file.readJSON( (path || "") + ".jshintrc" ),
settings = {
options: rc,
globals: rc.globals || {}
};
(rc.predef || []).forEach(function( prop ) {
settings.globals[ prop ] = true;
});
delete rc.predef;
return settings;
}
return {
src: parserc(),
grunt: parserc(),
test: parserc( "test/unit/" )
};
}()),
qunit: {
files: "test/index.html"
},
concat: concat,
min: minify,
watch: {
files: [ "<config:lint.src>", "<config:lint.test>", "<config:lint.grunt>" ],
tasks: "default"
},
compare_size: {
"color": [ max[0], min[0] ],
"svg-names": [ max[1], min[1] ],
"combined": [ combined, min[2] ]
}
});
grunt.registerHelper( "git-date", function( fn ) {
grunt.utils.spawn({
cmd: "git",
args: [ "log", "-1", "--pretty=format:%ad" ]
}, function( error, result ) {
if ( error ) {
grunt.log.error( error );
return fn( error );
}
fn( null, result );
});
});
grunt.registerTask( "submodules", function() {
var done = this.async();
grunt.verbose.write( "Updating submodules..." );
grunt.utils.spawn({
cmd: "git",
args: [ "submodule", "update", "--init" ]
}, function( err, result ) {
if ( err ) {
grunt.verbose.error();
done( err );
return;
}
grunt.log.writeln( result );
done();
});
});
grunt.registerTask( "max", function() {
var done = this.async(),
version = grunt.config( "pkg.version" );
if ( process.env.COMMIT ) {
version += " " + process.env.COMMIT;
}
grunt.helper( "git-date", function( error, date ) {
if ( error ) {
return done( false );
}
max.forEach( function( dist ) {
grunt.file.copy( dist.replace( "dist/", "" ), dist, {
process: function( source ) {
return source
.replace( /@VERSION/g, version )
.replace( /@DATE/g, date );
}
});
});
done();
});
});
grunt.registerTask( "testswarm", function( commit, configFile ) {
var testswarm = require( "testswarm" ),
config = grunt.file.readJSON( configFile ).jquerycolor,
done = this.async();
testswarm.createClient( {
url: config.swarmUrl,
pollInterval: 10000,
timeout: 1000 * 60 * 30
} )
.addReporter( testswarm.reporters.cli )
.auth( {
id: config.authUsername,
token: config.authToken
})
.addjob(
{
name: "Commit <a href='https://github.com/jquery/jquery-color/commit/" + commit + "'>" + commit.substr( 0, 10 ) + "</a>",
runs: {
"jQuery color": config.testUrl + commit + "/test/index.html"
},
runMax: config.runMax,
browserSets: ["popular"]
}, function( err, passed ) {
if ( err ) {
grunt.log.error( err );
}
done( passed );
}
);
});
grunt.registerTask( "manifest", function() {
var pkg = grunt.config( "pkg" );
grunt.file.write( "color.jquery.json", JSON.stringify({
name: "color",
title: pkg.title,
description: pkg.description,
keywords: pkg.keywords,
version: pkg.version,
author: {
name: pkg.author.name,
url: pkg.author.url.replace( "master", pkg.version )
},
maintainers: pkg.maintainers,
licenses: pkg.licenses.map(function( license ) {
license.url = license.url.replace( "master", pkg.version );
return license;
}),
bugs: pkg.bugs,
homepage: pkg.homepage,
docs: pkg.homepage,
download: "http://code.jquery.com/#color",
dependencies: {
jquery: ">=1.5"
}
}, null, "\t" ) );
});
grunt.registerTask( "default", "lint submodules qunit build compare_size" );
grunt.registerTask( "build", "max concat min" );
};