forked from jquery/jquery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
250 lines (224 loc) · 5.89 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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
module.exports = function( grunt ) {
"use strict";
function readOptionalJSON( filepath ) {
var stripJSONComments = require( "strip-json-comments" ),
data = {};
try {
data = JSON.parse( stripJSONComments(
fs.readFileSync( filepath, { encoding: "utf8" } )
) );
} catch ( e ) {}
return data;
}
var fs = require( "fs" ),
gzip = require( "gzip-js" ),
oldNode = /^v0\./.test( process.version );
// Support: Node.js <4
// Skip running tasks that dropped support for Node.js 0.12
// in this Node version.
function runIfNewNode( task ) {
return oldNode ? "print_old_node_message:" + task : task;
}
if ( !grunt.option( "filename" ) ) {
grunt.option( "filename", "jquery.js" );
}
grunt.initConfig( {
pkg: grunt.file.readJSON( "package.json" ),
dst: readOptionalJSON( "dist/.destination.json" ),
"compare_size": {
files: [ "dist/jquery.js", "dist/jquery.min.js" ],
options: {
compress: {
gz: function( contents ) {
return gzip.zip( contents, {} ).length;
}
},
cache: "build/.sizecache.json"
}
},
babel: {
options: {
sourceMap: "inline",
retainLines: true
},
nodeSmokeTests: {
files: {
"test/node_smoke_tests/lib/ensure_iterability.js":
"test/node_smoke_tests/lib/ensure_iterability_es6.js"
}
}
},
build: {
all: {
dest: "dist/jquery.js",
minimum: [
"core",
"selector"
],
// Exclude specified modules if the module matching the key is removed
removeWith: {
ajax: [ "manipulation/_evalUrl", "event/ajax" ],
callbacks: [ "deferred" ],
css: [ "effects", "dimensions", "offset" ],
"css/showHide": [ "effects" ],
deferred: {
remove: [ "ajax", "effects", "queue", "core/ready" ],
include: [ "core/ready-no-deferred" ]
},
sizzle: [ "css/hiddenVisibleSelectors", "effects/animatedSelector" ]
}
}
},
npmcopy: {
all: {
options: {
destPrefix: "external"
},
files: {
"sizzle/dist": "sizzle/dist",
"sizzle/LICENSE.txt": "sizzle/LICENSE.txt",
"npo/npo.js": "native-promise-only/npo.js",
"qunit/qunit.js": "qunitjs/qunit/qunit.js",
"qunit/qunit.css": "qunitjs/qunit/qunit.css",
"qunit/LICENSE.txt": "qunitjs/LICENSE.txt",
"qunit-assert-step/qunit-assert-step.js":
"qunit-assert-step/qunit-assert-step.js",
"qunit-assert-step/MIT-LICENSE.txt":
"qunit-assert-step/MIT-LICENSE.txt",
"requirejs/require.js": "requirejs/require.js",
"sinon/sinon.js": "sinon/pkg/sinon.js",
"sinon/LICENSE.txt": "sinon/LICENSE"
}
}
},
jsonlint: {
pkg: {
src: [ "package.json" ]
}
},
eslint: {
options: {
// See https://github.com/sindresorhus/grunt-eslint/issues/119
quiet: true
},
// We have to explicitly declare "src" property otherwise "newer"
// task wouldn't work properly :/
dist: {
src: "dist/jquery.js"
},
dev: {
src: [ "src/**/*.js", "Gruntfile.js", "test/**/*.js", "build/**/*.js" ]
}
},
testswarm: {
tests: [
// A special module with basic tests, meant for
// not fully supported environments like Android 2.3,
// jsdom or PhantomJS. We run it everywhere, though,
// to make sure tests are not broken.
"basic",
"ajax",
"animation",
"attributes",
"callbacks",
"core",
"css",
"data",
"deferred",
"deprecated",
"dimensions",
"effects",
"event",
"manipulation",
"offset",
"queue",
"selector",
"serialize",
"support",
"traversing",
"tween"
]
},
watch: {
files: [ "<%= eslint.dev.src %>" ],
tasks: [ "dev" ]
},
uglify: {
all: {
files: {
"dist/<%= grunt.option('filename').replace('.js', '.min.js') %>":
"dist/<%= grunt.option('filename') %>"
},
options: {
preserveComments: false,
sourceMap: true,
ASCIIOnly: true,
sourceMapName:
"dist/<%= grunt.option('filename').replace('.js', '.min.map') %>",
report: "min",
beautify: {
"ascii_only": true
},
banner: "/*! jQuery v<%= pkg.version %> | " +
"(c) JS Foundation and other contributors | jquery.org/license */",
compress: {
"hoist_funs": false,
loops: false,
unused: false
}
}
}
}
} );
// Load grunt tasks from NPM packages
// Support: Node.js <4
// Don't load the eslint task in old Node.js, it won't parse.
require( "load-grunt-tasks" )( grunt, {
pattern: oldNode ? [ "grunt-*", "!grunt-eslint" ] : [ "grunt-*" ]
} );
// Integrate jQuery specific tasks
grunt.loadTasks( "build/tasks" );
grunt.registerTask( "print_old_node_message", function() {
var task = [].slice.call( arguments ).join( ":" );
grunt.log.writeln( "Old Node.js detected, running the task \"" + task + "\" skipped..." );
} );
grunt.registerTask( "lint", [
"jsonlint",
// Running the full eslint task without breaking it down to targets
// would run the dist target first which would point to errors in the built
// file, making it harder to fix them. We want to check the built file only
// if we already know the source files pass the linter.
runIfNewNode( "eslint:dev" ),
runIfNewNode( "eslint:dist" )
] );
grunt.registerTask( "lint:newer", [
"newer:jsonlint",
// Don't replace it with just the task; see the above comment.
runIfNewNode( "newer:eslint:dev" ),
runIfNewNode( "newer:eslint:dist" )
] );
grunt.registerTask( "test:fast", runIfNewNode( "node_smoke_tests" ) );
grunt.registerTask( "test:slow", runIfNewNode( "promises_aplus_tests" ) );
grunt.registerTask( "test", [
"test:fast",
"test:slow"
] );
grunt.registerTask( "dev", [
"build:*:*",
runIfNewNode( "newer:eslint:dev" ),
"newer:uglify",
"remove_map_comment",
"dist:*",
"compare_size"
] );
grunt.registerTask( "default", [
runIfNewNode( "eslint:dev" ),
"build:*:*",
"uglify",
"remove_map_comment",
"dist:*",
runIfNewNode( "eslint:dist" ),
"test:fast",
"compare_size"
] );
};