This repository has been archived by the owner on Jun 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
129 lines (114 loc) · 3.58 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
/* global require, exports */
const babel = require('gulp-babel');
const cleancss = require('gulp-clean-css');
const concat = require('gulp-concat');
const eslint = require('gulp-eslint');
const gulp = require('gulp');
const js = require('gulp-uglify-es').default;
const livereload = require('gulp-livereload');
const notify = require('gulp-notify');
const plumber = require('gulp-plumber');
const scss = require('gulp-sass');
const sourcemaps = require('gulp-sourcemaps');
const stylelint = require('gulp-stylelint');
const path_dest = './';
const path_js = 'assets/js/*.js';
const path_scss = 'assets/scss/**/*.scss';
const path_style = 'assets/scss/style.scss';
const path_admin_dest = './admin/';
const path_scss_admin = './admin/scss/**/*.scss';
const path_css_admin = './admin/css/**/*.css';
const path_style_admin = './admin/scss/blocks-admin.scss';
const blocks_javascripts = [
'admin/js/Select2FieldsSetup.js',
'admin/js/P4FieldsSetup.js',
'admin/js/WPShortcakeHooksSetup.js',
'admin/js/blocks/*.js',
'admin/js/blocks-admin.js',
];
const path_git_hooks = '.githooks/*';
let error_handler = {
errorHandler: notify.onError({
title: 'Gulp',
message: 'Error: <%= error.message %>'
})
};
function lint_css() {
return gulp.src([path_scss, path_scss_admin, path_css_admin])
.pipe(plumber(error_handler))
.pipe(stylelint({
reporters: [{ formatter: 'string', console: true}]
}))
.pipe(livereload());
}
function lint_js() {
return gulp.src([path_js, ...blocks_javascripts])
.pipe(plumber(error_handler))
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
.pipe(livereload());
}
function sass() {
return gulp.src(path_style)
.pipe(plumber(error_handler))
.pipe(sourcemaps.init())
.pipe(scss().on('error', scss.logError))
.pipe(cleancss({rebase: false}))
.pipe(sourcemaps.write(path_dest))
.pipe(gulp.dest(path_dest))
.pipe(livereload());
}
function sass_admin() {
return gulp.src(path_style_admin)
.pipe(plumber(error_handler))
.pipe(sourcemaps.init())
.pipe(scss().on('error', scss.logError))
.pipe(cleancss({rebase: false}))
.pipe(sourcemaps.write(path_admin_dest))
.pipe(gulp.dest(path_admin_dest))
.pipe(livereload());
}
function uglify() {
return gulp.src(path_js)
.pipe(plumber(error_handler))
.pipe(sourcemaps.init())
.pipe(concat('main.js'))
.pipe(babel({
presets: ['@babel/env']
}))
.pipe(js())
.pipe(sourcemaps.write(path_dest))
.pipe(gulp.dest(path_dest))
.pipe(livereload());
}
function uglify_admin() {
return gulp.src(blocks_javascripts)
.pipe(plumber(error_handler))
.pipe(sourcemaps.init())
.pipe(concat('blocks-admin.min.js'))
.pipe(js())
.pipe(sourcemaps.write(path_admin_dest))
.pipe(gulp.dest(path_admin_dest))
.pipe(livereload());
}
function watch() {
livereload.listen({'port': 35729});
gulp.watch(path_scss, gulp.series(lint_css, sass));
gulp.watch(path_scss_admin, gulp.series(lint_css, sass_admin));
gulp.watch(path_js, gulp.series(lint_js, uglify));
gulp.watch(blocks_javascripts, gulp.series(lint_js, uglify_admin));
}
function git_hooks() {
return gulp.src(path_git_hooks)
.pipe(plumber(error_handler))
.pipe(gulp.dest('.git/hooks/', {'mode': '755', 'overwrite': true}))
.pipe(notify('Copied git hooks'));
}
exports.sass = sass;
exports.uglify = uglify;
exports.uglify_admin = uglify_admin;
exports.watch = watch;
exports.git_hooks = git_hooks;
exports.test = gulp.parallel(lint_css, lint_js);
exports.default = gulp.series(lint_css, lint_js, sass, sass_admin, uglify, uglify_admin);