forked from nozzle/nzAnimate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
96 lines (84 loc) · 2.97 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
var gulp = require('gulp');
var rename = require('gulp-rename');
var beep = require('beepbeep');
var gutil = require('gulp-util');
var plumber = require('gulp-plumber');
var uglify = require('gulp-uglifyjs');
var stylus = require('gulp-stylus');
var tap = require('gulp-tap');
var hjson = require('hjson');
var nib = require('nib');
var config;
gulp.task('opts', optsTask);
gulp.task('replaceOpts', replaceOptsTask);
gulp.task('stylus', ['opts', 'replaceOpts'], stylusTask);
gulp.task('watch', watchTask);
gulp.task('build', ['stylus']);
gulp.task('default', ['build', 'watch']);
function optsTask() {
return gulp.src('./src/config.hjson')
.pipe(tap(function(file) {
config = hjson.parse(String(file.contents));
}));
}
function replaceOptsTask() {
return gulp.src('./src/nzAnimate.styl')
.pipe(tap(function(file) {
var contents = String(file.contents);
contents = contents.replace(/\{\{([\d\D\s]+?)\}\}/g, function(match, inner) {
switch (inner) {
case 'vendors':
return config.vendors.join(' ');
case 'ieSupport':
return config.ieSupport;
case 'animations':
return config.animations.join(' ');
case 'defaultSpeed':
return config.speed.default;
case 'speedStart':
return config.speed.start;
case 'speedEnd':
return Math.floor((config.speed.end - config.speed.start) / config.speed.increment);
case 'speedIncrement':
return config.speed.increment;
case 'staggerStart':
return config.stagger.start;
case 'staggerEnd':
return Math.floor((config.stagger.end - config.stagger.start) / config.stagger.increment);
case 'staggerIncrement':
return config.stagger.increment;
default:
return match;
}
});
file.contents = new Buffer(String(contents));
return file;
}))
.pipe(rename(".nzAnimate.styl.temp"))
.pipe(gulp.dest('./'));
}
function stylusTask() {
gulp.src('./.nzAnimate.styl.temp')
.pipe(stylus({
use: [nib()],
compress: false,
"include css": true
}))
.pipe(rename("nzAnimate.css"))
.pipe(gulp.dest('./dist/'));
return gulp.src('./.nzAnimate.styl.temp')
.pipe(stylus({
use: [nib()],
compress: true,
"include css": true
}))
.pipe(rename("nzAnimate.min.css"))
.pipe(gulp.dest('./dist/'));
}
function watchTask() {
gulp.watch('./**.styl', ['build']);
}
function onError(err) {
beep([0, 0, 0]);
gutil.log(gutil.colors.green(err));
}