diff --git a/generators/app/templates/gulp/tasks/pug.js b/generators/app/templates/gulp/tasks/pug.js index 140f7cb9..b363a354 100644 --- a/generators/app/templates/gulp/tasks/pug.js +++ b/generators/app/templates/gulp/tasks/pug.js @@ -1,42 +1,31 @@ -var gulp = require('gulp'); -var pug = require('gulp-pug'); -var plumber = require('gulp-plumber'); -var changed = require('gulp-changed'); -var gulpif = require('gulp-if'); -var frontMatter = require('gulp-front-matter'); -var prettify = require('gulp-prettify'); -var config = require('../config'); - -function renderHtml(onlyChanged) { - return gulp - .src([config.src.templates + '/[^_]*.pug']) - .pipe(plumber({ errorHandler: config.errorHandler })) - .pipe(gulpif(onlyChanged, changed(config.dest.html, { extension: '.html' }))) - .pipe(frontMatter({ property: 'data' })) - .pipe(pug()) - .pipe(prettify({ - indent_size: 2, - wrap_attributes: 'auto', // 'force' - preserve_newlines: true, - // unformatted: [], - end_with_newline: true - })) - .pipe(gulp.dest(config.dest.html)); +import gulp from 'gulp'; +import pug from 'gulp-pug'; +import plumber from 'gulp-plumber' +import changed from 'gulp-changed'; +import gulpif from 'gulp-if'; +import frontMatter from 'gulp-front-matter'; +import prettify from 'gulp-prettify'; +import config from '../config'; + +const renderHtml = (onlyChanged) => { + return gulp + .src([config.src.templates + '/[^_]*.pug']) + .pipe(plumber({ errorHandler: config.errorHandler })) + .pipe(gulpif(onlyChanged, changed(config.dest.html, { extension: '.html' }))) + .pipe(frontMatter({ property: 'data' })) + .pipe(pug()) + .pipe(prettify({ + indent_size: 2, + wrap_attributes: 'auto', // 'force' + preserve_newlines: true, + // unformatted: [], + end_with_newline: true + })) + .pipe(gulp.dest(config.dest.html)); } -gulp.task('pug', function() { - return renderHtml(); -}); - -gulp.task('pug:changed', function() { - return renderHtml(true); -}); - -gulp.task('pug:watch', function() { - gulp.watch([config.src.templates + '/**/_*.pug'], ['pug']); - gulp.watch([config.src.templates + '/**/[^_]*.pug'], ['pug:changed']); -}); - +gulp.task('pug', () => renderHtml()); +gulp.task('pug:changed', () => renderHtml(true)); const build = gulp => gulp.parallel('pug'); const watch = gulp => { diff --git a/generators/app/templates/gulp/tasks/swig.js b/generators/app/templates/gulp/tasks/swig.js new file mode 100644 index 00000000..b06c35a8 --- /dev/null +++ b/generators/app/templates/gulp/tasks/swig.js @@ -0,0 +1,53 @@ +var gulp = require('gulp'); +var swig = require('gulp-swig'); +var plumber = require('gulp-plumber'); +var gulpif = require('gulp-if'); +var changed = require('gulp-changed'); +var prettify = require('gulp-prettify'); +var frontMatter = require('gulp-front-matter'); +var config = require('../config'); + +function renderHtml(onlyChanged) { + return gulp + .src([config.src.templates + '/**/[^_]*.html']) + .pipe(plumber({ + errorHandler: config.errorHandler + })) + .pipe(gulpif(onlyChanged, changed(config.dest.html))) + .pipe(frontMatter({ property: 'data' })) + .pipe(swig({ + load_json: true, + json_path: config.src.templatesData, + defaults: { + cache: false + } + })) + .pipe(prettify({ + indent_size: 2, + wrap_attributes: 'auto', // 'force' + preserve_newlines: true, + // unformatted: [], + + end_with_newline: true + })) + .pipe(gulp.dest(config.dest.html)); +} + +gulp.task('swig', function() { + return renderHtml(); +}); + +gulp.task('swig:changed', function() { + return renderHtml(true); +}); + +gulp.task('swig:watch', function() { + gulp.watch([ + config.src.templates + '/**/[^_]*.html' + ], ['swig:changed']); + + gulp.watch([ + config.src.templates + '/**/_*.html', + config.src.templatesData + '/*.json' + ], ['swig']); +}); diff --git a/generators/app/templates/gulpfile.babel.js b/generators/app/templates/gulpfile.babel.js index 0fc9512d..09157fc7 100644 --- a/generators/app/templates/gulpfile.babel.js +++ b/generators/app/templates/gulpfile.babel.js @@ -4,28 +4,25 @@ import config from './gulp/config'; const getTaskBuild = task => require('./gulp/tasks/' + task).build(gulp); const getTaskWatch = task => require('./gulp/tasks/' + task).watch(gulp); - - - - - gulp.task('clean', getTaskBuild('clean')); gulp.task('copy', getTaskBuild('copy')); -gulp.task('nunjucks', () => getTaskBuild('nunjucks')); -gulp.task('sass', () => getTaskBuild('sass')); -gulp.task('server', () => getTaskBuild('server')); -gulp.task('svgo', () => getTaskBuild('svgo')); +gulp.task('server', () => getTaskBuild('server'));<% if (templates === 'nunjucks') { %> +gulp.task('nunjucks', () => getTaskBuild('nunjucks'));<% } %><% if (templates === 'pug') { %> +gulp.task('pug', () => getTaskBuild('pug'));<% } %><% if (css === 'sass') { %> +gulp.task('sass', () => getTaskBuild('sass'));<% } %><% if (sprites.indexOf('svg') !== -1) { %> +gulp.task('sprite:svg', () => getTaskBuild('sprite-svg'));<% } %><% if (svgo) { %> +gulp.task('svgo', () => getTaskBuild('svgo'));<% } %><% if (preview) { %> +gulp.task('list-pages', getTaskBuild('list-pages'));<% } %> gulp.task('webpack', getTaskBuild('webpack')); -gulp.task('list-pages', getTaskBuild('list-pages')); -gulp.task('sprite:svg', () => getTaskBuild('sprite-svg')); -gulp.task('copy:watch', getTaskWatch('copy')); -gulp.task('nunjucks:watch', getTaskWatch('nunjucks')); -gulp.task('sass:watch', getTaskWatch('sass')); -gulp.task('svgo:watch', getTaskWatch('svgo')); +gulp.task('copy:watch', getTaskWatch('copy'));<% if (templates === 'nunjucks') { %> +gulp.task('nunjucks:watch', getTaskWatch('nunjucks'));<% } %><% if (templates === 'pug') { %> +gulp.task('pug:watch', getTaskWatch('pug'));<% } %><% if (css === 'sass') { %> +gulp.task('sass:watch', getTaskWatch('sass'));<% } %><% if (sprites.indexOf('svg') !== -1) { %> +gulp.task('sprite:svg:watch', getTaskWatch('sprite-svg'));<% } %><% if (svgo) { %> +gulp.task('svgo:watch', getTaskWatch('svgo'));<% } %><% if (preview) { %> +gulp.task('list-pages:watch', getTaskWatch('list-pages'));<% } %> gulp.task('webpack:watch', getTaskWatch('webpack')); -gulp.task('list-pages:watch', getTaskWatch('list-pages')); -gulp.task('sprite:svg:watch', getTaskWatch('sprite-svg')); const setmodeProd = done => { config.setEnv('production'); @@ -35,7 +32,7 @@ const setmodeProd = done => { const setmodeDev = done => { config.setEnv('development'); - config.logEnv(); + config.logEnv(); done(); } @@ -43,30 +40,30 @@ gulp.task( 'build', gulp.series( setmodeProd, - 'clean', - <% if (sprites.indexOf('svg') !== -1) { %>'sprite:svg',<% } %> - <% if (svgo) { %>'svgo',<% } %> - <% if (css === 'sass') { %>'sass',<% } %> - <% if (templates === 'nunjucks') { %>'nunjucks',<% } %> - <% if (templates === 'pug') { %>'pug',<% } %> - 'webpack', - 'copy', - <% if (preview) { %>'list-pages'<% } %> - ) + 'clean',<% if (sprites.indexOf('svg') !== -1) { %> + 'sprite:svg',<% } %><% if (svgo) { %> + 'svgo',<% } %><% if (css === 'sass') { %> + 'sass',<% } %><% if (templates === 'nunjucks') { %> + 'nunjucks',<% } %><% if (templates === 'pug') { %> + 'pug',<% } %> + 'webpack',<% if (preview) { %> + 'list-pages',<% } %> + 'copy' + ) ); gulp.task( 'build:dev', gulp.series( setmodeDev, - 'clean', - <% if (sprites.indexOf('svg') !== -1) { %>'sprite:svg',<% } %> - <% if (svgo) { %>'svgo',<% } %> - <% if (css === 'sass') { %>'sass',<% } %> - <% if (templates === 'nunjucks') { %>'nunjucks',<% } %> - <% if (templates === 'pug') { %>'pug',<% } %> - 'webpack', - <% if (preview) { %>'list-pages',<% } %> + 'clean',<% if (sprites.indexOf('svg') !== -1) { %> + 'sprite:svg',<% } %><% if (svgo) { %> + 'svgo',<% } %><% if (css === 'sass') { %> + 'sass',<% } %><% if (templates === 'nunjucks') { %> + 'nunjucks',<% } %><% if (templates === 'pug') { %> + 'pug',<% } %> + 'webpack',<% if (preview) { %> + 'list-pages',<% } %> 'copy' ) ); @@ -74,14 +71,14 @@ gulp.task( gulp.task( 'watch', gulp.parallel( - 'copy:watch', - <% if (templates === 'nunjucks') { %>'nunjucks:watch',<% } %> - <% if (templates === 'pug') { %>'pug:watch',<% } %> - <% if (sprites.indexOf('svg') !== -1) { %>'sprite:svg:watch',<% } %> - <% if (svgo) { %>'svgo:watch',<% } %> - <% if (preview) { %>'list-pages:watch',<% } %> - 'webpack:watch', - <% if (css === 'sass') { %>'sass:watch'<% } %> + 'copy:watch',<% if (templates === 'nunjucks') { %> + 'nunjucks:watch',<% } %><% if (templates === 'pug') { %> + 'pug:watch',<% } %><% if (sprites.indexOf('svg') !== -1) { %> + 'sprite:svg:watch',<% } %><% if (svgo) { %> + 'svgo:watch',<% } %><% if (preview) { %> + 'list-pages:watch',<% } %> + 'webpack:watch',<% if (css === 'sass') { %> + 'sass:watch'<% } %> ) ); diff --git a/generators/app/writing.js b/generators/app/writing.js index 9a25d594..206f1498 100644 --- a/generators/app/writing.js +++ b/generators/app/writing.js @@ -36,18 +36,18 @@ module.exports = function () { this.fs.copy(this.templatePath('gulp/util/handle-errors.js'),'gulp/util/handle-errors.js'); // common tasks - this.fs.copyTpl(this.templatePath('gulp/tasks/default.js'),'gulp/tasks/default.js'); + // this.fs.copyTpl(this.templatePath('gulp/tasks/default.js'),'gulp/tasks/default.js'); // this.fs.copyTpl(this.templatePath('gulp/tasks/build.js'),'gulp/tasks/build.js', props); - // this.fs.copyTpl(this.templatePath('gulp/tasks/watch.js'),'gulp/tasks/watch.js', props); + this.fs.copyTpl(this.templatePath('gulp/tasks/copy.js'),'gulp/tasks/copy.js', props); - this.fs.copy(this.templatePath('gulp/tasks/clean.js'),'gulp/tasks/clean.js'); this.fs.copy(this.templatePath('gulp/tasks/server.js'),'gulp/tasks/server.js'); - this.fs.copy(this.templatePath('gulp/tasks/index/index.html'),'gulp/tasks/index/index.html'); - this.fs.copy(this.templatePath('gulp/tasks/list-pages.js'),'gulp/tasks/list-pages.js'); - + if(props.preview){ + this.fs.copy(this.templatePath('gulp/tasks/index/index.html'),'gulp/tasks/index/index.html'); + this.fs.copy(this.templatePath('gulp/tasks/list-pages.js'),'gulp/tasks/list-pages.js'); + } this.sprites = props.sprites; // or in /templates/src/sass/app.sass use options.sprites @@ -172,17 +172,21 @@ module.exports = function () { this.fs.copyTpl(this.templatePath('src/sass/app.sss'), 'src/sass/app.sss',props); } - - - - - switch (props.templates) { case 'nunjucks': this.fs.copy(this.templatePath('src/templates-nunjucks'), 'src/templates'); - this.fs.delete('src/templates/page.html'); - this.fs.copy(this.templatePath('src/templates-nunjucks/page.html'), 'src/templates/index.html'); + if(!props.preview){ + this.fs.delete('src/templates/page.html'); + this.fs.copy(this.templatePath('src/templates-nunjucks/page.html'), 'src/templates/index.html'); + } + break; + case 'pug': + this.fs.copy(this.templatePath('src/templates-pug'), 'src/templates'); + if(!props.preview){ + this.fs.delete('src/templates/page.pug'); + this.fs.copy(this.templatePath('src/templates-pug/page.pug'), 'src/templates/index.pug'); + } break; case 'swig': this.fs.copy(this.templatePath('src/templates-swig'), 'src/templates'); @@ -190,9 +194,6 @@ module.exports = function () { case 'jade': this.fs.copy(this.templatePath('src/templates-jade'), 'src/templates'); break; - case 'pug': - this.fs.copy(this.templatePath('src/templates-pug'), 'src/templates'); - break; case 'html': this.fs.copy(this.templatePath('src/templates-html'), 'src'); break;