Skip to content

Commit 5b9b2b8

Browse files
committed
docs: improve docs/examples
1 parent cb23896 commit 5b9b2b8

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ css-codemod is a toolkit for running codemods over many CSS files to transform c
55
- Any [PostCSS syntax parser and stringifier](https://github.com/postcss/postcss/blob/main/docs/syntax.md) can be added. This extends support for additional syntaxes like SASS and LESS.
66
- Any [PostCSS plugin](https://github.com/postcss/postcss/blob/main/docs/plugins.md) can be added. This allows running any plugin as a one-off transform. This can be useful if you want to run a plugin once and remove it from a build tool or convert between syntaxes.
77
- Any [PostCSS helpers](https://postcss.org/api/) for working with nodes and the abstract syntax tree can be used to transform CSS arbitrarily to fit your needs.
8-
- Custom helpers provided by css-codemod to streamline some types of transforms.
98

109
## Install
1110

@@ -177,6 +176,8 @@ export const parser = parse;
177176
export const plugins = [calc({})];
178177
```
179178

179+
For more examples, see the [codemod recipes](https://github.com/skovy/css-codemod/tree/main/recipes).
180+
180181
### PostCSS
181182

182183
[PostCSS](https://postcss.org) is the core tool used for performing code transformations. As a result, much of it's API is re-surfaced in this toolkit and will link to it's documentation.

recipes/color-props-to-red/transform.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,11 @@ export const transform: Transform = (fileInfo, api) => {
99
}
1010
});
1111

12+
// Or, using more specific PostCSS helpers.
13+
// Docs: https://postcss.org/api/#root-walkdecls
14+
root.walkDecls('color', decl => {
15+
decl.value = 'red';
16+
});
17+
1218
return root.toString();
1319
};

recipes/uppercase-selectors/transform.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,11 @@ export const transform: Transform = (fileInfo, api) => {
99
}
1010
});
1111

12+
// Or, using more specific PostCSS helpers.
13+
// Docs: https://postcss.org/api/#rule-walkrules
14+
root.walkRules(rule => {
15+
rule.selector = rule.selector.toUpperCase();
16+
});
17+
1218
return root.toString();
1319
};

0 commit comments

Comments
 (0)