From 0d1f21ce643753547924715980ef330dbd6a1cf5 Mon Sep 17 00:00:00 2001 From: blond Date: Tue, 14 Feb 2017 21:37:27 +0300 Subject: [PATCH 1/6] chore(package): update bem-naming to 2.x --- lib/index.js | 2 +- lib/walkers/flat.js | 2 +- lib/walkers/nested.js | 8 ++++---- package.json | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/index.js b/lib/index.js index 3bfeb6a..1679ee2 100644 --- a/lib/index.js +++ b/lib/index.js @@ -15,7 +15,7 @@ const walkers = require('./walkers'); * @param {object} options.levels The level map. A key is path to a level, * a value is an options object for this level. * @param {object} options.defaults The options for levels by default. - * @param {object} options.defaults.naming Any options for `bem-naming`. + * @param {object} options.defaults.naming Any options for `@bem/naming`. * @param {string} options.defaults.scheme The name of level scheme. Available values: `flat` or `nested`. * * @returns {module:stream.Readable} stream with info about found files and directories. diff --git a/lib/walkers/flat.js b/lib/walkers/flat.js index a3d2966..9b5fd64 100644 --- a/lib/walkers/flat.js +++ b/lib/walkers/flat.js @@ -3,7 +3,7 @@ const fs = require('fs'); const path = require('path'); -const bemNaming = require('bem-naming'); +const bemNaming = require('@bem/naming'); const BemEntityName = require('@bem/entity-name'); const BemCell = require('@bem/cell'); diff --git a/lib/walkers/nested.js b/lib/walkers/nested.js index f517285..89ace22 100644 --- a/lib/walkers/nested.js +++ b/lib/walkers/nested.js @@ -4,7 +4,7 @@ const fs = require('fs'); const path = require('path'); const each = require('async-each'); -const bemNaming = require('bem-naming'); +const bemNaming = require('@bem/naming'); const BemEntityName = require('@bem/entity-name'); const BemCell = require('@bem/cell'); @@ -77,7 +77,7 @@ class LevelWalker { scanLevel (callback) { this._eachDirItem(this.levelpath, (item, cb) => { const entity = this.naming.parse(item.stem); - const type = this.naming.typeOf(entity); + const type = entity && entity.type; if (!item.tech && type === 'block') { return this.scanBlockDir(item.path, item.basename, cb); @@ -115,7 +115,7 @@ class LevelWalker { } const entity = this.naming.parse(blockname + stem); - const type = this.naming.typeOf(entity); + const type = entity && entity.type; if (type === 'blockMod') { return this.scanBlockModDir(filename, entity, cb); @@ -187,7 +187,7 @@ class LevelWalker { } const entity = this.naming.parse(scope.block + path.basename(dirname) + stem); - const type = this.naming.typeOf(entity); + const type = entity && entity.type; if (type === 'elemMod') { return this.scanElemModDir(filename, entity, cb); diff --git a/package.json b/package.json index 829a24c..bbd60c4 100644 --- a/package.json +++ b/package.json @@ -23,8 +23,8 @@ "dependencies": { "@bem/cell": "0.2.5", "@bem/entity-name": "1.3.1", - "async-each": "1.0.1", - "bem-naming": "1.0.1" + "@bem/naming": "2.0.0-5", + "async-each": "1.0.1" }, "devDependencies": { "ava": "^0.18.0", From 4c9ae3e557d420fe950f546c02763e5c15df4d01 Mon Sep 17 00:00:00 2001 From: blond Date: Tue, 14 Feb 2017 21:37:52 +0300 Subject: [PATCH 2/6] test: update bem-naming to 2.x --- bench/run.js | 2 +- test/naming/naming.test.js | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/bench/run.js b/bench/run.js index 690e12c..6bf959e 100644 --- a/bench/run.js +++ b/bench/run.js @@ -5,7 +5,7 @@ const stream = require('stream'); const Benchmark = require('Benchmark'); const series = require('promise-map-series'); -const stringifyEntity = require('bem-naming').stringify; +const stringifyEntity = require('@bem/naming').stringify; const fixtures = require('./fixtures'); diff --git a/test/naming/naming.test.js b/test/naming/naming.test.js index f227f3e..a7f4546 100644 --- a/test/naming/naming.test.js +++ b/test/naming/naming.test.js @@ -20,7 +20,7 @@ test('should support original naming', t => { const options = { levels: { blocks: { - naming: { elem: '__', mod: '_' }, + naming: { delims: { elem: '__', mod: '_' } }, scheme: 'flat' } } @@ -48,7 +48,7 @@ test('should support Convention by Harry Roberts', t => { const options = { levels: { blocks: { - naming: { elem: '__', mod: { name: '--', val: '_' } }, + naming: { delims: { elem: '__', mod: { name: '--', val: '_' } } }, scheme: 'flat' } } @@ -77,8 +77,10 @@ test('should support custom naming', t => { levels: { blocks: { naming: { - elem: '-', - mod: '--', + delims: { + elem: '-', + mod: '--' + }, wordPattern: '[a-zA-Z0-9]+' }, scheme: 'flat' @@ -111,11 +113,11 @@ test('should support several naming', t => { const options = { levels: { 'original.blocks': { - naming: { elem: '__', mod: '_' }, + naming: { delims: { elem: '__', mod: '_' } }, scheme: 'flat' }, 'csswizardry.blocks': { - naming: { elem: '__', mod: { name: '--', val: '_' } }, + naming: { delims: { elem: '__', mod: { name: '--', val: '_' } } }, scheme: 'flat' } } From 74407715dfc60e06bfbcb2c9d8b59536a3e22d24 Mon Sep 17 00:00:00 2001 From: blond Date: Tue, 14 Feb 2017 21:39:14 +0300 Subject: [PATCH 3/6] docs: update bem-naming to 2.x --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 97ae679..d50ba75 100644 --- a/README.md +++ b/README.md @@ -79,10 +79,10 @@ The table shows the possible values that can be set for each of the schemes. | `scheme` | File system.|`nested`|`nested`, `flat`| More information: -* [ bem-naming]( https://en.bem.info/toolbox/sdk/bem-naming/) +* [ @bem/naming]( https://en.bem.info/toolbox/sdk/bem-naming/) * [ bem-fs-scheme]( https://en.bem.info/toolbox/sdk/bem-fs-scheme/) -**Note** Instead of defining the project's levels manually, use the [` bem-config`]( https://en.bem.info/toolbox/sdk/bem-config/) tool. +**Note** Instead of defining the project's levels manually, use the [`bem-config`]( https://en.bem.info/toolbox/sdk/bem-config/) tool. ```js const config = require('bem-config')(); From 1c60bc35d2f7f24ea0a05e01db12a70eb34ae93e Mon Sep 17 00:00:00 2001 From: blond Date: Wed, 8 Mar 2017 18:53:10 +0300 Subject: [PATCH 4/6] refactor(test): use naming presets --- test/naming/naming.test.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/naming/naming.test.js b/test/naming/naming.test.js index a7f4546..d5f7d43 100644 --- a/test/naming/naming.test.js +++ b/test/naming/naming.test.js @@ -20,7 +20,7 @@ test('should support original naming', t => { const options = { levels: { blocks: { - naming: { delims: { elem: '__', mod: '_' } }, + naming: 'origin', scheme: 'flat' } } @@ -38,7 +38,7 @@ test('should support original naming', t => { }); }); -test('should support Convention by Harry Roberts', t => { +test('should support two-dashes naming', t => { mockFs({ blocks: { 'block__elem--mod_val.tech': '' @@ -48,7 +48,7 @@ test('should support Convention by Harry Roberts', t => { const options = { levels: { blocks: { - naming: { delims: { elem: '__', mod: { name: '--', val: '_' } } }, + naming: 'two-dashes', scheme: 'flat' } } @@ -102,28 +102,28 @@ test('should support custom naming', t => { test('should support several naming', t => { mockFs({ - 'original.blocks': { + 'origin.blocks': { 'block_mod.tech': '' }, - 'csswizardry.blocks': { + 'two-dashes.blocks': { 'block--mod_val.tech': '' } }); const options = { levels: { - 'original.blocks': { - naming: { delims: { elem: '__', mod: '_' } }, + 'origin.blocks': { + naming: 'origin', scheme: 'flat' }, - 'csswizardry.blocks': { - naming: { delims: { elem: '__', mod: { name: '--', val: '_' } } }, + 'two-dashes.blocks': { + naming: 'two-dashes', scheme: 'flat' } } }; - return toArray(walk(['original.blocks', 'csswizardry.blocks'], options)) + return toArray(walk(['origin.blocks', 'two-dashes.blocks'], options)) .then(files => { const entities = files.map(file => file.cell.entity.valueOf()); From 0ed21f1140e4a35f456fde3a469111e70588139d Mon Sep 17 00:00:00 2001 From: blond Date: Fri, 10 Mar 2017 17:07:03 +0300 Subject: [PATCH 5/6] refactor(entity): should not to create BemEntityName twice --- lib/walkers/flat.js | 3 +-- lib/walkers/nested.js | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/walkers/flat.js b/lib/walkers/flat.js index 9b5fd64..cdf2f1a 100644 --- a/lib/walkers/flat.js +++ b/lib/walkers/flat.js @@ -4,7 +4,6 @@ const fs = require('fs'); const path = require('path'); const bemNaming = require('@bem/naming'); -const BemEntityName = require('@bem/entity-name'); const BemCell = require('@bem/cell'); const BemFile = require('../bem-file'); @@ -37,7 +36,7 @@ module.exports = (info, add, callback) => { if (entity) { const cell = new BemCell({ - entity: new BemEntityName(entity), + entity: entity, tech: basename.substring(dotIndex + 1), layer: levelpath }); diff --git a/lib/walkers/nested.js b/lib/walkers/nested.js index 89ace22..3bfbdb2 100644 --- a/lib/walkers/nested.js +++ b/lib/walkers/nested.js @@ -144,7 +144,7 @@ class LevelWalker { if (tech && entity && scope.block === entity.block && scope.modName === entity.modName) { this.add(new BemFile( new BemCell({ - entity: new BemEntityName(entity), + entity: entity, tech: tech, layer: this.levelpath }), @@ -175,7 +175,7 @@ class LevelWalker { this.add(new BemFile( new BemCell({ - entity: new BemEntityName(entity), + entity: entity, tech: tech, layer: this.levelpath }), @@ -216,7 +216,7 @@ class LevelWalker { ) { this.add(new BemFile( new BemCell({ - entity: new BemEntityName(entity), + entity: entity, tech: tech, layer: this.levelpath }), From 2b5252f0148ba2387785e17d16578e631c7a8ad6 Mon Sep 17 00:00:00 2001 From: blond Date: Fri, 10 Mar 2017 17:18:15 +0300 Subject: [PATCH 6/6] refactor(entities): use mod field for entities The `modName` and the `modVal` fields are deprecated. --- lib/walkers/nested.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/walkers/nested.js b/lib/walkers/nested.js index 3bfbdb2..0789d8e 100644 --- a/lib/walkers/nested.js +++ b/lib/walkers/nested.js @@ -141,7 +141,8 @@ class LevelWalker { const tech = item.tech; // Find file with same modifier name. - if (tech && entity && scope.block === entity.block && scope.modName === entity.modName) { + if (tech && entity && scope.block === entity.block + && scope.mod.name === (entity.mod && entity.mod.name)) { this.add(new BemFile( new BemCell({ entity: entity, @@ -212,7 +213,7 @@ class LevelWalker { if (tech && entity && scope.block === entity.block && scope.elem === entity.elem - && scope.modName === entity.modName + && scope.mod.name === (entity.mod && entity.mod.name) ) { this.add(new BemFile( new BemCell({