2012-06-05 17:10:01 +00:00
|
|
|
/**
|
|
|
|
* Resources
|
|
|
|
*
|
|
|
|
* https://gist.github.com/2489540
|
|
|
|
*
|
|
|
|
*/
|
2012-04-25 15:18:07 +00:00
|
|
|
|
2012-04-18 20:07:35 +00:00
|
|
|
/*global config:true, task:true*/
|
|
|
|
module.exports = function( grunt ) {
|
|
|
|
|
2012-06-05 17:10:01 +00:00
|
|
|
// readOptionalJSON
|
|
|
|
// by Ben Alman
|
|
|
|
// https://gist.github.com/2876125
|
|
|
|
function readOptionalJSON( filepath ) {
|
|
|
|
var data = {};
|
|
|
|
try {
|
|
|
|
data = grunt.file.readJSON(filepath);
|
|
|
|
grunt.log.write( "Reading data from " + filepath + "..." ).ok();
|
|
|
|
} catch(e) {}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2012-04-18 20:07:35 +00:00
|
|
|
var task = grunt.task;
|
|
|
|
var file = grunt.file;
|
|
|
|
var utils = grunt.utils;
|
|
|
|
var log = grunt.log;
|
|
|
|
var verbose = grunt.verbose;
|
|
|
|
var fail = grunt.fail;
|
|
|
|
var option = grunt.option;
|
|
|
|
var config = grunt.config;
|
|
|
|
var template = grunt.template;
|
2012-06-04 16:48:18 +00:00
|
|
|
var distpaths = [
|
|
|
|
"dist/jquery.js",
|
|
|
|
"dist/jquery.min.js"
|
|
|
|
];
|
2012-04-18 20:07:35 +00:00
|
|
|
|
|
|
|
grunt.initConfig({
|
|
|
|
pkg: "<json:package.json>",
|
2012-06-05 17:10:01 +00:00
|
|
|
dst: readOptionalJSON("dist/.destination.json"),
|
2012-04-18 20:07:35 +00:00
|
|
|
meta: {
|
|
|
|
banner: "/*! jQuery v@<%= pkg.version %> jquery.com | jquery.org/license */"
|
|
|
|
},
|
|
|
|
compare_size: {
|
2012-06-04 16:48:18 +00:00
|
|
|
files: distpaths
|
2012-04-18 20:07:35 +00:00
|
|
|
},
|
|
|
|
selector: {
|
|
|
|
"src/selector.js": [
|
|
|
|
"src/sizzle-jquery.js",
|
|
|
|
"src/sizzle/sizzle.js"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
build: {
|
|
|
|
"dist/jquery.js": [
|
|
|
|
"src/intro.js",
|
|
|
|
"src/core.js",
|
|
|
|
"src/callbacks.js",
|
|
|
|
"src/deferred.js",
|
|
|
|
"src/support.js",
|
|
|
|
"src/data.js",
|
|
|
|
"src/queue.js",
|
|
|
|
"src/attributes.js",
|
|
|
|
"src/event.js",
|
|
|
|
"src/selector.js",
|
|
|
|
"src/traversing.js",
|
|
|
|
"src/manipulation.js",
|
|
|
|
"src/css.js",
|
|
|
|
"src/ajax.js",
|
|
|
|
"src/ajax/jsonp.js",
|
|
|
|
"src/ajax/script.js",
|
|
|
|
"src/ajax/xhr.js",
|
2012-05-29 02:25:04 +00:00
|
|
|
{ flag: "effects", src: "src/effects.js" },
|
2012-04-18 20:07:35 +00:00
|
|
|
"src/offset.js",
|
|
|
|
"src/dimensions.js",
|
|
|
|
"src/exports.js",
|
|
|
|
"src/outro.js"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
min: {
|
|
|
|
"dist/jquery.min.js": [ "<banner>", "dist/jquery.js" ]
|
|
|
|
},
|
|
|
|
lint: {
|
|
|
|
files: [ "grunt.js", "dist/jquery.js" ]
|
|
|
|
},
|
2012-05-09 07:34:00 +00:00
|
|
|
qunit: {
|
|
|
|
files: "test/index.html"
|
|
|
|
},
|
2012-04-18 20:07:35 +00:00
|
|
|
watch: {
|
2012-06-04 16:48:18 +00:00
|
|
|
files: [ "<config:lint.files>", "src/**/*.js" ],
|
2012-06-05 15:50:49 +00:00
|
|
|
tasks: "dev"
|
2012-04-18 20:07:35 +00:00
|
|
|
},
|
|
|
|
jshint: {
|
|
|
|
options: {
|
|
|
|
evil: true,
|
|
|
|
browser: true,
|
|
|
|
wsh: true,
|
|
|
|
eqnull: true,
|
|
|
|
expr: true,
|
|
|
|
curly: true,
|
|
|
|
trailing: true,
|
|
|
|
undef: true,
|
|
|
|
smarttabs: true,
|
|
|
|
predef: [
|
|
|
|
"define",
|
|
|
|
"DOMParser",
|
|
|
|
"__dirname"
|
|
|
|
],
|
|
|
|
maxerr: 100
|
|
|
|
},
|
|
|
|
globals: {
|
|
|
|
jQuery: true,
|
|
|
|
global: true,
|
|
|
|
module: true,
|
|
|
|
exports: true,
|
|
|
|
require: true,
|
|
|
|
file: true,
|
|
|
|
log: true,
|
|
|
|
console: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
uglify: {}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Default grunt.
|
2012-06-04 16:48:18 +00:00
|
|
|
grunt.registerTask( "default", "submodules selector build:*:* dist:* lint min compare_size" );
|
2012-04-18 20:07:35 +00:00
|
|
|
|
2012-06-05 15:50:49 +00:00
|
|
|
// Short list as a high frequency watch task
|
|
|
|
grunt.registerTask( "dev", "selector build:*:* lint" );
|
|
|
|
|
|
|
|
// Load the "compare_size" task from NPM packages
|
2012-04-22 21:49:16 +00:00
|
|
|
grunt.loadNpmTasks("grunt-compare-size");
|
2012-04-18 20:07:35 +00:00
|
|
|
|
2012-05-07 10:06:12 +00:00
|
|
|
grunt.registerTask( "testswarm", function( commit, configFile ) {
|
|
|
|
var testswarm = require( "testswarm" ),
|
|
|
|
testUrls = [];
|
|
|
|
var tests = "ajax attributes callbacks core css data deferred dimensions effects event manipulation offset queue selector support traversing".split( " " );
|
|
|
|
tests.forEach(function( test ) {
|
|
|
|
testUrls.push( "http://swarm.jquery.org/git/jquery/" + commit + "/test/index.html?filter=" + test );
|
|
|
|
});
|
|
|
|
testswarm({
|
|
|
|
url: "http://swarm.jquery.org/",
|
|
|
|
pollInterval: 10000,
|
2012-05-18 12:47:04 +00:00
|
|
|
timeout: 1000 * 60 * 30,
|
2012-05-07 10:06:12 +00:00
|
|
|
done: this.async()
|
|
|
|
}, {
|
2012-05-07 10:13:08 +00:00
|
|
|
authUsername: "jquery",
|
2012-05-07 10:06:12 +00:00
|
|
|
authToken: grunt.file.readJSON( configFile ).jquery.authToken,
|
2012-05-07 17:43:43 +00:00
|
|
|
jobName: 'jQuery commit #<a href="https://github.com/jquery/jquery/commit/' + commit + '">' + commit.substr( 0, 10 ) + '</a>',
|
2012-05-07 10:06:12 +00:00
|
|
|
runMax: 4,
|
|
|
|
"runNames[]": tests,
|
|
|
|
"runUrls[]": testUrls,
|
|
|
|
"browserSets[]": ["popular"]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2012-04-18 20:07:35 +00:00
|
|
|
// Build src/selector.js
|
|
|
|
grunt.registerMultiTask( "selector", "Build src/selector.js", function() {
|
|
|
|
|
|
|
|
var name = this.file.dest,
|
|
|
|
files = this.file.src,
|
|
|
|
sizzle = {
|
|
|
|
api: file.read( files[0] ),
|
|
|
|
src: file.read( files[1] )
|
|
|
|
},
|
|
|
|
compiled;
|
|
|
|
|
|
|
|
// sizzle-jquery.js -> sizzle after "EXPOSE", replace window.Sizzle
|
|
|
|
compiled = sizzle.src.replace( "window.Sizzle = Sizzle;", sizzle.api );
|
|
|
|
verbose.write("Injected sizzle-jquery.js into sizzle.js");
|
|
|
|
|
|
|
|
// Write concatenated source to file
|
|
|
|
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." );
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Special concat/build task to handle various jQuery build requirements
|
2012-05-29 02:25:04 +00:00
|
|
|
grunt.registerMultiTask(
|
|
|
|
"build",
|
|
|
|
"Concatenate source (include/exclude modules with +/- flags), embed date/version",
|
|
|
|
function() {
|
|
|
|
// Concat specified files.
|
|
|
|
var compiled = "",
|
|
|
|
modules = this.flags,
|
|
|
|
optIn = !modules["*"],
|
|
|
|
name = this.file.dest;
|
|
|
|
|
|
|
|
this.file.src.forEach(function( filepath ) {
|
|
|
|
// Include optional modules per build flags; exclusion trumps inclusion
|
|
|
|
var flag = filepath.flag;
|
|
|
|
if ( flag ) {
|
|
|
|
if ( modules[ "-" + flag ] ||
|
|
|
|
optIn && !modules[ flag ] && !modules[ "+" + flag ] ) {
|
|
|
|
|
|
|
|
log.writeln( "Excluding " + filepath.flag + ": '" + filepath.src + "'." );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
log.writeln( "Including " + filepath.flag + ": '" + filepath.src + "'." );
|
|
|
|
filepath = filepath.src;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unwrap redundant IIFEs
|
2012-06-04 16:48:18 +00:00
|
|
|
compiled += file.read( filepath );
|
|
|
|
//.replace( /^\(function\( jQuery \) \{|\}\)\( jQuery \);\s*$/g, "" );
|
2012-05-29 02:25:04 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Embed Date
|
|
|
|
// Embed Version
|
|
|
|
compiled = compiled.replace( "@DATE", new Date() )
|
2012-06-04 16:48:18 +00:00
|
|
|
.replace( "@VERSION", config("pkg.version") );
|
2012-05-29 02:25:04 +00:00
|
|
|
|
|
|
|
// Write concatenated source to file
|
|
|
|
file.write( name, compiled );
|
|
|
|
|
|
|
|
// Fail task if errors were logged.
|
|
|
|
if ( this.errorCount ) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-04-18 20:07:35 +00:00
|
|
|
|
2012-05-29 02:25:04 +00:00
|
|
|
// Otherwise, print a success message.
|
|
|
|
log.writeln( "File '" + name + "' created." );
|
2012-04-18 20:07:35 +00:00
|
|
|
});
|
2012-06-04 16:48:18 +00:00
|
|
|
|
|
|
|
grunt.registerTask( "submodules", function() {
|
|
|
|
var done = this.async();
|
|
|
|
|
|
|
|
grunt.verbose.write( "Updating submodules..." );
|
|
|
|
|
|
|
|
// TODO: migrate remaining `make` to grunt tasks
|
|
|
|
//
|
|
|
|
grunt.utils.spawn({
|
|
|
|
cmd: "make"
|
|
|
|
}, function( err, result ) {
|
|
|
|
if ( err ) {
|
|
|
|
grunt.verbose.error();
|
|
|
|
done( err );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
grunt.log.writeln( result );
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Allow custom dist file locations
|
|
|
|
grunt.registerTask( "dist", function() {
|
2012-06-05 17:10:01 +00:00
|
|
|
var flags, paths, stored;
|
2012-06-04 16:48:18 +00:00
|
|
|
|
2012-06-05 17:10:01 +00:00
|
|
|
// Check for stored destination paths
|
|
|
|
// ( set in dist/.destination.json )
|
|
|
|
stored = Object.keys( config("dst") );
|
2012-06-04 16:48:18 +00:00
|
|
|
|
2012-06-05 17:10:01 +00:00
|
|
|
// Allow command line input as well
|
|
|
|
flags = Object.keys( this.flags );
|
2012-06-05 16:16:48 +00:00
|
|
|
|
2012-06-05 17:10:01 +00:00
|
|
|
// Combine all output target paths
|
|
|
|
paths = [].concat( stored, flags ).filter(function( path ) {
|
|
|
|
return path !== "*";
|
|
|
|
});
|
2012-06-05 16:16:48 +00:00
|
|
|
|
2012-06-04 16:48:18 +00:00
|
|
|
|
2012-06-05 17:10:01 +00:00
|
|
|
// Proceed only if there are actual
|
|
|
|
// paths to write to
|
|
|
|
if ( paths.length ) {
|
2012-06-04 16:48:18 +00:00
|
|
|
|
|
|
|
// 'distpaths' is declared at the top of the
|
2012-06-05 17:10:01 +00:00
|
|
|
// module.exports function scope. It is an array
|
|
|
|
// of default files that jQuery creates
|
2012-06-04 16:48:18 +00:00
|
|
|
distpaths.forEach(function( filename ) {
|
2012-06-05 17:10:01 +00:00
|
|
|
paths.forEach(function( path ) {
|
|
|
|
var created;
|
|
|
|
|
|
|
|
if ( !/\/$/.test( path ) ) {
|
|
|
|
path += "/";
|
|
|
|
}
|
|
|
|
|
|
|
|
created = path + filename.replace( "dist/", "" );
|
|
|
|
|
|
|
|
if ( !/^\//.test( path ) ) {
|
|
|
|
log.error( "File '" + created + "' was NOT created." );
|
|
|
|
return;
|
|
|
|
}
|
2012-06-04 16:48:18 +00:00
|
|
|
|
2012-06-05 17:10:01 +00:00
|
|
|
file.write( created, file.read(filename) );
|
2012-06-04 16:48:18 +00:00
|
|
|
|
2012-06-05 17:10:01 +00:00
|
|
|
log.writeln( "File '" + created + "' created." );
|
|
|
|
});
|
2012-06-04 16:48:18 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2012-04-18 20:07:35 +00:00
|
|
|
};
|