-
Notifications
You must be signed in to change notification settings - Fork 6
/
gulpfile.js
executable file
·266 lines (248 loc) · 6.13 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
260
261
262
263
264
265
266
'use strict';
// Load plugins
const autoprefixer = require('autoprefixer');
const browsersync = require('browser-sync').create();
const cp = require('child_process');
const cssnano = require('cssnano');
const del = require('del');
const gulp = require('gulp');
const imagemin = require('gulp-imagemin');
const newer = require('gulp-newer');
const plumber = require('gulp-plumber');
const postcss = require('gulp-postcss');
const rename = require('gulp-rename');
const sass = require('gulp-sass')(require('sass'));
const uglify = require('gulp-uglify');
const concat = require('gulp-concat');
const terser = require('gulp-terser');
const combineMediaQuery = require('postcss-combine-media-query');
// BrowserSync
function browserSync(done)
{
browsersync.init({
open: false,
//proxy: 'http://pluginsetup.chandresh.php/', // replace it with yours
port: 3000,
server: {
baseDir: './'
}
});
done();
}
// html
function html()
{
return gulp
.src([
'./*.html',
])
.pipe(browsersync.stream());
}
// clean
function clean()
{
return del(['./assets/dist/']);
}
// Images Frontend
function images()
{
return gulp
.src('assets/src/front-end/image/**/*')
.pipe(newer('public/image'))
.pipe(
imagemin([
imagemin.gifsicle({ interlaced: true }),
imagemin.jpegtran({ progressive: true }),
imagemin.optipng({ optimizationLevel: 5 }),
imagemin.svgo({
plugins: [
{
removeViewBox: false,
collapseGroups: true
}
]
})
])
)
.pipe(gulp.dest('public/image'));
}
// Images Dashboard
function imagesBackend()
{
return gulp
.src('assets/src/back-end/image/**/*')
.pipe(newer('admin/images'))
.pipe(
imagemin([
imagemin.gifsicle({ interlaced: true }),
imagemin.jpegtran({ progressive: true }),
imagemin.optipng({ optimizationLevel: 5 }),
imagemin.svgo({
plugins: [
{
removeViewBox: false,
collapseGroups: true
}
]
})
])
)
.pipe(gulp.dest('admin/image'));
}
// CSS
function css()
{
return gulp
.src([
'./assets/src/front-end/scss/main.scss',
])
.pipe(plumber())
.pipe(concat('woo-refund-and-exchange-lite-public.css'))
.pipe(sass({ outputStyle: "expanded" }))
.pipe(gulp.dest("public/css"))
.pipe(postcss([autoprefixer(), combineMediaQuery()]))
.pipe(gulp.dest("public/css"))
.pipe(rename({ suffix: ".min" }))
.pipe(postcss([cssnano()]))
.pipe(gulp.dest("public/css"))
.pipe(browsersync.stream());
}
// CSS Dashboard
function cssBackend()
{
return gulp
.src([
'assets/src/back-end/scss/main.scss',
])
.pipe(plumber())
.pipe(concat('woo-refund-and-exchange-lite-admin.css'))
.pipe(sass({ outputStyle: "expanded" }))
.pipe(gulp.dest("admin/css"))
.pipe(postcss([autoprefixer(), combineMediaQuery()]))
.pipe(gulp.dest("admin/css"))
.pipe(rename({ suffix: ".min" }))
.pipe(postcss([cssnano()]))
.pipe(gulp.dest("admin/css"))
.pipe(browsersync.stream());
}
// CSS Order Edit Page
function cssOrderEditBackend()
{
return gulp
.src([
'assets/src/back-end/scss/wps-order-edit-page-lite.scss',
])
.pipe(plumber())
.pipe(concat('wps-order-edit-page-lite.scss.css'))
.pipe(sass({ outputStyle: "expanded" }))
.pipe(gulp.dest("admin/css"))
.pipe(postcss([autoprefixer(), combineMediaQuery()]))
.pipe(gulp.dest("admin/css"))
.pipe(rename({ suffix: ".min" }))
.pipe(postcss([cssnano()]))
.pipe(gulp.dest("admin/css"))
.pipe(browsersync.stream());
}
// Scripts
function scripts()
{
return (
gulp
.src([
'assets/src/front-end/js/**/*',
])
.pipe(plumber())
.pipe(concat('woo-refund-and-exchange-lite-public.js'))
.pipe(gulp.dest('public/js'))
.pipe(terser())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('public/js'))
.pipe(browsersync.stream())
);
}
// Scripts Backend
function scriptsBackend()
{
return (
gulp
.src([
'assets/src/back-end/js/**/*',
])
.pipe(plumber())
.pipe(concat('woo-refund-and-exchange-lite-admin.js'))
.pipe(gulp.dest('admin/js'))
.pipe(terser())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('admin/js'))
.pipe(browsersync.stream())
);
}
// Scripts Common
function scriptsCommon()
{
return (
gulp
.src([
'assets/src/common/js/**/*',
])
.pipe(plumber())
.pipe(concat('woo-refund-and-exchange-lite-common.js'))
.pipe(gulp.dest('common/js'))
.pipe(terser())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('common/js'))
.pipe(browsersync.stream())
);
}
// Fonts
function fonts()
{
return (
gulp
.src('assets/src/front-end/fonts/**/*')
.pipe(plumber())
.pipe(gulp.dest('public/fonts'))
.pipe(browsersync.stream())
);
}
// Fonts Backend
function fontsBackend()
{
return (
gulp
.src('assets/src/back-end/fonts/**/*')
.pipe(plumber())
.pipe(gulp.dest('admin/fonts'))
.pipe(browsersync.stream())
);
}
// watch changes
function watchFiles()
{
gulp.watch('./assets/src/front-end/scss/**/*', css);
gulp.watch('assets/src/front-end/js/**/*', scripts);
gulp.watch('assets/src/front-end/image/**/*', images);
gulp.watch('assets/src/front-end/fonts/**/*', fonts);
gulp.watch('./*.html', html);
gulp.watch('assets/src/back-end/image/**/*', imagesBackend);
gulp.watch('assets/src/back-end/scss/**/*', cssBackend);
gulp.watch('assets/src/back-end/scss/**/*', cssOrderEditBackend);
gulp.watch('assets/src/back-end/js/**/*', scriptsBackend);
gulp.watch('assets/src/front-end/fonts/**/*', fontsBackend);
gulp.watch('assets/src/common/js/**/*', scriptsCommon);
}
const start = gulp.series(clean, images, fonts, css, scripts, html, imagesBackend, cssBackend, cssOrderEditBackend, scriptsBackend, scriptsCommon, fontsBackend);
const watch = gulp.parallel(watchFiles, browserSync);
// export tasks
exports.images = images;
exports.css = css;
exports.scripts = scripts;
exports.clean = clean;
exports.imagesBackend = imagesBackend;
exports.cssBackend = cssBackend;
exports.cssOrderEditBackend = cssOrderEditBackend;
exports.scriptsBackend = scriptsBackend;
exports.scriptsCommon = scriptsCommon;
exports.fontsBackend = fontsBackend;
exports.watch = watch;
exports.default = gulp.series(start, watch);