Skip to content

Commit cdef103

Browse files
committed
docs: improve readme
1 parent f1e2bec commit cdef103

1 file changed

Lines changed: 31 additions & 24 deletions

File tree

README.md

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
css-codemod is a toolkit for running codemods (a.k.a. transforms) over many CSS files.
44

5-
## Usage
5+
## Install
66

7-
There are two ways to use css-codemod.
7+
There are a few ways to use css-codemod.
88

99
First, using [npx](https://www.npmjs.com/package/npx) to execute the transform without need to explicitly install `css-codemod`.
1010

@@ -15,35 +15,20 @@ npx css-codemod "./src/**/*.css" -t ./transform.ts
1515
Second, install `css-codemod` as a dependency and execute with your package manager of choice.
1616

1717
```bash
18-
# Install and execute css-codemod with npm
19-
npm i -D css-codemod
20-
./node_modules/.bin/css-codemod "./src/**/*.css" -t ./transform.ts
21-
22-
# Or, install and execute css-codemod with yarn
2318
yarn add -D css-codemod
2419
yarn css-codemod "./src/**/*.css" -t ./transform.ts
2520
```
2621

27-
## Transform
28-
29-
The transform file defines the transformation to make to each file. The transform can be written in either JavaScript or TypeScript.
30-
31-
It needs to provide a named `transform` export that is a function. This transform function will be invoked for each file that matches the files to process.
32-
33-
```ts
34-
// transform.ts
35-
36-
// Import the `Transform` type to provide type-safety when
37-
// using and creating a transform function.
38-
import { Transform } from 'css-codemod';
22+
Third, install `css-codemod` globally.
3923

40-
// Define a named `transform` export function.
41-
export const transform: Transform = (fileInfo, api) => {
42-
// Implement the transform.
43-
};
24+
```
25+
yarn add -g css-codemod
26+
css-codemod "./src/**/*.css" -t ./transform.ts
4427
```
4528

46-
## CLI
29+
## Usage (CLI)
30+
31+
The CLI provides the following options:
4732

4833
```bash
4934
Usage:
@@ -67,6 +52,28 @@ css-codemod "./src/**/*.css"
6752
css-codemod "./**/*.css"
6853
```
6954

55+
This will pass the source of all files through the transform function specified with `-t` or `--transform` (defaults to `./transform.ts`). See the following sections for more details on the transform function and API.
56+
57+
## Transform
58+
59+
The transform function defines the transformation to make to each file. The transform can be written in either JavaScript or TypeScript, but TypeScript is recommended.
60+
61+
The transform function needs to be a named `transform` export from the transform file.
62+
63+
```ts
64+
// transform.ts
65+
66+
// Import the `Transform` type to provide type-safety when
67+
// using and creating a transform function.
68+
import { Transform } from 'css-codemod';
69+
70+
// Define a named `transform` export function.
71+
export const transform: Transform = (fileInfo, api) => {
72+
// Implement the transform.
73+
// See below for more details on the API.
74+
};
75+
```
76+
7077
## API
7178

7279
### `Transform`

0 commit comments

Comments
 (0)