This repository has been archived by the owner on Feb 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 87
/
gulpfile.js
259 lines (234 loc) · 7.38 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
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var runSequence = require('run-sequence');
var browserSync = require('browser-sync').create();
var reload = browserSync.reload;
var path = require('path');
var streamqueue = require('streamqueue');
var eslint = require('gulp-eslint');
var postcss = require('gulp-postcss');
var postcssOpacity = require('postcss-opacity');
var postcssFilterGradient = require('postcss-filter-gradient');
var autoprefixer = require('autoprefixer');
// UI JavaScript
var uiJS = require('./libs/files/ui').JS;
// Mobile JavaScript
var mobileJS = require('./libs/files/mobile').JS;
// Package data
var pkg = require('./package.json');
var distPath = './dist';
var banner = {
full: [
'/*!',
' * Chico UI v' + pkg.version,
' * http://chico-ui.com.ar/',
' *',
' * Copyright (c) ' + (new Date().getFullYear()) + ', MercadoLibre.com',
' * Released under the MIT license.',
' * http://chico-ui.com.ar/license',
' */\n'
].join('\n'),
'min': '/*! Chico UI v' + pkg.version + ' chico-ui.com.ar | chico-ui.com.ar/license */\n'
};
// Copy Chico related assets
gulp.task('copy', function () {
// Everything in the assets folder
return gulp
.src(['./src/shared/assets/**/*.*'], {
base: './src/shared/'
})
.pipe(gulp.dest(distPath));
});
// Compile Sass
gulp.task('sass', [
'sass:ui',
'sass:mobile'
]);
gulp.task('sass:ui', function () {
return gulp.src('src/ui/styles/ui-theme.scss')
.pipe($.sourcemaps.init())
.pipe($.sass({
outputStyle: 'expanded' // nested, compact, compressed, expanded
}))
.pipe(postcss([
postcssFilterGradient,
autoprefixer({'browsers': ['last 5 versions', '> 1%']}),
postcssOpacity
]))
.pipe($.rename('chico.css'))
.pipe($.wrapper({
header: banner.full
}))
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest(path.join(distPath, 'ui')))
.pipe(browserSync.stream());
});
gulp.task('sass:mobile', function () {
return gulp.src('src/mobile/styles/mobile-theme.scss')
.pipe($.sourcemaps.init())
.pipe($.sass({
outputStyle: 'expanded' // nested, compact, compressed, expanded
}))
.pipe(postcss([
autoprefixer({'browsers': ['last 5 versions', 'android >= 2.1', '> 1%']})
]))
.pipe($.rename('chico.css'))
.pipe($.wrapper({
header: banner.full
}))
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest(path.join(distPath, 'mobile')))
.pipe(browserSync.stream());
});
// Minify the compiled CSS
gulp.task('minifyCSS', function() {
return gulp.src(['dist/**/*.css', '!dist/**/*.min.css'])
.pipe($.cssnano())
.pipe($.rename({suffix: '.min'}))
.pipe(gulp.dest(distPath));
});
// Concatenate and copy Chico JS
gulp.task('concatJS', [
'concatJS:ui',
'concatJS:mobile'
]);
gulp.task('concatJS:ui', function() {
return streamqueue({ objectMode: true },
gulp.src(uiJS.core).pipe($.concat('core.js')).pipe($.wrapper({
header: "\n(function (window) {\n\t'use strict';\n\n",
footer: '\n\tch.version = \'' + pkg.version + '\';\n\twindow.ch = ch;\n}(this));'
})),
gulp.src(uiJS.abilities.concat(uiJS.components))
)
.pipe($.concat('chico.js'))
.pipe($.wrapper({
header: banner.full
}))
.pipe(gulp.dest(path.join(distPath, 'ui')));
});
gulp.task('concatJS:mobile', function() {
return streamqueue({ objectMode: true },
gulp.src(mobileJS.core).pipe($.concat('core.js')).pipe($.wrapper({
header: "\n(function (window) {\n\t'use strict';\n\n",
footer: '\n\tch.version = \'' + pkg.version + '\';\n\twindow.ch = ch;\n}(this));'
})),
gulp.src(mobileJS.abilities.concat(mobileJS.components))
)
.pipe($.concat('chico.js'))
.pipe($.wrapper({
header: banner.full
}))
.pipe(gulp.dest(path.join(distPath, 'mobile')));
});
// Minify the JS
gulp.task('minifyJS', [
'minifyJS:ui',
'minifyJS:mobile'
]);
// UI JavaScript
gulp.task('minifyJS:ui', function () {
return gulp.src(path.join(distPath, 'ui/chico.js'))
.pipe($.uglify({
beautify: true,
mangle: false
}).on('error', function(e) {
console.log(e);
}))
.pipe($.wrapper({
header: banner.min
}))
.pipe($.rename({suffix: '.min'}))
.pipe(gulp.dest(path.join(distPath, 'ui')));
});
// Mobile JavaScript
gulp.task('minifyJS:mobile', function () {
return gulp.src(path.join(distPath, 'mobile/chico.js'))
.pipe($.uglify({
beautify: true,
mangle: false
}).on('error', function(e) {
console.log(e);
}))
.pipe($.wrapper({
header: banner.min
}))
.pipe($.rename({suffix: '.min'}))
.pipe(gulp.dest(path.join(distPath, 'mobile')));
});
// Start a BrowserSync server, which you can view at http://localhost:3040
gulp.task('browser-sync', ['build'], function () {
browserSync.init({
port: 3040,
startPath: '/ui.html',
server: {
baseDir: [
// base path for views and demo assets
'views/',
// root folder for everything else
'./'
],
middleware: [
function(req, res, next) {
var redirectTo;
switch (req.url) {
case '/':
case '/ui':
redirectTo = '/ui.html';
break;
case '/m':
case '/mobile':
redirectTo = '/mobile.html';
break;
}
if (redirectTo) {
res.writeHead(301, {Location: redirectTo});
res.end();
} else {
next();
}
}
]
},
bsFiles: {
src: [
'dist/**/*.css',
'dist/**/*.js',
'views/*.html'
]
}
});
gulp.watch(['src/shared/**/*.js', 'src/ui/**/*.js'], ['concatJS:ui']);
gulp.watch(['src/shared/**/*.js', 'src/mobile/**/*.js'], ['concatJS:mobile']);
gulp.watch('dist/**/*.js').on('change', reload);
gulp.watch('src/views/*.html').on('change', reload);
gulp.watch('src/**/styles/**/*.scss', ['sass']);
});
// Validates JavaScript files with ESLint
gulp.task('lint', function () {
return gulp.src(['src/**/*.js'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failOnError());
});
// Build all files without starting a server
gulp.task('build', function (done) {
runSequence([
'copy',
'sass',
'concatJS'
], done);
});
// Build and minify all files without starting a server
gulp.task('dist', function (done) {
runSequence('build', [
'minifyCSS',
'minifyJS'
], done);
});
// Dev task: build the Chico and start a server
gulp.task('dev', [
'build',
'browser-sync'
]);
// Default task: run the dev
gulp.task('default', ['dev']);