Skip to content
Permalink
Browse files

Update to Grunt 0.4, and Uglify2 with Source Maps!

  • Loading branch information...
mikesherov committed Dec 19, 2012
1 parent 92001a3 commit cc97125560d16fde1fad54974b10b5526f1309af
Showing with 86 additions and 99 deletions.
  1. +79 −95 grunt.js → Gruntfile.js
  2. +7 −4 package.json
@@ -1,40 +1,22 @@
/**
* Resources
*
* https://gist.github.com/2489540
*/

module.exports = function( grunt ) {

"use strict";

// readOptionalJSON
// by Ben Alman
// https://gist.github.com/2876125
function readOptionalJSON( filepath ) {
var data = {};
try {
data = grunt.file.readJSON( filepath );
grunt.verbose.write( "Reading " + filepath + "..." ).ok();
} catch(e) {}
return data;
}

var file = grunt.file,
log = grunt.log,
verbose = grunt.verbose,
config = grunt.config,
distpaths = [
var distpaths = [
"dist/jquery.js",
"dist/jquery.min.js"
];
],
readOptionalJSON = function( filepath ) {
var data = {};
try {
data = grunt.file.readJSON( filepath );
} catch(e) {}
return data;
};

grunt.initConfig({
pkg: "<json:package.json>",
pkg: grunt.file.readJSON("package.json"),
dst: readOptionalJSON("dist/.destination.json"),
meta: {
banner: "/*! jQuery v<%= pkg.version %> jquery.com | jquery.org/license */"
},
compare_size: {
files: distpaths
},
@@ -74,69 +56,54 @@ module.exports = function( grunt ) {
"src/outro.js"
]
},
min: {
"dist/jquery.min.js": [ "<banner>", "dist/jquery.js" ]
},

lint: {
dist: "dist/jquery.js",
grunt: "grunt.js",
// TODO: Once .jshintignore is supported, use that instead.
tests: ["test/data/{test,testinit,testrunner}.js", "test/unit/**/*.js"]
},

jshint: (function() {
function jshintrc( path ) {
return readOptionalJSON( (path || "") + ".jshintrc" ) || {};
}

return {
grunt: {
options: jshintrc()
},
dist: {
options: jshintrc( "src/" )
},
tests: {
options: jshintrc( "test/" )
jshint: {
dist: {
src: [ "dist/jquery.js" ],
options: {
jshintrc: "src/.jshintrc"
}
};
})(),

qunit: {
files: "test/index.html"
},
grunt: {
src: [ "Gruntfile.js" ],
options: {
jshintrc: ".jshintrc"
}
},
tests: {
// TODO: Once .jshintignore is supported, use that instead.
src: [ "test/data/{test,testinit,testrunner}.js", "test/unit/**/*.js" ],
options: {
jshintrc: "test/.jshintrc"
}
}
},

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

watch: {
files: [
"<config:lint.grunt>", "<config:lint.tests>",
"src/**/*.js"
],
files: [ "<%= jshint.grunt.src %>", "<%= jshint.tests.src %>", "src/**/*.js" ],
tasks: "dev"
},

uglify: {
codegen: {
ascii_only: true
all: {
files: {
"dist/jquery.min.js": [ "dist/jquery.js" ]
},
options: {
banner: "/*! jQuery v<%= pkg.version %> jquery.com | jquery.org/license */",
sourceMap: "dist/jquery.source-map.js",
beautify: {
ascii_only: true
}
}
}
}
});

// Default grunt.
grunt.registerTask( "default", "update_submodules selector build:*:* lint min dist:* compare_size" );

// Short list as a high frequency watch task
grunt.registerTask( "dev", "selector build:*:* lint" );

// Load grunt tasks from NPM packages
grunt.loadNpmTasks( "grunt-compare-size" );
grunt.loadNpmTasks( "grunt-git-authors" );
grunt.loadNpmTasks( "grunt-update-submodules" );

grunt.registerTask( "testswarm", function( commit, configFile ) {
var jobName,
testswarm = require( "testswarm" ),
@@ -179,8 +146,8 @@ module.exports = function( grunt ) {
var name = this.file.dest,
files = this.file.src,
sizzle = {
api: file.read( files[0] ),
src: file.read( files[1] )
api: grunt.file.read( files[0] ),
src: grunt.file.read( files[1] )
},
compiled, parts;

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


verbose.write("Injected sizzle-jquery.js into sizzle.js");
grunt.verbose.write("Injected sizzle-jquery.js into sizzle.js");

// Write concatenated source to file
file.write( name, compiled );
grunt.file.write( name, compiled );

// Fail task if errors were logged.
if ( this.errorCount ) {
return false;
}

// Otherwise, print a success message.
log.writeln( "File '" + name + "' created." );
grunt.log.writeln( "File '" + name + "' created." );
});


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

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

grunt.utils.spawn({
grunt.util.spawn({
cmd: process.platform === "win32" ? "grunt.cmd" : "grunt",
args: [ "build:*:*:" + modules, "min" ]
args: [ "build:*:*:" + modules, "uglify" ]
}, function( err, result ) {
if ( err ) {
grunt.verbose.error();
done( err );
return;
}

grunt.log.writeln( result.replace("Done, without errors.", "") );
grunt.log.writeln( result.stdout.replace("Done, without errors.", "") );

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

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


// conditionally concatenate source
this.file.src.forEach(function( filepath ) {
src.forEach(function( filepath ) {
var flag = filepath.flag,
specified = false,
omit = false,
@@ -389,7 +356,7 @@ module.exports = function( grunt ) {
}

if ( !omit ) {
compiled += file.read( filepath );
compiled += grunt.file.read( filepath );
}
});

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

// Write concatenated source to file
file.write( name, compiled );
grunt.file.write( name, compiled );

// Fail task if errors were logged.
if ( this.errorCount ) {
return false;
}

// Otherwise, print a success message.
log.writeln( "File '" + name + "' created." );
grunt.log.writeln( "File '" + name + "' created." );
});

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

// Check for stored destination paths
// ( set in dist/.destination.json )
stored = Object.keys( config("dst") );
stored = Object.keys( grunt.config("dst") );

// Allow command line input as well
flags = Object.keys( this.flags );
@@ -438,16 +405,17 @@ module.exports = function( grunt ) {
// Ensure the dist files are pure ASCII
var fs = require("fs"),
nonascii = false;

distpaths.forEach(function( filename ) {
var buf = fs.readFileSync( filename, "utf8" ),
i, c;
if ( buf.length !== Buffer.byteLength( buf, "utf8" ) ) {
log.writeln( filename + ": Non-ASCII characters detected:" );
grunt.log.writeln( filename + ": Non-ASCII characters detected:" );
for ( i = 0; i < buf.length; i++ ) {
c = buf.charCodeAt( i );
if ( c > 127 ) {
log.writeln( "- position " + i + ": " + c );
log.writeln( "-- " + buf.substring( i - 20, i + 20 ) );
grunt.log.writeln( "- position " + i + ": " + c );
grunt.log.writeln( "-- " + buf.substring( i - 20, i + 20 ) );
nonascii = true;
}
}
@@ -474,11 +442,27 @@ module.exports = function( grunt ) {

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

file.write( created, file.read(filename) );
grunt.file.write( created, grunt.file.read(filename) );

log.writeln( "File '" + created + "' created." );
grunt.log.writeln( "File '" + created + "' created." );
});
});
}
});

// Load grunt tasks from NPM packages
grunt.loadNpmTasks( "grunt-compare-size" );
grunt.loadNpmTasks( "grunt-git-authors" );
grunt.loadNpmTasks( "grunt-update-submodules" );

// grunt contrib tasks
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-contrib-jshint");
grunt.loadNpmTasks("grunt-contrib-uglify");

// Default grunt
grunt.registerTask( "default", [ "update_submodules", "selector", "build:*:*", "jshint", "uglify", "dist:*", "compare_size" ] );

// Short list as a high frequency watch task
grunt.registerTask( "dev", [ "selector", "build:*:*", "jshint" ] );
};
@@ -23,10 +23,13 @@
],
"dependencies": {},
"devDependencies": {
"grunt-compare-size": "~0.2.0",
"grunt-git-authors": "=1.0.0",
"grunt-update-submodules": "=0.1.2",
"grunt": "~0.3.17",
"grunt-compare-size": "0.3.1",
"grunt-git-authors": "1.1.0-beta.1",
"grunt-update-submodules": "0.2.0",
"grunt-contrib-watch": "~0.1.4",
"grunt-contrib-jshint": "~0.1.0",
"grunt-contrib-uglify": "~0.1.0",
"grunt": "~0.4.0rc4",
"testswarm": "0.2.2"
},
"keywords": []

0 comments on commit cc97125

Please sign in to comment.
You can’t perform that action at this time.