Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 26 additions & 37 deletions generators/app/templates/gulp/tasks/pug.js
Original file line number Diff line number Diff line change
@@ -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 => {
Expand Down
53 changes: 53 additions & 0 deletions generators/app/templates/gulp/tasks/swig.js
Original file line number Diff line number Diff line change
@@ -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']);
});
85 changes: 41 additions & 44 deletions generators/app/templates/gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -35,53 +32,53 @@ const setmodeProd = done => {

const setmodeDev = done => {
config.setEnv('development');
config.logEnv();
config.logEnv();
done();
}

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'
)
);

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'<% } %>
)
);

Expand Down
33 changes: 17 additions & 16 deletions generators/app/writing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -172,27 +172,28 @@ 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');
break;
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;
Expand Down