@oceanbase/codemod 0.4.13 → 0.4.14

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 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() {
@@ -1,9 +1,6 @@
1
1
  node_modules
2
2
  *.css
3
3
  *.json
4
- *.less
5
- *.sass
6
- *.scss
7
4
  .umi
8
5
  .umi-production
9
6
  .umi-test
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oceanbase/codemod",
3
- "version": "0.4.13",
3
+ "version": "0.4.14",
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.13",
26
+ "@oceanbase/design": "^0.4.14",
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": "2d9213d7c374b9dc207ebd40663f1c50828e72b7"
50
+ "gitHead": "e5b9f06614070e38c9d6a77244da2320679e3ffa"
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 };
@@ -11,6 +11,7 @@ const tests = [
11
11
  'existed-useToken',
12
12
  'top-identifier',
13
13
  'case-insensitive',
14
+ 'antd-style',
14
15
  ];
15
16
 
16
17
  describe(testUnit, () => {
@@ -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