-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
136 lines (110 loc) · 3.47 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
/*
Copyright 2019 Myles Borins
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
'use strict';
const path = require('path');
const { rm } = require('node:fs/promises');
const {
series,
parallel,
watch,
src,
dest
} = require('gulp');
const autoprefixer = require('gulp-autoprefixer');
const browserify = require('gulp-bro');
const connect = require('gulp-connect');
const csso = require('gulp-csso');
const jade = require('gulp-pug-too');
const plumber = require('gulp-plumber');
const rename = require('gulp-rename');
const stylus = require('gulp-stylus');
const through = require('through');
const uglify = require('gulp-uglify');
const isDist = process.argv.indexOf('serve') === -1;
async function cleanJS() {
await rm('dist/build/build.js', { force: true });
}
function buildJS() {
return src('src/scripts/main.js')
.pipe(isDist ? through() : plumber())
.pipe(browserify({ debug: !isDist }))
.pipe(isDist ? uglify() : through())
.pipe(rename('build.js'))
.pipe(dest('dist/build'))
.pipe(connect.reload());
}
exports.js = series(cleanJS, buildJS);
async function cleanHTML() {
await rm('dist/index.html', { force: true });
}
function buildHTML() {
return src('src/index.jade')
.pipe(isDist ? through() : plumber())
.pipe(jade({ pretty: true }))
.pipe(rename('index.html'))
.pipe(dest('dist'))
.pipe(connect.reload());
}
exports.html = series(cleanHTML, buildHTML);
async function cleanCSS() {
await rm('dist/build/build.css', { force: true });
}
function buildCSS() {
return src('src/styles/main.styl')
.pipe(isDist ? through() : plumber())
.pipe(stylus({
// Allow CSS to be imported from node_modules and bower_components
'include css': true,
'paths': ['./node_modules', './bower_components']
}))
.pipe(autoprefixer('last 2 versions', { map: false }))
.pipe(isDist ? csso() : through())
.pipe(rename('build.css'))
.pipe(dest('dist/build'))
.pipe(connect.reload());
}
exports.css = series(cleanCSS, buildCSS);
async function cleanImages() {
await rm('dist/images', { recursive: true, force: true });
}
function copyImages() {
return src('src/images/**/*', {encoding: false})
.pipe(dest('dist/images'))
.pipe(connect.reload());
}
exports.images = series(cleanImages, copyImages)
async function cleanTask () {
await rm('dist', { recursive: true, force: true });
}
exports.clean = cleanTask;
function connectTask(done) {
connect.server({
root: 'dist/',
livereload: true
});
done();
}
function watchTask(done) {
watch('src/**/*.jade', exports.html);
watch('src/styles/**/*.styl', exports.css);
watch('src/images/**/*', exports.images);
watch([
'src/scripts/**/*.js',
'bespoke-theme-*/dist/*.js' // Allow themes to be developed in parallel
], exports.js);
done();
}
exports.build = parallel(exports.js, exports.html, exports.css, exports.images);
exports.connect = series(exports.build, connectTask)
exports.serve = parallel(exports.connect, watchTask);
exports.default = exports.build;