Commit 191f37e4 authored by Nikolay Gromov's avatar Nikolay Gromov

Автоматизация: рефакторинг

parent d5b93c82
...@@ -257,9 +257,10 @@ function writeJsRequiresFile(cb) { ...@@ -257,9 +257,10 @@ function writeJsRequiresFile(cb) {
nth.config.addJsBefore.forEach(function(src) { nth.config.addJsBefore.forEach(function(src) {
jsRequires += `require('${src}');\n`; jsRequires += `require('${src}');\n`;
}); });
let allBlocksWithJsFiles = getDirectories('js'); const allBlocksWithJsFiles = getDirectories('js');
const allUsedBlocks = nth.blocksFromHtml.concat(nth.config.alwaysAddBlocks);
allBlocksWithJsFiles.forEach(function(blockWithJsFile){ allBlocksWithJsFiles.forEach(function(blockWithJsFile){
if (nth.blocksFromHtml.indexOf(blockWithJsFile) == -1) return; if (allUsedBlocks.indexOf(blockWithJsFile) == -1) return;
jsRequires += `require('../blocks/${blockWithJsFile}/${blockWithJsFile}.js');\n`; jsRequires += `require('../blocks/${blockWithJsFile}/${blockWithJsFile}.js');\n`;
}); });
nth.config.addJsAfter.forEach(function(src) { nth.config.addJsAfter.forEach(function(src) {
...@@ -267,6 +268,7 @@ function writeJsRequiresFile(cb) { ...@@ -267,6 +268,7 @@ function writeJsRequiresFile(cb) {
}); });
jsRequires += msg; jsRequires += msg;
fs.writeFileSync(`${dir.src}js/entry.js`, jsRequires); fs.writeFileSync(`${dir.src}js/entry.js`, jsRequires);
console.log('---------- Write new entry.js');
cb(); cb();
} }
exports.writeJsRequiresFile = writeJsRequiresFile; exports.writeJsRequiresFile = writeJsRequiresFile;
...@@ -336,13 +338,6 @@ function serve() { ...@@ -336,13 +338,6 @@ function serve() {
notify: false, notify: false,
}); });
// Конфигурационный файл
watch([`config.js`], { events: ['change'], delay: 100 }, series(
parallel(writeSassImportsFile, writeJsRequiresFile),
parallel(compileSass, buildJs),
reload
));
// Страницы: изменение, добавление // Страницы: изменение, добавление
watch([`${dir.src}pages/**/*.pug`], { events: ['change', 'add'], delay: 100 }, series( watch([`${dir.src}pages/**/*.pug`], { events: ['change', 'add'], delay: 100 }, series(
compilePugFast, compilePugFast,
...@@ -484,7 +479,7 @@ function getClassesToBlocksList(file, enc, cb) { ...@@ -484,7 +479,7 @@ function getClassesToBlocksList(file, enc, cb) {
// Добавляем класс в список // Добавляем класс в список
nth.blocksFromHtml.push(item); nth.blocksFromHtml.push(item);
} }
console.log('---------- Used blocks: ' + nth.blocksFromHtml.join(', ')); console.log('---------- Used HTML blocks: ' + nth.blocksFromHtml.join(', '));
file.contents = new Buffer(fileContent); file.contents = new Buffer(fileContent);
} }
this.push(file); this.push(file);
......
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