require("es6-promise").polyfill();
var gulp = require("gulp"),
concat = require("gulp-concat"),
twig = require("gulp-twig"),
data = require("gulp-data"),
postcss = require("gulp-postcss"),
autoprefixer = require("autoprefixer"),
browserSync = require("browser-sync").create(),
copy = require('gulp-copy'),
typogr = require('gulp-typogr'),
imagemin = require('gulp-imagemin'),
pngquant = require('imagemin-pngquant');
gulp.task("css", function () {
var processors = [
require("postcss-import"),
require("postcss-mixins"),
require("postcss-nested"),
require("postcss-simple-vars"),
require("postcss-color-function"),
require("postcss-calc"),
autoprefixer({
browsers: ["last 2 version"]
})
];
gulp.src("source/assets/css/style.css")
.pipe(postcss(processors))
.pipe(gulp.dest("public/css"));
});
gulp.task("copy-fonts", function() {
gulp.src("source/assets/fonts/**/*.{ttf,woff,eot,svg}").pipe(copy("public/fonts", {prefix: 3}));
});
gulp.task("copy-data", function() {
gulp.src("source/data/ru/stores.json").pipe(copy("public/data", {prefix: 4}));
});
gulp.task("images", function() {
gulp.src("source/assets/images/**/*.{jpg,svg,png,gif}")
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant()]
}))
.pipe(gulp.dest("public/images"));
});
gulp.task("js-libs", function() {
gulp.src([
"source/assets/js/components/jquery/dist/jquery.min.js",
"source/assets/js/components/fotorama/fotorama.js",
"source/assets/js/fotorama-responsive.js",
"source/assets/js/components/parsleyjs/dist/parsley.min.js",
"source/assets/js/components/parsleyjs/src/i18n/ru.js",
'source/assets/js/components/bootstrap/js/transition.js',
'source/assets/js/components/bootstrap/js/modal.js',
'source/assets/js/components/lightbox2/dist/js/lightbox.min.js'
])
.pipe(concat("libs.js"))
.pipe(gulp.dest("public/js"));
});
gulp.task("js-source", function() {
gulp.src([
"source/assets/js/up-btn.js",
"source/assets/js/main.js"
])
.pipe(concat("script.js"))
.pipe(gulp.dest("public/js"));
});
gulp.task("compile-ru", function () {
gulp.src(["source/views/*.twig",])
.pipe(data(require("./source/data/ru/home.json")))
.pipe(data(require("./source/data/ru/about.json")))
.pipe(data(require("./source/data/ru/contacts.json")))
.pipe(data(require("./source/data/ru/header.json")))
.pipe(data(require("./source/data/ru/common.json")))
.pipe(data(require("./source/data/ru/footer.json")))
.pipe(data(require("./source/data/ru/buy.json")))
.pipe(data(require("./source/data/ru/dealers.json")))
.pipe(data(require("./source/data/ru/retailer.json")))
.pipe(data(require("./source/data/ru/products.json")))
.pipe(twig())
// .pipe(typogr())
.pipe(gulp.dest("./public"));
gulp.src(["source/views/products/*.twig"])
.pipe(data(require("./source/data/ru/header.json")))
.pipe(data(require("./source/data/ru/common.json")))
.pipe(data(require("./source/data/ru/footer.json")))
.pipe(data(require("./source/data/ru/products.json")))
.pipe(twig())
.pipe(gulp.dest("./public/products"));
gulp.src(["source/views/where-to-buy/*.twig"])
.pipe(data(require("./source/data/ru/header.json")))
.pipe(data(require("./source/data/ru/common.json")))
.pipe(data(require("./source/data/ru/stores.json")))
.pipe(data(require("./source/data/ru/footer.json")))
.pipe(data(require("./source/data/ru/buy.json")))
.pipe(twig())
.pipe(gulp.dest("./public/where-to-buy"));
});
gulp.task("compile-en", function () {
gulp.src([
"source/views/index.twig",
"source/views/about.twig",
"source/views/contacts.twig",
"source/views/products.twig"
])
.pipe(data(require("./source/data/en/home.json")))
.pipe(data(require("./source/data/en/about.json")))
.pipe(data(require("./source/data/en/contacts.json")))
.pipe(data(require("./source/data/en/header.json")))
.pipe(data(require("./source/data/en/common.json")))
.pipe(data(require("./source/data/en/products.json")))
.pipe(data(require("./source/data/en/footer.json")))
.pipe(twig())
// .pipe(typogr())
.pipe(gulp.dest("./public/en"));
gulp.src(["source/views/products/*.twig"])
.pipe(data(require("./source/data/en/header.json")))
.pipe(data(require("./source/data/en/common.json")))
.pipe(data(require("./source/data/en/footer.json")))
.pipe(data(require("./source/data/en/products.json")))
.pipe(twig())
.pipe(gulp.dest("./public/en/products"));
});
gulp.task("server", function () {
browserSync.init({
server: {
baseDir: "./public"
}
});
gulp.watch("public/js/**/*.js").on("change", browserSync.reload);
gulp.watch("public/css/**/*.css").on("change", browserSync.reload);
gulp.watch("public/**/*.html").on("change", browserSync.reload);
});
gulp.task("watch", function() {
gulp.watch("source/assets/css/**/*.css", ["css"]);
gulp.watch("source/assets/js/components/**/*.js", ["js-libs"]);
gulp.watch("source/assets/js/plugins/**/*.js", ["js-libs"]);
gulp.watch("source/assets/js/**/*.js", ["js-source"]);
gulp.watch("source/assets/fonts/**/*.{ttf,woff,eot,svg}", ["copy-fonts"]);
gulp.watch("source/assets/images/**/*.{jpg,svg,png}", ["images"]);
gulp.watch("source/views/**/*.twig", ["compile"]);
gulp.watch("source/data/**/*.json", ["compile"]);
});
gulp.task("js", ["js-libs", "js-source"]);
gulp.task("compile", ["compile-ru", "compile-en"]);
gulp.task("default", ["js-libs", "js-source", "css", "compile", "copy-fonts", "copy-data"]);