Commit b41b3073 authored by Nikolay Gromov's avatar Nikolay Gromov

Допилил автоматизацию

parent ef5c65eb
...@@ -33,6 +33,7 @@ lists.css.forEach(function(blockPath) { ...@@ -33,6 +33,7 @@ lists.css.forEach(function(blockPath) {
}); });
fs.writeFileSync('./src/scss/style.scss', styleImports); fs.writeFileSync('./src/scss/style.scss', styleImports);
// Определим разработка это или финальная сборка
// Запуск `NODE_ENV=production npm start [задача]` приведет к сборке без sourcemaps // Запуск `NODE_ENV=production npm start [задача]` приведет к сборке без sourcemaps
const isDev = !process.env.NODE_ENV || process.env.NODE_ENV == 'dev'; const isDev = !process.env.NODE_ENV || process.env.NODE_ENV == 'dev';
...@@ -78,7 +79,7 @@ gulp.task('style', function () { ...@@ -78,7 +79,7 @@ gulp.task('style', function () {
showTotal: false, showTotal: false,
})) }))
.pipe(gulp.dest(dirs.buildPath + '/css')) .pipe(gulp.dest(dirs.buildPath + '/css'))
.pipe(browserSync.stream()); .pipe(browserSync.stream({match: '**/*.css'}));
}); });
// Копирование добавочных CSS, которые хочется иметь отдельными файлами // Копирование добавочных CSS, которые хочется иметь отдельными файлами
...@@ -123,7 +124,7 @@ gulp.task('copy:js', function () { ...@@ -123,7 +124,7 @@ gulp.task('copy:js', function () {
// Копирование шрифтов // Копирование шрифтов
gulp.task('copy:fonts', function () { gulp.task('copy:fonts', function () {
console.log('---------- Копирование шрифтов'); console.log('---------- Копирование шрифтов');
return gulp.src(dirs.source + '/fonts/*.{ttf,woff,woff2,eot,svg}') return gulp.src(dirs.srcPath + '/fonts/*.{ttf,woff,woff2,eot,svg}')
.pipe(newer(dirs.buildPath + '/fonts')) // оставить в потоке только изменившиеся файлы .pipe(newer(dirs.buildPath + '/fonts')) // оставить в потоке только изменившиеся файлы
.pipe(size({ .pipe(size({
title: 'Размер', title: 'Размер',
...@@ -134,11 +135,11 @@ gulp.task('copy:fonts', function () { ...@@ -134,11 +135,11 @@ gulp.task('copy:fonts', function () {
}); });
// Сборка SVG-спрайта для блока sprite-svg // Сборка SVG-спрайта для блока sprite-svg
let spritePath = dirs.srcPath + dirs.blocksDirName + '/sprite-svg/svg/';
gulp.task('sprite:svg', function (callback) { gulp.task('sprite:svg', function (callback) {
const svgstore = require('gulp-svgstore'); const svgstore = require('gulp-svgstore');
const svgmin = require('gulp-svgmin'); const svgmin = require('gulp-svgmin');
const cheerio = require('gulp-cheerio'); const cheerio = require('gulp-cheerio');
let spritePath = dirs.srcPath + dirs.blocksDirName + '/sprite-svg/svg/';
if(fileExist(spritePath) !== false) { if(fileExist(spritePath) !== false) {
console.log('---------- Сборка SVG спрайта'); console.log('---------- Сборка SVG спрайта');
return gulp.src(spritePath + '*.svg') return gulp.src(spritePath + '*.svg')
...@@ -239,11 +240,22 @@ gulp.task('build', function (callback) { ...@@ -239,11 +240,22 @@ gulp.task('build', function (callback) {
gulpSequence( gulpSequence(
'clean', 'clean',
'sprite:svg', 'sprite:svg',
['style', 'copy:css', 'copy:img', 'copy:js', 'copy:fonts'], ['style', 'js', 'copy:css', 'copy:img', 'copy:js', 'copy:fonts'],
'html', 'html',
callback); callback);
}); });
// Отправка в GH pages (ветку gh-pages репозитория)
gulp.task('deploy', function() {
const ghPages = require('gulp-gh-pages');
console.log('---------- Публикация содержимого ./build/ на GH pages');
return gulp.src(dirs.buildPath + '**/*')
.pipe(ghPages());
});
// Задача по умолчанию
gulp.task('default', ['serve']);
// Локальный сервер, слежение // Локальный сервер, слежение
gulp.task('serve', ['build'], function() { gulp.task('serve', ['build'], function() {
browserSync.init({ browserSync.init({
...@@ -255,54 +267,44 @@ gulp.task('serve', ['build'], function() { ...@@ -255,54 +267,44 @@ gulp.task('serve', ['build'], function() {
gulp.watch([ gulp.watch([
dirs.srcPath + dirs.blocksDirName + '/**/*.scss', dirs.srcPath + dirs.blocksDirName + '/**/*.scss',
dirs.srcPath + '/scss/**/*.scss', dirs.srcPath + '/scss/**/*.scss',
], function (event) { ], ['style']);
gulpSequence('style')(function (err) { // Слежение за добавочными стилями
if (err) console.log(err); if(pjson.configProject.copiedCss.length) {
}) gulp.watch(pjson.configProject.copiedCss, ['copy:css']);
}); }
// Слежение за изображениями
if(lists.img.length) {
gulp.watch(lists.img, ['watch:img']);
}
// Слежение за добавочными JS
if(pjson.configProject.copiedJs.length) {
gulp.watch(pjson.configProject.copiedJs, ['watch:copied:js']);
}
// Слежение за шрифтами
gulp.watch(dirs.srcPath + '/fonts/*.{ttf,woff,woff2,eot,svg}', ['watch:fonts']);
// Слежение за SVG для спрайта
if(fileExist(spritePath) !== false) {
gulp.watch(spritePath + '*.svg', ['watch:svg:sprite']);
}
// Слежение за html // Слежение за html
gulp.watch([ gulp.watch([
dirs.srcPath + '/*.html', dirs.srcPath + '/*.html',
dirs.srcPath + '/_include/*.html', dirs.srcPath + '/_include/*.html',
dirs.srcPath + dirs.blocksDirName + '/**/*.html', dirs.srcPath + dirs.blocksDirName + '/**/*.html',
], function (event) { ], ['watch:html']);
gulpSequence('html', browserSync.reload())(function (err) {
if (err) console.log(err);
})
});
// Слежение за изображениями
if(lists.img) {
gulp.watch(lists.img, function (event) {
gulpSequence('copy:img', browserSync.reload())(function (err) {
if (err) console.log(err);
})
});
}
// Слежение за JS // Слежение за JS
if(lists.js) { if(lists.js.length) {
gulp.watch(lists.js, function (event) { gulp.watch(lists.js, ['watch:js']);
gulpSequence('js', browserSync.reload())(function (err) {
if (err) console.log(err);
})
});
}
// Слежение за добавочными стилями
if(pjson.configProject.copiedCss.length) {
console.log(pjson.configProject.copiedCss);
gulp.watch(pjson.configProject.copiedCss, ['copy:css']);
} }
}); });
// Отправка в GH pages (ветку gh-pages репозитория) // Браузерсинк с 3-м галпом — такой браузерсинк...
// gulp.task('deploy', function() { gulp.task('watch:img', ['copy:img'], reload);
// console.log('---------- Публикация ./build/ на GH pages'); gulp.task('watch:copied:js', ['copy:js'], reload);
// console.log('---------- '+ ghPagesUrl); gulp.task('watch:fonts', ['copy:fonts'], reload);
// return gulp.src('./build/**/*') gulp.task('watch:svg:sprite', ['sprite:svg'], reload);
// .pipe(ghPages()); gulp.task('watch:html', ['html'], reload);
// }); gulp.task('watch:js', ['js'], reload);
// Задача по умолчанию
gulp.task('default', ['serve']);
...@@ -365,3 +367,9 @@ function fileExist(path) { ...@@ -365,3 +367,9 @@ function fileExist(path) {
return !(err && err.code === 'ENOENT'); return !(err && err.code === 'ENOENT');
} }
} }
// Перезагрузка браузера
function reload (done) {
browserSync.reload();
done();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment