Open Vittly opened 6 years ago
How can I build full path from level and cell ? Put project root in bemFile.level is good or not ?
It's fine if you have something like "BemFile" with absolute paths:
{
path: '/home/vasya/projects/super-site/blocks/b/b.js',
level: '/home/vasya/projects/super-site/blocks/',
cell: { entity: { block: 'b' }, tech: 'js', layer: 'common' }
}
It's possible to get b/b.js
from content of cell
property with @bem/sdk.cell.stringify
and it's bases on scheme and pattern we use: https://github.com/bem/bem-sdk/blob/master/packages/naming.presets/origin.js#L10
See also https://github.com/bem/bem-sdk/blob/master/packages/naming.cell.pattern-parser/test/pattern-parser.test.js#L19 and we should tell somehow to users about difference between layers and levels. Levels can contain one or few layers. File can be applied to only one layer.
E.g. if we have something like b:button
at common, b:button m:size=l
at desktop we can place it in few different ways:
/lib/common.blocks/button/button.js
and desktop.blocks/button/_size/button_size_l.css
for origin preset and /lib
library level./lib/blocks/button/button.js
and /lib/desktop.blocks/button/_size/button_size_l.css
for react preset and /lib/blocks
library level/node_modules/button/button.js
and /node_modules/button/button_size_l@desktop.css
for '${entity}${layer?@${layer}}.${tech}'
pattern, flat
scheme and /node_modules/button
level.Do you still think we need to fix here something?
Firstly. If level is not equal to layer why do we write in .bemrc
:
{
levels: [{ layer: 'desktop' }], // levels item is layer not level ?
// ...
}
and we can write js like:
const level = levels[0];
level.layer // Oo ?
and we should tell somehow to users about difference between layers and levels.
Lets do this in docs 👍 And may be fix bemrc
structure.
Secondly. Lets return to my problem in details:
,bemrc
has level/layer declaration:
{ layer: 'desktop', path: '/absolute/path/to/desktop.blocks' }
I've created a BemCell
with layer: 'desktop'
:
{ entity: { ... }, tech: 'js', layer: 'desktop' }
To use file.stringify
I need to build BemFile:
stringify({
level: path.resolve(level.path, '..'), // to eliminate layer-part. Is it weird ?
cell: { ... }
})
I think that is not ok. And problem is about level/layer mess
I'm agree with anything except:
To use file.stringify I need to build BemFile:
Yes, if you need a path to file you need to use file.stringify, but you should not be forced to build BemFile to build a path to it.
level: path.resolve(level.path, '..'), // to eliminate layer-part. Is it weird ?
You don't need to eliminate it manually. Pattern can use layer or can NOT do it. We should hide it away from the end point user — to shine as Buddha or his little finger
@tadatuta Vladimir, can I ask you to join discussion about .bemrc
-related stuff?
From webpack-bem-plugin.
level.path
frombemrc
contains layer-part. Cell also has layer part (common is default). How can I build full path from level and cell ? Put project root inbemFile.level
is good or not ?