@oceanbase/codemod 0.4.13 → 0.4.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/bin/cli.js +2 -1
- package/bin/codemod.ignore +0 -3
- package/package.json +3 -3
- package/transforms/__testfixtures__/style-to-token/antd-style.input.js +27 -0
- package/transforms/__testfixtures__/style-to-token/antd-style.output.js +33 -0
- package/transforms/__tests__/style-to-token.test.ts +1 -0
- package/transforms/style-to-token.js +46 -0
package/README.md
CHANGED
|
@@ -19,6 +19,7 @@ npx -p @oceanbase/codemod codemod src
|
|
|
19
19
|
# options
|
|
20
20
|
# --transformer=t1,t2 // run specify transformers
|
|
21
21
|
# --disablePrettier // disable prettier
|
|
22
|
+
# --ignore-config // ignore config file
|
|
22
23
|
```
|
|
23
24
|
|
|
24
25
|
Run specific transformers:
|
|
@@ -27,6 +28,23 @@ Run specific transformers:
|
|
|
27
28
|
npx -p @oceanbase/codemod codemod src --transformer=style-to-token,less-to-token
|
|
28
29
|
```
|
|
29
30
|
|
|
31
|
+
Ignore config file:
|
|
32
|
+
|
|
33
|
+
```shell
|
|
34
|
+
npx -p @oceanbase/codemod codemod src --ignore-config=.codemodignore
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
- `.codemodignore`:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
node_modules
|
|
41
|
+
*.css
|
|
42
|
+
*.json
|
|
43
|
+
.umi
|
|
44
|
+
.umi-production
|
|
45
|
+
.umi-test
|
|
46
|
+
```
|
|
47
|
+
|
|
30
48
|
## Codemod transformers introduction
|
|
31
49
|
|
|
32
50
|
### `antd-to-oceanbase-design`
|
package/bin/cli.js
CHANGED
|
@@ -94,7 +94,7 @@ function getRunnerArgs(transformerPath, parser = 'babylon', options = {}) {
|
|
|
94
94
|
extensions: ['js', 'jsx', 'ts', 'tsx'].join(','),
|
|
95
95
|
transform: transformerPath,
|
|
96
96
|
ignorePattern: '**/node_modules',
|
|
97
|
-
ignoreConfig,
|
|
97
|
+
ignoreConfig: options.ignoreConfig || ignoreConfig,
|
|
98
98
|
};
|
|
99
99
|
|
|
100
100
|
return args;
|
|
@@ -257,6 +257,7 @@ async function upgradeDetect(targetDir, needOBCharts, needObUtil) {
|
|
|
257
257
|
* --cpus=1 // specify cpus cores to use
|
|
258
258
|
* --disablePrettier // disable prettier
|
|
259
259
|
* --transformer=t1,t2 // specify target transformer
|
|
260
|
+
* --ignore-config // ignore config file
|
|
260
261
|
*/
|
|
261
262
|
|
|
262
263
|
async function bootstrap() {
|
package/bin/codemod.ignore
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oceanbase/codemod",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.15",
|
|
4
4
|
"description": "Codemod for OceanBase Design upgrade",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"oceanbase",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"build": "father build"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@oceanbase/design": "^0.4.
|
|
26
|
+
"@oceanbase/design": "^0.4.15",
|
|
27
27
|
"chalk": "^3.0.0",
|
|
28
28
|
"command-exists": "^1.2.9",
|
|
29
29
|
"execa": "^5.1.1",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"enzyme": "^3.11.0",
|
|
48
48
|
"enzyme-to-json": "^3.6.2"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "b88518b0f25b30d616d829813ba50eff7830499a"
|
|
51
51
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createStyles } from 'antd-style';
|
|
2
|
+
|
|
3
|
+
const useStyle1 = createStyles(() => {
|
|
4
|
+
return {
|
|
5
|
+
main: {
|
|
6
|
+
background: '#1890ff',
|
|
7
|
+
},
|
|
8
|
+
};
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const useStyle2 = createStyles(({}) => {
|
|
12
|
+
return {
|
|
13
|
+
main: {
|
|
14
|
+
background: '#1890ff',
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const useStyle3 = createStyles(({ token }) => {
|
|
20
|
+
return {
|
|
21
|
+
main: {
|
|
22
|
+
background: '#1890ff',
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export { useStyle1, useStyle2, useStyle3 };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createStyles } from 'antd-style';
|
|
2
|
+
|
|
3
|
+
const useStyle1 = createStyles((
|
|
4
|
+
{
|
|
5
|
+
token
|
|
6
|
+
}
|
|
7
|
+
) => {
|
|
8
|
+
return {
|
|
9
|
+
main: {
|
|
10
|
+
background: token.colorInfo,
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const useStyle2 = createStyles(({
|
|
16
|
+
token
|
|
17
|
+
}) => {
|
|
18
|
+
return {
|
|
19
|
+
main: {
|
|
20
|
+
background: token.colorInfo,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const useStyle3 = createStyles(({ token }) => {
|
|
26
|
+
return {
|
|
27
|
+
main: {
|
|
28
|
+
background: token.colorInfo,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export { useStyle1, useStyle2, useStyle3 };
|
|
@@ -36,6 +36,12 @@ function isFirstUpperCase(str) {
|
|
|
36
36
|
return upperFirst(str) === str;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
// ref: https://github.com/facebook/jscodeshift/issues/403#issuecomment-991759561
|
|
40
|
+
function shorthandProperty(property) {
|
|
41
|
+
property.shorthand = true;
|
|
42
|
+
return property;
|
|
43
|
+
}
|
|
44
|
+
|
|
39
45
|
function importComponent(j, root, options) {
|
|
40
46
|
let hasChanged = false;
|
|
41
47
|
|
|
@@ -83,6 +89,7 @@ function importComponent(j, root, options) {
|
|
|
83
89
|
: parentType === 'ArrowFunctionExpression'
|
|
84
90
|
? path.parentPath.parentPath?.value?.id?.name
|
|
85
91
|
: undefined;
|
|
92
|
+
const calleeName = path.parentPath.parentPath?.parentPath?.value?.callee?.name;
|
|
86
93
|
if (
|
|
87
94
|
includeJSXElement &&
|
|
88
95
|
functionName &&
|
|
@@ -101,6 +108,45 @@ function importComponent(j, root, options) {
|
|
|
101
108
|
importKind: 'value',
|
|
102
109
|
});
|
|
103
110
|
}
|
|
111
|
+
}
|
|
112
|
+
// antd-style createStyles
|
|
113
|
+
else if (parentType === 'ArrowFunctionExpression' && calleeName === 'createStyles') {
|
|
114
|
+
const arrowFunc = path.parentPath?.parentPath?.value?.[0];
|
|
115
|
+
if (arrowFunc && arrowFunc.type === 'ArrowFunctionExpression') {
|
|
116
|
+
let hasToken = false;
|
|
117
|
+
if (arrowFunc.params.length > 0) {
|
|
118
|
+
const param = arrowFunc.params[0];
|
|
119
|
+
if (param.type === 'ObjectPattern') {
|
|
120
|
+
hasToken = param.properties.some(
|
|
121
|
+
p => p.type === 'ObjectProperty' && p.key && p.key.name === 'token'
|
|
122
|
+
);
|
|
123
|
+
// 如果参数对象中没有 token 属性,则插入 token 属性
|
|
124
|
+
if (!hasToken) {
|
|
125
|
+
param.properties.push(
|
|
126
|
+
shorthandProperty(
|
|
127
|
+
j.property('init', j.identifier('token'), j.identifier('token'))
|
|
128
|
+
)
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
} else {
|
|
132
|
+
// 如果参数不是对象结构,则替换为 { token }
|
|
133
|
+
arrowFunc.params[0] = j.objectPattern([
|
|
134
|
+
shorthandProperty(
|
|
135
|
+
j.property('init', j.identifier('token'), j.identifier('token'))
|
|
136
|
+
),
|
|
137
|
+
]);
|
|
138
|
+
}
|
|
139
|
+
} else {
|
|
140
|
+
// 如果没有参数,则插入 { token }
|
|
141
|
+
arrowFunc.params = [
|
|
142
|
+
j.objectPattern([
|
|
143
|
+
shorthandProperty(
|
|
144
|
+
j.property('init', j.identifier('token'), j.identifier('token'))
|
|
145
|
+
),
|
|
146
|
+
]),
|
|
147
|
+
];
|
|
148
|
+
}
|
|
149
|
+
}
|
|
104
150
|
} else {
|
|
105
151
|
// React class component and static file (not react component)
|
|
106
152
|
// import `token` from @oceanbase/design
|