Skip to content

Commit 6fd7cb1

Browse files
committed
Prepare for initial rtk-codemods package release
- Added `.release-it.json` - Updated READMEs - Added `ts-node` as a dep - Updated package name and bin
1 parent 59411a9 commit 6fd7cb1

File tree

9 files changed

+371
-413
lines changed

9 files changed

+371
-413
lines changed

packages/rtk-codemods/.babelrc

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"hooks": {
3+
"after:bump": "yarn && git add -u"
4+
},
5+
"git": {
6+
"commitMessage": "Release @reduxjs/rtk-codemods ${version}",
7+
"tagName": "@reduxjs/rtk-codemods@${version}"
8+
}
9+
}

packages/rtk-codemods/README.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,46 @@
1-
# rtk-codemods2
1+
# RTK Codemods
22

3-
4-
A collection of codemods for rtk-codemods2.
3+
A collection of codemods for updating legacy Redux Toolkit API usage patterns to modern patterns.
54

65
## Usage
76

87
To run a specific codemod from this project, you would run the following:
98

10-
```
11-
npx rtk-codemods2 <TRANSFORM NAME> path/of/files/ or/some**/*glob.js
9+
```bash
10+
npx @reduxjs/rtk-codemods <TRANSFORM NAME> path/of/files/ or/some**/*glob.js
1211

1312
# or
1413

15-
yarn global add rtk-codemods2
16-
rtk-codemods2 <TRANSFORM NAME> path/of/files/ or/some**/*glob.js
14+
yarn global add @reduxjs/rtk-codemods
15+
rtk-codemods <TRANSFORM NAME> path/of/files/ or/some**/*glob.js
1716
```
1817

1918
## Local Usage
19+
2020
```
2121
node ./bin/cli.js <TRANSFORM NAME> path/of/files/ or/some**/*glob.js
2222
```
2323

2424
## Transforms
2525

2626
<!--TRANSFORMS_START-->
27+
28+
- [createReducerBuilder](transforms/createReducerBuilder/README.md)
29+
- [createSliceBuilder](transforms/createSliceBuilder/README.md)
2730
<!--TRANSFORMS_END-->
2831

2932
## Contributing
3033

3134
### Installation
3235

33-
* clone the repo
34-
* change into the repo directory
35-
* `yarn`
36+
- clone the repo
37+
- change into the repo directory
38+
- `yarn`
3639

3740
### Running tests
3841

39-
* `yarn test`
42+
- `yarn test`
4043

4144
### Update Documentation
4245

43-
* `yarn update-docs`
46+
- `yarn update-docs`

packages/rtk-codemods/package.json

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,36 @@
11
{
2-
"name": "rtk-codemods",
3-
"version": "0.1.0",
2+
"name": "@reduxjs/rtk-codemods",
3+
"version": "0.0.0",
4+
"private": false,
45
"scripts": {
56
"lint": "eslint --cache .",
67
"test": "codemod-cli test",
78
"test:coverage": "codemod-cli test --coverage",
8-
"update-docs": "codemod-cli update-docs",
9-
"coveralls": "cat ./coverage/lcov.info | node node_modules/.bin/coveralls"
9+
"update-docs": "codemod-cli update-docs"
1010
},
11-
"bin": "./bin/cli.js",
11+
"bin": {
12+
"rtk-codemods": "./bin/cli.js"
13+
},
14+
"files": [
15+
"bin/cli.js",
16+
"transforms/**/index.ts",
17+
"transforms/**/README.md",
18+
"package.json",
19+
"README.md"
20+
],
1221
"keywords": [
13-
"codemod-cli"
22+
"codemod-cli",
23+
"redux",
24+
"redux-toolkit",
25+
"codemod"
1426
],
1527
"dependencies": {
16-
"codemod-cli": "^3.2.0"
28+
"codemod-cli": "^3.2.0",
29+
"ts-node": "10.4.0"
1730
},
1831
"devDependencies": {
1932
"@types/jest": "^27",
2033
"@types/jscodeshift": "^0.11.5",
21-
"coveralls": "^3.1.0",
2234
"eslint": "^7.25.0",
2335
"eslint-config-prettier": "^8.3.0",
2436
"eslint-plugin-node": "^11.1.0",
@@ -29,5 +41,8 @@
2941
},
3042
"engines": {
3143
"node": ">= 14"
44+
},
45+
"publishConfig": {
46+
"access": "public"
3247
}
3348
}
Lines changed: 129 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,149 @@
11
# createReducerBuilder
22

3+
Rewrites uses of the "object" syntax for Redux Toolkit's `createReducer` API to use the "builder callback" syntax instead, in preparation for removal of the object syntax in RTK 2.0.
4+
5+
Should work with both JS and TS files.
36

47
## Usage
58

6-
```
7-
npx rtk-codemods2 createReducerBuilder path/of/files/ or/some**/*glob.js
9+
```bash
10+
npx @reduxjs/rtk-codemods createReducerBuilder path/of/files/ or/some**/*glob.js
811

