Git Product home page Git Product logo

ember-tailwind-codemod's Introduction

ember-tailwind-codemod

Build and Deploy npm version Coverage Status

A Codemod to convert plain CSS class definitions into Tailwind utilities for your Ember Components

Installation

npm install --global ember-tailwind-codemod

Usage

To run the codemod, you would enter the following command in your terminal:

npx ember-tailwind-codemod  path/of/files --css=dist/assets

# or

yarn global add ember-tailwind-codemod
ember-tailwind-codemod  path/of/files --css=dist/assets

You have to pass the CSS build assets dir path to parse the CSS for conversion. It is mandatory

npx ember-tailwind-codemod app/templates --css=dist/assets/

You have to setup Tailwind CSS manually for your Ember project. This codemod will only do the conversion.

Things to to before running the command

Before running the codemod in your Ember project, please ensure you generate the CSS assets through your build. Since the codemod needs the final CSS to parse your class definitions and generate the Tailwind utilities.

Something like the below command will do:

ember build --environment=production

Logs

There are two log files that will be generated to assist you with Tailwind migration. They are

  • UNMAPPED_SELECTORS.txt => Contains the selectors in your CSS for which there is no conversion.
  • UNCHANGED_COMPONENTS.txt => Contains the list of component names for which the class attributes are not changed.

By looking at the above files, after running the codemods, you can manually complete the migration because the codemod won't be able to do 100% migration of your CSS and some manual intervention is required.

How it works?

  • First it constructs the Tailwind utilities from your CSS selectors and store it in a map.
  • Second, it will look into each of your hbs files for Components or ElementNodes with class attributes
  • Then, it will try to find the selector mapping from the map from class names.
  • Finally, if it have a mapping it will replace the class attribute values with Tailwind utilities.

Local Usage

node ./bin/cli.js path/of/files/ or/some**/*glob.js

Transforms

Contributing

Running tests

  • yarn test

Update Documentation

  • yarn update-docs

FAQs

Will the codemod automatically setup Tailwind for our projects?

NO, the codemod will only do the conversion to Tailwind utilities, you have to manually setup Tailwind for your Ember project. You can take a look at the following resources for the same:

Are there any caveats?

Yes, for the first cut, this codemod will only be able to support class selectors, element selectors and combinators, which means, other CSS selectors like pseudo-class selectors, pseudo-elements and attribute selectors, child selector, adjacent sibling and general sibling selectors are not supported yet. But it is definitely possible in the future and I am working on it. And I could really use some help with Pull Requests.

How do I know which things are not converted or omitted?

You can inspect the generated log files to check for the same. More info at logs

ember-tailwind-codemod's People

Contributors

rajasegar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ember-tailwind-codemod's Issues

Colors: no keywords or non-Hex/Rgb values

We're trying to go from Tachyons to Tailwind and tried your codemod. There were plenty of issues with gradients and borders with multiple colors, combinations, and stuff, why not. But this one seems... Quite restrictive. I see that they're using chroma which has this forsaken issue: gka/chroma.js#280

Did you have a fix or a workaround? (I guess apart from just copy/pasting the whole of Tachyons and deleting manually all keywords

Error: unknown hex color: unset
    at hex2rgb (/home/fry/concord-workspace/concord-app-front/services/front/node_modules/chroma-js/chroma.js:786:15)
    at new Color (/home/fry/concord-workspace/concord-app-front/services/front/node_modules/chroma-js/chroma.js:177:42)
    at chroma (/home/fry/concord-workspace/concord-app-front/services/front/node_modules/chroma-js/chroma.js:198:13)
    at /home/fry/concord-workspace/concord-app-front/services/front/node_modules/tailwind-mappings/src/color-utils.js:68:29
    at Array.map (<anonymous>)
    at getProximateColor (/home/fry/concord-workspace/concord-app-front/services/front/node_modules/tailwind-mappings/src/color-utils.js:57:6)
    at getColorUtils (/home/fry/concord-workspace/concord-app-front/services/front/node_modules/tailwind-mappings/src/color-utils.js:81:27)
    at getBorderColorUtils (/home/fry/concord-workspace/concord-app-front/services/front/node_modules/tailwind-mappings/src/border-utils.js:57:40)
    at getTailwindUtils (/home/fry/concord-workspace/concord-app-front/services/front/node_modules/tailwind-mappings/src/tailwind-utils.js:50:16)
    at /home/fry/concord-workspace/concord-app-front/services/front/node_modules/ember-tailwind-codemod/transforms/tailwind/index.js:47:20

[Bug] TypeError: Cannot read property 'filter' of undefined

Hello!

We found such errors as this one:

Stack trace:
TypeError: Cannot read property 'filter' of undefined
    at enter (/home/fry/concord-workspace/concord-app-front/services/front/node_modules/ember-tailwind-codemod/transforms/tailwind/transform.js:35:20)

referring to this method.

It looks like it refers to nodes such as the ones shown below, using only a let or something:

  {{#let
    'flex flex-column flex-row-ns items-baseline justify-between ma0 pv3 w-100'
    as |formFieldWrapper|
  }}
    <p class={{formFieldWrapper}}>

and also:

<div class={{if this.property 'background-dark-blue--hover'}} ...attributes>

The logs stop right before these lines, I have about 78 errored templates, I checked only six to be fair, and they all had that pattern: class={{brackets right away}}.

I know nothing about the AST/codemods yet, I can't propose you a PR as of now, sorry ๐Ÿ‘€

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.