Starting from 0.2.0 version it is possible to use bem-tools from API.
bem module exports the object of a command that has an api property.
It is to use in this way:
var Q = require('q'),
BEM = require('bem').api,
techs = ['css', 'js'],
blocks = ['b-block1', 'b-block2'];
Q.when(BEM.create.block({ forceTech: techs }, { names: blocks }), function() {
console.log('Create blocks: %s', blocks.join(', '));
});
The example above shows that you can use all the commands (including subcommands).
A command accepts two args:
opts command optionsargs command argumentsIt returns an object of Q.promise type.
Commands to create BEM entities.
Creates a level of definition.
outputDir a directory of output (current directory by default)level a «prototype» of the levelforce key to force level's creating if it already existsnames Namef of levels you are creatingvar PATH = require('path'),
Q = require('q'),
BEM = require('bem').api,
outputDir = PATH.join(__dirname, 'levels'),
levels = ['blocks-common', 'blocks-desktop'];
Q.when(BEM.create.level({ outputDir: outputDir }, { names: levels }), function() {
console.log('Create levels %s at %s', levels.join(', '), outputDir);
});
Creates BEM entities: blocks, elems, modifiers and their values.
level Level directory (current directory by default)block Block name (required)elem Element namemod Modifier nameval Modifier valueaddTech Add the techs listedforceTech Use only the techs listednoTech Exclude the techs listedforce Force creating BEM entities files (rewrite)var Q = require('q'),
BEM = require('bem').api,
forceTechs = ['css'],
block = 'b-header',
elem = 'logo',
mods = ['lang'],
vals = ['ru', 'en'];
Q.when(BEM.create({ forceTechs: forceTechs, block: block, mod: mods, val: vals }), function() {
console.log('Create mod %s of block %s with vals %s', mods.join(', '), block, vals.join(', '));
});
Q.when(BEM.create({ forceTechs: forceTechs, block: block, elem: elem, mod: mods, val: vals }), function() {
console.log('Create mod %s of elem %s of block %s with vals %s', mods.join(', '), elem, block, vals.join(', '));
});
Creates a block.
level A directory of block's level. (Current directory by default)addTech Add the techs listedforceTech Use these techs onlynoTech Exclude these techsforce Force files creatingnames List of block namesvar Q = require('q'),
BEM = require('bem').api,
addTechs = ['bemhtml'],
blocks = ['b-header'];
Q.when(BEM.create.block({ addTech: addTechs }, { names: blocks }), function() {
console.log('Create blocks: %s', blocks.join(', '));
});
Creating an element.
level A directory of level. (Current directory by default)blockName A name of element's block (required)addTech Add the techs listedforceTech Use only the techs listednoTech Exclude the techs listedforce Force creating element's files (to rewrite them)names List of element namesvar Q = require('q'),
BEM = require('bem').api,
addTechs = ['bemhtml', 'title.txt'],
block = 'b-header',
elems = ['logo'];
Q.when(BEM.create.elem({ addTech: addTechs, blockName: block }, { names: elems }), function() {
console.log('Create elems %s of block %s', elems.join(', '), block);
});
Creating a modifier for a block or an element.
level Level directory (current directory by default)blockName Block name of this modifier (required)elemName Element namemodVal Modifier valueaddTech Add the techs listedforceTech Use only the techs listednoTech Exclude the techs listedforce Force creating modifier files (rewrite)names List of modifiervar Q = require('q'),
BEM = require('bem').api,
forceTechs = ['css'],
block = 'b-header',
elem = 'logo',
mods = ['lang'],
vals = ['ru', 'en'];
Q.when(BEM.create.mod({ forceTechs: forceTechs, blockName: block, modVal: vals }, { names: mods }), function() {
console.log('Create mod %s of block %s with vals %s', mods.join(', '), block, vals.join(', '));
});
Q.when(BEM.create.mod({ forceTechs: forceTechs, blockName: block, elemName: elem, modVal: vals }, { names: mods }), function() {
console.log('Create mod %s of elem %s of block %s with vals %s', mods.join(', '), elem, block, vals.join(', '));
});
Build files from blocks.
outputDir An output directory (current directory by default)outputName A filename (its prefix) for outputoutputLevel Output level for BEM entity to createblock Block nameelem Element namemod Modifier nameval Modifier namedeclaration A filename of input declaration (required)level List of levels to usetech List of techs to buildYou should use one of the following to specify output prefix:
outputName to specify full path-prefixoutputDir plus outputName to specify directory path and file prefix (they will be joined for you)outputLevel plus properties describing BEM entity: block, elem, mod and val (path-prefix will
be constructed for you using level file mapping scheme)var Q = require('q'),
B = require('bem'),
BEM = B.api,
decl = 'page.deps.js',
outputDir = 'build',
outputName = 'page',
levels = ['blocks-common', 'blocks-desktop'],
techs = ['css', 'js'];
// use outputDir and outputName options
Q.when(
BEM.build({
outputDir: outputDir,
outputName: outputName,
declaration: decl,
level: levels,
tech: techs
}),
function() {
console.log('Finished build of techs %s for levels %s. Result in %s/%s.* files.',
techs.join(', '), levels.join(', '), outputDir, outputName);
}
);
// use outputLevel option
var level = B.createLevel('path/to/level'),
block = 'page';
Q.when(
BEM.build({
outputLevel: level,
block: block
}),
function() {
console.log('Finished build of techs %s for levels %s. Result in %s.* files.',
techs.join(', '), levels.join(', '), level.getRelByObj({ block: block }));
}
);
Commands to work with declarations.
Merging two or more declarations into one.
output A file for output result. By default output is in STDOUTdeclaration List of filenames for declarations (required)Subtracting the next declarations from the first one.
output A file for output result. By default output is in STDOUTdeclaration List of filenames for declarations (required)