implement notifications

This commit is contained in:
Lukas Juhas 2017-11-21 17:27:56 +00:00
parent 29e510c1b6
commit 4296b41faf
4 changed files with 106 additions and 71 deletions

BIN
assets/icons/error.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

BIN
assets/icons/success.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -16,10 +16,13 @@ import multiEntry from 'rollup-plugin-multi-entry';
import uglify from 'rollup-plugin-uglify'; import uglify from 'rollup-plugin-uglify';
import { minify } from 'uglify-js'; import { minify } from 'uglify-js';
import imagemin from 'gulp-imagemin'; import imagemin from 'gulp-imagemin';
import notify from 'gulp-notify';
import runSequence from 'run-sequence'; import runSequence from 'run-sequence';
import path from 'path';
const log = console.log; const log = console.log;
let production = false; let production = false;
let error = false;
/** /**
* Config * Config
@ -34,6 +37,21 @@ const config = {
*/ */
const tasks = ['styles', 'scripts', 'images']; const tasks = ['styles', 'scripts', 'images'];
/**
* Notification
*
* @param {string} message
* @param {string} status
*/
function notification(message = '', status = 'success') {
return gulp.src('./node_modules/gulp-notify/test/fixtures/1.txt')
.pipe(notify({
title: 'Barebones',
message,
icon: path.join(__dirname, `assets/icons/${status}.png`),
}));
}
/** /**
* Styles * Styles
*/ */
@ -49,7 +67,11 @@ gulp.task('styles', ['clean-styles'], () => (
.pipe(gulpif(!production, sourcemaps.init())) .pipe(gulpif(!production, sourcemaps.init()))
.pipe(sass({ .pipe(sass({
outputStyle: production ? 'compressed' : 'nested', outputStyle: production ? 'compressed' : 'nested',
}).on('error', sass.logError)) }).on('error', (err) => {
notification('Failed to compile styles. 😱', 'error');
log(err.stack);
error = true;
}))
.pipe(autoprefixer({ .pipe(autoprefixer({
browsers: ['last 10 versions'], browsers: ['last 10 versions'],
})) }))
@ -105,7 +127,11 @@ gulp.task('scripts', ['clean-scripts'], () => {
sourceMap: !production, sourceMap: !production,
dest: `${config.public}/js/script.min.js`, dest: `${config.public}/js/script.min.js`,
}); });
}).catch(err => log(err.stack)); }).catch(err => {
notification('Failed to compile scripts. 😱', 'error');
log(err.stack);
error = true;
});
}); });
/** /**
@ -136,12 +162,20 @@ gulp.task('images', () => {
* Main Tasks * Main Tasks
*/ */
gulp.task('watch', () => ( gulp.task('watch', () => (
runSequence(tasks, 'watch-files') runSequence(tasks, 'watch-files', () => {
if (!error) {
notification('Watching files... 👀');
}
})
)); ));
gulp.task('build', () => { gulp.task('build', () => {
production = true; production = true;
runSequence(tasks); runSequence(tasks, () => {
if(!error) {
notification('Build complete! 🍻');
}
});
}); });
gulp.task('default', () => ( gulp.task('default', () => (

View File

@ -31,6 +31,7 @@
"gulp-clean": "^0.3.2", "gulp-clean": "^0.3.2",
"gulp-if": "^2.0.2", "gulp-if": "^2.0.2",
"gulp-imagemin": "^3.4.0", "gulp-imagemin": "^3.4.0",
"gulp-notify": "^3.0.0",
"gulp-rename": "^1.2.2", "gulp-rename": "^1.2.2",
"gulp-sass": "^3.1.0", "gulp-sass": "^3.1.0",
"gulp-sourcemaps": "^2.6.1", "gulp-sourcemaps": "^2.6.1",