-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.mjs
84 lines (71 loc) · 1.74 KB
/
gulpfile.mjs
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
import gulp from 'gulp'
import pump from 'pump'
import gulpSass from 'gulp-sass'
import dartSass from 'sass'
import replace from 'gulp-replace'
import rename from 'gulp-rename'
import { deleteAsync } from 'del'
import zip from 'gulp-zip'
import minimist from 'minimist'
const {
_: [, , task],
theme,
dest,
version,
} = minimist(process.argv)
if (!theme) {
throw new Error(`'theme' parameter is required`)
}
if (task === 'build' && !version) {
throw new Error(`'version' parameter is required`)
}
const sass = gulpSass(dartSass);
const sassGlob = `themes/${theme}/sass/**/*.scss`
const imagesGlob = `themes/${theme}/images/*.png`
const destPath = dest || `./dist/`
const imagesDest = `${destPath}/${theme}/`
const destGlobs = [`${destPath}/${theme}*`, `${imagesDest}**`]
function clean() {
return deleteAsync(destGlobs, {
force: true,
})
}
function copyImages(done) {
pump([gulp.src(imagesGlob), gulp.dest(imagesDest)], done)
}
function buildCss(done) {
pump(
[
gulp.src(sassGlob),
sass.sync().on('error', sass.logError),
replace('/*POSTSASS ', ''),
replace(' POSTSASS*/', ''),
replace('VERSION', version),
rename({ extname: '.qss' }),
gulp.dest(destPath),
],
done
)
}
function zipTheme(done) {
pump(
[
gulp.src(destGlobs, { base: destPath }),
zip(`${theme}-${version}.zip`),
gulp.dest(destPath),
],
done
)
}
function watchSass() {
return gulp.watch(sassGlob, { ignoreInitial: false }, buildCss)
}
function watchImages() {
return gulp.watch(imagesGlob, { ignoreInitial: false }, copyImages)
}
export const build = gulp.series(
clean,
gulp.parallel(buildCss, copyImages),
zipTheme
)
export const watch = gulp.parallel(watchSass, watchImages)