animate.css/gulpfile.js

105 lines
2.5 KiB
JavaScript
Raw Normal View History

2015-12-14 20:03:02 +01:00
// Utilities
2016-02-11 19:15:33 +01:00
var autoprefixer = require('autoprefixer');
var cssnano = require('cssnano');
2015-12-14 20:03:02 +01:00
var fs = require('fs');
// Gulp
var gulp = require('gulp');
// Gulp plugins
var concat = require('gulp-concat');
2016-02-11 19:15:33 +01:00
var gutil = require('gulp-util');
2015-12-14 20:41:16 +01:00
var header = require('gulp-header');
2016-02-11 19:15:33 +01:00
var postcss = require('gulp-postcss');
2015-12-14 20:41:16 +01:00
var rename = require('gulp-rename');
2016-02-11 19:15:33 +01:00
var runSequence = require('run-sequence');
2015-12-14 20:03:02 +01:00
// Misc/global vars
2015-12-26 17:36:37 +01:00
var pkg = JSON.parse(fs.readFileSync('package.json'));
2015-12-14 20:41:16 +01:00
var activatedAnimations = activateAnimations();
2015-12-26 17:36:37 +01:00
// Task options
var opts = {
destPath: './',
concatName: 'animate.css',
autoprefixer: {
browsers: ['last 2 versions'],
cascade: false
},
minRename: {
suffix: '.min'
},
banner: [
'@charset "UTF-8";\n',
'/*!',
' * <%= name %> -<%= homepage %>',
' * Version - <%= version %>',
' * Licensed under the MIT license - http://opensource.org/licenses/MIT',
' *',
' * Copyright (c) <%= new Date().getFullYear() %> <%= author.name %>',
' */\n\n'
].join('\n')
};
2015-12-14 20:41:16 +01:00
// ----------------------------
// Gulp task definitions
// ----------------------------
gulp.task('default', function() {
2015-12-26 17:36:37 +01:00
runSequence('createCSS', 'addHeader');
2015-12-14 20:41:16 +01:00
});
2015-12-26 17:36:37 +01:00
gulp.task('createCSS', function() {
2015-12-14 20:41:16 +01:00
return gulp.src(activatedAnimations)
2015-12-26 17:36:37 +01:00
.pipe(concat(opts.concatName))
2016-02-11 19:15:33 +01:00
.pipe(postcss([
autoprefixer(opts.autoprefixer)
]))
2015-12-26 17:36:37 +01:00
.pipe(gulp.dest(opts.destPath))
2016-02-11 19:15:33 +01:00
.pipe(postcss([
cssnano({reduceIdents: {keyframes: false}})
]))
2015-12-26 17:36:37 +01:00
.pipe(rename(opts.minRename))
.pipe(gulp.dest(opts.destPath));
2015-12-14 20:41:16 +01:00
});
2015-12-26 14:27:24 +01:00
gulp.task('addHeader', function() {
return gulp.src('*.css')
2015-12-26 17:36:37 +01:00
.pipe(header(opts.banner, pkg))
.pipe(gulp.dest(opts.destPath));
2015-12-26 14:27:24 +01:00
});
2015-12-14 20:41:16 +01:00
// ----------------------------
// Helpers/functions
// ----------------------------
2015-12-14 20:03:02 +01:00
// Read the config file and return an array of the animations to be activated
2015-12-14 20:41:16 +01:00
function activateAnimations() {
2015-12-14 20:03:02 +01:00
var categories = JSON.parse(fs.readFileSync('animate-config.json')),
category, files, file,
target = [ 'source/_base.css' ],
count = 0;
for (category in categories) {
if (categories.hasOwnProperty(category)) {
files = categories[category];
2016-01-02 18:57:22 +01:00
for (var i = 0; i < files.length; ++i) {
target.push('source/' + category + '/' + files[i] + '.css');
count += 1;
2015-12-14 20:03:02 +01:00
}
}
}
if (!count) {
gutil.log('No animations activated.');
} else {
gutil.log(count + (count > 1 ? ' animations' : ' animation') + ' activated.');
}
return target;
}