forked from DotCamp/wp-table-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
171 lines (159 loc) · 4.68 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
const gulp = require('gulp');
const sourcemaps = require('gulp-sourcemaps');
const autoprefixer = require('gulp-autoprefixer');
const csso = require('gulp-csso');
const babel = require('gulp-babel');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const sass = require('gulp-sass')(require('sass'));
const gulpif = require('gulp-if');
const path = require('path');
/**
* Gulp configuration object for path locations.
*
* @type {Object}
*/
const gulpConfig = {
adminJs: {
src: [
'./inc/admin/js/core/*.js',
'./inc/admin/js/core-premium/*.js',
'./inc/admin/js/core/rollup-source/WPTB_IconManager.js',
],
dest: '.',
},
frontEndJs: {
src: [
'./inc/frontend/js/frontend-only/WPTB_FrontendBase.js',
'./inc/admin/js/core/WPTB_ExtraStyles.js',
'./inc/admin/js/core/WPTB_Logger.js',
'./inc/admin/js/core/WPTB_CutGlueTable.js',
'./inc/admin/js/core/WPTB_GetDirectionAfterReconstruction.js',
'./inc/admin/js/core/WPTB_SortableTable.js',
'./inc/admin/js/core/WPTB_RecalculateIndexes.js',
'./inc/admin/js/WPTB_ResponsiveFrontend.js',
'./inc/frontend/js/frontend-only/WPTB_StylePass.js',
'./inc/frontend/js/frontend-only/WPTB_LazyLoad.js',
'./inc/frontend/js/frontend-only/WPTB_ScrollManager.js',
'./inc/frontend/js/frontend-only/wp-table-builder-frontend.js',
],
dest: './inc/frontend/js/wp-table-builder-frontend.js',
},
adminCss: {
src: ['./inc/admin/css/src/*.css', '!./inc/admin/css/src/admin.css'],
dest: './inc/admin/css',
},
adminSass: {
src: ['./inc/admin/css/src/*.scss', '!./inc/admin/css/src/admin.scss'],
dest: './inc/admin/css',
},
onlyAdminCss: {
src: ['./inc/admin/css/src/admin.css', './inc/admin/js/WPTB_BuilderControls.css'],
dest: './inc/admin/css/admin.css',
},
onlyAdminSass: {
src: ['./inc/admin/css/src/admin.scss', './inc/admin/js/WPTB_BuilderControls.css'],
dest: './inc/admin/css/admin.css',
extraWatch: ['./inc/admin/css/src/inc/*.scss'],
},
};
function adminJs() {
return gulp
.src(gulpConfig.adminJs.src, { allowEmpty: true })
.pipe(sourcemaps.init())
.pipe(
babel({
presets: [['@babel/env', { modules: false }]],
babelrc: false,
})
)
.pipe(concat('./inc/admin/js/admin.js'))
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(gulpConfig.adminJs.dest));
}
function minify() {
gulp.src('./inc/admin/js/admin.js').pipe(uglify()).pipe(gulp.dest('./inc/admin/js/'));
}
function frontendJs() {
return gulp
.src(gulpConfig.frontEndJs.src)
.pipe(sourcemaps.init())
.pipe(
babel({
presets: [['@babel/env', { modules: false }]],
plugins: ['@babel/plugin-proposal-object-rest-spread'],
babelrc: false,
})
)
.pipe(concat(gulpConfig.frontEndJs.dest))
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('.'));
}
function cssAdmin() {
return gulp
.src(gulpConfig.adminCss.src)
.pipe(autoprefixer())
.pipe(csso())
.pipe(gulp.dest(gulpConfig.adminCss.dest));
}
function adminSass() {
return gulp
.src(gulpConfig.adminSass.src)
.pipe(sass({ outputStyle: 'compressed' }).on('error', sass.logError))
.pipe(gulp.dest(gulpConfig.adminSass.dest));
}
function onlyCssAdmin() {
return gulp
.src(gulpConfig.onlyAdminCss.src)
.pipe(autoprefixer())
.pipe(concat(gulpConfig.onlyAdminCss.dest))
.pipe(csso())
.pipe(gulp.dest('.'));
}
function onlyAdminSass() {
const filter = (file) => {
return path.parse(file.path).ext === '.scss';
};
return gulp
.src(gulpConfig.onlyAdminSass.src)
.pipe(gulpif(filter, sass({ outputStyle: 'compressed' }).on('error', sass.logError)))
.pipe(autoprefixer())
.pipe(concat(gulpConfig.onlyAdminSass.dest))
.pipe(gulp.dest('.'));
}
function cssFrontend() {
return gulp
.src(['./inc/frontend/css/src/*.css'])
.pipe(autoprefixer())
.pipe(csso())
.pipe(gulp.dest('./inc/frontend/css'));
}
exports.watch = gulp.parallel(
async function watchAdminJs() {
await adminJs();
return gulp.watch(gulpConfig.adminJs.src, adminJs);
},
async function watchFrontendJs() {
await frontendJs();
return gulp.watch(gulpConfig.frontEndJs.src, frontendJs);
},
async function watchAdminStyles() {
await cssAdmin();
return gulp.watch(['./inc/admin/css/src/*.css'], cssAdmin);
},
async function watchAdminSass() {
await adminSass();
return gulp.watch(gulpConfig.adminSass.src, adminSass);
},
async function watchOnlyAdminSass() {
await onlyAdminSass();
return gulp.watch([...gulpConfig.onlyAdminSass.src, ...gulpConfig.onlyAdminSass.extraWatch], onlyAdminSass);
},
async function watchFrontendStyles() {
await cssFrontend();
return gulp.watch(['./inc/frontend/css/src/*.css'], cssFrontend);
}
);
exports.default = gulp.parallel(adminJs, frontendJs, cssAdmin, adminSass, onlyAdminSass, cssFrontend);