forked from animate-css/animate.css
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
107 lines (90 loc) · 2.51 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Utilities
var autoprefixer = require('autoprefixer');
var cssnano = require('cssnano');
var fs = require('fs');
// Gulp
var gulp = require('gulp');
// Gulp plugins
var concat = require('gulp-concat');
var gutil = require('gulp-util');
var header = require('gulp-header');
var postcss = require('gulp-postcss');
var rename = require('gulp-rename');
var runSequence = require('run-sequence');
// Misc/global vars
var pkg = JSON.parse(fs.readFileSync('package.json'));
var activatedAnimations = activateAnimations();
// Task options
var opts = {
destPath: './',
concatName: 'animate.css',
autoprefixer: {
browsers: ['> 1%', 'last 2 versions', 'Firefox ESR'],
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'),
};
// ----------------------------
// Gulp task definitions
// ----------------------------
gulp.task('default', function() {
runSequence('createCSS', 'addHeader');
});
gulp.task('createCSS', function() {
return gulp
.src(activatedAnimations)
.pipe(concat(opts.concatName))
.pipe(postcss([autoprefixer(opts.autoprefixer)]))
.pipe(gulp.dest(opts.destPath))
.pipe(postcss([cssnano({reduceIdents: {keyframes: false}})]))
.pipe(rename(opts.minRename))
.pipe(gulp.dest(opts.destPath));
});
gulp.task('addHeader', function() {
return gulp
.src('*.css')
.pipe(header(opts.banner, pkg))
.pipe(gulp.dest(opts.destPath));
});
// ----------------------------
// Helpers/functions
// ----------------------------
// Read the config file and return an array of the animations to be activated
function activateAnimations() {
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];
for (file in files) {
if (files[file]) {
// marked as true
target.push('source/' + category + '/' + file + '.css');
count += 1;
}
}
}
}
if (!count) {
gutil.log('No animations activated.');
} else {
gutil.log(count + (count > 1 ? ' animations' : ' animation') + ' activated.');
}
return target;
}