forked from Modernizr/Modernizr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
242 lines (228 loc) · 6.36 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
/*jshint node: true */
/*global module */
module.exports = function( grunt ) {
'use strict';
var modConfig = grunt.file.readJSON('lib/config-all.json');
var browsers = grunt.file.readJSON('lib/sauce-browsers.json');
// Load grunt dependencies
require('load-grunt-tasks')(grunt);
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
banner: {
compact: '/*! <%= pkg.name %> <%= pkg.version %> (Custom Build) | <%= pkg.license %> */',
full: '/*!\n' +
' * <%= pkg.name %> v<%= pkg.version %>\n' +
' * modernizr.com\n *\n' +
' * Copyright (c) <%= _.pluck(pkg.contributors, "name").join(", ") %>\n' +
' * <%= pkg.license %> License\n */' +
' \n' +
'/*\n' +
' * Modernizr tests which native CSS3 and HTML5 features are available in the\n' +
' * current UA and makes the results available to you in two ways: as properties on\n' +
' * a global `Modernizr` object, and as classes on the `<html>` element. This\n' +
' * information allows you to progressively enhance your pages with a granular level\n' +
' * of control over the experience.\n' +
' *\n' +
' */'
},
meta: {
},
qunit: {
files: ['test/index.html']
},
nodeunit: {
files: ['test/api/*.js']
},
stripdefine: {
build: ['dist/modernizr-build.js']
},
generateinit: {
build: {
src: ['tmp/modernizr-init.js']
}
},
uglify: {
options: {
stripbanners: true,
banner: '<%= banner.compact %>',
mangle: {
except: ['Modernizr']
},
beautify: {
ascii_only: true
}
},
dist: {
src: ['dist/modernizr-build.js'],
dest: 'dist/modernizr-build.min.js'
}
},
watch: {
files: '<%= jshint.files %>',
tasks: 'jshint',
tests: {
files: '<%= jshint.tests.files.src %>',
tasks: [
'jshint:tests',
'qunit'
]
}
},
jshint: {
options: {
jshintrc: true,
ignores: [
'src/html5printshiv.js',
'src/html5shiv.js'
]
},
files: [
'Gruntfile.js',
'src/*.js',
'feature-detects/**/*.js'
],
tests: {
options: {
jquery: true,
globals: {
Modernizr: true,
TEST: true,
QUnit: true
}
},
files: {
src: ['test/js/*.js']
}
},
lib: {
options: {
node: true
},
files: {
src: ['lib/*.js']
}
}
},
clean: {
dist: ['dist'],
postbuild: [
'build',
'tmp'
]
},
copy: {
build: {
files: {
'dist/modernizr-build.js': 'build/src/modernizr-build.js'
}
}
},
requirejs: {
compile: {
options: {
dir: 'build',
appDir: '.',
baseUrl: 'src',
optimize: 'none',
optimizeCss: 'none',
useStrict: true,
paths: {
'test': '../feature-detects',
'modernizr-init': '../tmp/modernizr-init'
},
modules: [{
'name': 'modernizr-build',
'include': ['modernizr-init'],
'create': true
}],
fileExclusionRegExp: /^(.git|node_modules|modulizr|media|test)$/,
wrap: {
start: '<%= banner.full %>' + '\n;(function(window, document, undefined){',
end: '})(this, document);'
},
onBuildWrite: function (id, path, contents) {
if ((/define\(.*?\{/).test(contents)) {
//Remove AMD ceremony for use without require.js or almond.js
contents = contents.replace(/define\(.*?\{/, '');
contents = contents.replace(/\}\);\s*?$/,'');
if ( !contents.match(/Modernizr\.addTest\(/) && !contents.match(/Modernizr\.addAsyncTest\(/) ) {
//remove last return statement and trailing })
contents = contents.replace(/return.*[^return]*$/,'');
}
}
else if ((/require\([^\{]*?\{/).test(contents)) {
contents = contents.replace(/require[^\{]+\{/, '');
contents = contents.replace(/\}\);\s*$/,'');
}
return contents;
}
}
}
},
connect: {
server: {
options: {
base: '',
port: 9999
}
}
},
'saucelabs-qunit': {
all: {
options: {
urls: ['http://127.0.0.1:9999/test/basic.html'],
tunnelTimeout: 5,
build: process.env.TRAVIS_JOB_ID,
concurrency: 2,
browsers: browsers,
testname: 'qunit tests',
tags: [
'master',
'<%= pkg.version %>'
]
}
}
}
});
// Strip define fn
grunt.registerMultiTask('stripdefine', 'Strip define call from dist file', function() {
this.filesSrc.forEach(function(filepath) {
// Remove `define('modernizr-init' ...)` and `define('modernizr-build' ...)`
var mod = grunt.file.read(filepath).replace(/define\("modernizr-(init|build)", function\(\)\{\}\);/g, '');
// Hack the prefix into place. Anything is way too big for something so small.
if ( modConfig && modConfig.classPrefix ) {
mod = mod.replace('classPrefix : \'\',', 'classPrefix : \'' + modConfig.classPrefix.replace(/"/g, '\\"') + '\',');
}
grunt.file.write(filepath, mod);
});
});
grunt.registerMultiTask('generateinit', 'Generate Init file', function() {
var requirejs = require('requirejs');
requirejs.config({
appDir: __dirname + '/src/',
baseUrl: __dirname + '/src/'
});
var generateInit = requirejs('generate');
grunt.file.write('tmp/modernizr-init.js', generateInit(modConfig));
});
// Testing tasks
grunt.registerTask('test', ['jshint', 'build', 'qunit', 'nodeunit']);
// Sauce labs CI task
grunt.registerTask('sauce', ['connect','saucelabs-qunit']);
// Travis CI task.
grunt.registerTask('travis', ['test']);
// Build
grunt.registerTask('build', [
'clean',
'generateinit',
'requirejs',
'copy',
'clean:postbuild',
'stripdefine',
'uglify'
]);
grunt.registerTask('default', [
'jshint',
'build'
]);
};