jquery/Gruntfile.js

323 lines
7.5 KiB
JavaScript
Raw Normal View History

2012-04-18 20:07:35 +00:00
module.exports = function( grunt ) {
"use strict";
function readOptionalJSON( filepath ) {
var stripJSONComments = require( "strip-json-comments" ),
data = {};
try {
data = JSON.parse( stripJSONComments(
fs.readFileSync( filepath, { encoding: "utf8" } )
) );
} catch ( e ) {}
return data;
}
var fs = require( "fs" ),
gzip = require( "gzip-js" );
if ( !grunt.option( "filename" ) ) {
grunt.option( "filename", "jquery.js" );
}
grunt.initConfig( {
pkg: grunt.file.readJSON( "package.json" ),
dst: readOptionalJSON( "dist/.destination.json" ),
"compare_size": {
files: [ "dist/jquery.js", "dist/jquery.min.js" ],
options: {
compress: {
gz: function( contents ) {
return gzip.zip( contents, {} ).length;
}
},
2013-10-15 20:14:10 +00:00
cache: "build/.sizecache.json"
}
2012-04-18 20:07:35 +00:00
},
babel: {
options: {
sourceMap: "inline",
retainLines: true,
plugins: [ "transform-es2015-for-of" ]
},
nodeSmokeTests: {
files: {
"test/node_smoke_tests/lib/ensure_iterability.js":
"test/node_smoke_tests/lib/ensure_iterability_es6.js"
}
}
},
2012-04-18 20:07:35 +00:00
build: {
all: {
dest: "dist/jquery.js",
minimum: [
"core",
"selector"
],
// Exclude specified modules if the module matching the key is removed
removeWith: {
ajax: [ "manipulation/_evalUrl", "event/ajax" ],
callbacks: [ "deferred" ],
css: [ "effects", "dimensions", "offset" ],
"css/showHide": [ "effects" ],
deferred: {
remove: [ "ajax", "effects", "queue", "core/ready" ],
include: [ "core/ready-no-deferred" ]
},
sizzle: [ "css/hiddenVisibleSelectors", "effects/animatedSelector" ]
}
}
2012-04-18 20:07:35 +00:00
},
npmcopy: {
all: {
options: {
destPrefix: "external"
},
files: {
"sizzle/dist": "sizzle/dist",
2014-07-01 20:50:27 +00:00
"sizzle/LICENSE.txt": "sizzle/LICENSE.txt",
"npo/npo.js": "native-promise-only/npo.js",
"qunit/qunit.js": "qunitjs/qunit/qunit.js",
"qunit/qunit.css": "qunitjs/qunit/qunit.css",
2014-12-15 17:30:43 +00:00
"qunit/LICENSE.txt": "qunitjs/LICENSE.txt",
"qunit-assert-step/qunit-assert-step.js":
"qunit-assert-step/qunit-assert-step.js",
"qunit-assert-step/MIT-LICENSE.txt":
"qunit-assert-step/MIT-LICENSE.txt",
"requirejs/require.js": "requirejs/require.js",
"sinon/sinon.js": "sinon/pkg/sinon.js",
"sinon/LICENSE.txt": "sinon/LICENSE"
}
}
},
2013-07-19 13:53:57 +00:00
jsonlint: {
pkg: {
src: [ "package.json" ]
}
},
eslint: {
options: {
// See https://github.com/sindresorhus/grunt-eslint/issues/119
quiet: true
},
// We have to explicitly declare "src" property otherwise "newer"
// task wouldn't work properly :/
dist: {
src: "dist/jquery.js"
},
dev: {
src: [ "src/**/*.js", "Gruntfile.js", "test/**/*.js", "build/**/*.js" ]
}
},
testswarm: {
tests: [
// A special module with basic tests, meant for
// not fully supported environments like Android 2.3,
// jsdom or PhantomJS. We run it everywhere, though,
// to make sure tests are not broken.
"basic",
"ajax",
"animation",
"attributes",
"callbacks",
"core",
"css",
"data",
"deferred",
"deprecated",
"dimensions",
"effects",
"event",
"manipulation",
"offset",
"queue",
"selector",
"serialize",
"support",
2015-05-18 21:11:21 +00:00
"traversing",
"tween"
]
},
karma: {
options: {
customContextFile: "test/karma.context.html",
customDebugFile: "test/karma.debug.html",
frameworks: [ "qunit" ],
middleware: [ "mockserver" ],
plugins: [
"karma-*",
{
"middleware:mockserver": [
"factory",
require( "./test/middleware-mockserver.js" )
]
}
],
files: [
"test/data/jquery-1.9.1.js",
"external/qunit-assert-step/qunit-assert-step.js",
"external/sinon/sinon.js",
"external/npo/npo.js",
"external/requirejs/require.js",
"test/data/testinit.js",
"dist/jquery.min.js",
// Replacement for testinit.js#loadTests()
"test/data/testrunner.js",
"test/unit/basic.js",
"test/unit/core.js",
"test/unit/callbacks.js",
"test/unit/deferred.js",
"test/unit/deprecated.js",
"test/unit/support.js",
"test/unit/data.js",
"test/unit/queue.js",
"test/unit/attributes.js",
"test/unit/event.js",
"test/unit/selector.js",
"test/unit/traversing.js",
"test/unit/manipulation.js",
"test/unit/wrap.js",
"test/unit/css.js",
"test/unit/serialize.js",
"test/unit/ajax.js",
"test/unit/effects.js",
"test/unit/offset.js",
"test/unit/dimensions.js",
"test/unit/animation.js",
"test/unit/tween.js",
"test/unit/ready.js",
{ pattern: "dist/jquery.js", included: false, served: true },
{ pattern: "dist/*.map", included: false, served: true },
{ pattern: "external/qunit/qunit.css", included: false, served: true },
{
pattern: "test/**/*.@(js|css|jpg|html|xml)",
included: false,
served: true
}
],
reporters: [ "dots" ],
autoWatch: false,
concurrency: 3,
captureTimeout: 20 * 1000,
// To debug tests with Karma:
// - Run 'grunt karma:chrome' or 'grunt karma:firefox'
// (any karma subtask that has singleRun=false)
// - Press "Debug" in the opened browser window.
singleRun: false
},
main: {
browsers: [ "ChromeHeadless" ],
singleRun: true
},
chrome: {
browsers: [ "Chrome" ]
},
firefox: {
browsers: [ "Firefox" ]
}
},
2012-04-18 20:07:35 +00:00
watch: {
files: [ "<%= eslint.dev.src %>" ],
tasks: [ "dev" ]
2012-04-18 20:07:35 +00:00
},
uglify: {
all: {
files: {
"dist/<%= grunt.option('filename').replace('.js', '.min.js') %>":
"dist/<%= grunt.option('filename') %>"
},
options: {
preserveComments: false,
sourceMap: true,
sourceMapName:
"dist/<%= grunt.option('filename').replace('.js', '.min.map') %>",
report: "min",
output: {
"ascii_only": true
},
banner: "/*! jQuery v<%= pkg.version %> | " +
"(c) JS Foundation and other contributors | jquery.org/license */",
compress: {
"hoist_funs": false,
loops: false,
unused: false,
// Support: IE <11
// typeofs transformation is unsafe for IE9-10
// See https://github.com/mishoo/UglifyJS2/issues/2198
typeofs: false
}
}
}
}
} );
2012-04-18 20:07:35 +00:00
// Load grunt tasks from NPM packages
require( "load-grunt-tasks" )( grunt );
// Integrate jQuery specific tasks
grunt.loadTasks( "build/tasks" );
grunt.registerTask( "lint", [
"jsonlint",
// Running the full eslint task without breaking it down to targets
// would run the dist target first which would point to errors in the built
// file, making it harder to fix them. We want to check the built file only
// if we already know the source files pass the linter.
"eslint:dev",
"eslint:dist"
] );
grunt.registerTask( "lint:newer", [
"newer:jsonlint",
// Don't replace it with just the task; see the above comment.
"newer:eslint:dev",
"newer:eslint:dist"
] );
grunt.registerTask( "test:fast", "node_smoke_tests" );
grunt.registerTask( "test:slow", "promises_aplus_tests" );
grunt.registerTask( "test", [
"test:fast",
"test:slow"
] );
grunt.registerTask( "dev", [
"build:*:*",
"newer:eslint:dev",
"newer:uglify",
"remove_map_comment",
"dist:*",
"qunit_fixture",
"compare_size"
] );
grunt.registerTask( "default", [
"eslint:dev",
"build:*:*",
"uglify",
"remove_map_comment",
"dist:*",
"qunit_fixture",
"eslint:dist",
"test:fast",
"compare_size"
] );
2012-04-18 20:07:35 +00:00
};