Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit c5aec2cc42ed122432ec33f011d94500b8a4d0d2 1 parent 7348e76
Rémy Bach authored
1  .gitignore
... ... @@ -0,0 +1 @@
  1 +node_modules/
81 Gruntfile.js
... ... @@ -0,0 +1,81 @@
  1 +/*global module:false*/
  2 +
  3 +module.exports = function(grunt) {
  4 +
  5 + // Project configuration.
  6 + grunt.initConfig({
  7 + pkg: grunt.file.readJSON('package.json'),
  8 + meta: {
  9 + version: '<%= pkg.version %>',
  10 + banner: '/*!\n' +
  11 + ' * Title: jQuery Super Labels Plugin - Give your forms a helping of awesome!\n' +
  12 + ' * Author: Rémy Bach\n' +
  13 + ' * Version: <%= pkg.version %>\n' +
  14 + ' * License: http://remybach.mit-license.org\n' +
  15 + ' * Url: http://github.com/remybach/jQuery.superLabels\n' +
  16 + ' * Description:\n' +
  17 + ' * This plugin allows you to display your form labels on top of your form fields, saving you space on your page.\n' +
  18 + ' */\n'+
  19 + ';'
  20 + },
  21 + jshint: {
  22 + files: ['jquery.superLabels.js'],
  23 + options: {
  24 + // Enforcing
  25 + curly: true,
  26 + immed: true,
  27 + indent: 4,
  28 + latedef: true,
  29 + newcap: true,
  30 + noarg: true,
  31 + noempty: true,
  32 + strict: true,
  33 + sub: true,
  34 + trailing: true,
  35 + undef: true,
  36 + unused: true,
  37 +
  38 + // Relaxing
  39 + boss: true,
  40 + eqnull: true,
  41 + globalstrict: true,
  42 + iterator: true,
  43 + loopfunc: true,
  44 + smarttabs: true,
  45 +
  46 + // Environments
  47 + browser: true,
  48 + jquery: true,
  49 + nonstandard: true,
  50 + white: false
  51 + }
  52 + },
  53 + checkBanner: {
  54 + filename: 'jquery.superLabels.js'
  55 + },
  56 + checkjQueryJSON: {
  57 + filename: 'superLabels.jquery.json'
  58 + },
  59 + minify: {
  60 + dest: 'jquery.superLabels.min.js',
  61 + filename: 'jquery.superLabels.js'
  62 + },
  63 + uglify: {
  64 + options: {
  65 + banner: '<%= meta.banner %>'
  66 + },
  67 + dist: {
  68 + files: {
  69 + 'jquery.superLabels.min.js': ['<banner:meta.banner>', 'jquery.superLabels.min.js']
  70 + }
  71 + }
  72 + }
  73 + });
  74 +
  75 + grunt.loadNpmTasks('grunt-contrib-jshint');
  76 + grunt.loadNpmTasks('grunt-contrib-uglify');
  77 + grunt.loadTasks('tasks');
  78 +
  79 + // 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.
  80 + grunt.registerTask('default', ["jshint", "checkjQueryJSON", "checkBanner", "minify"]);
  81 +};
25 package.json
... ... @@ -0,0 +1,25 @@
  1 +{
  2 + "name": "jQuery.superLabels",
  3 + "version": "2.0.3",
  4 + "description": "Give your forms a helping of awesome!",
  5 + "homepage": "http://remy.bach.me.uk/superlabels_demo/",
  6 + "bugs": {
  7 + "url": "https://github.com/remybach/jQuery.superLabels/issues"
  8 + },
  9 + "contributors": [
  10 + {
  11 + "name": "Rémy Bach",
  12 + "url": "http://remy.bach.me.uk"
  13 + }
  14 + ],
  15 + "repository": {
  16 + "type": "git",
  17 + "url": "https://github.com/remybach/jQuery.superLabels"
  18 + },
  19 + "private": true,
  20 + "devDependencies": {
  21 + "grunt": "0.4.0rc7",
  22 + "grunt-contrib-jshint": "0.1.1",
  23 + "grunt-contrib-uglify": "0.1.1"
  24 + }
  25 +}
