|
| 1 | +/*jshint node: true */ |
| 2 | +module.exports = function( grunt ) { |
| 3 | + |
| 4 | +"use strict"; |
| 5 | + |
| 6 | +grunt.loadNpmTasks( "grunt-compare-size" ); |
| 7 | +grunt.loadNpmTasks( "grunt-git-authors" ); |
| 8 | + |
| 9 | +grunt.initConfig({ |
| 10 | + pkg: "<json:package.json>", |
| 11 | + |
| 12 | + meta: { |
| 13 | + banner: "/*! jQuery Simulate v@<%= pkg.version %> http://github.com/jquery/jquery-simulate | jquery.org/license */" |
| 14 | + }, |
| 15 | + |
| 16 | + lint: { |
| 17 | + src: [ "jquery.simulate.js" ], |
| 18 | + grunt: "grunt.js", |
| 19 | + test: "test/unit/**" |
| 20 | + }, |
| 21 | + |
| 22 | + jshint: (function() { |
| 23 | + function parserc( path ) { |
| 24 | + var rc = grunt.file.readJSON( (path || "") + ".jshintrc" ), |
| 25 | + settings = { |
| 26 | + options: rc, |
| 27 | + globals: rc.globals || {} |
| 28 | + }; |
| 29 | + |
| 30 | + (rc.predef || []).forEach(function( prop ) { |
| 31 | + settings.globals[ prop ] = true; |
| 32 | + }); |
| 33 | + delete rc.predef; |
| 34 | + |
| 35 | + return settings; |
| 36 | + } |
| 37 | + |
| 38 | + return { |
| 39 | + src: parserc(), |
| 40 | + grunt: parserc(), |
| 41 | + test: parserc( "test/unit/" ) |
| 42 | + }; |
| 43 | + })(), |
| 44 | + |
| 45 | + qunit: { |
| 46 | + files: "test/index.html" |
| 47 | + }, |
| 48 | + |
| 49 | + min: { |
| 50 | + "dist/jquery.simulate.min.js": [ "<banner>", "dist/jquery.simulate.js" ] |
| 51 | + }, |
| 52 | + |
| 53 | + watch: { |
| 54 | + files: [ "<config:lint.src>", "<config:lint.test>", "<config:lint.grunt>" ], |
| 55 | + tasks: "default" |
| 56 | + }, |
| 57 | + |
| 58 | + compare_size: { |
| 59 | + files: [ "dist/jquery.simulate.js" ] |
| 60 | + } |
| 61 | +}); |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | +grunt.registerHelper( "git-date", function( fn ) { |
| 66 | + grunt.utils.spawn({ |
| 67 | + cmd: "git", |
| 68 | + args: [ "log", "-1", "--pretty=format:%ad" ] |
| 69 | + }, function( error, result ) { |
| 70 | + if ( error ) { |
| 71 | + grunt.log.error( error ); |
| 72 | + return fn( error ); |
| 73 | + } |
| 74 | + |
| 75 | + fn( null, result ); |
| 76 | + }); |
| 77 | +}); |
| 78 | + |
| 79 | +grunt.registerTask( "submodules", function() { |
| 80 | + var done = this.async(); |
| 81 | + |
| 82 | + grunt.verbose.write( "Updating submodules..." ); |
| 83 | + |
| 84 | + grunt.utils.spawn({ |
| 85 | + cmd: "git", |
| 86 | + args: [ "submodule", "update", "--init" ] |
| 87 | + }, function( err, result ) { |
| 88 | + if ( err ) { |
| 89 | + grunt.verbose.error(); |
| 90 | + done( err ); |
| 91 | + return; |
| 92 | + } |
| 93 | + |
| 94 | + grunt.log.writeln( result ); |
| 95 | + |
| 96 | + done(); |
| 97 | + }); |
| 98 | +}); |
| 99 | + |
| 100 | +grunt.registerTask( "max", function() { |
| 101 | + var dist = "dist/jquery.simulate.js", |
| 102 | + done = this.async(), |
| 103 | + version = grunt.config( "pkg.version" ); |
| 104 | + |
| 105 | + if ( process.env.COMMIT ) { |
| 106 | + version += " " + process.env.COMMIT; |
| 107 | + } |
| 108 | + |
| 109 | + grunt.helper( "git-date", function( error, date ) { |
| 110 | + if ( error ) { |
| 111 | + return done( false ); |
| 112 | + } |
| 113 | + |
| 114 | + grunt.file.copy( dist.replace( "dist/", "" ), dist, { |
| 115 | + process: function( source ) { |
| 116 | + return source |
| 117 | + .replace( /@VERSION/g, version ) |
| 118 | + .replace( /@DATE/g, date ); |
| 119 | + } |
| 120 | + }); |
| 121 | + |
| 122 | + done(); |
| 123 | + }); |
| 124 | +}); |
| 125 | + |
| 126 | +grunt.registerTask( "testswarm", function( commit, configFile ) { |
| 127 | + var testswarm = require( "testswarm" ), |
| 128 | + config = grunt.file.readJSON( configFile ).jquerycolor; |
| 129 | + config.jobName = "jQuery Simulate commit #<a href='https://github.com/jquery/jquery-simulate/commit/" + commit + "'>" + commit.substr( 0, 10 ) + "</a>"; |
| 130 | + config["runNames[]"] = "jQuery Simulate"; |
| 131 | + config["runUrls[]"] = config.testUrl + commit + "/test/index.html"; |
| 132 | + config["browserSets[]"] = ["popular"]; |
| 133 | + testswarm({ |
| 134 | + url: config.swarmUrl, |
| 135 | + pollInterval: 10000, |
| 136 | + timeout: 1000 * 60 * 30, |
| 137 | + done: this.async() |
| 138 | + }, config); |
| 139 | +}); |
| 140 | + |
| 141 | +grunt.registerTask( "manifest", function() { |
| 142 | + var pkg = grunt.config( "pkg" ); |
| 143 | + grunt.file.write( "simulate.jquery.json", JSON.stringify({ |
| 144 | + name: "color", |
| 145 | + title: pkg.title, |
| 146 | + description: pkg.description, |
| 147 | + keywords: pkg.keywords, |
| 148 | + version: pkg.version, |
| 149 | + author: { |
| 150 | + name: pkg.author.name, |
| 151 | + url: pkg.author.url.replace( "master", pkg.version ) |
| 152 | + }, |
| 153 | + maintainers: pkg.maintainers, |
| 154 | + licenses: pkg.licenses.map(function( license ) { |
| 155 | + return license.url.replace( "master", pkg.version ); |
| 156 | + }), |
| 157 | + bugs: pkg.bugs, |
| 158 | + homepage: pkg.homepage, |
| 159 | + docs: pkg.homepage, |
| 160 | + dependencies: { |
| 161 | + jquery: ">=1.6" |
| 162 | + } |
| 163 | + }, null, "\t" ) ); |
| 164 | +}); |
| 165 | + |
| 166 | +grunt.registerTask( "default", "lint submodules qunit build compare_size" ); |
| 167 | +grunt.registerTask( "build", "max min" ); |
| 168 | + |
| 169 | +}; |
0 commit comments