bem / bem-sdk

BEM SDK packages
https://en.bem.info/toolbox/sdk/
88 stars 25 forks source link

Add method to build path to file from cell + level #278

Open Vittly opened 6 years ago

Vittly commented 6 years ago

From webpack-bem-plugin. level.path from bemrc contains layer-part. Cell also has layer part (common is default). How can I build full path from level and cell ? Put project root in bemFile.level is good or not ?

qfox commented 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:

Do you still think we need to fix here something?

Vittly commented 6 years ago

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

qfox commented 6 years ago

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

qfox commented 6 years ago

@tadatuta Vladimir, can I ask you to join discussion about .bemrc-related stuff?