Completed
Push — master ( bc288c...0733c5 )
by Xu
428:11 queued 388:29
created

resources/lib/animate.css/gulpfile.js   A

Complexity

Total Complexity 10
Complexity/F 2.5

Size

Lines of Code 106
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 1
dl 0
loc 106
rs 10
wmc 10
mnd 4
bc 10
fnc 4
bpm 2.5
cpm 2.5
noi 0

4 Functions

Rating   Name   Duplication   Size   Complexity  
C gulpfile.js ➔ activateAnimations 0 30 7
A gulp.task(ꞌcreateCSSꞌ) 0 10 1
A gulp.task(ꞌdefaultꞌ) 0 3 1
A gulp.task(ꞌaddHeaderꞌ) 0 6 1
1
// Utilities
2
var autoprefixer = require('autoprefixer');
3
var cssnano = require('cssnano');
4
var fs = require('fs');
5
6
// Gulp
7
var gulp = require('gulp');
8
9
// Gulp plugins
10
var concat = require('gulp-concat');
11
var gutil = require('gulp-util');
12
var header = require('gulp-header');
13
var postcss = require('gulp-postcss');
14
var rename = require('gulp-rename');
15
var runSequence = require('run-sequence');
16
17
// Misc/global vars
18
var pkg = JSON.parse(fs.readFileSync('package.json'));
19
var activatedAnimations = activateAnimations();
20
21
// Task options
22
var opts = {
23
  destPath: './',
24
  concatName: 'animate.css',
25
26
  autoprefixer: {
27
    browsers: ['> 1%', 'last 2 versions', 'Firefox ESR'],
28
    cascade: false,
29
  },
30
31
  minRename: {
32
    suffix: '.min',
33
  },
34
35
  banner: [
36
    '@charset "UTF-8";\n',
37
    '/*!',
38
    ' * <%= name %> -<%= homepage %>',
39
    ' * Version - <%= version %>',
40
    ' * Licensed under the MIT license - http://opensource.org/licenses/MIT',
41
    ' *',
42
    ' * Copyright (c) <%= new Date().getFullYear() %> <%= author.name %>',
43
    ' */\n\n',
44
  ].join('\n'),
45
};
46
47
// ----------------------------
48
// Gulp task definitions
49
// ----------------------------
50
51
gulp.task('default', function() {
52
  runSequence('createCSS', 'addHeader');
53
});
54
55
gulp.task('createCSS', function() {
56
  return gulp
57
    .src(activatedAnimations)
58
    .pipe(concat(opts.concatName))
59
    .pipe(postcss([autoprefixer(opts.autoprefixer)]))
60
    .pipe(gulp.dest(opts.destPath))
61
    .pipe(postcss([cssnano({reduceIdents: {keyframes: false}})]))
62
    .pipe(rename(opts.minRename))
63
    .pipe(gulp.dest(opts.destPath));
64
});
65
66
gulp.task('addHeader', function() {
67
  return gulp
68
    .src('*.css')
69
    .pipe(header(opts.banner, pkg))
70
    .pipe(gulp.dest(opts.destPath));
71
});
72
73
// ----------------------------
74
// Helpers/functions
75
// ----------------------------
76
77
// Read the config file and return an array of the animations to be activated
78
function activateAnimations() {
79
  var categories = JSON.parse(fs.readFileSync('animate-config.json')),
80
    category,
81
    files,
82
    file,
83
    target = ['source/_base.css'],
84
    count = 0;
85
86
  for (category in categories) {
87
    if (categories.hasOwnProperty(category)) {
88
      files = categories[category];
89
90
      for (file in files) {
91
        if (files[file]) {
92
          // marked as true
93
          target.push('source/' + category + '/' + file + '.css');
94
          count += 1;
95
        }
96
      }
97
    }
98
  }
99
100
  if (!count) {
101
    gutil.log('No animations activated.');
102
  } else {
103
    gutil.log(count + (count > 1 ? ' animations' : ' animation') + ' activated.');
104
  }
105
106
  return target;
107
}
108