|
| 1 | +module.exports = function(grunt) { |
| 2 | + |
| 3 | + require('load-grunt-tasks')(grunt); |
| 4 | + |
| 5 | + var concatAnim; |
| 6 | + |
| 7 | + grunt.initConfig({ |
| 8 | + |
| 9 | + pkg: grunt.file.readJSON('package.json'), |
| 10 | + |
| 11 | + concat: { |
| 12 | + dist: { |
| 13 | + src: [ 'source/_base.css', 'source/**/*.css' ], // _base.css required for .animated helper class |
| 14 | + dest: 'animate.css' |
| 15 | + } |
| 16 | + }, |
| 17 | + |
| 18 | + autoprefixer: { // https://github.com/nDmitry/grunt-autoprefixer |
| 19 | + options: { |
| 20 | + browsers: ['last 2 versions', 'bb 10'] |
| 21 | + }, |
| 22 | + no_dest: { |
| 23 | + src: 'animate.css' // output file |
| 24 | + } |
| 25 | + }, |
| 26 | + |
| 27 | + cssmin: { |
| 28 | + minify: { |
| 29 | + src: ['animate.css'], |
| 30 | + dest: 'animate.min.css', |
| 31 | + } |
| 32 | + }, |
| 33 | + |
| 34 | + watch: { |
| 35 | + css: { |
| 36 | + files: [ 'source/**/*', 'animate-config.json' ], |
| 37 | + tasks: ['default'] |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + }); |
| 42 | + |
| 43 | + // fuction to perform custom task |
| 44 | + concatAnim = function () { |
| 45 | + |
| 46 | + var categories = grunt.file.readJSON('animate-config.json'), |
| 47 | + category, files, file, |
| 48 | + target = [ 'source/_base.css' ], |
| 49 | + count = 0; |
| 50 | + |
| 51 | + for ( category in categories ) { |
| 52 | + if ( categories.hasOwnProperty(category) ) { |
| 53 | + files = categories[category] |
| 54 | + for (file in files) { |
| 55 | + if ( files.hasOwnProperty(file) && files[file] ) { |
| 56 | + target.push('source/' + category + '/' + file + '.css'); |
| 57 | + count += 1; |
| 58 | + } |
| 59 | + } |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + if (!count) { |
| 64 | + grunt.log.writeln('No animations activated.'); |
| 65 | + } else { |
| 66 | + grunt.log.writeln(count + (count > 1 ? ' animations' : ' animation') + ' activated.'); |
| 67 | + } |
| 68 | + |
| 69 | + grunt.config('concat', { 'animate.css': target }); |
| 70 | + grunt.task.run('concat'); |
| 71 | + |
| 72 | + }; |
| 73 | + |
| 74 | + // register task |
| 75 | + grunt.registerTask('concat-anim', 'Concatenates activated animations', concatAnim); // custom task |
| 76 | + grunt.registerTask('default', ['concat-anim', 'autoprefixer', 'cssmin']); |
| 77 | + grunt.registerTask('dev', ['watch']); |
| 78 | + |
| 79 | +}; |
0 commit comments