From 7e415f900d61a3d4f1a72726db7f2823d9e77d9d Mon Sep 17 00:00:00 2001 From: Praseetha-KR Date: Sun, 16 Oct 2016 03:18:46 +0530 Subject: [PATCH 1/4] Adds build & dev-build tasks --- gulpfile.js | 174 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 127 insertions(+), 47 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index b803ffe..b7e0d19 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -16,71 +16,85 @@ var gulp = require('gulp'), deploy = require('gulp-gh-pages'), notify = require('gulp-notify'), sassLint = require('gulp-sass-lint'), - twig = require('gulp-twig'); + twig = require('gulp-twig'), + runSequence = require('run-sequence'), + del = require('del'); +var is_prod = false; + +var paths = { + libscss: 'source/scss/**/*.scss', + sitescss: 'site/scss/**/*.scss', + sitetwig: 'site/**/*.twig', + siteimg: 'site/img', + testimg: 'site/test/ref', + testcss: 'site/test/css', + filtersjson: 'site/filters.json', + dev: '.dev/' +} +var compiledPaths = { + libcss: 'source/css/', + sitecss: 'site/css/' +} gulp.task('lib-scss', function() { - var onError = function(err) { - notify.onError({ - title: "Gulp", - subtitle: "Failure!", - message: "Error: <%= error.message %>", - sound: "Beep" - })(err); - this.emit('end'); + var dest = paths.dev + compiledPaths.libcss; + if (is_prod) { + dest = compiledPaths.libcss; + } + var onError = function(err) { + notify.onError({ + title: "Gulp", + subtitle: "Failure!", + message: "Error: <%= error.message %>", + sound: "Beep" + })(err); + this.emit('end'); }; - return gulp.src('source/scss/**/*.scss') + return gulp.src(paths.libscss) .pipe(plumber({errorHandler: onError})) .pipe(sass()) .pipe(size({ gzip: true, showFiles: true })) .pipe(prefix()) - .pipe(gulp.dest('source/css')) + .pipe(gulp.dest(dest)) .pipe(cssmin()) .pipe(size({ gzip: true, showFiles: true })) .pipe(rename({ suffix: '.min' })) - .pipe(gulp.dest('source/css')) + .pipe(gulp.dest(dest)) .pipe(gulp.dest('site/css')) .pipe(reload({stream:true})); }); gulp.task('site-scss', function() { - var onError = function(err) { - notify.onError({ - title: "Gulp", - subtitle: "Failure!", - message: "Error: <%= error.message %>", - sound: "Beep" - })(err); - this.emit('end'); + var dest = paths.dev + compiledPaths.sitecss; + if (is_prod) { + dest = compiledPaths.sitecss; + } + var onError = function(err) { + notify.onError({ + title: "Gulp", + subtitle: "Failure!", + message: "Error: <%= error.message %>", + sound: "Beep" + })(err); + this.emit('end'); }; - return gulp.src('site/scss/**/*.scss') + return gulp.src(paths.sitescss) .pipe(plumber({errorHandler: onError})) .pipe(sass()) .pipe(size({ gzip: true, showFiles: true })) .pipe(prefix()) - .pipe(gulp.dest('site/css')) + .pipe(gulp.dest(dest)) + .pipe(reload({stream:true})) .pipe(cssmin()) .pipe(size({ gzip: true, showFiles: true })) .pipe(rename({ suffix: '.min' })) - .pipe(gulp.dest('site/css')) + .pipe(gulp.dest(dest)) .pipe(reload({stream:true})); }); -gulp.task('browser-sync', function() { - browserSync({ - server: { - baseDir: "site" - } - }); -}); - -gulp.task('deploy', function () { - return gulp.src('site/**/*') - .pipe(deploy()); -}); - gulp.task('sass-lint', function () { gulp.src('scss/**/*.scss') .pipe(sassLint()) @@ -88,27 +102,93 @@ gulp.task('sass-lint', function () { .pipe(sassLint.failOnError()); }); +gulp.task('jshint', function() { + gulp.src('js/*.js') + .pipe(jshint()) + .pipe(jshint.reporter('default')); +}); + gulp.task('twig', function () { - gulp.src(['site/**/*.twig', "!site/twig/template.twig"], {base: './'}) + var dest = paths.dev; + if (is_prod) { + dest = './'; + } + gulp.src([paths.sitetwig, "!site/twig/template.twig"], {base: './'}) .pipe(twig({ data: require('./site/filters.json') })) - .pipe(gulp.dest('./')); + .pipe(gulp.dest(dest)); }); +function copytask(src, dest) { + return function() { + return gulp.src(src) + .pipe(gulp.dest(dest)); + } +} + +gulp.task('copy-site-img', copytask( + paths.siteimg + '/**/*', + paths.dev + paths.siteimg +)); +gulp.task('copy-test-img', copytask( + paths.testimg + '/**/*', + paths.dev + paths.testimg +)); +gulp.task('copy-test-css', copytask( + paths.testcss + '/**/*', + paths.dev + paths.testcss +)); +gulp.task('copy-files', ['copy-site-img', 'copy-test-img', 'copy-test-css']); -gulp.task('watch', function() { - gulp.watch('source/scss/**/*.scss', ['lib-scss', 'site-scss', 'sass-lint']); - gulp.watch('site/scss/**/*.scss', ['site-scss', 'sass-lint']); +gulp.task('dev-build', function(cb) { + is_prod = false; + runSequence( + 'cleandev', + 'copy-files', + 'site-scss', + 'lib-scss', + 'twig', + cb + ); +}); +gulp.task('watch', ['dev-build'], function() { + browserSync({ + server: { + baseDir: paths.dev + 'site' + } + }); + gulp.watch(paths.libscss, ['lib-scss', 'site-scss', 'sass-lint']); + gulp.watch(paths.sitescss, ['site-scss', 'sass-lint']); gulp.watch('source/scss/**/*.html', ['minify-html']); - gulp.watch('site/**/*.twig', ['twig']); + gulp.watch(paths.sitetwig, ['twig']); }); +gulp.task('cleandev', function() { + return del([paths.dev]); +}); -gulp.task('jshint', function() { - gulp.src('js/*.js') - .pipe(jshint()) - .pipe(jshint.reporter('default')); +gulp.task('build', function(cb) { + is_prod = true; + runSequence( + 'site-scss', + 'lib-scss', + 'twig', + cb + ); +}); + +gulp.task('server', function() { + browserSync({ + server: { + baseDir: 'site' + } + }); +}); + +gulp.task('deploy', function () { + return gulp.src('site/**/*') + .pipe(deploy()); }); -gulp.task('default', ['browser-sync', 'twig', 'lib-scss', 'site-scss', 'watch']); +gulp.task('default', ['watch']); From 18f16d752549f188d8a1cec5ee631378b136e5cc Mon Sep 17 00:00:00 2001 From: Praseetha-KR Date: Sun, 16 Oct 2016 03:19:59 +0530 Subject: [PATCH 2/4] Adds run-sequence & del to dev deps --- package.json | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index f2e33ff..9196947 100644 --- a/package.json +++ b/package.json @@ -20,22 +20,24 @@ ], "devDependencies": { "browser-sync": "^2.16.1", + "del": "^2.2.2", "gulp": "^3.9.1", "gulp-autoprefixer": "^3.1.1", "gulp-cached": "^1.1.0", + "gulp-clean-css": "^2.0.13", "gulp-concat": "^2.6.0", "gulp-gh-pages": "^0.5.4", - "gulp-imagemin": "^3.0.3", - "gulp-clean-css": "^2.0.13", "gulp-htmlmin": "^3.0.0", + "gulp-imagemin": "^3.0.3", "gulp-notify": "^2.2.0", "gulp-plumber": "^1.1.0", "gulp-rename": "^1.2.2", "gulp-sass": "^2.3.2", "gulp-sass-lint": "1.2.0", "gulp-size": "^2.1.0", + "gulp-twig": "~0.5.0", "gulp-uglify": "^2.0.0", "imagemin-pngquant": "^5.0.0", - "gulp-twig": "~0.5.0" + "run-sequence": "^1.2.2" } } From c773b4857ab6d9c2b3b92bc203ed99416ff76c33 Mon Sep 17 00:00:00 2001 From: Praseetha-KR Date: Wed, 26 Oct 2016 11:36:21 +0530 Subject: [PATCH 3/4] Add .dev/ to gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d444c16..99b857e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules/ -assets/ \ No newline at end of file +assets/ +.dev/ From 726e5d500ca02170bd5c1ef776b50aca8df0d13b Mon Sep 17 00:00:00 2001 From: Praseetha-KR Date: Wed, 26 Oct 2016 11:38:04 +0530 Subject: [PATCH 4/4] Remove site/css dest for lib-scss task --- gulpfile.js | 1 - 1 file changed, 1 deletion(-) diff --git a/gulpfile.js b/gulpfile.js index b7e0d19..8aa7bd6 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -62,7 +62,6 @@ gulp.task('lib-scss', function() { .pipe(size({ gzip: true, showFiles: true })) .pipe(rename({ suffix: '.min' })) .pipe(gulp.dest(dest)) - .pipe(gulp.dest('site/css')) .pipe(reload({stream:true})); });