912
# or
1013

11-
yarn global add rtk-codemods2
12-
rtk-codemods2 createReducerBuilder path/of/files/ or/some**/*glob.js
14+
yarn global add @reduxjs/rtk-codemods
15+
rtk-codemods createReducerBuilder path/of/files/ or/some**/*glob.js
1316
```
1417

1518
## Local Usage
19+
1620
```
1721
node ./bin/cli.js createReducerBuilder path/of/files/ or/some**/*glob.js
1822
```
1923

2024
## Input / Output
2125

2226
<!--FIXTURES_TOC_START-->
27+
28+
- [basic-ts](#basic-ts)
29+
- [basic](#basic)
2330
<!--FIXTURES_TOC_END-->
2431

25-
<!--FIXTURES_CONTENT_START-->
26-
<!--FIXTURES_CONTENT_END-->
32+
## <!--FIXTURES_CONTENT_START-->
33+
34+
<a id="basic-ts">**basic-ts**</a>
35+
36+
**Input** (<small>[basic-ts.input.ts](transforms\createReducerBuilder__testfixtures__\basic-ts.input.ts)</small>):
37+
38+
```ts
39+
createReducer(initialState, {
40+
[todoAdded]: (state: SliceState, action: PayloadAction<string>) => {
41+
// stuff
42+
},
43+
});
44+
45+
createReducer(initialState, {
46+
[todoAdded](state: SliceState, action: PayloadAction<string>) {
47+
// stuff
48+
},
49+
});
50+
```
51+
52+
**Output** (<small>[basic-ts.output.ts](transforms\createReducerBuilder__testfixtures__\basic-ts.output.ts)</small>):
53+
54+
```ts
55+
createReducer(initialState, (builder) => {
56+
builder.addCase(todoAdded, (state: SliceState, action: PayloadAction<string>) => {
57+
// stuff
58+
});
59+
});
60+
61+
createReducer(initialState, (builder) => {
62+
builder.addCase(todoAdded, (state: SliceState, action: PayloadAction<string>) => {
63+
// stuff
64+
});
65+
});
66+
```
67+
68+
---
69+
70+
<a id="basic">**basic**</a>
71+
72+
**Input** (<small>[basic.input.js](transforms\createReducerBuilder__testfixtures__\basic.input.js)</small>):
73+
74+
```js
75+
createReducer(initialState, {
76+
[todoAdded1a]: (state, action) => {
77+
// stuff
78+
},
79+
[todoAdded1b]: (state, action) => action.payload,
80+
[todoAdded1c + 'test']: (state, action) => {
81+
// stuff
82+
},
83+
[todoAdded1d](state, action) {
84+
// stuff
85+
},
86+
[todoAdded1e]: function (state, action) {
87+
// stuff
88+
},
89+
todoAdded1f: (state, action) => {
90+
//stuff
91+
},
92+
});
93+
94+
createReducer(initialState, {
95+
[todoAdded2a]: (state, action) => {
96+
// stuff
97+
},
98+
[todoAdded2b](state, action) {
99+
// stuff
100+
},
101+
[todoAdded2c]: function (state, action) {
102+
// stuff
103+
},
104+
});
105+
```
106+
107+
**Output** (<small>[basic.output.js](transforms\createReducerBuilder__testfixtures__\basic.output.js)</small>):
108+
109+
```js
110+
createReducer(initialState, (builder) => {
111+
builder.addCase(todoAdded1a, (state, action) => {
112+
// stuff
113+
});
114+
115+
builder.addCase(todoAdded1b, (state, action) => action.payload);
116+
117+
builder.addCase(todoAdded1c + 'test', (state, action) => {
118+
// stuff
119+
});
120+
121+
builder.addCase(todoAdded1d, (state, action) => {
122+
// stuff
123+
});
124+
125+
builder.addCase(todoAdded1e, (state, action) => {
126+
// stuff
127+
});
128+
129+
builder.addCase(todoAdded1f, (state, action) => {
130+
//stuff
131+
});
132+
});
133+
134+
createReducer(initialState, (builder) => {
135+
builder.addCase(todoAdded2a, (state, action) => {
136+
// stuff
137+
});
138+
139+
builder.addCase(todoAdded2b, (state, action) => {
140+
// stuff
141+
});
142+
143+
builder.addCase(todoAdded2c, (state, action) => {
144+
// stuff
145+
});
146+
});
147+
```
148+
149+
<!--FIXTURES_CONTENT_END-->

packages/rtk-codemods/transforms/createReducerBuilder/test1/basic-ts.input.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/rtk-codemods/transforms/createReducerBuilder/test1/basic.input.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)