Skip to content

Commit

Permalink
Improve Gruntfile
Browse files Browse the repository at this point in the history
1. Standardize formatting of arrays and objects
    - Fixes formatting inconsistencies in the Gruntfile. Now arrays and objects
    are:
    single_space: after_colon,
    One value: [single_line],
    Multiple values: [
      multiple,
      lines
    ]

2. Use load-grunt-tasks to... load grunt tasks!
    - Sindre wrote a nice plugin that is used widely in the Yeoman and Grunt
    communities to load tasks in a cleaner fashion than matchdep.
    - Moves loading tasks to the top near our other require statements.
    - Since we're asking users to run `npm install` there should be no need to check
    if a package is installed or not. If the project is installed as a dependency
    all of the required packages will be installed as well.

3. Fix config-all.json formatting
    - Running `grunt test` reformats the config-all file, leaving your working
    directory dirty. Committing the reformatted file so that running a test task
    doesn't impact the repo at all :).

4. Move jshint before build
    - It's convention to jshint source files before you build, so that if there are
    glaring jshint errors your build won't complete.

5. Rename clean targets to be more descriptive

6. Revise the readme to ask people to run all tests (jshint, qunit, and nodeunit)
  • Loading branch information
Rob Wierzbowski committed Jan 4, 2014
1 parent 23e3da9 commit 5914214
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 51 deletions.
91 changes: 50 additions & 41 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
module.exports = function( grunt ) {
'use strict';

var fs = require('fs');
var path = require('path');
var modConfig = grunt.file.readJSON('lib/config-all.json');
var browsers = grunt.file.readJSON('lib/sauce-browsers.json');

// Load grunt dependencies
require('load-grunt-tasks')(grunt);

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
banner: {
Expand All @@ -32,7 +33,6 @@ module.exports = function( grunt ) {
' */'
},
meta: {

},
qunit: {
files: ['test/index.html']
Expand All @@ -41,16 +41,14 @@ module.exports = function( grunt ) {
files: ['test/api/*.js']
},
stripdefine: {
build: [
'dist/modernizr-build.js'
]
build: ['dist/modernizr-build.js']
},
generateinit : {
generateinit: {
build: {
src: ['tmp/modernizr-init.js']
}
},
uglify : {
uglify: {
options: {
stripbanners: true,
banner: '<%= banner.compact %>',
Expand All @@ -62,9 +60,7 @@ module.exports = function( grunt ) {
}
},
dist: {
src: [
'dist/modernizr-build.js'
],
src: ['dist/modernizr-build.js'],
dest: 'dist/modernizr-build.min.js'
}
},
Expand All @@ -73,7 +69,10 @@ module.exports = function( grunt ) {
tasks: 'jshint',
tests: {
files: '<%= jshint.tests.files.src %>',
tasks: ['jshint:tests', 'qunit']
tasks: [
'jshint:tests',
'qunit'
]
}
},
jshint: {
Expand All @@ -100,12 +99,15 @@ module.exports = function( grunt ) {
Modernizr: true,
DocumentTouch: true,
TEST: true,
SVGFEColorMatrixElement : true,
SVGFEColorMatrixElement: true,
Blob: true,
define: true,
require: true
},
ignores: ['src/load.js', 'src/require.js']
ignores: [
'src/load.js',
'src/require.js'
]
},
files: [
'Gruntfile.js',
Expand Down Expand Up @@ -135,8 +137,11 @@ module.exports = function( grunt ) {
}
},
clean: {
build: ['build', 'dist', 'tmp'],
postbuild: ['build', 'tmp']
dist: ['dist'],
postbuild: [
'build',
'tmp'
]
},
copy: {
build: {
Expand All @@ -154,13 +159,13 @@ module.exports = function( grunt ) {
optimize: 'none',
optimizeCss: 'none',
paths: {
'test' : '../feature-detects',
'modernizr-init' : '../tmp/modernizr-init'
'test': '../feature-detects',
'modernizr-init': '../tmp/modernizr-init'
},
modules : [{
'name' : 'modernizr-build',
'include' : ['modernizr-init'],
'create' : true
modules: [{
'name': 'modernizr-build',
'include': ['modernizr-init'],
'create': true
}],
fileExclusionRegExp: /^(.git|node_modules|modulizr|media|test)$/,
wrap: {
Expand Down Expand Up @@ -206,24 +211,15 @@ module.exports = function( grunt ) {
concurrency: 2,
browsers: browsers,
testname: 'qunit tests',
tags: ['master', '<%= pkg.version %>']
tags: [
'master',
'<%= pkg.version %>'
]
}
}
}
});

// Load required contrib packages
require('matchdep').filter(['grunt-*', '!grunt-cli']).forEach(grunt.loadNpmTasks);

// devDependencies may or may not be installed
require('matchdep').filterDev('grunt-*').forEach(function (contrib) {
module.paths.forEach(function (dir) {
if (fs.existsSync(path.join(dir, contrib))) {
grunt.loadNpmTasks(contrib);
}
});
});

// Strip define fn
grunt.registerMultiTask('stripdefine', 'Strip define call from dist file', function() {
this.filesSrc.forEach(function(filepath) {
Expand All @@ -241,22 +237,35 @@ module.exports = function( grunt ) {
grunt.registerMultiTask('generateinit', 'Generate Init file', function() {
var requirejs = require('requirejs');
requirejs.config({
appDir : __dirname + '/src/',
baseUrl : __dirname + '/src/'
appDir: __dirname + '/src/',
baseUrl: __dirname + '/src/'
});
var generateInit = requirejs('generate');
grunt.file.write('tmp/modernizr-init.js', generateInit(modConfig));
});

// Testing tasks
grunt.registerTask('test', ['build', 'jshint', 'qunit', 'nodeunit']);
grunt.registerTask('test', ['jshint', 'build', 'qunit', 'nodeunit']);

// Sauce labs CI task
grunt.registerTask('sauce', ['connect', 'saucelabs-qunit']);
grunt.registerTask('sauce', ['connect','saucelabs-qunit']);

// Travis CI task.
grunt.registerTask('travis', ['test']);

// Build
grunt.registerTask('build', ['clean', 'generateinit', 'requirejs', 'copy', 'clean:postbuild', 'stripdefine', 'uglify']);
grunt.registerTask('default', ['build', 'jshint']);
grunt.registerTask('build', [
'clean',
'generateinit',
'requirejs',
'copy',
'clean:postbuild',
'stripdefine',
'uglify'
]);

grunt.registerTask('default', [
'jshint',
'build'
]);
};
2 changes: 1 addition & 1 deletion lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module.exports = function (opts, callback) {
}
}

var build = cp.spawn(__dirname + '/../node_modules/.bin/' + 'grunt', ['build'], {
var build = cp.spawn(__dirname + '/../node_modules/.bin/' + 'grunt', ['build'], {
stdio: verbose ? 'inherit' : [0, 'pipe', 2],
cwd: localRoot
});
Expand Down
4 changes: 2 additions & 2 deletions lib/config-all.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"classPrefix" : "",
"classPrefix": "",
"options": [
"setClasses",
"addTest",
Expand Down Expand Up @@ -212,4 +212,4 @@
"test/workers/sharedworkers",
"test/workers/webworkers"
]
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
"requirejs": "~2.1.4",
"underscore": "~1.4.4",
"marked": "~0.2.8",
"matchdep": "~0.3",
"grunt": "~0.4.0",
"grunt-contrib-jshint": "~0.5",
"grunt-contrib-uglify": "~0.2.0",
"grunt-contrib-watch": "~0.3.1",
"grunt-contrib-clean": "~0.4.0",
"grunt-contrib-copy": "~0.4.0",
"grunt-contrib-requirejs": "~0.4.0",
"grunt-cli": "~0.1.11"
"grunt-cli": "~0.1.11",
"load-grunt-tasks": "~0.2.1"
},
"devDependencies": {
"grunt-contrib-connect": "~0.5.0",
Expand Down
11 changes: 6 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ We guarantee that we'll only invoke your function once (per time that you call `
a method for exposing the `trigger` functionality. Instead, if you'd like to have control over async tests, use the
`src/addTest` feature, and any test that you set will automatically expose and trigger the `on` functionality.

## Getting Started

- Clone or download the repository
- Install project dependencies with `npm install`

## Test suite

Run the [test suite](http://modernizr.github.com/Modernizr/test/)


## Building Modernizr v3

### To generate everything in 'config-all.json':
Expand All @@ -50,7 +54,7 @@ grunt build
### To run tests (in phantom):

```js
grunt qunit
grunt test
```

### To run tests (in browser):
Expand All @@ -65,18 +69,15 @@ visit <url>/test

serve the root dir, `<url>/test/modular.html`


### To see the build tool:


* checkout the modernizr.com code
* install all your gems and bundles and jekyll and shit
* `jekyll`
* `serve ./_sites`
* visit <url>/download
* It should be just a big list of things you can build with no frills.


### API Reference

Modernizr can be used programmatically via npm:
Expand Down

0 comments on commit 5914214

Please sign in to comment.