diff --git a/bin/sassTocss.js b/bin/sassTocss.js index 7f041e0..61b0ef5 100644 --- a/bin/sassTocss.js +++ b/bin/sassTocss.js @@ -26,13 +26,21 @@ const convertToCSS = (fullPath, targetPath) => { }); }; -fs.readdirSync(dir).forEach(file => { - const fullPath = path.join(dir, file); - const targetPath = fullPath.replace('app/', 'public/'); - const targetCSS = targetPath.replace('.scss', '.css'); +const readCSSDir = () => { + fs.readdirSync(dir).forEach(file => { + const fullPath = path.join(dir, file); + const targetPath = fullPath.replace('app/', 'public/'); + const targetCSS = targetPath.replace('.scss', '.css'); + + // to exclude modules folder + if (!fs.lstatSync(fullPath).isDirectory()) { + convertToCSS(fullPath, targetCSS); + } + }); +} + +readCSSDir(); + +module.exports = { readCSSDir } + - // to exclude modules folder - if (!fs.lstatSync(fullPath).isDirectory()) { - convertToCSS(fullPath, targetCSS); - } -}); diff --git a/bin/watch.js b/bin/watch.js index dc6671b..6faeaec 100644 --- a/bin/watch.js +++ b/bin/watch.js @@ -6,7 +6,7 @@ const partials = require('./partials.js'); const utils = require('./utils.js'); const path = require('path'); const config = require('./config.js'); -const sass = require('sass'); +const sass = require('./sassToCss.js'); const precompileHbsTemplates = require('./hbs.js'); /* watching js files for bundling */ @@ -33,28 +33,10 @@ const watcher = chokidar.watch('.', { cwd: 'app' }); -const watchCSS = () => { - sass.render({ - file: './app/resources/css/styles.scss', - includePaths: ['./app/resources/css/modules/'] - }, function(err, result) { - if(!err) { - // No errors during the compilation, write this result on the disk - fs.writeFile('public/resources/css/styles.css', result.css, function(err){ - if(!err){ - //file written on disk - } - }); - } else { - console.error(err); - } - }); -}; - /* copies assets and resources to public folder */ const copyFile = (filepath) => { if (filepath.indexOf('resources/css') >= 0) { - watchCSS(); + sass.readCSSDir(); } else if (filepath.indexOf('resources/hbs') >= 0) { precompileHbsTemplates(); } else { diff --git a/package.json b/package.json index f6300ed..29c387f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "build", - "version": "1.0.3", + "version": "1.0.4", "description": "A frontend build for HTML Websites", "repository": { "type": "git",