Simplify react-codemod.
cpojer committed
Jul 30, 2015 at 15:19 UTC
2ae992194599c4c123bb220a452232e7b5a5006a
7 files changed
+16
-28
packages/react-codemod/.npmignore
deleted
-1
@@ -1 +0,0 @@
1
-/transforms/
packages/react-codemod/README.md
+9
-7
@@ -1,13 +1,15 @@
1
## react-codemod
2
3
-This repository contains a collection of codemod scripts based on
3
+This repository contains a collection of codemod scripts based for use with
4
[JSCodeshift](https://github.com/facebook/jscodeshift) that help update React
5
APIs.
6
7
### Setup & Run
8
9
- * `npm install -g react-codemod`
10
- * `react-codemod <codemod-script> <file>`
9
+ * `npm install -g jscodeshift`
10
+ * `git clone https://github.com/facebook/react.git` or download a zip file
11
+ from `https://github.com/facebook/react/archive/master.zip`
12
+ * `jscodeshift -t <codemod-script> <file>`
13
* Use the `-d` option for a dry-run and use `-p` to print the output
14
for comparison
15
@@ -20,7 +22,7 @@ update calls on the component instance or its refs. You can use this script to
22
update most calls to `getDOMNode` and then manually go through the remaining
23
calls.
24
23
- * `react-codemod findDOMNode <file>`
25
+ * `jscodeshift -t react/packages/react-codemod/transforms/findDOMNode.js <file>`
26
27
`pure-render-mixin` removes `PureRenderMixin` and inlines
28
`shouldComponentUpdate` so that the ES6 class transform can pick up the React
@@ -28,7 +30,7 @@ component and turn it into an ES6 class. NOTE: This currently only works if you
30
are using the master version (>0.13.1) of React as it is using
31
`React.addons.shallowCompare`
32
31
- * `react-codemod pure-render-mixin <file>`
33
+ * `jscodeshift -t react/packages/react-codemod/transforms/pure-render-mixin.js <file>`
34
* If `--mixin-name=<name>` is specified it will look for the specified name
35
instead of `PureRenderMixin`. Note that it is not possible to use a
36
namespaced name for the mixin. `mixins: [React.addons.PureRenderMixin]` will
@@ -36,7 +38,7 @@ are using the master version (>0.13.1) of React as it is using
38
39
`class` transforms `React.createClass` calls into ES6 classes.
40
39
- * `react-codemod class <file>`
41
+ * `jscodeshift -t react/packages/react-codemod/transforms/class.js <file>`
42
* If `--no-super-class=true` is specified it will not extend
43
`React.Component` if `setState` and `forceUpdate` aren't being called in a
44
class. We do recommend always extending from `React.Component`, especially
@@ -97,4 +99,4 @@ The constructor logic is as follows:
99
Options to [recast](https://github.com/benjamn/recast)'s printer can be provided
100
through the `printOptions` command line argument
101
100
- * `react-codemod class <file> --printOptions='{"quote":"double"}'`
102
+ * `jscodeshift -t transform.js <file> --printOptions='{"quote":"double"}'`
packages/react-codemod/package.json
+3
-9
@@ -1,6 +1,6 @@
1
{
2
"name": "react-codemod",
3
- "version": "2.0.0",
3
+ "version": "3.0.0",
4
"description": "React codemod scripts",
5
"license": "BSD-3-Clause",
6
"repository": {
@@ -8,18 +8,12 @@
8
"url": "https://github.com/facebook/react"
9
},
10
"scripts": {
11
- "build": "rm -rf build; babel transforms/ --out-dir=build/",
12
- "test": "jest",
13
- "prepublish": "npm run build"
14
- },
15
- "bin": {
16
- "react-codemod": "./react-codemod"
11
+ "test": "jest"
12
},
13
"dependencies": {
19
- "jscodeshift": "^0.1.0"
14
+ "jscodeshift": "^0.3.2"
15
},
16
"devDependencies": {
22
- "babel": "^4.7.16",
17
"babel-jest": "^4.0.0",
18
"jest-cli": "^0.4.0"
19
},
packages/react-codemod/react-codemod
deleted
-7
@@ -1,7 +0,0 @@
1
-#!/bin/bash
2
-
3
-DIR=$(npm root -g)/react-codemod
4
-TRANSFORM=$1
5
-shift
6
-
7
-$DIR/node_modules/.bin/jscodeshift -t $DIR/build/$TRANSFORM.js $@
packages/react-codemod/transforms/class.js
+2
-2
@@ -222,7 +222,7 @@ function updateReactCreateClassToES6(file, api, options) {
222
// Boom!
223
const createMethodDefinition = fn =>
224
withComments(j.methodDefinition(
225
- '',
225
+ 'method',
226
fn.key,
227
fn.value
228
), fn);
@@ -495,7 +495,7 @@ function updateReactCreateClassToES6(file, api, options) {
495
) > 0;
496
497
if (didTransform) {
498
- return root.toSource(printOptions) + '\n';
498
+ return root.toSource(printOptions);
499
}
500
}
501
packages/react-codemod/transforms/findDOMNode.js
+1
-1
@@ -133,7 +133,7 @@ function getDOMNodeToFindDOMNode(file, api, options) {
133
.size() > 0;
134
135
if (didTransform) {
136
- return root.toSource(printOptions) + '\n';
136
+ return root.toSource(printOptions);
137
}
138
}
139
packages/react-codemod/transforms/pure-render-mixin.js
+1
-1
@@ -177,7 +177,7 @@ function removePureRenderMixin(file, api, options) {
177
178
if (didTransform) {
179
deletePureRenderMixin(root);
180
- return root.toSource(printOptions) + '\n';
180
+ return root.toSource(printOptions);
181
}
182
}
183