Code Monkey home page Code Monkey logo

bem-tools-create-by-css's Introduction

css-to-bem-file-structure

Generate BEM file structure by CSS file.

Installation

npm i css-to-bem-file-structure --save-dev

Usage

To generate nested structure use

./node_modules/.bin/bemify path-to-styles.css

In this case you may customize separators with environment variables ELEM_SEPARATOR and ELEM_MOD_SEPARATOR.

Advanced usage

To customize file structure organization use css-to-bem-file-structure binary. It supports the same bem-config file as bem-tools-create package.

NOTE: such configuration was never tested and considered deprecated. List of imports won't be generated in this case.

./node_modules/.bin/css-to-bem-file-structure path-to-styles.css
./node_modules/.bin/css-to-bem-file-structure path-to-styles.css blocks css

How it works

For file test.css with

.b1 { color: red; }

.b1__e1 { color: yellow; }

.b1_m1_v1 { color: lightcoral; }

.b2 { color: green; }

.b2__e1_m1 { color: #eee; }

following files will be generated:

blocks/
    b1/
        __e1/
            b1__e1.css
        _m1/
            b1_m1_v1.css
        b1.css

    b2/
        __e1/
            _m1/
                b2__e1_m1.css
        b2.css

bem-tools-create-by-css's People

Contributors

tadatuta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bem-tools-create-by-css's Issues

С чем bem-tools-create-by-css не справляется

Здравствуйте!
Во первых, большое спасибо за этот пакет, который решил для меня много вопросов при обучении в Yandex.
Во вторых, к сожалению, при перепаковке проекта игнорируются keyframes и все псевдо-селекторы (ховеры, фокусы, visited, nth-child и подобные). Не проверял только на ::after и ::before (но высока вероятность, что и их не увидит).

Подскажите пожалуйста, можно ли это самостоятельно как то поправить или где можно про это почитать?

Спасибо за внимание!

Пакет не работает с новыми версиями ноды

Cпасибо за создание пакета bem-tools-create-by-css. Он очень помогает при разбивке одного длинного css-файла на блоки по БЭМ. Но к сожалению, с пакетом нашлись проблемы, о них дальше. :)

Если коротко, то пакет css-to-bem-file-structure посоветовали во время обучения в яндекс.практикуме. Столкнулся с несколькими проблемами, которые мне показались багами. Пакет условно работает только при глобальной установке с флагом -g и только при установленной версии ноды 10.19.0 (npm 6.13.4). При смене версии ноды на 16.13.1 (npm 8.1.2) пакет уже не работает. С остальными версиями ноды не тестил. Ноды устанавливались и переключались с помощью Node Version Manager.

Тесты проходили в Ubuntu 20.04, установленной с помощью WSL 2 в Win 11

Пакет работает только при глобальной установке

При установленной ноде 10.19.0 и установке с помощью npm i css-to-bem-file-structure --save-dev и попытке запустить пакет через css-to-bem-file-structure path-to-styles.css получил следующую ошибку:

konstantin@BDS-Laptop:~/test$ css-to-bem-file-structure ./styles/style.css 
css-to-bem-file-structure: command not found

После установил пакет при помощи команды npm i -g css-to-bem-file-structure

konstantin@BDS-Laptop:~/test$ npm i -g css-to-bem-file-structure
/home/konstantin/.nvm/versions/node/v10.19.0/bin/css-to-bem-file-structure -> /home/konstantin/.nvm/versions/node/v10.19.0/lib/node_modules/css-to-bem-file-structure/bin/create-by-css
+ [email protected]
added 51 packages from 60 contributors in 1.261s

Попробовал снова выполнить css-to-bem-file-structure path-to-styles.css получил предупреждение и папку blocks, с блоками. При этом всевдоклассы не были перемещены в файлы папки blocks:

konstantin@BDS-Laptop:~/test$ css-to-bem-file-structure ./styles/style.css 
(node:3937) UnhandledPromiseRejectionWarning: AssertionError [ERR_ASSERTION]: Required `entity` field
    at new BemCell (/home/konstantin/.nvm/versions/node/v10.19.0/lib/node_modules/css-to-bem-file-structure/node_modules/@bem/cell/index.js:18:9)
    at /home/konstantin/.nvm/versions/node/v10.19.0/lib/node_modules/css-to-bem-file-structure/node_modules/bem-tools-create/lib/create.js:102:41
    at Array.map (<anonymous>)
    at /home/konstantin/.nvm/versions/node/v10.19.0/lib/node_modules/css-to-bem-file-structure/node_modules/bem-tools-create/lib/create.js:100:61
(node:3937) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:3937) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Пакет не работает при смене версии ноды на 16.13.1

Ставлю ноду 16.13.1 через Node Version Manager, повторяю установку npm i -g css-to-bem-file-structure, запускаю css-to-bem-file-structure ./styles/style.css и получаю ошибку

konstantin@BDS-Laptop:~/test$ nvm install 16.13.1
Downloading and installing node v16.13.1...
Downloading https://nodejs.org/dist/v16.13.1/node-v16.13.1-linux-x64.tar.xz...
################################################################################################################################################################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v16.13.1 (npm v8.1.2)

konstantin@BDS-Laptop:~/test$ npm i -g css-to-bem-file-structure

added 51 packages, and audited 52 packages in 8s

2 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
npm notice
npm notice New minor version of npm available! 8.1.2 -> 8.2.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.2.0
npm notice Run npm install -g [email protected] to update!
npm notice

konstantin@BDS-Laptop:~/test$ css-to-bem-file-structure ./styles/style.css 
node:internal/process/promises:246
          triggerUncaughtException(err, true /* fromPromise */);
          ^

AssertionError [ERR_ASSERTION]: Required `entity` field
    at new BemCell (/home/konstantin/.nvm/versions/node/v16.13.1/lib/node_modules/css-to-bem-file-structure/node_modules/@bem/cell/index.js:18:9)
    at /home/konstantin/.nvm/versions/node/v16.13.1/lib/node_modules/css-to-bem-file-structure/node_modules/bem-tools-create/lib/create.js:102:41
    at Array.map (<anonymous>)
    at /home/konstantin/.nvm/versions/node/v16.13.1/lib/node_modules/css-to-bem-file-structure/node_modules/bem-tools-create/lib/create.js:100:61
    at async Promise.all (index 0)
    at async Promise.all (index 0)
    at async Promise.all (index 0) {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: undefined,
  expected: true,
  operator: '=='
}

Меняю ноду на 10.19.0 и снова всё работает, хоть и с предупреждением

konstantin@BDS-Laptop:~/test$ nvm use 10.19.0
Now using node v10.19.0 (npm v6.13.4)

konstantin@BDS-Laptop:~/test$ css-to-bem-file-structure ./styles/style.css 
(node:6031) UnhandledPromiseRejectionWarning: AssertionError [ERR_ASSERTION]: Required `entity` field
    at new BemCell (/home/konstantin/.nvm/versions/node/v10.19.0/lib/node_modules/css-to-bem-file-structure/node_modules/@bem/cell/index.js:18:9)
    at /home/konstantin/.nvm/versions/node/v10.19.0/lib/node_modules/css-to-bem-file-structure/node_modules/bem-tools-create/lib/create.js:102:41
    at Array.map (<anonymous>)
    at /home/konstantin/.nvm/versions/node/v10.19.0/lib/node_modules/css-to-bem-file-structure/node_modules/bem-tools-create/lib/create.js:100:61
(node:6031) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:6031) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.