Skip to content

Commit

Permalink
Merge branch 'release/1.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Igloczek committed Jun 17, 2017
2 parents db26c45 + be26a7b commit 4cfb981
Show file tree
Hide file tree
Showing 21 changed files with 1,405 additions and 1,020 deletions.
4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
extends: idiomatic
extends:
- eslint:recommended
- idiomatic
env:
node: true
es6: true
Expand Down
22 changes: 8 additions & 14 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ Set of front-end tools for Magento 2, based on Gulp.js
## Questions
If you have any questions about this project let's go to offical Magento forum - [Less to Sass Community Project](https://community.magento.com/t5/Less-to-Sass-Community-Project/bd-p/less-to-sass)

## LESS themes support
LESS support was dropped in version 1.0.0. Feel free to use an older version (0.11.4 and lower) or create a fork and customize newer versions to fit your needs.

## NPM and Yarn support
Up from version 1.0.0 we are supporting both Node.js packages managers. If you want to keep modules in safe versions all the time, use Yarn, `yarn.lock` is already added to the repository.

## Requirements
* Node.js LTS version (v6 branch). We recommend to use [avn](https://github.com/wbyoung/avn) to automate version switching. Required configuration is already added to repository as `.node-version` file.
* Gulp CLI global package - `npm install -g gulp-cli` or `yarn global add gulp-cli`
* Unix-like OS (please, do not ask about Windows support)
* Node.js LTS version (currently branch v6). We recommend to use [avn](https://github.com/wbyoung/avn) to automate version switching. Required configuration is already added to repository as `.node-version` file.
* Gulp CLI global package - `yarn global add gulp-cli` or `npm install -g gulp-cli`
* Magento 2 project with SASS based theme i.e. [SASS version of "Blank"](https://github.com/SnowdogApps/magento2-theme-blank-sass)

## Installation
Expand All @@ -32,9 +27,9 @@ Check `config/themes.json.sample` to get samples.
- `src` - full path to theme
- `dest` - full path to `pub/static/[theme_area]/[theme_vendor]/[theme_name]`
- `locale` - array of available locales
- `localeOverwrites` - (default `false`) set to `true` if you want to overwrite some styles for specifilc language. Remember that path to overwriting file has to be same as base file after removing `/i18n/{lang_code}`.
- `parent` - name of parent theme
- `stylesDir` - (default `styles`) path to styles directory. For `theme-blank-sass` it's `styles`. By default Magento 2 use `web/css`.
- `disableSuffix` - disable adding `.min` sufix using `--prod` flag.
- `postcss` - (deafult `["plugins.autoprefixer()"]`) PostCSS plugins config. Have to be an array.
- `modules` - list of modules witch you want to map inside your theme
- `ignore` - array of ignore patterns
Expand All @@ -45,21 +40,18 @@ You will find sample config files for theses plugins in `vendor/snowdog/frontool
* Create [eslint](https://github.com/adametry/gulp-eslint) configuration
* Create [sass-lint](https://github.com/sasstools/sass-lint) configuration
* Create [stylelint](https://github.com/stylelint/stylelint) configuration
* Create [svg-sprite](https://github.com/jkphl/gulp-svg-sprite) configuration

## Tasks list
* `babel` - Run [Babel](https://babeljs.io/), a compiler for writing next generation JavaScript.
* `--theme name` - Process single theme.
* `--prod` - Production output - minifies and uglyfy code.
* `browser-sync` - Run [browserSync](https://www.browsersync.io/).
* `clean` - Removes `/pub/static` directory content.
* `csslint` - Run [stylelint](https://github.com/stylelint/stylelint) based tests.
* `--theme name` - Process single theme.
* `--ci` - Enable throwing errors. Useful in CI/CD pipelines.
* `default` - type `gulp` to see this readme in console.
* `deploy` - Symlink or copy all static assets to `pub/static`. Runs `clean` and `inheritance` tasks.
* `--theme name` - Specify theme to deploy.
* `--prod` - Copy files instead of making symlinks.
* `dev` - Runs `browser-sync`, `inheritance` and `watch` tasks.
* `dev` - Runs [browserSync](https://www.browsersync.io/) and `inheritance`, `babel`, `styles`, `watch` tasks.
* `--theme name` - Process single theme.
* `--disableLinting` - Disable SASS and CSS linting.
* `--disableMaps` - Toggles source maps generation.
Expand All @@ -76,6 +68,8 @@ You will find sample config files for theses plugins in `vendor/snowdog/frontool
* `--disableMaps` - Toggles source maps generation.
* `--prod` - Production output - minifies styles and add `.min` sufix.
* `--ci` - Enable throwing errors. Useful in CI/CD pipelines.
* `svg` - Run [svg-sprite](https://github.com/jkphl/gulp-svg-sprite) to generate SVG sprite.
* `--theme name` - Process single theme.
* `watch` - Watch for style changes and run processing tasks.
* `--theme name` - Process single theme.
* `--disableLinting` - Disable SASS and CSS linting.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "snowdog/frontools",
"description": "Set of front-end tools for Magento 2, based on Gulp.js",
"version": "1.4.5",
"version": "1.5.0",
"license": "MIT",
"type": "magento2-component"
}
8 changes: 7 additions & 1 deletion config/browser-sync.json.sample
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
{
"proxy": "m2test.dev"
"proxy": "m2test.dev",
"rewriteRules": [
{
"match": ".m2test.dev",
"replace": ""
}
]
}
4 changes: 4 additions & 0 deletions config/svg-sprite.yml.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mode:
symbol:
dest: 'images'
sprite: 'icons-sprite.svg'
3 changes: 1 addition & 2 deletions config/themes.json.sample
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@
"src": "vendor/snowdog/theme-custom",
"dest": "pub/static/frontend/Snowdog/child-with-locale-overwrites",
"locale": ["en_US", "pl_PL"],
"localeOverwrites": true,
"parent": "blank"
},
"all-possible-options": {
"src": "vendor/snowdog/theme-all-possible-options",
"dest": "pub/static/frontend/Snowdog/all-possible-options",
"locale": ["en_US", "pl_PL"],
"localeOverwrites": true,
"parent": "blank",
"stylesDir": "web/css",
"postcss": ["plugins.autoprefixer()"],
"disableSuffix": true,
"modules": {
"Snowdog_Sample": "vendor/snowdog/module-sample"
},
Expand Down
91 changes: 28 additions & 63 deletions helper/babel.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module.exports = function(gulp, plugins, config, name, file) { // eslint-disable-line func-names
const theme = config.themes[name],
srcBase = config.projectPath + 'var/view_preprocessed/frontools' + theme.dest.replace('pub/static', ''),
stylesDir = theme.stylesDir ? theme.stylesDir : 'styles',
dest = [],
disableMaps = plugins.util.env.disableMaps || false,
production = plugins.util.env.prod || false,
babelConfig = {
Expand All @@ -14,68 +14,33 @@ module.exports = function(gulp, plugins, config, name, file) { // eslint-disable
return file;
}

if (!theme.localeOverwrites) {
const dest = [];
theme.locale.forEach(locale => {
dest.push(config.projectPath + theme.dest + '/' + locale);
});
theme.locale.forEach(locale => {
dest.push(config.projectPath + theme.dest + '/' + locale);
});

return gulp.src(
file || srcBase + '/**/*.babel.js',
{ base: srcBase }
)
.pipe(
plugins.if(
!plugins.util.env.ci,
plugins.plumber({
errorHandler: plugins.notify.onError('Error: <%= error.message %>')
})
)
return gulp.src(
file || srcBase + '/**/*.babel.js',
{ base: srcBase }
)
.pipe(
plugins.if(
!plugins.util.env.ci,
plugins.plumber({
errorHandler: plugins.notify.onError('Error: <%= error.message %>')
})
)
.pipe(plugins.if(!disableMaps && !production, plugins.sourcemaps.init()))
.pipe(plugins.babel(babelConfig))
.pipe(plugins.if(production, plugins.uglify()))
.pipe(plugins.if(!disableMaps && !production, plugins.sourcemaps.write()))
.pipe(plugins.if(production, plugins.rename({ suffix: '.min' })))
.pipe(plugins.rename(adjustDestinationDirectory))
.pipe(plugins.multiDest(dest))
.pipe(plugins.logger({
display : 'name',
beforeEach: 'Theme: ' + name + ' ',
afterEach : ' Compiled!'
}))
.pipe(plugins.browserSync.stream());
}
else {
const streams = plugins.mergeStream();
theme.locale.forEach(locale => {
streams.add(
gulp.src(
file || srcBase + '/' + locale + '/**/*.babel.js',
{ base: srcBase + '/' + locale }
)
.pipe(
plugins.if(
!plugins.util.env.ci,
plugins.plumber({
errorHandler: plugins.notify.onError('Error: <%= error.message %>')
})
)
)
.pipe(plugins.if(!disableMaps && !production, plugins.sourcemaps.init()))
.pipe(plugins.babel(babelConfig))
.pipe(plugins.if(production, plugins.uglify()))
.pipe(plugins.if(production, plugins.rename({ suffix: '.min' })))
.pipe(plugins.rename(adjustDestinationDirectory))
.pipe(gulp.dest(config.projectPath + theme.dest + '/' + locale))
.pipe(plugins.logger({
display : 'name',
beforeEach: 'Theme: ' + name + ' Locale: ' + locale + ' ',
afterEach : ' Compiled!'
}))
.pipe(plugins.browserSync.stream())
);
});
return streams;
}
)
.pipe(plugins.if(!disableMaps && !production, plugins.sourcemaps.init()))
.pipe(plugins.babel(babelConfig))
.pipe(plugins.if(production, plugins.uglify()))
.pipe(plugins.if(!disableMaps && !production, plugins.sourcemaps.write()))
.pipe(plugins.if(production, plugins.rename({ suffix: '.min' })))
.pipe(plugins.rename(adjustDestinationDirectory))
.pipe(plugins.multiDest(dest))
.pipe(plugins.logger({
display : 'name',
beforeEach: 'Theme: ' + name + ' ',
afterEach : ' Compiled!'
}))
.pipe(plugins.browserSync.stream());
};
2 changes: 1 addition & 1 deletion helper/dependency-tree-builder.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
module.exports = function(theme, file, plugins) { // eslint-disable-line func-names
module.exports = function(plugins, file) { // eslint-disable-line func-names
function findDependencies(file, dependencyTree) {
if (plugins.fs.existsSync(file)) {
const content = plugins.fs.readFileSync(file, 'utf8'),
Expand Down
118 changes: 21 additions & 97 deletions helper/inheritance-resolver.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,34 +1,15 @@
'use strict';
module.exports = function(plugins, config, name) { // eslint-disable-line func-names
const path = require('path'),
ignorePaths = config.themes[name].ignore || [];
module.exports = function(plugins, config, name, tree = true) { // eslint-disable-line func-names
const path = require('path');

function createSymlink(srcPath, destPath) {
plugins.fs.removeSync(destPath);
plugins.fs.ensureSymlinkSync(srcPath, destPath);
}

function generateSymlinks(src, dest, replacePattern, ignore = []) {
src = path.normalize(src);
dest = path.normalize(dest);

if (Array.isArray(replacePattern)) {
replacePattern = replacePattern.map(pattern => {
pattern[0] = path.normalize(pattern[0]);
if (pattern[1] !== '') {
pattern[1] = path.normalize(pattern[1]);
}
return pattern;
});
}
else {
replacePattern = path.normalize(replacePattern);
}

plugins.globby.sync(
[src + '/**']
.concat(ignorePaths.map(pattern => '!/**/' + pattern))
.concat(ignore.map(pattern => '!/**/' + pattern + '/**')),
[src + '/**'].concat(ignore.map(pattern => '!/**/' + pattern)),
{ nodir: true }
).forEach(srcPath => {
let destPath = path.join(dest, srcPath);
Expand All @@ -48,6 +29,11 @@ module.exports = function(plugins, config, name) { // eslint-disable-line func-n
function themeDependencyTree(themeName, dependencyTree) {
dependencyTree = dependencyTree ? dependencyTree : [];
dependencyTree.push(themeName);

if (!tree) {
return dependencyTree;
}

if (config.themes[themeName].parent) {
return themeDependencyTree(
config.themes[themeName].parent,
Expand All @@ -59,16 +45,15 @@ module.exports = function(plugins, config, name) { // eslint-disable-line func-n
}
}

themeDependencyTree(name).forEach(themeName => {
const theme = config.themes[themeName],
themeSrc = config.projectPath + theme.src,
themeDest = config.tempPath + theme.dest.replace('pub/static', '');
return new Promise(resolve => {
themeDependencyTree(name).forEach(themeName => {
const theme = config.themes[themeName],
themeSrc = config.projectPath + theme.src,
themeDest = config.tempPath + theme.dest.replace('pub/static', '');

// Clean destination dir before generating new symlinks
plugins.fs.removeSync(themeDest);
// Clean destination dir before generating new symlinks
plugins.fs.removeSync(themeDest);

// Create symlinks for themes without any per locale modifcations (default)
if (!theme.localeOverwrites) {
// Create symlinks for theme modules
if (theme.modules) {
Object.keys(theme.modules).forEach(name => {
Expand All @@ -78,82 +63,21 @@ module.exports = function(plugins, config, name) { // eslint-disable-line func-n
themeDest,
[
[moduleSrc, '/' + name]
]
],
theme.ignore
);
});
}

if (theme.parent) {
const parentSrc = config.tempPath + config.themes[theme.parent].dest.replace('pub/static', '');
generateSymlinks(parentSrc, themeDest, parentSrc);
generateSymlinks(parentSrc, themeDest, parentSrc, config.themes[theme.parent].ignore);
}

// Create symlinks to all files in this theme. Will overwritte parent symlinks if exist.
generateSymlinks(themeSrc, themeDest, themeSrc);
}
// Create symlinks for themes with per locale modifcations
else {
// We have to handle every locale independly, b/c of possible overwrites
theme.locale.forEach(locale => {
// Create symlinks for theme modules
if (theme.modules) {
Object.keys(theme.modules).forEach(name => {
const moduleSrc = config.projectPath + theme.modules[name];
generateSymlinks(
moduleSrc,
themeDest + '/' + locale,
[
[moduleSrc, '/' + name]
],
['i18n']
);
});
}

// If theme have parent, create symlinks to all avaliabe files and then overwitte only neccessary
if (theme.parent) {
const parentSrc = config.tempPath + config.themes[theme.parent].dest.replace('pub/static', '');
generateSymlinks(
parentSrc,
themeDest + '/' + locale,
parentSrc,
['i18n']
);
}

// Create symlinks to all files in this theme. Will overwritte parent symlinks if exist.
generateSymlinks(
themeSrc,
themeDest + '/' + locale,
themeSrc,
['i18n']
);

// Overwritte parent/current modules symlinks with locale specific files
if (theme.modules) {
Object.keys(theme.modules).forEach(name => {
const moduleSrc = config.projectPath + theme.modules[name];
generateSymlinks(
moduleSrc + '/**/i18n/' + locale,
themeDest + '/' + locale,
[
[moduleSrc, '/' + name],
['/i18n/' + locale, '']
]
);
});
}
generateSymlinks(themeSrc, themeDest, themeSrc, theme.ignore);
});

// Overwritte parent/current theme symlinks with locale specific files
generateSymlinks(
themeSrc + '/**/i18n/' + locale,
themeDest + '/' + locale,
[
[themeSrc, ''],
['/i18n/' + locale, '']
]
);
});
}
resolve();
});
};
Loading

0 comments on commit 4cfb981

Please sign in to comment.