diff --git a/composer.json b/composer.json index 19f497cc..94580819 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "snowdog/frontools", "description": "Set of front-end tools for Magento 2, based on Gulp.js", - "version": "0.6.1", + "version": "0.7.0", "license": "MIT", "type": "magento2-component", "extra": { diff --git a/configs/themes.json b/configs/themes.json.example similarity index 100% rename from configs/themes.json rename to configs/themes.json.example diff --git a/gulpfile.js b/gulpfile.js index a47110a2..db6e5e95 100755 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,24 +1,41 @@ -var gulp = require('gulp'); -var plugins = require('gulp-load-plugins')({ +var gulp = require('gulp'), + plugins = require('gulp-load-plugins')({ pattern: ['*', '!gulp', '!gulp-load-plugins'], rename: { - 'browser-sync': 'browserSync', - 'run-sequence': 'runSequence' + 'browser-sync' : 'browserSync', + 'marked-terminal': 'markedTerminal', + 'run-sequence' : 'runSequence' } }); -plugins.browserSync.create(); + +// Check if user create themes configuration +if (!plugins.globby.sync('./configs/themes.json').length) { + plugins.util.log( + plugins.util.colors.red('\n========================================= \n') + + plugins.util.colors.yellow('You have to create ') + + plugins.util.colors.blue('configs/themes.json') + + plugins.util.colors.red('\n=========================================') + ); + throw new plugins.util.PluginError({ + plugin: 'configs', + message: 'You have to create configs/themes.json' + }); +} + var configs = { - 'browserSync': require('./configs/browser-sync.json'), - 'csslint' : require('./configs/css-lint.json'), - 'eslint' : require('./configs/eslint.json'), - 'themes' : require('./configs/themes.json') -}; -var tasks = require('gulp-task-loader')({ + 'browserSync': require('./configs/browser-sync.json'), + 'csslint' : require('./configs/css-lint.json'), + 'eslint' : require('./configs/eslint.json'), + 'themes' : require('./configs/themes.json') + }, + tasks = require('gulp-task-loader')({ dir : 'tasks', plugins: plugins, configs: configs }); +plugins.browserSync.create(); + // define task for each theme, locale, lang, processing type etc. // gulp can't run same task in parallel, so we need different names Object.keys(configs.themes).forEach(name => { diff --git a/helpers/css-lint-custom-reporter.js b/helpers/css-lint-custom-reporter.js index 8155fc9c..ea1003d4 100755 --- a/helpers/css-lint-custom-reporter.js +++ b/helpers/css-lint-custom-reporter.js @@ -1,7 +1,9 @@ module.exports = function(gulp, plugins, configs) { function customReporter(file) { - plugins.util.log(plugins.util.colors.cyan(file.csslint.errorCount) - + ' errors in ' + plugins.util.colors.magenta(file.path)); + plugins.util.log( + plugins.util.colors.cyan(file.csslint.errorCount) + + ' errors in ' + plugins.util.colors.magenta(file.path) + ); file.csslint.results.forEach(function(result) { if (result.error.type === 'warning') { diff --git a/helpers/dependency-tree-builder.js b/helpers/dependency-tree-builder.js index 71e105c2..a35953c6 100644 --- a/helpers/dependency-tree-builder.js +++ b/helpers/dependency-tree-builder.js @@ -1,7 +1,6 @@ module.exports = function(theme, file) { - var globby = require('globby'), - fs = require('fs'); - + const fs = require('fs'); + function findDependencies(file, dependencyTree) { var content = fs.readFileSync(file, 'utf8'), path = file.replace(/(.*)\/.*/g, '$1'), @@ -36,10 +35,5 @@ module.exports = function(theme, file) { return dependencyTree; } - if (theme.lang === 'less') { - return findDependencies(file, []); - } - else { - return [theme.src + '/**/*.' + theme.lang]; - } + return findDependencies(file, []); }; diff --git a/helpers/less.js b/helpers/less.js index 2607ac11..639e5dbe 100644 --- a/helpers/less.js +++ b/helpers/less.js @@ -11,9 +11,12 @@ module.exports = function(gulp, plugins, configs, name, locale, file) { // less compiler is dumb as f*ck // can't figure out what files to process when path is like "theme/**/*.less" if (!lessFiles.length) { - var globby = require('globby'), - files = globby.sync([src + '/**/*.less', '!' + src + '/**/_*.less']); - + var files = plugins.globby.sync([ + src + '/**/*.less', + '!' + src + '/**/_*.less', + '!/**/node_modules/**' + ]); + files.forEach(file => lessFiles.push(file)); } diff --git a/helpers/scss.js b/helpers/scss.js index 8048c6b6..0aa42332 100644 --- a/helpers/scss.js +++ b/helpers/scss.js @@ -8,7 +8,7 @@ module.exports = function(gulp, plugins, configs, name, locale, file) { production = plugins.util.env.prod || false, postcss = theme.postcss || false; - return gulp.src(src, {base: theme.src + '/web'}) + return gulp.src([src, '!/**/node_modules/**'], {base: theme.src + '/web'}) .pipe(plugins.plumber({ errorHandler: plugins.notify.onError("Error: <%= error.message %>") })) .pipe(plugins.if(maps, plugins.sourcemaps.init())) .pipe(plugins.sass()) diff --git a/package.json b/package.json index a43da31d..95761551 100644 --- a/package.json +++ b/package.json @@ -4,34 +4,33 @@ "name": "Bartek Igielski", "email": "igloczek@gmail.com" }, - "verions": "0.6.0", "repository": { "type": "git", "url": "https://github.com/SnowdogApps/magento2-frontools" }, "license": "MIT", - "engine": "node >= 4.2.6", + "engines": "node >= 4.2.6", "devDependencies": { - "autoprefixer": "6.3.1", - "browser-sync": "2.11.1", - "cssnano": "3.4.0", + "autoprefixer": "6.3.6", + "browser-sync": "2.12.2", + "cssnano": "3.5.2", "globby": "4.0.0", - "gulp": "3.9.0", + "gulp": "3.9.1", "gulp-concat": "2.6.0", - "gulp-csslint": "0.2.0", + "gulp-csslint": "0.3.0", "gulp-eslint": "1.1.1", "gulp-if": "2.0.0", "gulp-less": "3.0.5", "gulp-load-plugins": "1.2.0", "gulp-logger": "0.0.2", "gulp-notify": "2.2.0", - "gulp-plumber": "1.0.1", - "gulp-postcss": "6.0.1", + "gulp-plumber": "1.1.0", + "gulp-postcss": "6.1.0", "gulp-rimraf": "0.2.0", - "gulp-sass": "2.1.1", + "gulp-sass": "2.2.0", "gulp-sourcemaps": "1.6.0", - "gulp-task-loader": "1.3.1", - "gulp-uglify": "1.5.1", + "gulp-task-loader": "1.4.2", + "gulp-uglify": "1.5.3", "gulp-util": "3.0.7", "marked": "0.3.5", "marked-terminal": "1.6.1", diff --git a/tasks/default.js b/tasks/default.js index 426c8e2b..c6b9a5ac 100644 --- a/tasks/default.js +++ b/tasks/default.js @@ -5,13 +5,11 @@ module.exports = function() { configs = this.opts.configs; // local plugins and configs - var marked = require('marked'), - renderer = require('marked-terminal') - fs = require('fs'); + const fs = require('fs'); - marked.setOptions({ - renderer: new renderer() + plugins.marked.setOptions({ + renderer: new plugins.markedTerminal() }); - console.log(marked(fs.readFileSync('./readme.md', 'UTF-8'))); + console.log(plugins.marked(fs.readFileSync('./readme.md', 'UTF-8'))); } diff --git a/tasks/deploy.js b/tasks/deploy.js index c97dfe81..90712eda 100644 --- a/tasks/deploy.js +++ b/tasks/deploy.js @@ -5,7 +5,7 @@ module.exports = function() { configs = this.opts.configs; // local plugins and configs - var execSync = require('child_process').execSync; + const execSync = require('child_process').execSync; // local vars var themeName = plugins.util.env.theme || false, diff --git a/tasks/watch.js b/tasks/watch.js index 093d9071..dbc8cf4d 100755 --- a/tasks/watch.js +++ b/tasks/watch.js @@ -5,15 +5,14 @@ module.exports = function() { configs = this.opts.configs; // local vars - var globby = require('globby'); - themeName = plugins.util.env.theme || false, + var themeName = plugins.util.env.theme || false, themes = themeName ? [themeName] : Object.keys(configs.themes); themes.forEach(name => { var theme = configs.themes[name]; theme.locale.forEach(locale => { var themePath = theme.default ? theme.dest + '/' + locale : theme.src, - files = globby.sync( + files = plugins.globby.sync( [ themePath + '/**/*.' + theme.lang, '!' + themePath + '/**/_*.' + theme.lang @@ -31,7 +30,7 @@ module.exports = function() { } else { var compiler = require('../helpers/' + theme.lang)(gulp, plugins, configs, name, locale, themePath + '/**/*.' + theme.lang); - gulp.watch(themePath + '/**/*.' + theme.lang, () => { + gulp.watch([themePath + '/**/*.' + theme.lang, '!/**/node_modules/**'], () => { compiler(); }); }