Skip to content

Commit a4ad2ff

Browse files
committed
Merge branch 'release/7.1.0'
2 parents 5c28064 + 9aa1052 commit a4ad2ff

File tree

9 files changed

+66
-36
lines changed

9 files changed

+66
-36
lines changed

build/gulp-config/properties.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ module.exports = {
88

99
buildOnly: false, //set to `true` when paired with Phing
1010

11-
viewsExt: ['html', 'njk'] //for php projects use: '*.{html,php,phtml}'
11+
viewsExt: ['html', 'njk'], //for php projects use: '*.{html,php,phtml}'
12+
13+
enableNotify: true //set to `false` to disable gulp-notify plugin
1214
};

build/gulp-tasks/fonts.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@
33
* ===============================
44
*/
55

6-
module.exports = (gulp, $, options) => () => {
6+
const { getNotifier } = require('./lib/plugins');
77

8+
module.exports = (gulp, $, options) => () => {
89
const paths = require('../gulp-config/paths');
9-
1010
const destFolder = paths.toPath('dist.assets/fonts');
1111
const filesMatch = '**/*.{eot,svg,ttf,woff,woff2}';
1212

13+
const { notify } = getNotifier(options);
14+
1315
return gulp.src([paths.toPath(`src.assets/fonts/${filesMatch}`)])
1416
.pipe($.changed(destFolder))
1517
.pipe(gulp.dest(destFolder))
16-
.pipe($.if(options.isWatching, $.notify({ message: 'Fonts synced', onLast: true })))
18+
.pipe(notify({ message: 'Fonts synced', onLast: true }))
1719
.pipe($.size({ title: 'fonts' }));
1820

1921
};

build/gulp-tasks/images.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
* ===============================
44
*/
55
const paths = require('../gulp-config/paths');
6+
const { getNotifier } = require('./lib/plugins');
67

78
module.exports = (gulp, $, options) => () => {
89
const destPath = paths.toPath('dist.assets/images');
910
const filesMatch = '**/*.{png,jpg,gif,svg,webp}';
1011
const plugins = [];
11-
const { production, isWatching } = options;
12+
const { production } = options;
13+
const { notify } = getNotifier(options);
1214

1315
plugins.push($.imagemin.svgo({
1416
plugins: [
@@ -31,7 +33,7 @@ module.exports = (gulp, $, options) => () => {
3133
.pipe(gulp.dest(destPath))
3234
.pipe($.if(production, $.rev.manifest({ merge: true, path: paths.toPath('dist.root/dist.revmap') })))
3335
.pipe($.if(production, gulp.dest('.')))
34-
.pipe($.if(isWatching, $.notify({ message: 'Images Processed', onLast: true })))
36+
.pipe(notify({ message: 'Images Processed', onLast: true }))
3537
.pipe($.size({ title: 'images' }));
3638

3739
};

build/gulp-tasks/lib/plugins.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
const through = require('through2');
66
const PluginError = require('plugin-error');
7+
const notify = require('gulp-notify');
78

8-
module.exports.map = function map(fn) {
9+
const map = function map(fn) {
910

1011
const mapFn = typeof fn === 'function' ? fn : (val) => val;
1112

@@ -32,4 +33,34 @@ module.exports.map = function map(fn) {
3233

3334
cb();
3435
});
36+
};
37+
38+
const noop = () => through.obj();
39+
40+
let reloadStream;
41+
const getReloadStream = ({ isWatching, livereload, buildHash }) => {
42+
if (isWatching && livereload) {
43+
return reloadStream || (reloadStream = require('browser-sync').get(buildHash).stream); //eslint-disable-line no-return-assign
44+
}
45+
return noop;
46+
};
47+
48+
const getNotifier = ({ isWatching, enableNotify }) => {
49+
if (isWatching && enableNotify) {
50+
return {
51+
notify,
52+
errorHandler: notify.onError('Error: <%= error.message %>')
53+
};
54+
}
55+
return {
56+
notify: noop,
57+
errorHandler: true
58+
};
59+
};
60+
61+
module.exports = {
62+
map,
63+
noop,
64+
getReloadStream,
65+
getNotifier
3566
};

build/gulp-tasks/media.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44
*/
55

66
const paths = require('../gulp-config/paths');
7+
const { getNotifier } = require('./lib/plugins');
78

89
module.exports = (gulp, $, options) => () => {
910

1011
const distPath = paths.toPath('dist.assets/media');
12+
const { notify } = getNotifier(options);
1113

1214
return gulp.src(paths.toPath('src.assets/media/**/*.*'))
1315
.pipe($.changed(distPath))
1416
.pipe(gulp.dest(distPath))
15-
.pipe($.if(options.isWatching, $.notify({ message: 'Media files synced', onLast: true })))
17+
.pipe(notify({ message: 'Media files synced', onLast: true }))
1618
.pipe($.size({ title: 'media' }));
1719

1820
};

build/gulp-tasks/scripts.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ const paths = require('../gulp-config/paths');
88
const srcPath = paths.toPath('src.assets/js');
99
const jsPath = paths.toPath('dist.assets/js');
1010
const rootPath = paths.toPath('dist.root');
11+
const { getNotifier } = require('./lib/plugins');
1112

1213
module.exports = (gulp, $, options) => () => {
13-
14-
const destPath = options.production ? jsPath.replace(rootPath, paths.get('tmp')) : jsPath;
14+
const { production } = options;
15+
const destPath = production ? jsPath.replace(rootPath, paths.get('tmp')) : jsPath;
16+
const { notify, errorHandler } = getNotifier(options);
1517

1618
return gulp.src([`${srcPath}/**/*.js`, `!${srcPath}/**/*.{spec,conf}.js`])
17-
.pipe($.plumber({
18-
errorHandler: $.notify.onError('Error: <%= error.message %>')
19-
}))
19+
.pipe($.plumber({ errorHandler }))
2020
.pipe($.babel())
2121
.pipe(gulp.dest(destPath))
22-
.pipe($.if(options.isWatching, $.notify({ message: 'Scripts Compiled', onLast: true })))
22+
.pipe(notify({ message: 'Scripts Compiled', onLast: true }))
2323
.pipe($.size({ title: 'scripts' }));
2424

2525
};

build/gulp-tasks/styles.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ module.exports = (gulp, $, options) => {
77

88
const path = require('path');
99
const autoprefixer = require('autoprefixer');
10-
const through = require('through2');
10+
const { noop, getReloadStream, getNotifier } = require('./lib/plugins');
1111
const paths = require('../gulp-config/paths');
1212
const sassFunctions = require('./lib/sass-functions')(options);
13-
const noop = () => through.obj();
14-
1513
const { production, banners } = options;
1614
let destPath = paths.toPath('dist.assets/css');
1715
let optimizePipe = noop;
@@ -35,21 +33,13 @@ module.exports = (gulp, $, options) => {
3533

3634
return () => {
3735

36+
const { notify, errorHandler } = getNotifier(options);
3837

39-
let reloadStream;
40-
function reloadStreamFn() {
41-
if (options.isWatching && options.livereload) {
42-
return reloadStream || (reloadStream = require('browser-sync').get(options.buildHash).stream); //eslint-disable-line no-return-assign
43-
}
44-
return noop;
45-
}
4638

4739
return gulp.src([
4840
paths.toPath('src.assets/styles/**/*.{sass,scss}')
4941
])
50-
.pipe($.plumber({
51-
errorHandler: $.notify.onError('Error: <%= error.message %>')
52-
}))
42+
.pipe($.plumber({ errorHandler }))
5343
.pipe($.sourcemaps.init())
5444
.pipe($.sass({
5545
precision: 10,
@@ -63,8 +53,8 @@ module.exports = (gulp, $, options) => {
6353
.pipe($.if(production, optimizePipe()))
6454
.pipe($.sourcemaps.write('.'))
6555
.pipe(gulp.dest(paths.toPath('dist.assets/css')))
66-
.pipe(reloadStreamFn()({ match: '**/*.css' }))
67-
.pipe($.if(options.isWatching, $.notify({ message: 'SASS Compiled', onLast: true })))
56+
.pipe(getReloadStream(options)({ match: '**/*.css' }))
57+
.pipe(notify({ message: 'SASS Compiled', onLast: true }))
6858
.pipe($.size({ title: 'styles' }));
6959
};
7060

build/gulp-tasks/views.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = (gulp, $, options) => {
1212
const _ = require('lodash');
1313
const glob = require('globby');
1414
const through = require('through2');
15-
const { map } = require('./lib/plugins');
15+
const { map, getNotifier } = require('./lib/plugins');
1616
const rendererCreator = require('./lib/renderers');
1717

1818
const baseData = {};
@@ -70,6 +70,7 @@ module.exports = (gulp, $, options) => {
7070
return () => {
7171

7272
const htmlFilter = $.filter(`**/${viewmatch}`, { restore: true });
73+
const { notify, errorHandler } = getNotifier(options);
7374

7475
const data = glob.sync('{,*/}*.json', { cwd: fixturesPath }).reduce((obj, filename) => {
7576
const id = _.camelCase(filename.toLowerCase().replace('.json', ''));
@@ -78,9 +79,7 @@ module.exports = (gulp, $, options) => {
7879
}, {});
7980

8081
return gulp.src([`${viewPath}/{,*/}${viewmatch}`, `!${viewPath}/{,*/}_*.*`])
81-
.pipe($.plumber({
82-
errorHandler: $.notify.onError('Error: <%= error.message %>')
83-
}))
82+
.pipe($.plumber({ errorHandler }))
8483
.pipe(map((code, filepath) => {
8584
const engine = renderer.match(filepath);
8685
if (engine) {
@@ -97,6 +96,6 @@ module.exports = (gulp, $, options) => {
9796
.pipe(htmlFilter.restore)
9897
.pipe($.if(production, $.rev.manifest(paths.toPath('dist.root/dist.revmap'), { merge: true })))
9998
.pipe($.if(production, gulp.dest('.')))
100-
.pipe($.if(options.isWatching, $.notify({ message: 'Views rendered', onLast: true })));
99+
.pipe(notify({ message: 'Views rendered', onLast: true }));
101100
};
102101
};

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "wok",
33
"description": "A Static Website Boilerplate",
4-
"version": "7.0.1",
4+
"version": "7.1.0",
55
"license": "MIT",
66
"repository": {
77
"type": "git",
@@ -26,7 +26,9 @@
2626
"node": ">=6.9.0"
2727
},
2828
"scripts": {
29-
"lint:build": "eslint -c ./.eslintrc.json ./build/**/*.js"
29+
"lint:build": "eslint -c ./.eslintrc.json ./build/**/*.js",
30+
"start": "gulp serve",
31+
"build": "gulp --production"
3032
},
3133
"browserslist": [
3234
"last 1 major version",

0 commit comments

Comments
 (0)