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: {
|
2017-12-10 04:18:47 +01:00
|
|
|
browsers: ['> 1%', 'last 2 versions', 'Firefox ESR'],
|
2018-07-24 00:25:37 +02:00
|
|
|
cascade: false,
|
2015-12-26 17:36:37 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
minRename: {
|
2018-07-24 00:25:37 +02:00
|
|
|
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',
|
2018-07-24 00:25:37 +02:00
|
|
|
].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
|
|
|
});
|
|
|
|
|
2018-07-24 00:25:37 +02: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,
|
2018-07-24 00:44:09 +02:00
|
|
|
target = [],
|
2015-12-14 20:03:02 +01:00
|
|
|
count = 0;
|
|
|
|
|
|
|
|
for (category in categories) {
|
|
|
|
if (categories.hasOwnProperty(category)) {
|
|
|
|
files = categories[category];
|
|
|
|
|
2017-11-10 01:33:55 +01:00
|
|
|
for (file in files) {
|
2017-11-16 00:20:46 +01:00
|
|
|
if (files[file]) {
|
|
|
|
// marked as true
|
2017-11-10 01:33:55 +01:00
|
|
|
target.push('source/' + category + '/' + file + '.css');
|
|
|
|
count += 1;
|
|
|
|
}
|
2015-12-14 20:03:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-24 00:44:09 +02: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;
|
2015-12-19 14:34:07 +01:00
|
|
|
}
|