This repository was archived by the owner on Oct 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgulpfile.js
More file actions
executable file
·223 lines (186 loc) · 5.71 KB
/
gulpfile.js
File metadata and controls
executable file
·223 lines (186 loc) · 5.71 KB
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
// gulpfile.js (Node 18 friendly / no fibers)
const argv = require('yargs').argv
const config = require('./frasco.config.js')
const { src, dest, watch, series, parallel } = require('gulp')
const autoprefixer = require('autoprefixer')
const babel = require('gulp-babel')
const browserSync = require('browser-sync')
const cp = require('child_process')
const eslint = require('gulp-eslint')
const imagemin = require('gulp-imagemin')
const named = require('vinyl-named')
const newer = require('gulp-newer')
const plumber = require('gulp-plumber')
const postcss = require('gulp-postcss')
const pngquant = require('imagemin-pngquant')
// --- CHANGED: use gulp-sass v5 + Dart Sass, no fibers ---
const dartSass = require('sass')
const gulpSass = require('gulp-sass')(dartSass)
// ---------------------------------------------------------
const styleLint = require('gulp-stylelint')
const t2 = require('through2')
const log = require('fancy-log')
const webpackStream = require('webpack-stream')
const webpack = require('webpack')
// browser-sync instance
const server = browserSync.create()
/*---------- SASS ----------*/
function sassTask() {
return src(`${config.assets}/${config.sass.src}/**/*.scss`)
.pipe(
// no { fiber: ... } option; Dart Sass is fast enough and fiber is deprecated
gulpSass.sync({ outputStyle: config.sass.outputStyle }),
'error',
gulpSass.logError
)
.pipe(postcss([autoprefixer(config.sass.autoprefixer)]))
.pipe(
t2.obj((chunk, enc, cb) => {
const date = new Date()
chunk.stat.atime = date
chunk.stat.mtime = date
cb(null, chunk)
})
)
.pipe(dest(`${config.assets}/${config.sass.dest}`))
.pipe(server.stream({ match: '**/*.css' }))
.on('end', () => log('SASS updated'))
}
exports.sass = sassTask
/*---------- StyleLint -----------*/
function styleLintTask() {
let autoFix = false
let failAfterError = false
if (argv.fix) autoFix = true
if (argv.allow_stylelint_fail) failAfterError = true
let stream = src(`${config.assets}/${config.sass.src}/**/*.scss`).pipe(
styleLint({
failAfterError,
reporters: [{ formatter: 'string', console: true }],
fix: autoFix
})
)
if (autoFix) {
stream = stream.pipe(dest(`${config.assets}/${config.sass.src}`))
}
return stream
}
exports.stylelint = styleLintTask
/*---------- JavaScript ----------*/
const jsFiles = []
for (let i = 0; i <= config.js.entry.length - 1; i++) {
jsFiles.push(`${config.assets}/${config.js.src}/${config.js.entry[i]}`)
}
if (config.tasks.eslint) config.webpack.module.rules.push(config.eslintLoader)
config.webpack.watch = argv.watch
config.webpack.mode = argv.mode || config.webpack.mode
function webpackTask() {
return src(jsFiles)
.pipe(plumber())
.pipe(named())
.pipe(babel())
.pipe(webpackStream(config.webpack, webpack))
.pipe(dest(`${config.assets}/${config.js.dest}`))
}
/*---------- esLint ----------*/
const runEslint = function () {
return src([`${config.assets}/${config.js.src}/**/*.js`, '!node_modules/**'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failOnError())
}
exports.eslint = runEslint
/*---------- Images ----------*/
function imagesTask() {
return src(`${config.assets}/${config.imagemin.src}/**/*`)
.pipe(plumber())
.pipe(newer(`${config.assets}/${config.imagemin.dest}`))
.pipe(
imagemin({
progressive: config.imagemin.progressive,
svgoPlugins: config.imagemin.svgoPlugins,
use: [pngquant()]
})
)
.pipe(dest(`${config.assets}/${config.imagemin.dest}`))
}
exports.imagemin = imagesTask
/*---------- Browsersync ----------*/
let browser =
config.browsersync.browsers[0] != null
? config.browsersync.browsers
: 'default'
function reload(done) {
server.reload()
done()
}
function serve(done) {
server.init({
port: config.port,
browser: browser,
server: {
baseDir: config.jekyll.dest
}
})
done()
}
/*---------- Watch ----------*/
const filesToWatch = [
'!./node_modules/**/*',
'!./README.md',
`!${config.jekyll.dest}/**/*`,
'_config*.yml',
'*.html',
'./**/*.md',
'./**/*.markdown',
'*.json',
`${config.jekyll.includes}/**/*`,
`${config.jekyll.layouts}/**/*`,
`${config.jekyll.posts}/**/*`,
`${config.assets}/${config.sass.dest}/**/*`,
`${config.assets}/${config.js.dest}/**/*`,
`${config.assets}/${config.imagemin.dest}/**/*`
]
function watchTask() {
watch(
`${config.assets}/${config.sass.src}/**/*`,
series(styleLintTask, sassTask)
)
watch(`${config.assets}/${config.js.src}/**/*`, series(webpackTask))
watch(`${config.assets}/${config.imagemin.src}/**/*`, series(imagesTask))
watch(filesToWatch, series(jekyllBuild, reload))
}
/*---------- Jekyll ----------*/
function jekyllBuild(done) {
let jekyllConfig = config.jekyll.config.default
if (argv.jekyllEnv == 'production') {
process.env.JEKYLL_ENV = 'production'
jekyllConfig += config.jekyll.config.production
? ',' + config.jekyll.config.production
: ''
} else {
jekyllConfig += config.jekyll.config.development
? ',' + config.jekyll.config.development
: ''
}
const buildArgs = ['exec', 'jekyll', 'build', '--config', jekyllConfig]
if (argv.preview) {
buildArgs.push('--drafts', '--unpublished', '--future')
}
if (argv.forestry) {
buildArgs.push('--destination', '_forestry_site')
}
return cp
.spawn('bundle', buildArgs, { stdio: 'inherit', env: process.env })
.on('close', done)
}
exports.default = series(
parallel(series(styleLintTask, sassTask), webpackTask, imagesTask),
jekyllBuild,
serve,
watchTask
)
exports.build = series(
parallel(series(styleLintTask, sassTask), webpackTask, imagesTask),
jekyllBuild
)