2012-06-05 17:10:01 +00:00
|
|
|
/**
|
|
|
|
* Resources
|
|
|
|
*
|
|
|
|
* https://gist.github.com/2489540
|
|
|
|
*
|
|
|
|
*/
|
2012-04-25 15:18:07 +00:00
|
|
|
|
2012-06-25 14:49:21 +00:00
|
|
|
/*jshint node: true */
|
2012-06-18 17:25:24 +00:00
|
|
|
/*global config:true, task:true, process:true*/
|
2012-04-18 20:07:35 +00:00
|
|
|
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 {
|
2012-06-25 14:49:21 +00:00
|
|
|
data = grunt.file.readJSON( filepath );
|
|
|
|
grunt.verbose.write( "Reading " + filepath + "..." ).ok();
|
2012-06-05 17:10:01 +00:00
|
|
|
} 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",
|
2012-06-25 14:02:28 +00:00
|
|
|
|
|
|
|
{ flag: "deprecated", src: "src/deprecated.js" },
|
2012-06-11 01:54:16 +00:00
|
|
|
{ flag: "css", src: "src/css.js" },
|
2012-06-11 16:51:28 +00:00
|
|
|
{ flag: "ajax", src: "src/ajax.js" },
|
|
|
|
{ flag: "ajax/jsonp", src: "src/ajax/jsonp.js", needs: [ "ajax", "ajax/script" ] },
|
|
|
|
{ flag: "ajax/script", src: "src/ajax/script.js", needs: ["ajax"] },
|
|
|
|
{ flag: "ajax/xhr", src: "src/ajax/xhr.js", needs: ["ajax"] },
|
2012-06-11 01:54:16 +00:00
|
|
|
{ flag: "effects", src: "src/effects.js", needs: ["css"] },
|
|
|
|
{ flag: "offset", src: "src/offset.js", needs: ["css"] },
|
|
|
|
{ flag: "dimensions", src: "src/dimensions.js", needs: ["css"] },
|
2012-06-25 14:02:28 +00:00
|
|
|
|
2012-04-18 20:07:35 +00:00
|
|
|
"src/exports.js",
|
|
|
|
"src/outro.js"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
min: {
|
|
|
|
"dist/jquery.min.js": [ "<banner>", "dist/jquery.js" ]
|
|
|
|
},
|
2012-06-25 14:49:21 +00:00
|
|
|
|
2012-04-18 20:07:35 +00:00
|
|
|
lint: {
|
2012-06-25 14:49:21 +00:00
|
|
|
dist: "dist/jquery.js",
|
|
|
|
grunt: "grunt.js",
|
|
|
|
tests: "tests/unit/**/*.js"
|
2012-04-18 20:07:35 +00:00
|
|
|
},
|
2012-06-25 14:49:21 +00:00
|
|
|
|
|
|
|
jshint: (function() {
|
|
|
|
function jshintrc( path ) {
|
|
|
|
return readOptionalJSON( (path || "") + ".jshintrc" ) || {};
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
options: jshintrc(),
|
|
|
|
dist: jshintrc( "src/" ),
|
|
|
|
tests: jshintrc( "test/" )
|
|
|
|
};
|
|
|
|
})(),
|
|
|
|
|
2012-05-09 07:34:00 +00:00
|
|
|
qunit: {
|
|
|
|
files: "test/index.html"
|
|
|
|
},
|
2012-04-18 20:07:35 +00:00
|
|
|
watch: {
|
2012-06-26 18:45:21 +00:00
|
|
|
files: [
|
2012-06-26 18:46:46 +00:00
|
|
|
"<config:lint.dist>", "<config:lint.grunt>", "<config:lint.tests>",
|
2012-06-26 18:45:21 +00:00
|
|
|
"src/**/*.js"
|
|
|
|
],
|
2012-06-05 15:50:49 +00:00
|
|
|
tasks: "dev"
|
2012-04-18 20:07:35 +00:00
|
|
|
},
|
|
|
|
uglify: {}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Default grunt.
|
2012-06-12 02:04:43 +00:00
|
|
|
grunt.registerTask( "default", "submodules selector build:*:* lint min dist:* 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" ),
|
2012-06-07 18:36:19 +00:00
|
|
|
testUrls = [],
|
|
|
|
config = grunt.file.readJSON( configFile ).jquery;
|
2012-05-07 10:06:12 +00:00
|
|
|
var tests = "ajax attributes callbacks core css data deferred dimensions effects event manipulation offset queue selector support traversing".split( " " );
|
|
|
|
tests.forEach(function( test ) {
|
2012-06-13 22:33:10 +00:00
|
|
|
testUrls.push( config.testUrl + commit + "/test/index.html?module=" + test );
|
2012-05-07 10:06:12 +00:00
|
|
|
});
|
|
|
|
testswarm({
|
2012-06-07 18:36:19 +00:00
|
|
|
url: config.swarmUrl,
|
2012-05-07 10:06:12 +00:00
|
|
|
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-06-07 18:36:19 +00:00
|
|
|
authUsername: config.authUsername,
|
|
|
|
authToken: config.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-06-11 19:36:29 +00:00
|
|
|
runMax: config.runMax,
|
2012-05-07 10:06:12 +00:00
|
|
|
"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." );
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-06-12 16:52:30 +00:00
|
|
|
// Special "alias" task to make custom build creation less grawlix-y
|
|
|
|
grunt.registerTask( "custom", function() {
|
|
|
|
var done = this.async(),
|
|
|
|
args = [].slice.call(arguments),
|
|
|
|
modules = args.length ? args[0].replace(/,/g, ":") : "";
|
|
|
|
|
|
|
|
|
|
|
|
// Translation example
|
|
|
|
//
|
2012-06-12 16:53:58 +00:00
|
|
|
// grunt custom:+ajax,-dimensions,-effects,-offset
|
2012-06-12 16:52:30 +00:00
|
|
|
//
|
|
|
|
// Becomes:
|
|
|
|
//
|
|
|
|
// grunt build:*:*:-ajax:-dimensions:-effects:-offset
|
|
|
|
|
|
|
|
grunt.log.writeln( "Creating custom build...\n" );
|
|
|
|
|
|
|
|
grunt.utils.spawn({
|
|
|
|
cmd: "grunt",
|
|
|
|
args: [ "build:*:*:" + modules ]
|
|
|
|
}, function( err, result ) {
|
|
|
|
if ( err ) {
|
|
|
|
grunt.verbose.error();
|
|
|
|
done( err );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
grunt.log.writeln( result.replace("Done, without errors.", "") );
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2012-04-18 20:07:35 +00:00
|
|
|
// Special concat/build task to handle various jQuery build requirements
|
2012-06-12 16:52:30 +00:00
|
|
|
//
|
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.
|
2012-06-11 01:54:16 +00:00
|
|
|
var i,
|
|
|
|
compiled = "",
|
|
|
|
modules = this.flags,
|
2012-06-12 16:52:30 +00:00
|
|
|
explicit = Object.keys(modules).length > 1,
|
2012-06-11 01:54:16 +00:00
|
|
|
optIn = !modules["*"],
|
|
|
|
name = this.file.dest,
|
|
|
|
excluded = {},
|
2012-06-18 17:25:24 +00:00
|
|
|
version = config( "pkg.version" ),
|
2012-06-11 01:54:16 +00:00
|
|
|
excluder = function( flag, needsFlag ) {
|
|
|
|
// explicit > implicit, so set this first and let it be overridden by explicit
|
|
|
|
if ( optIn && !modules[ flag ] && !modules[ "+" + flag ] ) {
|
|
|
|
excluded[ flag ] = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( excluded[ needsFlag ] || modules[ "-" + flag ] ) {
|
|
|
|
// explicit exclusion from flag or dependency
|
|
|
|
excluded[ flag ] = true;
|
|
|
|
} else if ( modules[ "+" + flag ] && ( excluded[ needsFlag ] === false ) ) {
|
|
|
|
// explicit inclusion from flag or dependency overriding a weak inclusion
|
|
|
|
delete excluded[ needsFlag ];
|
|
|
|
}
|
|
|
|
};
|
2012-05-29 02:25:04 +00:00
|
|
|
|
2012-06-18 17:25:24 +00:00
|
|
|
if ( process.env.COMMIT ) {
|
|
|
|
version += " " + process.env.COMMIT;
|
|
|
|
}
|
2012-06-12 16:52:30 +00:00
|
|
|
|
2012-06-11 01:54:16 +00:00
|
|
|
// figure out which files to exclude based on these rules in this order:
|
|
|
|
// explicit > implicit (explicit also means a dependency/dependent that was explicit)
|
|
|
|
// exclude > include
|
|
|
|
// examples:
|
|
|
|
// *: none (implicit exclude)
|
|
|
|
// *:* all (implicit include)
|
|
|
|
// *:*:-effects all except effects (explicit > implicit)
|
2012-06-12 16:52:30 +00:00
|
|
|
// *:*:-css all except css and its deps (explicit)
|
|
|
|
// *:*:-css:+effects all except css and its deps (explicit exclude from dep. trumps explicit include)
|
|
|
|
// *:+effects none except effects and its deps (explicit include from dep. trumps implicit exclude)
|
2012-05-29 02:25:04 +00:00
|
|
|
this.file.src.forEach(function( filepath ) {
|
|
|
|
var flag = filepath.flag;
|
2012-06-11 01:54:16 +00:00
|
|
|
|
2012-05-29 02:25:04 +00:00
|
|
|
if ( flag ) {
|
|
|
|
|
2012-06-11 01:54:16 +00:00
|
|
|
excluder(flag);
|
|
|
|
|
|
|
|
// check for dependencies
|
|
|
|
if ( filepath.needs ) {
|
|
|
|
filepath.needs.forEach(function( needsFlag ) {
|
|
|
|
excluder( flag, needsFlag );
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// conditionally concatenate source
|
|
|
|
this.file.src.forEach(function( filepath ) {
|
2012-06-12 16:52:30 +00:00
|
|
|
var flag = filepath.flag,
|
|
|
|
specified = false,
|
2012-06-21 00:39:22 +00:00
|
|
|
omit = false,
|
2012-06-12 16:52:30 +00:00
|
|
|
message = "";
|
|
|
|
|
2012-06-11 01:54:16 +00:00
|
|
|
if ( flag ) {
|
|
|
|
if ( excluded[ flag ] !== undefined ) {
|
2012-06-12 16:52:30 +00:00
|
|
|
message = ( "Excluding " + flag ).red;
|
|
|
|
specified = true;
|
2012-06-21 00:39:22 +00:00
|
|
|
omit = true;
|
2012-06-12 16:52:30 +00:00
|
|
|
} else {
|
|
|
|
message = ( "Including " + flag ).green;
|
|
|
|
|
|
|
|
// If this module was actually specified by the
|
|
|
|
// builder, then st the flag to include it in the
|
|
|
|
// output list
|
|
|
|
if ( modules[ "+" + flag ] ) {
|
|
|
|
specified = true;
|
|
|
|
}
|
2012-05-29 02:25:04 +00:00
|
|
|
}
|
2012-06-12 16:52:30 +00:00
|
|
|
|
|
|
|
// Only display the inclusion/exclusion list when handling
|
|
|
|
// an explicit list.
|
|
|
|
//
|
|
|
|
// Additionally, only display modules that have been specified
|
|
|
|
// by the user
|
|
|
|
if ( explicit && specified ) {
|
|
|
|
grunt.log.writetableln([ 27, 30 ], [
|
|
|
|
message,
|
|
|
|
( "(" + filepath.src + ")").grey
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2012-05-29 02:25:04 +00:00
|
|
|
filepath = filepath.src;
|
|
|
|
}
|
|
|
|
|
2012-06-21 00:39:22 +00:00
|
|
|
if ( !omit ) {
|
|
|
|
compiled += file.read( filepath );
|
|
|
|
}
|
2012-05-29 02:25:04 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Embed Date
|
|
|
|
// Embed Version
|
|
|
|
compiled = compiled.replace( "@DATE", new Date() )
|
2012-06-23 23:43:12 +00:00
|
|
|
.replace( /@VERSION/g, 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
|
|
|
};
|