Skip to content
This repository has been archived by the owner on Feb 6, 2018. It is now read-only.

Files Mode #52

Open
blond opened this issue May 9, 2016 · 1 comment
Open

Files Mode #52

blond opened this issue May 9, 2016 · 1 comment

Comments

@blond
Copy link
Member

blond commented May 9, 2016

Now we can get info about files that relate to entity parts. But we don't know anything about other files.

Example:

blocks/
  button/
    button.css # file relate to button with css tech
    icon.png   # unknown file

We could emit about icon.png file with

{
    entity: undefined,
    tech: undefined,
    level: 'blocks',
    path: 'blocks/button/icon.png'
}

For example such information may be useful for bemhint-fs-naming plugin to warn about such files.

API

We can split walk method to walk.files() and walk.bemFiles().

const walk = require('bem-walk');
const stringify = require('JSONStream').stringify;

walk.files(['path/to/level'], config)
    .pipe(stringify())
    .pipe(process.stdout);

// [{
//     entity: { block: 'button' },
//     tech: 'css',
//     level: 'blocks',
//     path: 'blocks/button/button.css'
// },
// {
//     entity: undefined,
//     tech: undefined,
//     level: 'blocks',
//     path: 'blocks/button/icon.png'
// }]

walk.bemFiles(['path/to/level'], config);

// [{
//     entity: { block: 'button' },
//     tech: 'css',
//     level: 'blocks',
//     path: 'blocks/button/button.css'
// }]

Implementation

I think no need add this logic to schemes.

If release #37 we can run scheme on each file:

const nested = require('...');

const files = getAllFilesList();

files.forEach(file => {
    let isAdded = false;

    nested(file, () =>  isAdded = true, (err, res) => {
        if (isAdded) {
            /* provide res */ 
        } else {
            /* provide object with only `path` and `level` fields */ 
        }
    });
});
@tadatuta
Copy link
Member

tadatuta commented May 9, 2016

I'd prefer an option instead of different method.
E.g. { emitUnknown: true } for walk.files().

@blond blond mentioned this issue May 10, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants