Skip to content

Commit 694c100

Browse files
committed
UPD gulp - switch to es6 modules
1 parent a81e403 commit 694c100

12 files changed

Lines changed: 2128 additions & 2672 deletions

File tree

gulp/_config.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
//--------- Include references
2-
const path = require('path')
1+
import path from 'path'
32

4-
//--------- Paths
5-
module.exports = {
3+
const __dirname = path.resolve()
4+
5+
const config = {
66
data: {
77
src: 'src/data/*.json',
88
temp: 'src/data/temp/',
@@ -19,7 +19,7 @@ module.exports = {
1919
},
2020
vendor: [
2121
//ADD VENDORS HERE - path from Node_modules path
22-
path.join(__dirname, '..', 'node_modules', 'fever-cookies-plugin', 'dist', 'js', 'cookie.min.js'), // USE IF USING COOKIES
22+
path.join(__dirname, 'node_modules', 'fever-cookies-plugin', 'dist', 'js', 'cookie.min.js'), // USE IF USING COOKIES
2323
]
2424
},
2525
json: {
@@ -52,7 +52,7 @@ module.exports = {
5252
},
5353
vendor: [
5454
//ADD VENDORS HERE - path from Node_modules folder
55-
path.join(__dirname, '..', 'node_modules', 'fever-cookies-plugin', 'dist', 'css', 'cookie.min.css') // USE IF USING COOKIES
55+
path.join(__dirname, 'node_modules', 'fever-cookies-plugin', 'dist', 'css', 'cookie.min.css') // USE IF USING COOKIES
5656
]
5757
},
5858
pdfs: {
@@ -75,4 +75,6 @@ module.exports = {
7575
watch: 'src/fonts/**/*.{ttf,otf,woff,woff2,eot}',
7676
dest: 'dist/assets/fonts/'
7777
}
78-
}
78+
}
79+
80+
export default config

gulp/clean.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
//--------- Include references
2-
const paths = require('./_config'),
3-
del = require('del')
1+
import config from './_config.js'
2+
import del from 'del'
43

5-
6-
//--------- Clean files
7-
function clean(done) {
8-
del.sync(`${paths.views.index.dest}*`)
4+
async function clean(done) {
5+
await del.sync(`${config.views.index.dest}*`)
96
done()
107
}
118

12-
exports.clean = clean
9+
export default clean

gulp/data.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
1-
//--------- Include references
2-
const { src, dest } = require('gulp'),
3-
paths = require('./_config'),
4-
path = require('path'),
5-
merge = require('gulp-merge-json'),
6-
lec = require('gulp-line-ending-corrector')
1+
import gulp from 'gulp'
2+
import config from './_config.js'
3+
import lec from 'gulp-line-ending-corrector'
4+
import path from 'path'
5+
import merge from 'gulp-merge-json'
6+
7+
const { src, dest } = gulp
78

8-
//--------- pug from json
99
function data() {
10-
return src(paths.data.src)
10+
return src(config.data.src)
1111
.pipe(merge({
12-
fileName: paths.data.file,
12+
fileName: config.data.file,
1313
edit: (json, file) => {
14-
// Extract the filename and strip the extension
15-
let filename = path.basename(file.path),
14+
const filename = path.basename(file.path),
1615
primaryKey = filename.replace(path.extname(filename), '')
1716

18-
// Set the filename as the primary key for our JSON data
1917
const data = {}
2018
data[primaryKey] = json
21-
19+
2220
return data
2321
}
2422
}))
25-
.pipe(lec({
26-
eolc: 'CRLF'
27-
}))
28-
.pipe(dest(paths.data.temp))
23+
.pipe(lec({ eolc: 'CRLF' }))
24+
.pipe(dest(config.data.temp))
25+
2926
}
3027

31-
exports.data = data
28+
export default data

gulp/extras.js

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,30 @@
1-
//--------- Include references
2-
const { src, dest, series, lastRun } = require('gulp'),
3-
paths = require('./_config'),
4-
lec = require('gulp-line-ending-corrector')
1+
import gulp from 'gulp'
2+
import config from './_config.js'
3+
import lec from 'gulp-line-ending-corrector'
4+
5+
const { src, dest, series, lastRun } = gulp
56

6-
//--------- Fonts
77
function fonts() {
8-
return src(paths.fonts.src, { since: lastRun(fonts) })
9-
.pipe(dest(paths.fonts.dest))
8+
return src(config.fonts.src, { since: lastRun(fonts) })
9+
.pipe(dest(config.fonts.dest))
1010
}
1111

12-
//--------- JSON
1312
function json() {
14-
return src(paths.json.src, { since: lastRun(json) })
15-
.pipe(lec({
16-
eolc: 'CRLF'
17-
}))
18-
.pipe(dest(paths.json.dest))
13+
return src(config.json.src, { since: lastRun(json) })
14+
.pipe(lec({ eolc: 'CRLF' }))
15+
.pipe(dest(config.json.dest))
1916
}
2017

21-
//---------PDFs
2218
function pdfs() {
23-
return src(paths.pdfs.src, { since: lastRun(pdfs) })
24-
.pipe(dest(paths.pdfs.dest))
19+
return src(config.pdfs.src, { since: lastRun(pdfs) })
20+
.pipe(dest(config.pdfs.dest))
2521
}
2622

27-
//--------- Videos
2823
function videos() {
29-
return src(paths.videos.src, { since: lastRun(videos) })
30-
.pipe(dest(paths.videos.dest))
24+
return src(config.videos.src, { since: lastRun(videos) })
25+
.pipe(dest(config.videos.dest))
3126
}
3227

3328
const extras = series(fonts, json, pdfs, videos)
3429

35-
exports.extras = extras
30+
export default extras

gulp/html.js

Lines changed: 25 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,40 @@
1-
//--------- Include references
2-
const { src, dest, series } = require('gulp'),
3-
paths = require('./_config'),
4-
plumber = require('gulp-plumber'),
5-
fs = require('graceful-fs'),
6-
pug = require('gulp-pug'),
7-
data = require('gulp-data'),
8-
lec = require('gulp-line-ending-corrector')
1+
import gulp from 'gulp'
2+
import config from './_config.js'
3+
import lec from 'gulp-line-ending-corrector'
4+
import plumber from 'gulp-plumber'
5+
import fs from 'graceful-fs'
6+
import pug from 'gulp-pug'
7+
import data from 'gulp-data'
8+
9+
const { src, dest, series } = gulp
910

10-
//--------- styleguide for presentation files
1111
function styleguide() {
12-
// list templates
13-
return src(paths.views.index.src)
12+
return src(config.views.index.src)
1413
.pipe(plumber())
15-
.pipe(data(() => JSON.parse(fs.readFileSync(`${paths.data.temp}${paths.data.file}`))))
16-
.pipe(pug({
17-
pretty: true,
18-
basedir: 'src'
19-
}))
20-
.pipe(lec({
21-
eolc: 'CRLF'
22-
}))
23-
.pipe(dest(paths.views.index.dest))
14+
.pipe(data(() => JSON.parse(fs.readFileSync(`${config.data.temp}${config.data.file}`))))
15+
.pipe(pug({ pretty: true, basedir: 'src' }))
16+
.pipe(lec({ eolc: 'CRLF' }))
17+
.pipe(dest(config.views.index.dest))
2418
}
2519

26-
//--------- Views : Pug
2720
function views() {
28-
// sources
29-
return src(paths.views.pug.src)
21+
return src(config.views.pug.src)
3022
.pipe(plumber())
31-
.pipe(data(() => JSON.parse(fs.readFileSync(`${paths.data.temp}${paths.data.file}`))))
32-
.pipe(pug({
33-
pretty: true,
34-
basedir: 'src'
35-
}))
36-
.pipe(lec({
37-
eolc: 'CRLF'
38-
}))
39-
.pipe(dest(paths.views.pug.dest))
23+
.pipe(data(() => JSON.parse(fs.readFileSync(`${config.data.temp}${config.data.file}`))))
24+
.pipe(pug({ pretty: true, basedir: 'src' }))
25+
.pipe(lec({ eolc: 'CRLF' }))
26+
.pipe(dest(config.views.pug.dest))
4027
}
4128

4229
function templates() {
43-
//templates
44-
return src(paths.views.pug.templates)
30+
return src(config.views.pug.templates)
4531
.pipe(plumber())
46-
.pipe(data(() => JSON.parse(fs.readFileSync(`${paths.data.temp}${paths.data.file}`))))
47-
.pipe(pug({
48-
pretty: true,
49-
basedir: 'src'
50-
}))
51-
.pipe(lec({
52-
eolc: 'CRLF'
53-
}))
54-
.pipe(dest(`${paths.views.pug.dest}/templates`))
32+
.pipe(data(() => JSON.parse(fs.readFileSync(`${config.data.temp}${config.data.file}`))))
33+
.pipe(pug({ pretty: true, basedir: 'src' }))
34+
.pipe(lec({ eolc: 'CRLF' }))
35+
.pipe(dest(`${config.views.pug.dest}/templates`))
5536
}
5637

5738
const html = series(views, templates, styleguide)
5839

59-
exports.html = html
40+
export default html

gulp/images.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
//--------- Include references
2-
const { src, dest, lastRun } = require('gulp'),
3-
paths = require('./_config'),
4-
min = require('gulp-imagemin')
1+
import gulp from 'gulp'
2+
import config from './_config.js'
3+
import min from 'gulp-imagemin'
4+
5+
const { src, dest, lastRun } = gulp
56

6-
//--------- Images
77
function images() {
8-
return src(paths.images.src, { since: lastRun(images) })
8+
return src(config.images.src, { since: lastRun(images) })
99
.pipe(min())
10-
.pipe(dest(paths.images.dest))
10+
.pipe(dest(config.images.dest))
1111
}
12-
exports.images = images
12+
13+
export default images

gulp/scripts.js

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,33 @@
1-
//--------- Include references
2-
const { src, dest, series } = require('gulp'),
3-
paths = require('./_config'),
4-
concat = require('gulp-concat'),
5-
plumber = require('gulp-plumber'),
6-
lec = require('gulp-line-ending-corrector'),
7-
esLint = require('gulp-eslint'),
8-
terser = require('gulp-terser')
1+
import gulp from 'gulp'
2+
import config from './_config.js'
3+
import lec from 'gulp-line-ending-corrector'
4+
import plumber from 'gulp-plumber'
5+
import concat from 'gulp-concat'
6+
import eslint from 'gulp-eslint'
7+
import gulpif from 'gulp-if'
8+
import terser from 'gulp-terser'
99

10+
const { src, dest } = gulp
1011

11-
//--------- Script : javascript
1212
function coreScripts(basename, source, dist) {
1313

14+
const isDev = dist === config.scripts.dist.app
15+
1416
return src(source, { sourcemaps: true })
15-
.pipe(terser())
17+
.pipe(plumber())
18+
.pipe(gulpif(isDev, eslint()))
19+
.pipe(eslint.format('table'))
20+
.pipe(eslint.failAfterError())
1621
.pipe(concat(`${basename}.min.js`))
17-
.pipe(lec({
18-
eolc: 'CRLF'
19-
}))
22+
.pipe(terser())
23+
.pipe(lec({ eolc: 'CRLF' }))
2024
.pipe(dest(dist, { sourcemaps: '.' }))
2125
}
2226

2327
function scripts(done) {
24-
coreScripts(
25-
'vendor',
26-
paths.scripts.vendor,
27-
paths.scripts.dist.vendor
28-
)
29-
coreScripts(
30-
'app',
31-
paths.scripts.app.src,
32-
paths.scripts.dist.app
33-
)
28+
coreScripts('vendor', config.scripts.vendor, config.scripts.dist.vendor)
29+
coreScripts('app', config.scripts.app.src, config.scripts.dist.app)
3430
done()
3531
}
3632

37-
function esLinter() {
38-
return src(paths.scripts.app.src)
39-
.pipe(plumber())
40-
.pipe(esLint())
41-
.pipe(esLint.format('table'))
42-
.pipe(esLint.failAfterError())
43-
}
44-
45-
exports.scripts = scripts
46-
exports.esLinter = esLinter
33+
export default scripts

gulp/server.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
//--------- Include references
2-
const { watch, series } = require('gulp'),
3-
paths = require('./_config'),
4-
browserSync = require('browser-sync'),
5-
dataFile = require('./data'),
6-
htmlFile = require('./html'),
7-
imagesFile = require('./images'),
8-
scriptsFile = require('./scripts'),
9-
stylesFile = require('./styles')
1+
import gulp from 'gulp'
2+
import config from './_config.js'
3+
import browserSync from 'browser-sync'
4+
import data from './data.js'
5+
import html from './html.js'
6+
import images from './images.js'
7+
import scripts from './scripts.js'
8+
import { styles, sassLinter } from './styles.js'
9+
10+
const { watch, series } = gulp
1011

1112
//--------- Browser sync - local Server
1213
function localServer(done) {
@@ -36,14 +37,15 @@ function reload(done) {
3637

3738
//--------- Watch
3839
function watchAssets(done) {
39-
watch(paths.styles.app.watch, series(stylesFile.styles, stylesFile.sassLinter, reload))
40-
watch(paths.scripts.app.watch, series(scriptsFile.scripts, scriptsFile.esLinter, reload))
41-
watch(paths.views.pug.watch, series(htmlFile.html, reload))
42-
watch(paths.images.watch, series(imagesFile.images, reload))
43-
watch(paths.data.src, series(dataFile.data, htmlFile.html, reload))
40+
watch(config.styles.app.watch, series(styles, sassLinter, reload))
41+
watch(config.scripts.app.watch, series(scripts, reload))
42+
watch(config.views.pug.watch, series(html, reload))
43+
watch(config.images.watch, series(images, reload))
44+
watch(config.data.src, series(data, html, reload))
4445

4546
done()
4647
}
4748

4849
const server = series(localServer, watchAssets)
49-
exports.server = server
50+
51+
export default server

0 commit comments

Comments
 (0)