// Requires
var pkg = require('./package.json');
var gulp = require('gulp');
var autoprefixer = require('gulp-autoprefixer');
var browserSync = require('browser-sync').create();
var changed = require('gulp-changed');
var concat = require('gulp-concat');
var cssnano = require('gulp-cssnano');
var data = require('gulp-data');
var del = require('del');
var fs = require('fs');
var imagemin = require('gulp-imagemin');
var plumber = require('gulp-plumber');
var rename = require('gulp-rename');
var sass = require('gulp-sass');
var size = require('gulp-size');
var svgSprite = require('gulp-svg-sprite');
var twig = require('gulp-twig');
var uglify = require('gulp-uglify');





// BrowserSync reload
function reload(done) {
  browserSync.reload();
  done();
};





// CSS task
gulp.task('css', function() {
  return gulp.src(pkg.paths.src.css + '**/*.scss')
    .pipe(plumber())
    .pipe(sass().on('error', sass.logError))
    .pipe(autoprefixer())
    .pipe(cssnano({ preset: 'default' }))
    .pipe(rename({ suffix: '.min' }))
    .pipe(size({ gzip: true, showFiles: true }))
    .pipe(gulp.dest(pkg.paths.dist.css))
    .pipe(browserSync.stream());
});

// JS task
gulp.task('js', function() {
  return gulp.src(pkg.globs.js)
    .pipe(plumber())
    .pipe(concat(pkg.vars.jsName))
    .pipe(uglify())
    .pipe(size({ gzip: true }))
    .pipe(gulp.dest(pkg.paths.dist.js));
});

// HTML task
function getData() {
  var data = JSON.parse(fs.readFileSync(pkg.paths.src.base + pkg.vars.dataName, 'utf8'));
  return data;
};

gulp.task('html', function() {
  return gulp.src(pkg.paths.src.html + '*.{html,twig}')
    .pipe(data(getData()))
    .pipe(twig())
    .pipe(gulp.dest(pkg.paths.dist.html));
});

// Images task
gulp.task('images', function() {
  return gulp.src(pkg.paths.src.img + '**/*.{png,jpg,jpeg,gif,svg}')
    .pipe(changed(pkg.paths.dist.img))
    .pipe(imagemin([
      imagemin.gifsicle({interlaced: true}),
      imagemin.jpegtran({progressive: true})
    ]))
    .pipe(size({ gzip: true }))
    .pipe(gulp.dest(pkg.paths.dist.img));
});

// Sprites task
gulp.task('sprites', function() {
  return gulp.src(pkg.paths.src.sprites + '**/*.svg')
    .pipe(svgSprite({
      mode: {
        symbol: {
          dest: '.',
          sprite: pkg.vars.spriteName
        }
      }
    }))
    .pipe(size({ gzip: true }))
    .pipe(gulp.dest(pkg.paths.dist.sprites));
});

// Fonts task
gulp.task('fonts', function() {
  return gulp.src(pkg.paths.src.fonts + '**/*.{eot,ttf,woff,woff2}')
    .pipe(changed(pkg.paths.dist.fonts))
    .pipe(size({ gzip: true }))
    .pipe(gulp.dest(pkg.paths.dist.fonts));
})

// Clean task
gulp.task('clean', function() {
  return del(pkg.globs.clean);
});

// Serve task
gulp.task('serve', function() {
  browserSync.init({
    server: pkg.urls.local
  });

  gulp.watch(pkg.paths.src.css + '**/*.scss', gulp.series('css'));
	gulp.watch(pkg.paths.src.js + '**/*.js', gulp.series('js', reload));
	gulp.watch([
      pkg.paths.src.html + '**/*.{html,twig}',
      pkg.paths.src.base + pkg.vars.dataName
    ], gulp.series('html', reload));
	gulp.watch(pkg.paths.src.img + '**/*.{png,jpg,jpeg,gif,svg}', gulp.series('images'));
  gulp.watch(pkg.paths.src.sprites + '**/*.svg', gulp.series('sprites'));
  gulp.watch(pkg.paths.src.fonts + '**/*.{eot,ttf,woff,woff2}', gulp.series('fonts'))
});





// Default task
gulp.task('default',
  gulp.series(
    gulp.parallel('css', 'js', 'html', 'images', 'sprites', 'fonts'),
    'serve'
  )
);

// Build task
gulp.task('build',
  gulp.series(
    'clean',
    gulp.parallel('css', 'js', 'html', 'images', 'sprites', 'fonts')
  )
);

@@ -755,16 +755,167 @@
 ();%0A%7D;%0A%0A
+// Get data for JSON%0Afunction getData() %7B%0A  var data = JSON.parse(fs.readFileSync(pkg.paths.src.base + pkg.vars.dataName, 'utf8'));%0A  return data;%0A%7D;%0A%0A
 %0A%0A%0A%0A// C
@@ -1546,138 +1546,8 @@
 ask%0A
-function getData() %7B%0A  var data = JSON.parse(fs.readFileSync(pkg.paths.src.base + pkg.vars.dataName, 'utf8'));%0A  return data;%0A%7D;%0A%0A
 gulp

Reorder code