Skip to content

Commit

Permalink
per level naming
Browse files Browse the repository at this point in the history
  • Loading branch information
awinogradov committed May 6, 2017
1 parent 024527e commit 7175636
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

[Webpack](https://github.com/webpack/webpack) loader for [bem-react-core](https://github.com/bem/bem-react-core)

# BEM import

BEM-entities auto resolver for custom import strings.
BEM-entities auto resolver for custom import strings:

``` js
import Block from 'b:block';
Expand All @@ -23,8 +21,10 @@ import BlockElem from 'b:block e:elem m:modName=modVal1|modVal2';

`webpack.config.js`

```
// setting for bem-import
//TODO: webpack 2

``` js
// setting for bem-loader
bemLoader: {
naming: 'react',
levels: ['./pathToBlocks'],
Expand Down Expand Up @@ -52,7 +52,7 @@ On file system:

```
blocks/Attach/
├── Attach.react.js
├── Attach.js
├── Attach.i18n
│   ├── en.js
│   ├── ru.js
Expand All @@ -72,7 +72,7 @@ module.exports = {
};
```

inside `Attach.react.js`:
inside `Attach.js`:

```js
import i18n from `b:Attach t:i18n`
Expand Down Expand Up @@ -106,4 +106,3 @@ console.log(i18n('button-text')) // → Dosya seç


### License MPL-2.0

16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ const path = require('path'),
bn = require('@bem/naming'),
BemCell = require('@bem/cell'),
BemEntityName = require('@bem/entity-name'),
bemFs = require('@bem/fs-scheme')(),
bemFs = require('@bem/fs-scheme')(), // TODO: plain
bemImport = require('@bem/import-notation'),
bemConfig = require('bem-config')(),
requiredPath = require('required-path'),
falafel = require('falafel'),
vow = require('vow'),
Expand All @@ -17,12 +18,9 @@ module.exports = function(source) {
this.cacheable && this.cacheable();

const callback = this.async(),
options = Object.assign(
{},
this.options.bemLoader,
loaderUtils.getOptions(this)
),
levels = options.levels,
options = Object.assign({}, this.options.bemLoader, loaderUtils.getOptions(this)),
levelsMap = bemConfig.levelMapSync() || opts.levels,
levels = Array.isArray(levelsMap) ? levelsMap : Object.keys(levelsMap),
techs = options.techs || ['js'],
langs = options.langs || ['en'],
techMap = techs.reduce((acc, tech) => {
Expand Down Expand Up @@ -53,6 +51,7 @@ module.exports = function(source) {

const existingEntitiesPromises = bemImport.parse(
node.arguments[0].value,
// FIXME: we really need this context for parsing import?
bemNaming.parse(path.basename(this.resourcePath).split('.')[0])
)
// expand entities by all provided levels
Expand All @@ -68,7 +67,8 @@ module.exports = function(source) {
}, [])
// find path for every entity and check it existance
.map(bemCell => {
const entityPath = path.resolve(bemFs.path(bemCell, namingOptions));
const localNamingOpts = levelsMap[bemCell.layer].naming || namingOptions;
const entityPath = path.resolve(bemFs.path(bemCell, localNamingOpts));

this.addDependency(entityPath);

Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
"lint": "eslint ."
},
"dependencies": {
"@bem/cell": "^0.2.5",
"@bem/entity-name": "^1.3.0",
"@bem/cell": "^0.2.6",
"@bem/entity-name": "^1.5.0",
"@bem/fs-scheme": "^2.1.0",
"@bem/import-notation": "^1.0.0",
"@bem/naming": "^2.0.0-3",
"falafel": "^1.2.0",
"loader-utils": "1.0.2",
"@bem/import-notation": "^1.1.2",
"@bem/naming": "^2.0.0-6",
"falafel": "^2.1.0",
"loader-utils": "1.1.0",
"required-path": "^1.0.1",
"vow": "^0.4.12",
"vow-fs": "^0.3.5"
"vow": "^0.4.15",
"vow-fs": "^0.3.6"
},
"devDependencies": {
"eslint": "^3.15.0"
"eslint": "^3.19.0"
}
}

0 comments on commit 7175636

Please sign in to comment.