forked from Modernizr/Modernizr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
220 lines (209 loc) · 6.51 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
/*jshint node: true */
/*global module */
module.exports = function( grunt ) {
'use strict';
var modConfig = grunt.file.readJSON('lib/config-all.json');
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' +
' * Modernizr has an optional (*not included*) conditional resource loader called\n' +
' * `Modernizr.load()`, based on [Yepnope.js](http://yepnopejs.com). You can get a\n' +
' * build that includes `Modernizr.load()`, as well as choosing which feature tests\n' +
' * to include on the [Download page](http://www.modernizr.com/download/).\n' +
' */'
},
meta: {
},
qunit: {
files: ['test/index.html']
},
stripdefine: {
build: [
'dist/modernizr-build.js'
]
},
generateinit : {
build: {
src: ['tmp/modernizr-init.js']
}
},
uglify : {
options: {
stripbanners: true,
banner: '<%= banner.compact %>',
mangle: {
except: ['Modernizr']
}
},
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: {
boss: true,
browser: true,
curly: false,
devel: true,
eqeqeq: false,
eqnull: true,
expr: true,
evil: true,
immed: false,
laxcomma: true,
newcap: false,
noarg: true,
smarttabs: true,
sub: true,
undef: true,
globals: {
Modernizr: true,
DocumentTouch: true,
TEST: true,
SVGFEColorMatrixElement : true,
Blob: true,
define: true,
require: true
}
},
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: {
build: ['build', 'dist', 'tmp'],
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",
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;
}
}
}
}
});
// Load required contrib packages
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-requirejs');
// Strip define fn
grunt.registerMultiTask('stripdefine', "Strip define call from dist file", function() {
this.filesSrc.forEach(function(filepath) {
var mod = grunt.file.read(filepath).replace('define("modernizr-init", function(){});', '');
// Hack the prefix into place. Anything is way to big for something so small.
if ( modConfig && modConfig.classPrefix ) {
mod = mod.replace("classPrefix : '',", "classPrefix : '" + modConfig.classPrefix.replace(/"/g, '\\"') + "',");
}
grunt.file.write( 'dist/modernizr-build.js', 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', 'qunit']);
// Travis CI task.
grunt.registerTask('travis', 'test');
// Build
grunt.registerTask('build', ['clean', 'generateinit', 'requirejs', 'copy', 'clean:postbuild', 'stripdefine', 'uglify', 'jshint']);
grunt.registerTask('default', 'build');
};