-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add code #1
Conversation
src/BemPluginConfig.js
Outdated
* b. libraries configs (like bem-react-components) for many reasons | ||
* example: https://github.com/bem/bem-sdk/issues/261 | ||
*/ | ||
__prepareRc(bemConfig, libs, self) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Разве это не должен делать bem-config?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Кто ж его заставит... @tadatuta
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it should be there. Now not all wanted libraries has their bemrc
and adding it (via PR for example) is not simple unfortunately. I'll do detailed comment
src/BemRequest.js
Outdated
const entityFromPath = require('./helpers/entityFromPath'); | ||
|
||
function completeRequest(request, ctx) { | ||
// TODO: move to @bem/sdk.import-notation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Заведи ишью?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
сс @Yeti-or
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const BemEntityParse = require('@bem/sdk.naming.entity.parse'); | ||
|
||
function trimFilename(filePath) { | ||
return path.basename(filePath).split('.')[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Уверен? block.react.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это должно быть реализовано примерно в районе @bem/sdk.naming.file.parse
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
path.basename('/foo/bar/b__e_m.react.js').split('.')[0];
returns 'b__e_m'
@awinogradov
@zxqfox - done bem/bem-sdk#276
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$ node -p "path.basename('/foo/bar/b__e_m.assets/random.png').split('.')[0];"
random
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And sdk.naming.file.parse
would handle it ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels like. But we didn't talk about it much, (bem) file here is '/foo/bar/b__e_m.assets/'
src/helpers/importedFiles.js
Outdated
}; | ||
}); | ||
|
||
// TODO: should we add __elem (in case of __elem_mod) and _mod (in case of _mod_val) ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, not sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Yeti-or Can you tell us what actually webpack-bem-loader
does?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, it adds, why do you think it's unnecessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this part. I think we should simple remove this comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add an example ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've checked:
parse('b:block e:elem m:mod')
/**
* returns [
* { block: 'block', elem: 'elem' }, // __elem is here
* { block: 'block', elem: 'elem', mod: { name: 'mod' } }
* ]
*/
parse('b:block m:mod=val')
/**
* returns [
* { block: 'block' },
* { block: 'block', mod: { name: 'mod' } }, // _mod is here
* { lock: 'block', mod: { name: 'mod', val: 'val' } }
* ]
*/
I'll remove nasty comment
README.md
Outdated
|
||
## Known issues | ||
|
||
* Small tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not enough ? Too few/small?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe there are too small and too fast? we need to fix it and write big heavy ones =)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Described in #3
README.md
Outdated
## Known issues | ||
|
||
* Small tests | ||
* Not picking changes in `bemrc` in watch-mode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rereading .bemrc
doesn't work in watch-mode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, in plugin. May be its a problem. May be we should fix it in newer version of plugin so I noted it
src/BemPluginConfig.js
Outdated
const oldSync = rc.sync; | ||
|
||
rc.sync = function(options) { | ||
return configsMap[options.cwd] || oldSync(options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
давай напишем что тут происходит, кроме тестов?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
src/BemRequest.js
Outdated
*/ | ||
class BemRequest { | ||
constructor(request, filePath, levels, setIndex) { | ||
const requestNaming = namingConvention.getFromLevelsByPath(levels, filePath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не получилось достать из bem-config?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more info in bem/bem-sdk#277
src/BemRequest.js
Outdated
class BemRequest { | ||
constructor(request, filePath, levels, setIndex) { | ||
const requestNaming = namingConvention.getFromLevelsByPath(levels, filePath); | ||
const ctx = entityFromPath(filePath, requestNaming); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
это должен быть @bem/sdk.naming.file.parse
в купе с @bem/sdk.config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep
src/BemRequest.js
Outdated
const ctx = entityFromPath(filePath, requestNaming); | ||
|
||
// TODO: remove duplicates from array in @bem/sdk.import-notation | ||
// https://github.com/bem/bem-sdk/issues/263 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тикет закрыт
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zxqfox я только не помню выпустили ли мы версию
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥
.sort(tech => tech === 'js') // js should be the last | ||
.map(tech => { | ||
const generator = tech === 'js' ? jsGenerator : generalGenerator; | ||
const existingFiles = techToFiles[tech].filter(fs.existsSync); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ммм, а нельзя это делать через webpack-овские ручки?
странно работать с фс напрямую, когда webpack должен всё контролировать
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. In my solution "No".
I do resolve bem-require b:b e:e
by module implemented with source (require('b.js'),require('b_e.js')).applyDecls()
. Lack of files causes module require error. To handle this we need to override requires of actual files. I want to avoid this and reduce amount of redefinitions of standard webpack mechanisms.
I can add a comment in a way "TODO: should do it more webpackable"
src/generator/techs/javascript.js
Outdated
'use strict'; | ||
|
||
function lastRequire(file) { | ||
return `require('${file}').default.applyDecls()`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
что ты имеешь ввиду?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
я имею ввиду надо делать явное const Class = bake(decl({block: 'b'}), decl({block: 'b'}), declMod({block: 'b'}))
/** | ||
* Returns path to file of BEM-cell using naming rules | ||
*/ | ||
module.exports = (bemCell, convention) => BemCellStringify(convention)(bemCell); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
точно не naming.file.stringify
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got cell
(block/elem/.../tech/layer) and level.path
(absolute) and want to build path to file. Now I do level.path
+ ..
(because layer part is already in cell) + cell
naming.file.stringify
do level
(any dir) + cell
.
What is level ? Layer is not equal to level ?
I don't think that:
fileStringify(
new BemFile({
cell,
level: level.path + '/..'
})
)
is better enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Started conversation in bem/bem-sdk#278
src/helpers/importedFiles.js
Outdated
// TODO: should we add __elem (in case of __elem_mod) and _mod (in case of _mod_val) ? | ||
// like webpack-bem-loader does | ||
|
||
bemDeps = bemDeps.concat(files); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[].push.apply(bemDeps, files);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why it's better ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think its faster?
src/helpers/importedFiles.js
Outdated
}); | ||
}); | ||
|
||
// FIXME: does it have right order ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guess we can't reorder this anyway. Or you know how we can?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes its rhetorical somehow. I'll remove it
levels: [{ layer: 'desktop' }], | ||
// TODO: remove sets after https://github.com/bem/bem-sdk/issues/262 | ||
sets: { | ||
desktop: 'desktop' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это нужно для того, чтобы можно было использовать слой отдельно? Но ведь это некорректно.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
README.md
Outdated
|
||
|Name|Type|Description| | ||
|----|----|-----------| | ||
|**`test`**|`{RegExp}`|Plugin processes `require` statements in matched files. Default is `/\.js$/`| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will it play nice with tech/techMap
? Do we really need both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tech
is to addcss
techMap
is to handle.react.js
test
is to skipbemhtml.js
iftest: /\.react\.js$/
... Should we usetechMap
here? Is it your proposal ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to #8
README.md
Outdated
|
||
## Known issues | ||
|
||
* Small tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe there are too small and too fast? we need to fix it and write big heavy ones =)
|
||
> npm test | ||
|
||
## Known issues |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to open an issue for each one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree
src/BemRequest.js
Outdated
const ctx = entityFromPath(filePath, requestNaming); | ||
|
||
// TODO: remove duplicates from array in @bem/sdk.import-notation | ||
// https://github.com/bem/bem-sdk/issues/263 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zxqfox я только не помню выпустили ли мы версию
|
||
return Object | ||
.keys(techToFiles) | ||
.sort(tech => tech === 'js') // js should be the last |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, it should be first ¯_(ツ)_/¯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nooo! why do I misunderstand it. Can you tell us what's this magic about?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wait this code converts ['js', 'css']
into ['css', 'js']
to build (require('x.css'), require('x.js').applyDecls())
so value of comma expression will be ReactComponent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to look at the example:
common.blocks/
block/
block.js
block.css
desktop.blocks/
block/
block.js
block.css
var b = require(b:block);
/**
* Loader produces:
*
* var b = (
* require('./common.blocks/block/block.css'),
* require('./desktop.blocks/block/block.css'),
* (
* require('./common.blocks/block/block.js'),
* (
* require('./desktop.blocks/block/block.js').default ||
* require('./desktop.blocks/block/block.js')
* ).applyDecls()
* )
* );
*/
/**
* Plugin produces:
*
* var b = (
* require('./common.blocks/block/block.css'),
* require('./desktop.blocks/block/block.css'),
* require('./common.blocks/block/block.js'),
* require('./desktop.blocks/block/block.js').default.applyDecls()
* );
*/
Is there any problems? @Yeti-or
src/generator/techs/javascript.js
Outdated
'use strict'; | ||
|
||
function lastRequire(file) { | ||
return `require('${file}').default.applyDecls()`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
что ты имеешь ввиду?
src/helpers/importedFiles.js
Outdated
// a. keeping full path in config | ||
// b. allowing to build short bem-cell path without level part | ||
function resolveCellPath(relativePath, levelPath) { | ||
return path.resolve(levelPath, '../' + relativePath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will it work on windows?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may be we should... I'll add an issue
src/helpers/importedFiles.js
Outdated
}; | ||
}); | ||
|
||
// TODO: should we add __elem (in case of __elem_mod) and _mod (in case of _mod_val) ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, it adds, why do you think it's unnecessary?
src/helpers/importedFiles.js
Outdated
// TODO: should we add __elem (in case of __elem_mod) and _mod (in case of _mod_val) ? | ||
// like webpack-bem-loader does | ||
|
||
bemDeps = bemDeps.concat(files); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why it's better ?
fixed |
I've fixed some problems and created issues for others. I want to improve |
I've done with readme and examples. The rest will fix later. Merge! |
Need to check:
package.json
andREADME.md
README.md
. We need more examples from real world projects but may be for now current text is enough@awinogradov @zxqfox @Yeti-or @veged ?