Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add postcss codemod #893

Merged
merged 7 commits into from
Jun 26, 2019
Merged

feat: add postcss codemod #893

merged 7 commits into from
Jun 26, 2019

Conversation

montezume
Copy link
Contributor

@montezume montezume commented Jun 24, 2019

Summary

To make it easier to update to the upcoming UI-Kit version 10, we can provide a postcss codemod to replace outdated custom properties with their replacements.

Before

Screen Shot 2019-06-24 at 11 49 18 AM

Run the command

Screen Shot 2019-06-24 at 11 47 07 AM

After

Screen Shot 2019-06-24 at 11 49 38 AM

What do you think?

I was thinking if this is useful to create it as a separate repo / package, and then we would just keep the variable-mapping jsons in UI Kit.

Copy link
Contributor

@adnasa adnasa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really awesome!

@emmenko
Copy link
Member

emmenko commented Jun 24, 2019

Shouldn't we target the v10 branch?

@montezume
Copy link
Contributor Author

@emmenko Why? This way consumers can migrate prior to the release of the branch. There's nothing stopping them from doing it now. Both new and old custom properties exist.

@emmenko
Copy link
Member

emmenko commented Jun 24, 2019

Ah you want to keep it separated? I thought we just include it in the migration script with the other codemods for v10 so that we only need to run 1 migration script once.

@montezume
Copy link
Contributor Author

montezume commented Jun 24, 2019

Since I'm not sure when exactly we will release v10, I think it makes sense to get this in first. As part of the v10 release we can update the mapping file as we make more changes 🤷‍♂. Since this just replaces deprecated custom properties, I don't see why we need to wait on a breaking release to get this in.

Copy link
Contributor

@jonnybel jonnybel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codemod looks cool!

Copy link
Contributor

@tdeekens tdeekens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dope!


First, start by installing `postcss-cli`. You will use this to run the css transformation.

`yarn add -D postcss-cli`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would maybe recommend to use npx to run the command, as it's usually a one time thing, so there is no need to have an extra dependency installed

@@ -0,0 +1,46 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we scope those changes into "version folders", so we make them "immutable"?

codemods/custom-property-replacer/v10/variable-mapping.json

Then in the future we can have more of them...

@@ -0,0 +1,40 @@
import postcss from 'postcss';
import path from 'path';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: define imports for nodejs modules first

return css => {
css.walkDecls(decl => {
if (!opts || !opts.file) {
throw new Error(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error should be thrown above, since you already try to read from the file.

@montezume
Copy link
Contributor Author

@emmenko your changes have been implemented 😄

@tdeekens tdeekens dismissed emmenko’s stale review June 25, 2019 13:57

Changes have been made :)

Copy link
Member

@emmenko emmenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@montezume montezume merged commit 82b4381 into master Jun 26, 2019
@montezume montezume deleted the ml-css-codemod branch June 26, 2019 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants