From 4331186ccafc545248bd47a308c610bb3ce6b006 Mon Sep 17 00:00:00 2001 From: jan Date: Thu, 16 Aug 2018 21:44:26 +0200 Subject: [PATCH] Moar changes to the gulp process --- gulpfile.js | 74 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 24 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 8689588..2914a78 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -9,10 +9,14 @@ var del = require('del'), plumber = require('gulp-plumber'), rename = require('gulp-rename'); +var Config = { + inputDir: '_source', + outputDir: '_dist' +} -var sassConfig = { - inputDirectory: '_source/sass/**/*.scss', - outputDirectory: '_dist/css', +var SassConfig = { + inputDir: '_source/sass/**/*.scss', + outputDir: '_dist/css', options: { outputStyle: 'expanded' }, @@ -23,46 +27,68 @@ var sassConfig = { // clean the folders gulp.task('clean', function(cb) { - return del([sassConfig.outputDirectory + '/*'], cb) -}); - -// watcher -gulp.task('watch', function() { - gulp.watch(sassConfig.inputDirectory, ['sass']); - livereload.listen() + return del([Config.outputDir], cb) }); // render SASS gulp.task('sass', function() {var onError = function(err) { notify.onError({ - title: "Gulp", - subtitle: "Failure!", - message: "Error: <%= error.message %>", - sound: "Submarine" + title: 'gulp', + subtitle: 'Error!', + message: '❌ <%= error.message %>', + sound: 'Submarine' })(err); this.emit('end'); }; return gulp - .src(sassConfig.inputDirectory) + .src(SassConfig.inputDir) .pipe(plumber({errorHandler: onError})) - .pipe(sass(sassConfig.options).on('error', sass.logError)) - .pipe(autoprefixer(sassConfig.autoprefixer)) - .pipe(gulp.dest(sassConfig.outputDirectory)) + .pipe(sass(SassConfig.options).on('error', sass.logError)) + .pipe(autoprefixer(SassConfig.autoprefixer)) + .pipe(gulp.dest(SassConfig.outputDir)) .pipe(cssnano()) .pipe(rename({suffix: '.min'})) - .pipe(gulp.dest(sassConfig.outputDirectory)) - .pipe(notify({ message: 'SASS rendered' })) + .pipe(gulp.dest(SassConfig.outputDir)) + .pipe(notify({ + title: 'gulp', + subtitle: 'Success!', + message: 'SASS compiled ✅', + timeout: '2' + })) .pipe(livereload()); }); gulp.task('sass-only', function() { return gulp - .src(sassConfig.inputDirectory) - .pipe(sass(sassConfig.options).on('error', sass.logError)) - .pipe(gulp.dest(sassConfig.outputDirectory)); + .src(SassConfig.inputDir) + .pipe(sass(SassConfig.options).on('error', sass.logError)) + .pipe(gulp.dest(SassConfig.outputDir)); +}); + +// Copy those other files +gulp.task('copy', function() { + gulp.src([Config.inputDir + '/*.*']) + .pipe(gulp.dest(Config.outputDir)) + .pipe(livereload()) + gulp.src([Config.inputDir + '/inc/**/*']) + .pipe(gulp.dest(Config.outputDir + '/inc')) + .pipe(livereload()) + gulp.src([Config.inputDir + '/js/**/*.*']) + .pipe(gulp.dest(Config.outputDir + '/js')) + .pipe(livereload()) +}) + +gulp.task('watch', function() { + livereload.listen() + + // Watch .scss files + gulp.watch(SassConfig.inputDir, ['sass']); + // Watch php files + gulp.watch(Config.inputDir + '/*.php', ['copy']) + gulp.watch(Config.inputDir + '/inc/*.php', ['copy']); }); // Default: First 'clean', then the rest gulp.task('default', ['clean'], function() { - gulp.start('sass'); + gulp.start('sass', 'copy'); });