forked from airbnb/lottie-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
158 lines (136 loc) · 4.71 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// include gulp
var gulp = require('gulp');
// include plug-ins
var uglify = require('gulp-uglify');
var usemin = require('gulp-usemin');
var replace = require('gulp-replace');
var rename = require('gulp-rename');
var wrap = require('gulp-wrap');
var gzip = require('gulp-gzip');
var concat = require('gulp-concat');
var watch = require('gulp-watch');
var cheerio = require('gulp-cheerio');
var fs = require('fs');
var htmlreplace = require('gulp-html-replace');
var eventstream = require("event-stream");
var jslint = require('gulp-jslint');
var bm_version = '5.0.2';
var files = [
{
light: true,
path: ''
}
]
var moduleWrap = fs.readFileSync("player/js/module.js", "utf8");
moduleWrap = moduleWrap.replace('/*<%= contents %>*/','<%= contents %>');
moduleWrap = moduleWrap.replace('[[BM_VERSION]]',bm_version);
gulp.task('gzipFile', function(){
gulp.src('player/exports/render/data.json')
.pipe(gzip({ append: false }))
.pipe(gulp.dest('demo/'));
});
gulp.task('lint-code', function () {
return gulp.src(['.player/js/**/*'])
.pipe(jslint({ /* this object represents the JSLint directives being passed down */ }))
.pipe(jslint.reporter( 'my-reporter' ));
});
gulp.task('buildPlayer', function(){
gulp.src('./player/index.html')
.pipe(usemin({
js: [uglify(uglifyOptions)]
}))
//.pipe(wrap('(function(window){"use strict";<%= contents %>}(window));'))
.pipe(wrap(moduleWrap))
.pipe(gulp.dest('build/player/'));
});
gulp.task('buildUnminifiedPlayer', function(){
gulp.src('./player/index.html')
//.pipe(wrap('(function(window){"use strict";<%= contents %>}(window));'))
.pipe(wrap(moduleWrap))
.pipe(gulp.dest('build/player/lottie.min.js'));
});
gulp.task('zipPlayer',['buildPlayer','buildUnminifiedPlayer'], function(){
gulp.src('./player/index.html')
.pipe(usemin({
js: [uglify(uglifyOptions)]
}))
//.pipe(wrap('(function(window){"use strict";<%= contents %>}(window));'))
.pipe(wrap(moduleWrap))
.pipe(gzip({ append: true }))
.pipe(gulp.dest('build/player/'));
});
var srcs = [];
var demoBuiltData = '';
var uglifyOptions = {output: {ascii_only:true}};
gulp.task('getBuildSources', function(cb) {
srcs.length = 0;
gulp.src('./player/index.html')
.pipe(cheerio(function ($, file) {
// Each file will be run through cheerio and each corresponding `$` will be passed here.
// `file` is the gulp file object
// Make all h1 tags uppercase
$('script').each(function (index, elem) {
//console.log(elem.attribs.src);
if(!elem.attribs['data-skip'] && elem.attribs.src){
srcs.push('./player/'+elem.attribs.src);
}
});
cb();
}))
});
function buildVersion(excluded){
srcs.length = 0;
return gulp.src('./player/index.html')
.pipe(cheerio(function ($, file) {
$('script').each(function (index, elem) {
//console.log(elem.attribs.src);
if(elem.attribs.src){
var i, len = excluded.length;
var exclude = false;
for(i=0;i<len;i+=1){
if(elem.attribs[excluded[i]]){
exclude = true;
}
}
if(!exclude){
srcs.push('./player/'+elem.attribs.src);
//console.log(srcs.length);
}
}
});
}));
}
gulp.task('buildSources', function() {
return buildVersion(['data-skip']);
});
gulp.task('buildLightSources', function() {
return buildVersion(['data-skip','data-light-skip']);
});
gulp.task('buildLight',['buildLightSources'], function() {
return gulp.src(srcs)
.pipe(concat('lottie_light.js'))
.pipe(wrap(moduleWrap))
.pipe(gulp.dest('build/player/'));
});
gulp.task('buildLightMin',['buildLightSources'], function() {
return gulp.src(srcs)
.pipe(concat('lottie_light.min.js'))
.pipe(wrap(moduleWrap))
.pipe(uglify(uglifyOptions))
.pipe(gulp.dest('build/player/'));
});
gulp.task('buildFullMin',['buildSources'], function() {
return gulp.src(srcs)
.pipe(concat('lottie.min.js'))
.pipe(wrap(moduleWrap))
.pipe(uglify(uglifyOptions))
.pipe(gulp.dest('build/player/'));
});
gulp.task('buildFull',['buildSources'], function() {
return gulp.src(srcs)
.pipe(concat('lottie.js'))
.pipe(wrap(moduleWrap))
.pipe(gulp.dest('build/player/'));
});
gulp.task('buildAll',['buildLightMin','buildLight','buildFullMin','buildFull'], function() {
});