Permalink
Browse files

Add Grunt.

Can now do the following: Run JS Hint, check that the version in the jquery.json file matches what's in packages.json file, update the banner in the jquery.superLabels.js file, and automatically minify.
  • Loading branch information...
1 parent 7348e76 commit c5aec2cc42ed122432ec33f011d94500b8a4d0d2 @remybach committed Mar 5, 2013
Showing with 205 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +81 −0 Gruntfile.js
  3. +25 −0 package.json
  4. +32 −0 tasks/checkBanner.js
  5. +29 −0 tasks/checkjQueryJSON.js
  6. +37 −0 tasks/minify.js
View
@@ -0,0 +1 @@
+node_modules/
View
@@ -0,0 +1,81 @@
+/*global module:false*/
+
+module.exports = function(grunt) {
+
+ // Project configuration.
+ grunt.initConfig({
+ pkg: grunt.file.readJSON('package.json'),
+ meta: {
+ version: '<%= pkg.version %>',
+ banner: '/*!\n' +
+ ' * Title: jQuery Super Labels Plugin - Give your forms a helping of awesome!\n' +
+ ' * Author: Rémy Bach\n' +
+ ' * Version: <%= pkg.version %>\n' +
+ ' * License: http://remybach.mit-license.org\n' +
+ ' * Url: http://github.com/remybach/jQuery.superLabels\n' +
+ ' * Description:\n' +
+ ' * This plugin allows you to display your form labels on top of your form fields, saving you space on your page.\n' +
+ ' */\n'+
+ ';'
+ },
+ jshint: {
+ files: ['jquery.superLabels.js'],
+ options: {
+ // Enforcing
+ curly: true,
+ immed: true,
+ indent: 4,
+ latedef: true,
+ newcap: true,
+ noarg: true,
+ noempty: true,
+ strict: true,
+ sub: true,
+ trailing: true,
+ undef: true,
+ unused: true,
+
+ // Relaxing
+ boss: true,
+ eqnull: true,
+ globalstrict: true,
+ iterator: true,
+ loopfunc: true,
+ smarttabs: true,
+
+ // Environments
+ browser: true,
+ jquery: true,
+ nonstandard: true,
+ white: false
+ }
+ },
+ checkBanner: {
+ filename: 'jquery.superLabels.js'
+ },
+ checkjQueryJSON: {
+ filename: 'superLabels.jquery.json'
+ },
+ minify: {
+ dest: 'jquery.superLabels.min.js',
+ filename: 'jquery.superLabels.js'
+ },
+ uglify: {
+ options: {
+ banner: '<%= meta.banner %>'
+ },
+ dist: {
+ files: {
+ 'jquery.superLabels.min.js': ['<banner:meta.banner>', 'jquery.superLabels.min.js']
+ }
+ }
+ }
+ });
+
+ grunt.loadNpmTasks('grunt-contrib-jshint');
+ grunt.loadNpmTasks('grunt-contrib-uglify');
+ grunt.loadTasks('tasks');
+
+ // Default task - Run JS Hint, check the version in the jquery.json file matches what's in packages.json, update the banner in the superlabels file, and minify.
+ grunt.registerTask('default', ["jshint", "checkjQueryJSON", "checkBanner", "minify"]);
+};
View
@@ -0,0 +1,25 @@
+{
+ "name": "jQuery.superLabels",
+ "version": "2.0.3",
+ "description": "Give your forms a helping of awesome!",
+ "homepage": "http://remy.bach.me.uk/superlabels_demo/",
+ "bugs": {
+ "url": "https://github.com/remybach/jQuery.superLabels/issues"
+ },
+ "contributors": [
+ {
+ "name": "Rémy Bach",
+ "url": "http://remy.bach.me.uk"
+ }
+ ],
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/remybach/jQuery.superLabels"
+ },
+ "private": true,
+ "devDependencies": {
+ "grunt": "0.4.0rc7",
+ "grunt-contrib-jshint": "0.1.1",
+ "grunt-contrib-uglify": "0.1.1"
+ }
+}
View
@@ -0,0 +1,32 @@
+module.exports = function(grunt) {
+ 'use strict';
+
+ grunt.registerTask('checkBanner', 'Update the banner of the given file.', function() {
+ var banner, filename;
+
+ grunt.config.requires('minify.filename');
+
+ banner = grunt.config('meta.banner');
+ filename = grunt.config('minify.filename');
+
+ var src;
+
+ // Warn on and remove invalid source files (if nonull was set).
+ if (!grunt.file.exists(filename)) {
+ grunt.log.warn('Source file not found at "' + filename + '"');
+ return false;
+ }
+
+ grunt.log.writeln('Updating Banner for: '+filename);
+
+ src = grunt.file.read(filename);
+
+ // Strip out the existing banner
+ src = src.replace(/\/\*![\r\n] \*\sTitle(.|[\r\n])*?\*\/[\r\n];/gm, banner);
+
+ grunt.file.write(filename, src);
+
+ grunt.log.writeln('Done updating banner in: '+filename);
+
+ });
+};
@@ -0,0 +1,29 @@
+module.exports = function(grunt) {
+ 'use strict';
+
+ grunt.registerTask('checkjQueryJSON', 'Update the version number in the jquery.json file.', function() {
+ var filename;
+
+ grunt.config.requires('checkjQueryJSON.filename');
+
+ filename = grunt.config('checkjQueryJSON.filename');
+
+ var json;
+
+ // Warn on and remove invalid source files (if nonull was set).
+ if (!grunt.file.exists(filename)) {
+ grunt.log.warn('Source file not found at "' + filename + '"');
+ return false;
+ }
+
+ grunt.log.writeln('Updating Banner for: '+filename);
+
+ json = grunt.file.readJSON(filename);
+
+ json.version = grunt.config('meta.version');
+
+ grunt.file.write(filename, JSON.stringify(json));
+
+ grunt.log.writeln('Done updating version in: '+filename);
+ });
+};
View
@@ -0,0 +1,37 @@
+module.exports = function(grunt) {
+ 'use strict';
+
+ grunt.registerTask('minify', 'Strip out some of the guff and uglify.', function() {
+ var dest,
+ filename;
+
+ // Fail task if we don't know which file/s to minify or where to put them
+ grunt.config.requires('minify.dest');
+ grunt.config.requires('minify.filename');
+
+ dest = grunt.config('minify.dest');
+ filename = grunt.config('minify.filename');
+
+ var src;
+
+ // Warn on and remove invalid source files (if nonull was set).
+ if (!grunt.file.exists(filename)) {
+ grunt.log.warn('Source file not found at "' + filename + '"');
+ return false;
+ }
+
+ grunt.log.writeln('Minifying: '+filename);
+
+ src = grunt.file.read(filename);
+
+ // Strip out anything we don't want in the minified version.
+ src = src.replace(/\/\* nominify \*\/(.|[\r\n])*?\/\* \/nominify \*\//gm, '');
+
+ grunt.file.write(dest, src);
+
+ grunt.task.run('uglify');
+
+ grunt.log.writeln('Done minifying, stripped and uglified file is at: '+dest);
+
+ });
+};

0 comments on commit c5aec2c

Please sign in to comment.