Skip to content
This repository has been archived by the owner on Feb 6, 2018. It is now read-only.

Commit

Permalink
Merge 2b5252f into c140d80
Browse files Browse the repository at this point in the history
  • Loading branch information
blond committed Mar 25, 2017
2 parents c140d80 + 2b5252f commit 89107d7
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 30 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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')();
Expand Down
2 changes: 1 addition & 1 deletion bench/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 2 additions & 3 deletions lib/walkers/flat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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
});
Expand Down
19 changes: 10 additions & 9 deletions lib/walkers/nested.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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
}),
Expand Down Expand Up @@ -175,7 +176,7 @@ class LevelWalker {

this.add(new BemFile(
new BemCell({
entity: new BemEntityName(entity),
entity: entity,
tech: tech,
layer: this.levelpath
}),
Expand All @@ -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);
Expand All @@ -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
}),
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
26 changes: 14 additions & 12 deletions test/naming/naming.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test('should support original naming', t => {
const options = {
levels: {
blocks: {
naming: { elem: '__', mod: '_' },
naming: 'origin',
scheme: 'flat'
}
}
Expand All @@ -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': ''
Expand All @@ -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'
}
}
Expand Down Expand Up @@ -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'
Expand All @@ -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());

Expand Down

0 comments on commit 89107d7

Please sign in to comment.