forked from pqina/flip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
192 lines (174 loc) · 5.2 KB
/
gulpfile.babel.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import gulp from 'gulp';
import util from 'gulp-util';
import clean from 'gulp-clean';
import header from 'gulp-header';
import sass from 'gulp-sass';
import cssnano from 'gulp-cssnano';
import postcss from 'gulp-postcss';
import autoprefixer from 'autoprefixer';
import sequence from 'run-sequence';
import concat from 'gulp-concat';
import rename from 'gulp-rename';
import rollup from 'rollup-stream';
import babel from 'rollup-plugin-babel';
import source from 'vinyl-source-stream';
import buffer from 'vinyl-buffer';
import uglify from 'gulp-uglify';
import size from 'gulp-size';
import replace from 'gulp-replace';
import fs from 'fs';
var pkg = require('./package.json');
pkg.year = new Date().getFullYear();
var banner =
'/*\n' +
' * <%= pkg.name %> v<%= pkg.version %> - <%= pkg.description %>\n' +
' * Copyright (c) <%= pkg.year %> <%= pkg.author.name %> - <%= pkg.homepage %>\n' +
' */\n';
var bannerJS = '/* eslint-disable */\n\n' + banner;
gulp.task('styles-base', () => {
return gulp
.src('./src/sass/*.scss')
.pipe(sass())
.on('error', util.log)
.pipe(
postcss([
autoprefixer({
browsers: [
'last 2 versions',
'Explorer >= 11',
'iOS >= 8',
'Android >= 4.0'
]
})
])
)
.pipe(header(banner, { pkg }))
.pipe(rename('tick.view.flip.css'))
.pipe(gulp.dest('./dist/'))
.pipe(cssnano({ safe: true }))
.pipe(header(banner, { pkg }))
.pipe(
rename(function(path) {
path.basename += '.min';
})
)
.pipe(gulp.dest('./dist/'));
});
gulp.task('styles-combined', () => {
return gulp
.src(['./tick/tick.core.css', './dist/tick.view.flip.css'])
.pipe(concat('flip.css'))
.pipe(gulp.dest('./dist'))
.pipe(cssnano({ safe: true }))
.pipe(header(banner, { pkg }))
.pipe(
rename(function(path) {
path.basename += '.min';
})
)
.pipe(gulp.dest('./dist/'));
});
gulp.task('scripts-core', () => {
return rollup({
entry: './src/js/index.js',
format: 'cjs',
plugins: [
babel({
exclude: 'node_modules/**',
babelrc: false,
presets: [['es2015', { modules: false }]],
plugins: [
'external-helpers',
'syntax-object-rest-spread',
'transform-object-rest-spread'
]
})
]
})
.pipe(source('index.js', './src/js/'))
.pipe(buffer())
.pipe(rename('tick.view.flip.js'))
.pipe(gulp.dest('./tmp'))
.pipe(uglify().on('error', util.log))
.pipe(size({ gzip: true }));
});
gulp.task('scripts-wrap', () => {
// wrap basic version with intro and outro so all classes are contained
return gulp
.src([
// wrapper start
'./src/wrapper/intro.js',
// lib
'./tmp/tick.view.flip.js',
// wrapper end
'./src/wrapper/outro.js'
])
.pipe(concat('tick.view.flip.wrapped.js'))
.pipe(gulp.dest('./tmp'));
});
gulp.task('scripts-variants', () => {
// read wrapped version of lib
var lib = fs.readFileSync('./tmp/tick.view.flip.wrapped.js', 'utf8');
// inject into variants
return gulp
.src('src/variants/*')
.pipe(replace('__LIB__', lib))
.pipe(replace('__TYPE__', 'view'))
.pipe(replace('__NAME__', 'flip'))
.pipe(header(bannerJS, { pkg }))
.pipe(gulp.dest('./dist'));
});
gulp.task('scripts-minify', () => {
return gulp
.src([
'./dist/tick.view.flip.global.js',
'./dist/tick.view.flip.jquery.js'
])
.pipe(uglify().on('error', util.log))
.pipe(
rename(function(path) {
path.basename += '.min';
})
)
.pipe(header(bannerJS, { pkg }))
.pipe(gulp.dest('./dist'));
});
gulp.task('scripts-combined', () => {
return gulp
.src([
'./tick/tick.core.polyfill.js',
'./dist/tick.view.flip.global.js',
'./tick/tick.core.kickstart.js'
])
.pipe(concat('flip.js'))
.pipe(gulp.dest('./dist'))
.pipe(uglify().on('error', util.log))
.pipe(
rename(function(path) {
path.basename += '.min';
})
)
.pipe(header(bannerJS, { pkg }))
.pipe(gulp.dest('./dist'));
});
gulp.task('scripts-clean', () => {
return gulp.src('./tmp', { read: false }).pipe(clean());
});
gulp.task('scripts', cb => {
sequence(
'scripts-core',
'scripts-wrap',
'scripts-variants',
'scripts-minify',
'scripts-combined',
'scripts-clean',
cb
);
});
gulp.task('styles', cb => {
sequence('styles-base', 'styles-combined', cb);
});
gulp.task('build', ['styles', 'scripts']);
gulp.task('default', ['build'], () => {
gulp.watch(['./src/**/*', './tick/*.js'], ['build']);
});