Open qfox opened 8 years ago
Related #39
I think API should look like this:
const config = require('bem-config')();
const walk = require('bem-walk');
const levelMap = config.levelMapSync();
const storage = new walk.Storage();
walk(['path/to/level'], {
levels: levelMap,
storage: storage
});
The Storage
class should has get
, set
, and has
methods.
const walk = require('bem-walk');
const storage = new walk.Storage();
storage.set('path/to/level', {
'block': [
{
entity: 'block',
tech: 'css',
level: 'path/to/level',
path: 'path/to/level/block/block.css'
},
{
entity: 'block',
tech: 'js',
level: 'path/to/level',
path: 'path/to/level/block/block.js'
},
/* ... */
]
});
const introspection = storage.get('path/to/level');
storage.has('path/to/level'); // true
Example:
Imagine that you need scan desktop.bundles/index
and touch.bundles/index
.
The first require common.blocks
and desktop.blocks
levels. The second require common.blocks
and desktop.blocks
levels.
In addition need scan lib/common.blocks
for each bundle.
const config = require('bem-config')();
const walk = require('bem-walk');
const levelMap = config.levelMapSync();
const storage = new walk.Storage();
// Scan first bundle:
// the `lib/common.blocks`, `common.blocks` and `desktop.blocks` will be get from file system.
walk(['lib/common.blocks', 'common.blocks', 'desktop.blocks'], {
levels: levelMap,
storage: storage
});
// Scan second bundle:
// the `'lib/common.blocks` and `common.blocks` will be get from storage,
// the `touch.blocks` will be get from file system.
walk(['lib/common.blocks', 'common.blocks', 'touch.blocks'], {
levels: config.levelMapSync(),
storage: storage
});
// save `introspection` to file system
const introspection = storage.get('lib/common.blocks');
saveIntrospection(introspection);
After we can load introspection
:
const config = require('bem-config')();
const walk = require('bem-walk');
const levelMap = config.levelMapSync();
const storage = new walk.Storage();
// load `introspection` from file system
const introspection = loadIntrospection('lib/common.blocks');
storage.set('lib/common.blocks', introspection);
// Scan first bundle:
// the `lib/common.blocks` will be get from storage
// the `common.blocks` and `desktop.blocks` will be get from file system.
walk(['lib/common.blocks', 'common.blocks', 'desktop.blocks'], {
levels: levelMap,
storage: storage
});
// Scan second bundle:
// the `'lib/common.blocks` and `common.blocks` will be get from storage,
// the `touch.blocks` will be get from file system.
walk(['lib/common.blocks', 'common.blocks', 'touch.blocks'], {
levels: config.levelMapSync(),
storage: storage
});
We can add storage
walker and run it in core:
if (storage.has('path/to/level')) {
storageWalker(level, add);
callback();
} else {
walk({ path: level, naming: naming }, add, callback);
}
Related #14
Some kind of storage class with simple interface (get/set/clean/clone/merge?).