diff --git a/Gruntfile.js b/Gruntfile.js index a4c48ea..dbc05e0 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -2,79 +2,78 @@ module.exports = function(grunt) { require('load-grunt-tasks')(grunt); - pkg: grunt.file.readJSON('package.json'), + var concatAnim; + grunt.initConfig({ - // Concatenate CSS files + pkg: grunt.file.readJSON('package.json'), + concat: { dist: { - src: [ - // _base.css required for .animated helper class - 'source/_base.css', - 'source/**/*.css' - ], + src: [ 'source/_base.css', 'source/**/*.css' ], // _base.css required for .animated helper class dest: 'animate.css' } }, - // Auto-prefix CSS properties using Can I Use? - autoprefixer: { + autoprefixer: { // https://github.com/nDmitry/grunt-autoprefixer options: { browsers: ['last 3 versions', 'bb 10', 'android 3'] }, no_dest: { - // File to output - src: 'animate.css' - }, + src: 'animate.css' // output file + } }, - // Minify CSS cssmin: { minify: { src: ['animate.css'], dest: 'animate.min.css', - }, + } }, - // Watch files for changes watch: { css: { - files: [ - 'source/**/*', - '!node_modules', - 'animate-config.json' - ], - // Run Sass, autoprefixer, and CSSO - tasks: ['concat-anim', 'autoprefixer', 'cssmin'], + files: [ 'source/**/*', 'animate-config.json' ], + tasks: ['default'] } } }); - // Register our tasks - grunt.registerTask('default', ['concat-anim', 'autoprefixer', 'cssmin', 'watch']); + // fuction to perform custom task + concatAnim = function () { - grunt.registerTask('concat-anim', 'Concatenates activated animations', function () { - var config = grunt.file.readJSON('animate-config.json'), - target = [ 'source/_base.css' ], - count = 0 + var categories = grunt.file.readJSON('animate-config.json'), + category, files, file, + target = [ 'source/_base.css' ], + count = 0; - for (var cat in config) { - for (var file in config[cat]) { - if (config[cat][file]) { - target.push('source/' + cat + '/' + file + '.css') - count++ + for ( category in categories ) { + if ( categories.hasOwnProperty(category) ) { + files = categories[category] + for (file in files) { + if ( files.hasOwnProperty(file) && files[file] ) { + target.push('source/' + category + '/' + file + '.css'); + count += 1; + } } } } if (!count) { - grunt.log.writeln('No animations activated.') + grunt.log.writeln('No animations activated.'); + } else { + grunt.log.writeln(count + (count > 1 ? ' animations' : ' animation') + ' activated.'); } - grunt.log.writeln(count + (count > 1 ? ' animations' : ' animation') + ' activated.') + grunt.config('concat', { 'animate.css': target }); + grunt.task.run('concat'); + + }; + + // register task + grunt.registerTask('concat-anim', 'Concatenates activated animations', concatAnim); // custom task + grunt.registerTask('default', ['concat-anim', 'autoprefixer', 'cssmin']); + grunt.registerTask('dev', ['watch']); - grunt.config('concat', { 'animate.css': target }) - grunt.task.run('concat') - }); };