2012-04-18 20:07:35 +00:00
|
|
|
module.exports = function( grunt ) {
|
|
|
|
|
2012-10-16 14:10:17 +00:00
|
|
|
"use strict";
|
|
|
|
|
2012-12-19 04:02:50 +00:00
|
|
|
var distpaths = [
|
2012-10-16 16:21:17 +00:00
|
|
|
"dist/jquery.js",
|
2012-12-23 19:45:49 +00:00
|
|
|
"dist/jquery.min.map",
|
|
|
|
"dist/jquery.min.js"
|
2012-12-19 04:02:50 +00:00
|
|
|
],
|
2013-03-25 04:47:46 +00:00
|
|
|
gzip = require("gzip-js"),
|
2012-12-19 04:02:50 +00:00
|
|
|
readOptionalJSON = function( filepath ) {
|
|
|
|
var data = {};
|
|
|
|
try {
|
|
|
|
data = grunt.file.readJSON( filepath );
|
|
|
|
} catch(e) {}
|
|
|
|
return data;
|
|
|
|
};
|
2012-04-18 20:07:35 +00:00
|
|
|
|
|
|
|
grunt.initConfig({
|
2012-12-19 04:02:50 +00:00
|
|
|
pkg: grunt.file.readJSON("package.json"),
|
2012-06-05 17:10:01 +00:00
|
|
|
dst: readOptionalJSON("dist/.destination.json"),
|
2012-04-18 20:07:35 +00:00
|
|
|
compare_size: {
|
2013-03-25 04:47:46 +00:00
|
|
|
files: [ "dist/jquery.js", "dist/jquery.min.js" ],
|
|
|
|
options: {
|
|
|
|
compress: {
|
|
|
|
gz: function( contents ) {
|
|
|
|
return gzip.zip( contents, {} ).length;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
cache: "dist/.sizecache.json"
|
|
|
|
}
|
2012-04-18 20:07:35 +00:00
|
|
|
},
|
|
|
|
selector: {
|
2013-02-27 02:59:08 +00:00
|
|
|
destFile: "src/selector-sizzle.js",
|
2013-01-26 18:38:04 +00:00
|
|
|
apiFile: "src/sizzle-jquery.js",
|
2013-03-19 19:31:53 +00:00
|
|
|
srcFile: "src/sizzle/dist/sizzle.js"
|
2012-04-18 20:07:35 +00:00
|
|
|
},
|
|
|
|
build: {
|
2013-01-26 18:38:04 +00:00
|
|
|
all:{
|
|
|
|
dest: "dist/jquery.js",
|
|
|
|
src: [
|
|
|
|
"src/intro.js",
|
|
|
|
"src/core.js",
|
2013-03-27 01:20:27 +00:00
|
|
|
"src/selector-sizzle.js",
|
2013-01-26 18:38:04 +00:00
|
|
|
"src/callbacks.js",
|
|
|
|
"src/deferred.js",
|
|
|
|
"src/support.js",
|
|
|
|
"src/data.js",
|
|
|
|
"src/queue.js",
|
|
|
|
"src/attributes.js",
|
|
|
|
"src/event.js",
|
|
|
|
"src/traversing.js",
|
|
|
|
"src/manipulation.js",
|
|
|
|
{ flag: "css", src: "src/css.js" },
|
|
|
|
"src/serialize.js",
|
2013-01-27 04:48:59 +00:00
|
|
|
{ flag: "event-alias", src: "src/event-alias.js" },
|
2013-01-26 18:38:04 +00:00
|
|
|
{ flag: "ajax", src: "src/ajax.js" },
|
|
|
|
{ flag: "ajax/script", src: "src/ajax/script.js", needs: ["ajax"] },
|
|
|
|
{ flag: "ajax/jsonp", src: "src/ajax/jsonp.js", needs: [ "ajax", "ajax/script" ] },
|
|
|
|
{ flag: "ajax/xhr", src: "src/ajax/xhr.js", needs: ["ajax"] },
|
|
|
|
{ flag: "effects", src: "src/effects.js", needs: ["css"] },
|
|
|
|
{ flag: "offset", src: "src/offset.js", needs: ["css"] },
|
|
|
|
{ flag: "dimensions", src: "src/dimensions.js", needs: ["css"] },
|
|
|
|
{ flag: "deprecated", src: "src/deprecated.js" },
|
|
|
|
|
|
|
|
"src/exports.js",
|
|
|
|
"src/outro.js"
|
|
|
|
]
|
|
|
|
}
|
2012-04-18 20:07:35 +00:00
|
|
|
},
|
2012-06-25 14:49:21 +00:00
|
|
|
|
2012-12-19 04:02:50 +00:00
|
|
|
jshint: {
|
|
|
|
dist: {
|
|
|
|
src: [ "dist/jquery.js" ],
|
|
|
|
options: {
|
|
|
|
jshintrc: "src/.jshintrc"
|
2012-11-25 19:30:16 +00:00
|
|
|
}
|
2012-12-19 04:02:50 +00:00
|
|
|
},
|
|
|
|
grunt: {
|
|
|
|
src: [ "Gruntfile.js" ],
|
|
|
|
options: {
|
|
|
|
jshintrc: ".jshintrc"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
tests: {
|
|
|
|
// TODO: Once .jshintignore is supported, use that instead.
|
2012-12-20 00:06:16 +00:00
|
|
|
// issue located here: https://github.com/gruntjs/grunt-contrib-jshint/issues/1
|
2012-12-19 04:02:50 +00:00
|
|
|
src: [ "test/data/{test,testinit,testrunner}.js", "test/unit/**/*.js" ],
|
|
|
|
options: {
|
|
|
|
jshintrc: "test/.jshintrc"
|
|
|
|
}
|
|
|
|
}
|
2012-05-09 07:34:00 +00:00
|
|
|
},
|
2012-12-13 01:19:18 +00:00
|
|
|
|
|
|
|
testswarm: {
|
|
|
|
tests: "ajax attributes callbacks core css data deferred dimensions effects event manipulation offset queue selector serialize support traversing Sizzle".split(" ")
|
|
|
|
},
|
|
|
|
|
2012-04-18 20:07:35 +00:00
|
|
|
watch: {
|
2012-12-19 04:02:50 +00:00
|
|
|
files: [ "<%= jshint.grunt.src %>", "<%= jshint.tests.src %>", "src/**/*.js" ],
|
2012-06-05 15:50:49 +00:00
|
|
|
tasks: "dev"
|
2012-04-18 20:07:35 +00:00
|
|
|
},
|
2012-12-13 01:19:18 +00:00
|
|
|
|
2012-10-11 13:38:44 +00:00
|
|
|
uglify: {
|
2012-12-19 04:02:50 +00:00
|
|
|
all: {
|
|
|
|
files: {
|
|
|
|
"dist/jquery.min.js": [ "dist/jquery.js" ]
|
|
|
|
},
|
|
|
|
options: {
|
2013-02-17 14:30:21 +00:00
|
|
|
banner: "/*! jQuery v<%= pkg.version %> | (c) 2005, 2013 jQuery Foundation, Inc. | jquery.org/license */",
|
2012-12-22 21:23:27 +00:00
|
|
|
sourceMap: "dist/jquery.min.map",
|
2013-01-29 00:04:58 +00:00
|
|
|
compress: {
|
|
|
|
hoist_funs: false,
|
|
|
|
join_vars: false,
|
|
|
|
loops: false,
|
|
|
|
unused: false
|
|
|
|
},
|
2012-12-19 04:02:50 +00:00
|
|
|
beautify: {
|
|
|
|
ascii_only: true
|
|
|
|
}
|
|
|
|
}
|
2012-10-11 13:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
2012-04-18 20:07:35 +00:00
|
|
|
});
|
|
|
|
|
2012-05-07 10:06:12 +00:00
|
|
|
grunt.registerTask( "testswarm", function( commit, configFile ) {
|
2012-11-24 23:59:56 +00:00
|
|
|
var jobName,
|
|
|
|
testswarm = require( "testswarm" ),
|
2012-06-07 18:36:19 +00:00
|
|
|
testUrls = [],
|
2012-11-24 23:59:56 +00:00
|
|
|
pull = /PR-(\d+)/.exec( commit ),
|
2012-07-11 13:54:01 +00:00
|
|
|
config = grunt.file.readJSON( configFile ).jquery,
|
2012-12-13 01:19:18 +00:00
|
|
|
tests = grunt.config([ this.name, "tests" ]);
|
2012-07-11 13:54:01 +00:00
|
|
|
|
2012-11-24 23:59:56 +00:00
|
|
|
if ( pull ) {
|
2012-11-25 18:50:49 +00:00
|
|
|
jobName = "jQuery pull <a href='https://github.com/jquery/jquery/pull/" +
|
2012-11-25 00:04:34 +00:00
|
|
|
pull[ 1 ] + "'>#" + pull[ 1 ] + "</a>";
|
2012-11-24 23:59:56 +00:00
|
|
|
} else {
|
|
|
|
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
|
|
|
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
|
|
|
});
|
2012-07-11 13:54:01 +00:00
|
|
|
|
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-11-24 23:59:56 +00:00
|
|
|
jobName: jobName,
|
2012-06-11 19:36:29 +00:00
|
|
|
runMax: config.runMax,
|
2012-05-07 10:06:12 +00:00
|
|
|
"runNames[]": tests,
|
|
|
|
"runUrls[]": testUrls,
|
2012-11-17 20:20:09 +00:00
|
|
|
"browserSets[]": config.browserSets
|
2012-05-07 10:06:12 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-02-27 02:59:08 +00:00
|
|
|
grunt.registerTask( "selector", "Build Sizzle-based selector module", function() {
|
2012-04-18 20:07:35 +00:00
|
|
|
|
2013-01-26 18:38:04 +00:00
|
|
|
var cfg = grunt.config("selector"),
|
|
|
|
name = cfg.destFile,
|
|
|
|
sizzle = {
|
|
|
|
api: grunt.file.read( cfg.apiFile ),
|
|
|
|
src: grunt.file.read( cfg.srcFile )
|
|
|
|
},
|
|
|
|
compiled, parts;
|
2012-07-09 15:21:35 +00:00
|
|
|
|
2012-07-09 15:23:55 +00:00
|
|
|
/**
|
2012-07-09 15:21:35 +00:00
|
|
|
|
2012-07-09 15:23:55 +00:00
|
|
|
sizzle-jquery.js -> sizzle between "EXPOSE" blocks,
|
|
|
|
replace define & window.Sizzle assignment
|
2012-07-09 15:21:35 +00:00
|
|
|
|
|
|
|
|
2012-07-09 15:23:55 +00:00
|
|
|
// EXPOSE
|
|
|
|
if ( typeof define === "function" && define.amd ) {
|
|
|
|
define(function() { return Sizzle; });
|
|
|
|
} else {
|
|
|
|
window.Sizzle = Sizzle;
|
|
|
|
}
|
|
|
|
// EXPOSE
|
|
|
|
|
|
|
|
Becomes...
|
|
|
|
|
|
|
|
Sizzle.attr = jQuery.attr;
|
|
|
|
jQuery.find = Sizzle;
|
|
|
|
jQuery.expr = Sizzle.selectors;
|
|
|
|
jQuery.expr[":"] = jQuery.expr.pseudos;
|
|
|
|
jQuery.unique = Sizzle.uniqueSort;
|
|
|
|
jQuery.text = Sizzle.getText;
|
|
|
|
jQuery.isXMLDoc = Sizzle.isXML;
|
|
|
|
jQuery.contains = Sizzle.contains;
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Break into 3 pieces
|
|
|
|
parts = sizzle.src.split("// EXPOSE");
|
|
|
|
// Replace the if/else block with api
|
|
|
|
parts[1] = sizzle.api;
|
|
|
|
// Rejoin the pieces
|
|
|
|
compiled = parts.join("");
|
2012-07-09 15:21:35 +00:00
|
|
|
|
2013-02-27 02:59:08 +00:00
|
|
|
grunt.verbose.writeln("Injected " + cfg.apiFile + " into " + cfg.srcFile);
|
2012-04-18 20:07:35 +00:00
|
|
|
|
2013-01-06 17:01:22 +00:00
|
|
|
// Write concatenated source to file, and ensure newline-only termination
|
|
|
|
grunt.file.write( name, compiled.replace( /\x0d\x0a/g, "\x0a" ) );
|
2012-04-18 20:07:35 +00:00
|
|
|
|
|
|
|
// Fail task if errors were logged.
|
|
|
|
if ( this.errorCount ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, print a success message.
|
2012-12-19 04:02:50 +00:00
|
|
|
grunt.log.writeln( "File '" + name + "' created." );
|
2012-04-18 20:07:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
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:
|
|
|
|
//
|
2012-08-22 21:40:15 +00:00
|
|
|
// grunt build:*:*:+ajax:-dimensions:-effects:-offset
|
2012-06-12 16:52:30 +00:00
|
|
|
|
|
|
|
grunt.log.writeln( "Creating custom build...\n" );
|
|
|
|
|
2012-12-19 04:02:50 +00:00
|
|
|
grunt.util.spawn({
|
2012-10-17 07:29:21 +00:00
|
|
|
cmd: process.platform === "win32" ? "grunt.cmd" : "grunt",
|
2012-12-22 21:10:06 +00:00
|
|
|
args: [ "build:*:*:" + modules, "uglify", "dist" ]
|
2012-06-12 16:52:30 +00:00
|
|
|
}, function( err, result ) {
|
|
|
|
if ( err ) {
|
|
|
|
grunt.verbose.error();
|
|
|
|
done( err );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-19 04:02:50 +00:00
|
|
|
grunt.log.writeln( result.stdout.replace("Done, without errors.", "") );
|
2012-06-12 16:52:30 +00:00
|
|
|
|
|
|
|
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() {
|
2013-01-26 18:38:04 +00:00
|
|
|
|
2012-05-29 02:25:04 +00:00
|
|
|
// Concat specified files.
|
2012-10-16 15:26:14 +00:00
|
|
|
var compiled = "",
|
2012-06-11 01:54:16 +00:00
|
|
|
modules = this.flags,
|
|
|
|
optIn = !modules["*"],
|
2012-11-01 04:29:58 +00:00
|
|
|
explicit = optIn || Object.keys(modules).length > 1,
|
2013-01-26 18:38:04 +00:00
|
|
|
name = this.data.dest,
|
|
|
|
src = this.data.src,
|
2012-11-01 04:29:58 +00:00
|
|
|
deps = {},
|
2012-06-11 01:54:16 +00:00
|
|
|
excluded = {},
|
2012-12-19 04:02:50 +00:00
|
|
|
version = grunt.config( "pkg.version" ),
|
2012-06-11 01:54:16 +00:00
|
|
|
excluder = function( flag, needsFlag ) {
|
2012-11-01 04:29:58 +00:00
|
|
|
// optIn defaults implicit behavior to weak exclusion
|
2012-06-11 01:54:16 +00:00
|
|
|
if ( optIn && !modules[ flag ] && !modules[ "+" + flag ] ) {
|
|
|
|
excluded[ flag ] = false;
|
|
|
|
}
|
|
|
|
|
2012-11-01 04:29:58 +00:00
|
|
|
// explicit or inherited strong exclusion
|
2012-06-11 01:54:16 +00:00
|
|
|
if ( excluded[ needsFlag ] || modules[ "-" + flag ] ) {
|
|
|
|
excluded[ flag ] = true;
|
2012-11-01 04:29:58 +00:00
|
|
|
|
|
|
|
// explicit inclusion overrides weak exclusion
|
|
|
|
} else if ( excluded[ needsFlag ] === false &&
|
|
|
|
( modules[ flag ] || modules[ "+" + flag ] ) ) {
|
|
|
|
|
2012-06-11 01:54:16 +00:00
|
|
|
delete excluded[ needsFlag ];
|
2012-11-01 04:29:58 +00:00
|
|
|
|
|
|
|
// ...all the way down
|
|
|
|
if ( deps[ needsFlag ] ) {
|
|
|
|
deps[ needsFlag ].forEach(function( subDep ) {
|
|
|
|
modules[ needsFlag ] = true;
|
|
|
|
excluder( needsFlag, subDep );
|
|
|
|
});
|
|
|
|
}
|
2012-06-11 01:54:16 +00:00
|
|
|
}
|
|
|
|
};
|
2012-05-29 02:25:04 +00:00
|
|
|
|
2012-07-11 13:54:01 +00:00
|
|
|
// append commit id to version
|
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:
|
2012-11-01 04:29:58 +00:00
|
|
|
// dependency explicit exclude
|
|
|
|
// > explicit exclude
|
|
|
|
// > explicit include
|
|
|
|
// > dependency implicit exclude
|
|
|
|
// > implicit exclude
|
2012-06-11 01:54:16 +00:00
|
|
|
// examples:
|
2012-11-01 04:29:58 +00:00
|
|
|
// * none (implicit exclude)
|
2012-06-11 01:54:16 +00:00
|
|
|
// *:* all (implicit include)
|
2012-11-01 04:29:58 +00:00
|
|
|
// *:*:-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)
|
2012-12-19 04:02:50 +00:00
|
|
|
src.forEach(function( filepath ) {
|
2012-05-29 02:25:04 +00:00
|
|
|
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 ) {
|
2012-11-01 04:29:58 +00:00
|
|
|
deps[ flag ] = filepath.needs;
|
2012-06-11 01:54:16 +00:00
|
|
|
filepath.needs.forEach(function( needsFlag ) {
|
|
|
|
excluder( flag, needsFlag );
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-07-11 13:54:01 +00:00
|
|
|
// append excluded modules to version
|
|
|
|
if ( Object.keys( excluded ).length ) {
|
|
|
|
version += " -" + Object.keys( excluded ).join( ",-" );
|
|
|
|
// set pkg.version to version with excludes, so minified file picks it up
|
|
|
|
grunt.config.set( "pkg.version", version );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-11 01:54:16 +00:00
|
|
|
// conditionally concatenate source
|
2012-12-19 04:02:50 +00:00
|
|
|
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,
|
2013-02-27 02:59:08 +00:00
|
|
|
messages = [];
|
2012-06-12 16:52:30 +00:00
|
|
|
|
2012-06-11 01:54:16 +00:00
|
|
|
if ( flag ) {
|
|
|
|
if ( excluded[ flag ] !== undefined ) {
|
2013-02-27 02:59:08 +00:00
|
|
|
messages.push([
|
|
|
|
( "Excluding " + flag ).red,
|
|
|
|
( "(" + filepath.src + ")" ).grey
|
|
|
|
]);
|
2012-06-12 16:52:30 +00:00
|
|
|
specified = true;
|
2013-02-27 02:59:08 +00:00
|
|
|
omit = !filepath.alt;
|
|
|
|
if ( !omit ) {
|
|
|
|
flag += " alternate";
|
|
|
|
filepath.src = filepath.alt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( excluded[ flag ] === undefined ) {
|
|
|
|
messages.push([
|
|
|
|
( "Including " + flag ).green,
|
|
|
|
( "(" + filepath.src + ")" ).grey
|
|
|
|
]);
|
2012-06-12 16:52:30 +00:00
|
|
|
|
|
|
|
// If this module was actually specified by the
|
2013-02-27 02:59:08 +00:00
|
|
|
// builder, then set the flag to include it in the
|
2012-06-12 16:52:30 +00:00
|
|
|
// output list
|
|
|
|
if ( modules[ "+" + flag ] ) {
|
|
|
|
specified = true;
|
|
|
|
}
|
2012-05-29 02:25:04 +00:00
|
|
|
}
|
2012-06-12 16:52:30 +00:00
|
|
|
|
2013-02-27 02:59:08 +00:00
|
|
|
filepath = filepath.src;
|
|
|
|
|
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 ) {
|
2013-02-27 02:59:08 +00:00
|
|
|
messages.forEach(function( message ) {
|
|
|
|
grunt.log.writetableln( [ 27, 30 ], message );
|
|
|
|
});
|
2012-06-12 16:52:30 +00:00
|
|
|
}
|
2012-05-29 02:25:04 +00:00
|
|
|
}
|
|
|
|
|
2012-06-21 00:39:22 +00:00
|
|
|
if ( !omit ) {
|
2012-12-19 04:02:50 +00:00
|
|
|
compiled += grunt.file.read( filepath );
|
2012-06-21 00:39:22 +00:00
|
|
|
}
|
2012-05-29 02:25:04 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Embed Version
|
2012-10-15 15:45:00 +00:00
|
|
|
// Embed Date
|
|
|
|
compiled = compiled.replace( /@VERSION/g, version )
|
|
|
|
.replace( "@DATE", function () {
|
|
|
|
// YYYY-MM-DD
|
2013-04-01 17:02:57 +00:00
|
|
|
return ( new Date() ).toISOString().replace( /T.*/, "" );
|
2012-10-15 15:45:00 +00:00
|
|
|
});
|
2012-05-29 02:25:04 +00:00
|
|
|
|
|
|
|
// Write concatenated source to file
|
2012-12-19 04:02:50 +00:00
|
|
|
grunt.file.write( name, compiled );
|
2012-05-29 02:25:04 +00:00
|
|
|
|
|
|
|
// 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.
|
2012-12-19 04:02:50 +00:00
|
|
|
grunt.log.writeln( "File '" + name + "' created." );
|
2012-04-18 20:07:35 +00:00
|
|
|
});
|
2012-06-04 16:48:18 +00:00
|
|
|
|
2012-12-22 21:10:06 +00:00
|
|
|
// Process files for distribution
|
2012-06-04 16:48:18 +00:00
|
|
|
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 )
|
2012-12-19 04:02:50 +00:00
|
|
|
stored = Object.keys( grunt.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-10-11 14:17:24 +00:00
|
|
|
// Ensure the dist files are pure ASCII
|
|
|
|
var fs = require("fs"),
|
|
|
|
nonascii = false;
|
2012-12-19 04:02:50 +00:00
|
|
|
|
2012-10-11 14:17:24 +00:00
|
|
|
distpaths.forEach(function( filename ) {
|
2013-01-23 22:42:28 +00:00
|
|
|
var i, c, map,
|
2013-01-06 17:01:22 +00:00
|
|
|
text = fs.readFileSync( filename, "utf8" );
|
|
|
|
|
|
|
|
// Ensure files use only \n for line endings, not \r\n
|
|
|
|
if ( /\x0d\x0a/.test( text ) ) {
|
|
|
|
grunt.log.writeln( filename + ": Incorrect line endings (\\r\\n)" );
|
|
|
|
nonascii = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure only ASCII chars so script tags don't need a charset attribute
|
2012-12-22 21:10:06 +00:00
|
|
|
if ( text.length !== Buffer.byteLength( text, "utf8" ) ) {
|
2012-12-19 04:02:50 +00:00
|
|
|
grunt.log.writeln( filename + ": Non-ASCII characters detected:" );
|
2012-12-22 21:10:06 +00:00
|
|
|
for ( i = 0; i < text.length; i++ ) {
|
|
|
|
c = text.charCodeAt( i );
|
2012-10-11 14:17:24 +00:00
|
|
|
if ( c > 127 ) {
|
2012-12-19 04:02:50 +00:00
|
|
|
grunt.log.writeln( "- position " + i + ": " + c );
|
2012-12-22 21:10:06 +00:00
|
|
|
grunt.log.writeln( "-- " + text.substring( i - 20, i + 20 ) );
|
|
|
|
break;
|
2012-10-11 14:17:24 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-06 17:01:22 +00:00
|
|
|
nonascii = true;
|
2012-10-11 14:17:24 +00:00
|
|
|
}
|
2012-06-04 16:48:18 +00:00
|
|
|
|
2013-01-10 15:35:50 +00:00
|
|
|
// Modify map/min so that it points to files in the same folder;
|
2012-12-22 21:10:06 +00:00
|
|
|
// see https://github.com/mishoo/UglifyJS2/issues/47
|
|
|
|
if ( /\.map$/.test( filename ) ) {
|
|
|
|
text = text.replace( /"dist\//g, "\"" );
|
|
|
|
fs.writeFileSync( filename, text, "utf-8" );
|
2013-01-10 15:35:50 +00:00
|
|
|
} else if ( /\.min\.js$/.test( filename ) ) {
|
2013-01-23 22:42:28 +00:00
|
|
|
// Wrap sourceMap directive in multiline comments (#13274)
|
|
|
|
text = text.replace( /\n?(\/\/@\s*sourceMappingURL=)(.*)/,
|
|
|
|
function( _, directive, path ) {
|
|
|
|
map = "\n" + directive + path.replace( /^dist\//, "" );
|
|
|
|
return "";
|
|
|
|
});
|
|
|
|
if ( map ) {
|
|
|
|
text = text.replace( /(^\/\*[\w\W]*?)\s*\*\/|$/,
|
|
|
|
function( _, comment ) {
|
|
|
|
return ( comment || "\n/*" ) + map + "\n*/";
|
|
|
|
});
|
|
|
|
}
|
2013-01-10 15:35:50 +00:00
|
|
|
fs.writeFileSync( filename, text, "utf-8" );
|
2012-12-22 21:10:06 +00:00
|
|
|
}
|
2012-06-05 17:10:01 +00:00
|
|
|
|
2012-12-22 21:10:06 +00:00
|
|
|
// Optionally copy dist files to other locations
|
|
|
|
paths.forEach(function( path ) {
|
|
|
|
var created;
|
2012-06-05 17:10:01 +00:00
|
|
|
|
2012-12-22 21:10:06 +00:00
|
|
|
if ( !/\/$/.test( path ) ) {
|
|
|
|
path += "/";
|
|
|
|
}
|
2012-06-04 16:48:18 +00:00
|
|
|
|
2012-12-22 21:10:06 +00:00
|
|
|
created = path + filename.replace( "dist/", "" );
|
|
|
|
grunt.file.write( created, text );
|
|
|
|
grunt.log.writeln( "File '" + created + "' created." );
|
2012-06-04 16:48:18 +00:00
|
|
|
});
|
2012-12-22 21:10:06 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return !nonascii;
|
2012-06-04 16:48:18 +00:00
|
|
|
});
|
2012-12-19 04:02:50 +00:00
|
|
|
|
|
|
|
// Load grunt tasks from NPM packages
|
2012-12-20 01:18:58 +00:00
|
|
|
grunt.loadNpmTasks("grunt-compare-size");
|
|
|
|
grunt.loadNpmTasks("grunt-git-authors");
|
|
|
|
grunt.loadNpmTasks("grunt-update-submodules");
|
2012-12-19 04:02:50 +00:00
|
|
|
grunt.loadNpmTasks("grunt-contrib-watch");
|
|
|
|
grunt.loadNpmTasks("grunt-contrib-jshint");
|
|
|
|
grunt.loadNpmTasks("grunt-contrib-uglify");
|
|
|
|
|
|
|
|
// Default grunt
|
2013-03-11 14:06:36 +00:00
|
|
|
grunt.registerTask( "default", [ "update_submodules", "selector", "build:*:*", "jshint", "uglify", "dist:*", "compare_size" ] );
|
2012-12-19 04:02:50 +00:00
|
|
|
|
|
|
|
// Short list as a high frequency watch task
|
|
|
|
grunt.registerTask( "dev", [ "selector", "build:*:*", "jshint" ] );
|
2012-04-18 20:07:35 +00:00
|
|
|
};
|