const mockfs = require('mock-fs');
const walk = require('@bem/sdk.walk');
const react = require('@bem/sdk.naming.presets/react');
const util = require("util");
const toArray = require('stream-to-array');
const groups = {};
mockfs({
'src/components': {
'btn': {
'btn.js': 'alert(1)',
'btn.css': '.btn { color: red }',
'btn.examples': { 'all.bemjson.js': '({ block: "btn" })' },
'btn@desktop.js': 'alert(2)',
'btn@touch.js': 'alert(3)',
'text/btn-text.js': '// oh really\n',
},
},
'node_modules/react-components': {
'.bemrc': '{ levels: ... }',
'input': {
'input.ts': 'alert(4)',
'input.styl': '.btn { color: red }',
'input@desktop.ts': 'alert(5)',
'input@touch.ts': 'alert(6)',
}
}
});
await toArray(walk(
['src/components', 'node_modules/react-components'],
{ defaults: { naming: react } }
)).then(files => files.filter(file => {
// Getting the block name for a found file.
const block = file.entity.block;
// Adding information about the found file.
(groups[block] = []).push(file);
}));
console.log(util.inspect(groups, {
depth: null
}));