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')(); 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/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..cdf2f1a 100644 --- a/lib/walkers/flat.js +++ b/lib/walkers/flat.js @@ -3,8 +3,7 @@ const fs = require('fs'); const path = require('path'); -const bemNaming = require('bem-naming'); -const BemEntityName = require('@bem/entity-name'); +const bemNaming = require('@bem/naming'); 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 f517285..0789d8e 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); @@ -141,10 +141,11 @@ 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: new BemEntityName(entity), + entity: entity, tech: tech, layer: this.levelpath }), @@ -175,7 +176,7 @@ class LevelWalker { this.add(new BemFile( new BemCell({ - entity: new BemEntityName(entity), + entity: entity, tech: tech, layer: this.levelpath }), @@ -187,7 +188,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); @@ -212,11 +213,11 @@ 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({ - entity: new BemEntityName(entity), + entity: entity, tech: tech, layer: this.levelpath }), 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", diff --git a/test/naming/naming.test.js b/test/naming/naming.test.js index f227f3e..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: { 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: { elem: '__', mod: { name: '--', val: '_' } }, + naming: 'two-dashes', 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' @@ -100,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: { elem: '__', mod: '_' }, + 'origin.blocks': { + naming: 'origin', scheme: 'flat' }, - 'csswizardry.blocks': { - naming: { 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());