Skip to content

Commit cc97125

Browse files
committed
Update to Grunt 0.4, and Uglify2 with Source Maps!
1 parent 92001a3 commit cc97125

File tree

2 files changed

+86
-99
lines changed

2 files changed

+86
-99
lines changed

grunt.js renamed to Gruntfile.js

+79-95
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,22 @@
1-
/**
2-
* Resources
3-
*
4-
* https://gist.github.com/2489540
5-
*/
6-
71
module.exports = function( grunt ) {
82

93
"use strict";
104

11-
// readOptionalJSON
12-
// by Ben Alman
13-
// https://gist.github.com/2876125
14-
function readOptionalJSON( filepath ) {
15-
var data = {};
16-
try {
17-
data = grunt.file.readJSON( filepath );
18-
grunt.verbose.write( "Reading " + filepath + "..." ).ok();
19-
} catch(e) {}
20-
return data;
21-
}
22-
23-
var file = grunt.file,
24-
log = grunt.log,
25-
verbose = grunt.verbose,
26-
config = grunt.config,
27-
distpaths = [
5+
var distpaths = [
286
"dist/jquery.js",
297
"dist/jquery.min.js"
30-
];
8+
],
9+
readOptionalJSON = function( filepath ) {
10+
var data = {};
11+
try {
12+
data = grunt.file.readJSON( filepath );
13+
} catch(e) {}
14+
return data;
15+
};
3116

3217
grunt.initConfig({
33-
pkg: "<json:package.json>",
18+
pkg: grunt.file.readJSON("package.json"),
3419
dst: readOptionalJSON("dist/.destination.json"),
35-
meta: {
36-
banner: "/*! jQuery v<%= pkg.version %> jquery.com | jquery.org/license */"
37-
},
3820
compare_size: {
3921
files: distpaths
4022
},
@@ -74,69 +56,54 @@ module.exports = function( grunt ) {
7456
"src/outro.js"
7557
]
7658
},
77-
min: {
78-
"dist/jquery.min.js": [ "<banner>", "dist/jquery.js" ]
79-
},
80-
81-
lint: {
82-
dist: "dist/jquery.js",
83-
grunt: "grunt.js",
84-
// TODO: Once .jshintignore is supported, use that instead.
85-
tests: ["test/data/{test,testinit,testrunner}.js", "test/unit/**/*.js"]
86-
},
8759

88-
jshint: (function() {
89-
function jshintrc( path ) {
90-
return readOptionalJSON( (path || "") + ".jshintrc" ) || {};
91-
}
92-
93-
return {
94-
grunt: {
95-
options: jshintrc()
96-
},
97-
dist: {
98-
options: jshintrc( "src/" )
99-
},
100-
tests: {
101-
options: jshintrc( "test/" )
60+
jshint: {
61+
dist: {
62+
src: [ "dist/jquery.js" ],
63+
options: {
64+
jshintrc: "src/.jshintrc"
10265
}
103-
};
104-
})(),
105-
106-
qunit: {
107-
files: "test/index.html"
66+
},
67+
grunt: {
68+
src: [ "Gruntfile.js" ],
69+
options: {
70+
jshintrc: ".jshintrc"
71+
}
72+
},
73+
tests: {
74+
// TODO: Once .jshintignore is supported, use that instead.
75+
src: [ "test/data/{test,testinit,testrunner}.js", "test/unit/**/*.js" ],
76+
options: {
77+
jshintrc: "test/.jshintrc"
78+
}
79+
}
10880
},
10981

11082
testswarm: {
11183
tests: "ajax attributes callbacks core css data deferred dimensions effects event manipulation offset queue selector serialize support traversing Sizzle".split(" ")
11284
},
11385

11486
watch: {
115-
files: [
116-
"<config:lint.grunt>", "<config:lint.tests>",
117-
"src/**/*.js"
118-
],
87+
files: [ "<%= jshint.grunt.src %>", "<%= jshint.tests.src %>", "src/**/*.js" ],
11988
tasks: "dev"
12089
},
12190

12291
uglify: {
123-
codegen: {
124-
ascii_only: true
92+
all: {
93+
files: {
94+
"dist/jquery.min.js": [ "dist/jquery.js" ]
95+
},
96+
options: {
97+
banner: "/*! jQuery v<%= pkg.version %> jquery.com | jquery.org/license */",
98+
sourceMap: "dist/jquery.source-map.js",
99+
beautify: {
100+
ascii_only: true
101+
}
102+
}
125103
}
126104
}
127105
});
128106

129-
// Default grunt.
130-
grunt.registerTask( "default", "update_submodules selector build:*:* lint min dist:* compare_size" );
131-
132-
// Short list as a high frequency watch task
133-
grunt.registerTask( "dev", "selector build:*:* lint" );
134-
135-
// Load grunt tasks from NPM packages
136-
grunt.loadNpmTasks( "grunt-compare-size" );
137-
grunt.loadNpmTasks( "grunt-git-authors" );
138-
grunt.loadNpmTasks( "grunt-update-submodules" );
139-
140107
grunt.registerTask( "testswarm", function( commit, configFile ) {
141108
var jobName,
142109
testswarm = require( "testswarm" ),
@@ -179,8 +146,8 @@ module.exports = function( grunt ) {
179146
var name = this.file.dest,
180147
files = this.file.src,
181148
sizzle = {
182-
api: file.read( files[0] ),
183-
src: file.read( files[1] )
149+
api: grunt.file.read( files[0] ),
150+
src: grunt.file.read( files[1] )
184151
},
185152
compiled, parts;
186153

@@ -218,19 +185,18 @@ module.exports = function( grunt ) {
218185
// Rejoin the pieces
219186
compiled = parts.join("");
220187

221-
222-
verbose.write("Injected sizzle-jquery.js into sizzle.js");
188+
grunt.verbose.write("Injected sizzle-jquery.js into sizzle.js");
223189

224190
// Write concatenated source to file
225-
file.write( name, compiled );
191+
grunt.file.write( name, compiled );
226192

227193
// Fail task if errors were logged.
228194
if ( this.errorCount ) {
229195
return false;
230196
}
231197

232198
// Otherwise, print a success message.
233-
log.writeln( "File '" + name + "' created." );
199+
grunt.log.writeln( "File '" + name + "' created." );
234200
});
235201

236202

@@ -251,17 +217,17 @@ module.exports = function( grunt ) {
251217

252218
grunt.log.writeln( "Creating custom build...\n" );
253219

254-
grunt.utils.spawn({
220+
grunt.util.spawn({
255221
cmd: process.platform === "win32" ? "grunt.cmd" : "grunt",
256-
args: [ "build:*:*:" + modules, "min" ]
222+
args: [ "build:*:*:" + modules, "uglify" ]
257223
}, function( err, result ) {
258224
if ( err ) {
259225
grunt.verbose.error();
260226
done( err );
261227
return;
262228
}
263229

264-
grunt.log.writeln( result.replace("Done, without errors.", "") );
230+
grunt.log.writeln( result.stdout.replace("Done, without errors.", "") );
265231

266232
done();
267233
});
@@ -279,9 +245,10 @@ module.exports = function( grunt ) {
279245
optIn = !modules["*"],
280246
explicit = optIn || Object.keys(modules).length > 1,
281247
name = this.file.dest,
248+
src = this.file.srcRaw,
282249
deps = {},
283250
excluded = {},
284-
version = config( "pkg.version" ),
251+
version = grunt.config( "pkg.version" ),
285252
excluder = function( flag, needsFlag ) {
286253
// optIn defaults implicit behavior to weak exclusion
287254
if ( optIn && !modules[ flag ] && !modules[ "+" + flag ] ) {
@@ -325,7 +292,7 @@ module.exports = function( grunt ) {
325292
// *:*:-css all except css and dependents (explicit > implicit)
326293
// *:*:-css:+effects same (excludes effects because explicit include is trumped by explicit exclude of dependency)
327294
// *:+effects none except effects and its dependencies (explicit include trumps implicit exclude of dependency)
328-
this.file.src.forEach(function( filepath ) {
295+
src.forEach(function( filepath ) {
329296
var flag = filepath.flag;
330297

331298
if ( flag ) {
@@ -351,7 +318,7 @@ module.exports = function( grunt ) {
351318

352319

353320
// conditionally concatenate source
354-
this.file.src.forEach(function( filepath ) {
321+
src.forEach(function( filepath ) {
355322
var flag = filepath.flag,
356323
specified = false,
357324
omit = false,
@@ -389,7 +356,7 @@ module.exports = function( grunt ) {
389356
}
390357

391358
if ( !omit ) {
392-
compiled += file.read( filepath );
359+
compiled += grunt.file.read( filepath );
393360
}
394361
});
395362

@@ -408,15 +375,15 @@ module.exports = function( grunt ) {
408375
});
409376

410377
// Write concatenated source to file
411-
file.write( name, compiled );
378+
grunt.file.write( name, compiled );
412379

413380
// Fail task if errors were logged.
414381
if ( this.errorCount ) {
415382
return false;
416383
}
417384

418385
// Otherwise, print a success message.
419-
log.writeln( "File '" + name + "' created." );
386+
grunt.log.writeln( "File '" + name + "' created." );
420387
});
421388

422389
// Allow custom dist file locations
@@ -425,7 +392,7 @@ module.exports = function( grunt ) {
425392

426393
// Check for stored destination paths
427394
// ( set in dist/.destination.json )
428-
stored = Object.keys( config("dst") );
395+
stored = Object.keys( grunt.config("dst") );
429396

430397
// Allow command line input as well
431398
flags = Object.keys( this.flags );
@@ -438,16 +405,17 @@ module.exports = function( grunt ) {
438405
// Ensure the dist files are pure ASCII
439406
var fs = require("fs"),
440407
nonascii = false;
408+
441409
distpaths.forEach(function( filename ) {
442410
var buf = fs.readFileSync( filename, "utf8" ),
443411
i, c;
444412
if ( buf.length !== Buffer.byteLength( buf, "utf8" ) ) {
445-
log.writeln( filename + ": Non-ASCII characters detected:" );
413+
grunt.log.writeln( filename + ": Non-ASCII characters detected:" );
446414
for ( i = 0; i < buf.length; i++ ) {
447415
c = buf.charCodeAt( i );
448416
if ( c > 127 ) {
449-
log.writeln( "- position " + i + ": " + c );
450-
log.writeln( "-- " + buf.substring( i - 20, i + 20 ) );
417+
grunt.log.writeln( "- position " + i + ": " + c );
418+
grunt.log.writeln( "-- " + buf.substring( i - 20, i + 20 ) );
451419
nonascii = true;
452420
}
453421
}
@@ -474,11 +442,27 @@ module.exports = function( grunt ) {
474442

475443
created = path + filename.replace( "dist/", "" );
476444

477-
file.write( created, file.read(filename) );
445+
grunt.file.write( created, grunt.file.read(filename) );
478446

479-
log.writeln( "File '" + created + "' created." );
447+
grunt.log.writeln( "File '" + created + "' created." );
480448
});
481449
});
482450
}
483451
});
452+
453+
// Load grunt tasks from NPM packages
454+
grunt.loadNpmTasks( "grunt-compare-size" );
455+
grunt.loadNpmTasks( "grunt-git-authors" );
456+
grunt.loadNpmTasks( "grunt-update-submodules" );
457+
458+
// grunt contrib tasks
459+
grunt.loadNpmTasks("grunt-contrib-watch");
460+
grunt.loadNpmTasks("grunt-contrib-jshint");
461+
grunt.loadNpmTasks("grunt-contrib-uglify");
462+
463+
// Default grunt
464+
grunt.registerTask( "default", [ "update_submodules", "selector", "build:*:*", "jshint", "uglify", "dist:*", "compare_size" ] );
465+
466+
// Short list as a high frequency watch task
467+
grunt.registerTask( "dev", [ "selector", "build:*:*", "jshint" ] );
484468
};

package.json

+7-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@
2323
],
2424
"dependencies": {},
2525
"devDependencies": {
26-
"grunt-compare-size": "~0.2.0",
27-
"grunt-git-authors": "=1.0.0",
28-
"grunt-update-submodules": "=0.1.2",
29-
"grunt": "~0.3.17",
26+
"grunt-compare-size": "0.3.1",
27+
"grunt-git-authors": "1.1.0-beta.1",
28+
"grunt-update-submodules": "0.2.0",
29+
"grunt-contrib-watch": "~0.1.4",
30+
"grunt-contrib-jshint": "~0.1.0",
31+
"grunt-contrib-uglify": "~0.1.0",
32+
"grunt": "~0.4.0rc4",
3033
"testswarm": "0.2.2"
3134
},
3235
"keywords": []

0 commit comments

Comments
 (0)