Skip to content

Commit

Permalink
Moved over build step to grunt
Browse files Browse the repository at this point in the history
- Added default build step which will combine modules, minify
  add license and create dist files.
- Added package.json for deps and source of truth for version
  • Loading branch information
ryanseddon committed Nov 11, 2012
1 parent 163d046 commit 0103e1c
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 11 deletions.
92 changes: 81 additions & 11 deletions grunt.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,37 @@ module.exports = function( grunt ) {
'use strict';

grunt.initConfig({
pkg: '<json:package.json>',
meta: {
version: '2.6.3pre',
banner: '/*!\n' +
' * Modernizr v<%= meta.version %>\n' +
' * <%= pkg.name %> v<%= pkg.version %>\n' +
' * modernizr.com\n *\n' +
' * Copyright (c) Faruk Ates, Paul Irish, Alex Sexton\n' +
' * MIT License\n */'
' * Copyright (c) <%= pkg.author %>\n' +
' * <%= pkg.license %> License\n */',
microbanner: '/*! <%= pkg.name %> <%= pkg.version %> (Custom Build) | <%= pkg.license %> */'
},
qunit: {
files: ['test/index.html']
},
stripdefine: {
build: {
src: ['dist/modernizr-build.js']
}
},
lint: {
files: [
'grunt.js',
'modernizr.js',
'src/*.js',
'feature-detects/*.js'
]
},
min: {
dist: {
src: [
'<banner:meta.banner>',
'modernizr.js'
'<banner:meta.microbanner>',
'dist/modernizr-build.js'
],
dest: 'modernizr.min.js'
dest: 'dist/modernizr-build.min.js'
}
},
watch: {
Expand Down Expand Up @@ -57,13 +63,77 @@ module.exports = function( grunt ) {
DocumentTouch: true,
TEST: true,
SVGFEColorMatrixElement : true,
Blob: true
Blob: true,
define: true,
require: true
}
}
},
clean: {
build: ['build', 'dist'],
postbuild: ['build']
},
copy: {
build: {
files: {
'dist/modernizr-build.js': 'build/src/modernizr-build.js'
}
}
},
requirejs: {
compile: {
options: {
dir: 'build',
appDir: '.',
baseUrl: 'src',
optimize: "none",
optimizeCss: "none",
paths: {
"test" : "../feature-detects"
},
modules : [{
"name" : "modernizr-build",
"include" : ["modernizr-init"],
"create" : true
}],
fileExclusionRegExp: /^(.git|node_modules|modulizr|media|test)$/,
wrap: {
start: ";(function(window, document, undefined){",
end: "})(this, document);"
},
onBuildWrite: function (id, path, contents) {
if ((/define\(.*?\{/).test(contents)) {
//Remove AMD ceremony for use without require.js or almond.js
contents = contents.replace(/define\(.*?\{/, '');

contents = contents.replace(/\}\);\s*?$/,'');

if ( !contents.match(/Modernizr\.addTest\(/) && !contents.match(/Modernizr\.addAsyncTest\(/) ) {
//remove last return statement and trailing })
contents = contents.replace(/return.*[^return]*$/,'');
}
}
else if ((/require\([^\{]*?\{/).test(contents)) {
contents = contents.replace(/require[^\{]+\{/, '');
contents = contents.replace(/\}\);\s*$/,'');
}
return contents;
}
}
}
}
});

grunt.registerTask('default', 'min');
// Strip define fn
grunt.registerMultiTask('stripdefine', "Strip define call from dist file", function() {
var mod = grunt.file.read( this.file.src[0] ).replace('define("modernizr-init",[], function(){});', '');
grunt.file.write( 'dist/modernizr-build.js', mod );
});

// Travis CI task.
grunt.registerTask('travis', 'qunit');

// Build
grunt.loadNpmTasks('grunt-contrib');
grunt.registerTask('build', 'clean requirejs copy clean:postbuild stripdefine min');
grunt.registerTask('default', 'build');
};
28 changes: 28 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "Modernizr",
"version": "3.0.0pre",
"description": "Modernizr is a JavaScript library that detects HTML5 and CSS3 features in the user’s browser.",
"directories": {
"test": "test"
},
"dependencies": {},
"devDependencies": {
"grunt": "~0.3.17",
"grunt-contrib": "~0.3.0"
},
"scripts": {
"test": "grunt qunit"
},
"repository": {
"type": "git",
"url": "git://github.com/Modernizr/Modernizr.git"
},
"keywords": [
"html5",
"css3",
"browser",
"feature detection"
],
"author": "Faruk Ates, Paul Irish, Alex Sexton, Ryan Seddon, Alexander Farkas",
"license": "MIT"
}

0 comments on commit 0103e1c

Please sign in to comment.