Refactored Gruntfile.js

This commit is contained in:
Sarbbottam Bandyopadhyay 2014-02-24 04:25:37 +05:30
parent 0bc05a7559
commit db8e990dfc

View file

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