32 tasks/checkBanner.js
... ... @@ -0,0 +1,32 @@
  1 +module.exports = function(grunt) {
  2 + 'use strict';
  3 +
  4 + grunt.registerTask('checkBanner', 'Update the banner of the given file.', function() {
  5 + var banner, filename;
  6 +
  7 + grunt.config.requires('minify.filename');
  8 +
  9 + banner = grunt.config('meta.banner');
  10 + filename = grunt.config('minify.filename');
  11 +
  12 + var src;
  13 +
  14 + // Warn on and remove invalid source files (if nonull was set).
  15 + if (!grunt.file.exists(filename)) {
  16 + grunt.log.warn('Source file not found at "' + filename + '"');
  17 + return false;
  18 + }
  19 +
  20 + grunt.log.writeln('Updating Banner for: '+filename);
  21 +
  22 + src = grunt.file.read(filename);
  23 +
  24 + // Strip out the existing banner
  25 + src = src.replace(/\/\*![\r\n] \*\sTitle(.|[\r\n])*?\*\/[\r\n];/gm, banner);
  26 +
  27 + grunt.file.write(filename, src);
  28 +
  29 + grunt.log.writeln('Done updating banner in: '+filename);
  30 +
  31 + });
  32 +};
29 tasks/checkjQueryJSON.js
... ... @@ -0,0 +1,29 @@
  1 +module.exports = function(grunt) {
  2 + 'use strict';
  3 +
  4 + grunt.registerTask('checkjQueryJSON', 'Update the version number in the jquery.json file.', function() {
  5 + var filename;
  6 +
  7 + grunt.config.requires('checkjQueryJSON.filename');
  8 +
  9 + filename = grunt.config('checkjQueryJSON.filename');
  10 +
  11 + var json;
  12 +
  13 + // Warn on and remove invalid source files (if nonull was set).
  14 + if (!grunt.file.exists(filename)) {
  15 + grunt.log.warn('Source file not found at "' + filename + '"');
  16 + return false;
  17 + }
  18 +
  19 + grunt.log.writeln('Updating Banner for: '+filename);
  20 +
  21 + json = grunt.file.readJSON(filename);
  22 +
  23 + json.version = grunt.config('meta.version');
  24 +
  25 + grunt.file.write(filename, JSON.stringify(json));
  26 +
  27 + grunt.log.writeln('Done updating version in: '+filename);
  28 + });
  29 +};
37 tasks/minify.js
... ... @@ -0,0 +1,37 @@
  1 +module.exports = function(grunt) {
  2 + 'use strict';
  3 +
  4 + grunt.registerTask('minify', 'Strip out some of the guff and uglify.', function() {
  5 + var dest,
  6 + filename;
  7 +
  8 + // Fail task if we don't know which file/s to minify or where to put them
  9 + grunt.config.requires('minify.dest');
  10 + grunt.config.requires('minify.filename');
  11 +
  12 + dest = grunt.config('minify.dest');
  13 + filename = grunt.config('minify.filename');
  14 +
  15 + var src;
  16 +
  17 + // Warn on and remove invalid source files (if nonull was set).
  18 + if (!grunt.file.exists(filename)) {
  19 + grunt.log.warn('Source file not found at "' + filename + '"');
  20 + return false;
  21 + }
  22 +
  23 + grunt.log.writeln('Minifying: '+filename);
  24 +
  25 + src = grunt.file.read(filename);
  26 +
  27 + // Strip out anything we don't want in the minified version.
  28 + src = src.replace(/\/\* nominify \*\/(.|[\r\n])*?\/\* \/nominify \*\//gm, '');
  29 +
  30 + grunt.file.write(dest, src);
  31 +
  32 + grunt.task.run('uglify');
  33 +
  34 + grunt.log.writeln('Done minifying, stripped and uglified file is at: '+dest);
  35 +
  36 + });
  37 +};

0 comments on commit c5aec2c

Please sign in to comment.
Something went wrong with that request. Please try again.