animate.css/gulpfile.js

108 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: ['> 1%', 'last 2 versions', 'Firefox ESR'],
cascade: false,
2015-12-26 17:36:37 +01:00
},
minRename: {
suffix: '.min',
2015-12-26 17:36:37 +01:00
},
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 %>',
2017-11-16 00:20:46 +01:00
' */\n\n',
].join('\n'),
2015-12-26 17:36:37 +01:00
};
2015-12-14 20:41:16 +01:00
// ----------------------------
// Gulp task definitions
// ----------------------------
2015-12-26 17:36:37 +01:00
gulp.task('createCSS', function() {
2017-11-16 00:20:46 +01:00
return gulp
.src(activatedAnimations)
2015-12-26 17:36:37 +01:00
.pipe(concat(opts.concatName))
2017-11-16 00:20:46 +01:00
.pipe(postcss([autoprefixer(opts.autoprefixer)]))
2015-12-26 17:36:37 +01:00
.pipe(gulp.dest(opts.destPath))
2017-11-16 00:20:46 +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() {
2017-11-16 00:20:46 +01:00
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
});
gulp.task('default', gulp.series('createCSS', 'addHeader'));
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')),
2017-11-16 00:20:46 +01:00
category,
files,
file,
target = [],
2015-12-14 20:03:02 +01:00
count = 0;
for (category in categories) {
if (categories.hasOwnProperty(category)) {
files = categories[category];
for (file in files) {
2017-11-16 00:20:46 +01:00
if (files[file]) {
// marked as true
target.push('source/' + category + '/' + file + '.css');
count += 1;
}
2015-12-14 20:03:02 +01:00
}
}
}
// prepend base CSS
target.push('source/_base.css');
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;
}