Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by pkosinski on 03.03.2016.
- */
- var gulp = require('gulp'),
- sass = require('gulp-sass'),
- del = require('del'),
- runSequence = require('run-sequence'),
- replace = require('gulp-replace'),
- cache = require('gulp-cached'),
- htmlmin = require('gulp-htmlmin'),
- livereload = require('gulp-livereload'),
- premailer = require('gulp-premailer'),
- fileinclude = require('gulp-file-include');
- var paths = {
- src: {
- sass: 'sample/sass/**/*.scss',
- css: 'sample/css/**/*.css',
- tmp: 'sample/tmp/**/*.html',
- templates: 'sample/template/**/*.html',
- preview: 'sample/preview/**/*.html',
- partials: 'sample/partials/**/*.html'
- },
- dest: {
- css: 'sample/styles/css',
- tmp: 'sample/tmp',
- preview: 'sample/preview'
- }
- };
- gulp.task('default', function () {
- gulp.watch([paths.src.templates, paths.src.partials, paths.src.css], ['watch']);
- gulp.watch(paths.src.sass, ['sass']);
- livereload.listen();
- });
- gulp.task('sass', function () {
- return gulp.src(paths.src.sass)
- .pipe(sass())
- .pipe(gulp.dest(paths.dest.css));
- });
- gulp.task('includePartials', function () {
- var fileIncludeConf = {
- basepath: '@root',
- context: {
- header: "'partials/header.html'",
- wrapper: "780",
- width: "690",
- grid: "690",
- col: "",
- col2: "345", // gird cols
- col3: "230",
- col4: "172",
- col2img: "310",
- col3img: "200",
- col4img: "142",
- btnClass: ""
- }
- };
- return gulp.src(paths.src.templates)
- .pipe(fileinclude(fileIncludeConf)).on("error",errLog)
- .pipe(gulp.dest(paths.dest.tmp));
- });
- gulp.task('includeNonPremailingPartials', function () {
- var fileIncludeConf = {
- basepath: '@root',
- prefix: '##'
- };
- return gulp.src(paths.src.tmp)
- .pipe(fileinclude(fileIncludeConf))
- .pipe(gulp.dest(paths.dest.tmp));
- });
- gulp.task('clean', function () {
- cache.caches = {};
- return del([paths.dest.preview, paths.dest.tmp]);
- });
- gulp.task('premailer', function () {
- return gulp.src(paths.src.tmp)
- .pipe(premailer({escape_url_attributes: false}))
- .pipe(replace('%60', '`'))
- .pipe(replace('%5B', '['))
- .pipe(replace('%5D', ']'))
- .pipe(gulp.dest(paths.dest.tmp));
- });
- gulp.task('minify', function() {
- // https://github.com/kangax/html-minifier
- var htmlMinConfig = {
- collapseWhitespace: true,
- conservativeCollapse: true,
- keepClosingSlash: true,
- removeEmptyAttributes: true,
- preventAttributesEscaping: true,
- caseSensitive: true,
- minifyCSS: true,
- maxLineLength: 76
- };
- return gulp.src(paths.src.tmp)
- .pipe(htmlmin(htmlMinConfig)).on('error', errLog)
- .pipe(gulp.dest(paths.dest.tmp));
- });
- gulp.task('watch', function(cb) {
- return runSequence('includePartials', 'premailer', 'includeNonPremailingPartials', 'minify', 'updatePreview', cb);
- });
- gulp.task('updatePreview', function () {
- return gulp.src(paths.src.tmp)
- .pipe(cache('preview'))
- .pipe(gulp.dest(paths.dest.preview))
- .pipe(livereload());
- });
- /**
- * Creates new mail template previews
- */
- gulp.task('build', function(cb) {
- return runSequence('clean', 'includePartials', 'premailer',
- 'includeNonPremailingPartials', 'minify', 'updatePreview', cb);
- });
- function errLog(err) {
- return console.error(err);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement