@oceanbase/codemod 0.2.0

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.
Files changed (36) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +119 -0
  3. package/package.json +44 -0
  4. package/src/bin/cli.js +271 -0
  5. package/src/bin/codemod.ignore +9 -0
  6. package/src/bin/codemod.js +3 -0
  7. package/src/bin/upgrade-list.json +23 -0
  8. package/src/transforms/__testfixtures__/.eslintrc.js +7 -0
  9. package/src/transforms/__testfixtures__/antd-charts-to-oceanbase-charts/antd-charts.input.tsx +9 -0
  10. package/src/transforms/__testfixtures__/antd-charts-to-oceanbase-charts/antd-charts.output.tsx +9 -0
  11. package/src/transforms/__testfixtures__/antd-to-oceanbase-design/antd.input.tsx +92 -0
  12. package/src/transforms/__testfixtures__/antd-to-oceanbase-design/antd.output.tsx +92 -0
  13. package/src/transforms/__testfixtures__/antd-to-oceanbase-design/bigfish-antd.input.tsx +92 -0
  14. package/src/transforms/__testfixtures__/antd-to-oceanbase-design/bigfish-antd.output.tsx +92 -0
  15. package/src/transforms/__testfixtures__/obui-to-oceanbase-design-and-ui/obui.input.tsx +11 -0
  16. package/src/transforms/__testfixtures__/obui-to-oceanbase-design-and-ui/obui.output.tsx +12 -0
  17. package/src/transforms/__testfixtures__/obutil-to-oceanbase-util/obutil.input.tsx +8 -0
  18. package/src/transforms/__testfixtures__/obutil-to-oceanbase-util/obutil.output.tsx +8 -0
  19. package/src/transforms/__testfixtures__/techui-to-oceanbase-ui/pro-components.input.tsx +9 -0
  20. package/src/transforms/__testfixtures__/techui-to-oceanbase-ui/pro-components.output.tsx +11 -0
  21. package/src/transforms/__testfixtures__/techui-to-oceanbase-ui/techui.input.tsx +9 -0
  22. package/src/transforms/__testfixtures__/techui-to-oceanbase-ui/techui.output.tsx +11 -0
  23. package/src/transforms/__tests__/antd-charts-to-oceanbase-charts.test.ts +10 -0
  24. package/src/transforms/__tests__/antd-to-oceanbase-design.test.ts +10 -0
  25. package/src/transforms/__tests__/obui-to-oceanbase-design-and-ui.test.ts +10 -0
  26. package/src/transforms/__tests__/obutil-to-oceanbase-util.test.ts +10 -0
  27. package/src/transforms/__tests__/techui-to-oceanbase-ui.test.ts +10 -0
  28. package/src/transforms/antd-charts-to-oceanbase-charts.js +17 -0
  29. package/src/transforms/antd-to-oceanbase-design.js +17 -0
  30. package/src/transforms/obui-to-oceanbase-design-and-ui.js +50 -0
  31. package/src/transforms/obutil-to-oceanbase-util.js +15 -0
  32. package/src/transforms/techui-to-oceanbase-ui.js +18 -0
  33. package/src/transforms/utils/config.js +11 -0
  34. package/src/transforms/utils/import-component.js +72 -0
  35. package/src/transforms/utils/index.js +224 -0
  36. package/src/transforms/utils/marker.js +35 -0
@@ -0,0 +1,92 @@
1
+ import React from 'react';
2
+ import {
3
+ // Genaral
4
+ Button,
5
+ FloatButton,
6
+ Typography,
7
+ // Layout
8
+ Divider,
9
+ Grid,
10
+ Layout,
11
+ Space,
12
+ // Navigation
13
+ Anchor,
14
+ Breadcrumb,
15
+ Dropdown,
16
+ Menu,
17
+ Pagination,
18
+ Steps,
19
+ // Data Entry
20
+ AutoComplete,
21
+ Cascader,
22
+ Checkbox,
23
+ ColorPicker,
24
+ DatePicker,
25
+ Form,
26
+ Input,
27
+ InputNumber,
28
+ Mentions,
29
+ Radio,
30
+ Rate,
31
+ Select,
32
+ Slider,
33
+ Switch,
34
+ TimePicker,
35
+ Transfer,
36
+ TreeSelect,
37
+ Upload,
38
+ // Data Display
39
+ Avatar,
40
+ Badge,
41
+ Calendar,
42
+ Card,
43
+ Carousel,
44
+ Callapse,
45
+ Descripions,
46
+ Empty,
47
+ Image,
48
+ List,
49
+ Popover,
50
+ QRCode,
51
+ Segmented,
52
+ Statistic,
53
+ Table,
54
+ Tabs,
55
+ Tag,
56
+ Timeline,
57
+ Tooltip,
58
+ Tour,
59
+ Tree,
60
+ // Feedback
61
+ Alert,
62
+ Drawer,
63
+ message,
64
+ Modal,
65
+ notification,
66
+ Popconfirm,
67
+ Progress,
68
+ Result,
69
+ Skeleton,
70
+ Spin,
71
+ Watermark,
72
+ // Other
73
+ Affix,
74
+ App,
75
+ ConfigProvider,
76
+ // Theme
77
+ theme,
78
+ } from '@oceanbase/design';
79
+ // type
80
+ import type { ButtonProps, CardProps } from '@oceanbase/design';
81
+ // es
82
+ import type { ModalProps } from '@oceanbase/design/es/modal';
83
+ import type { Route } from '@oceanbase/design/es/breadcrumb/Breadcrumb';
84
+ // lib
85
+ import type { TooltipProps } from '@oceanbase/design/lib/tooltip';
86
+ import type { FilterDropdownProps } from '@oceanbase/design/lib/table/interface';
87
+
88
+ const Demo = () => {
89
+ return <div />;
90
+ };
91
+
92
+ export default Demo;
@@ -0,0 +1,92 @@
1
+ import React from 'react';
2
+ import {
3
+ // Genaral
4
+ Button,
5
+ FloatButton,
6
+ Typography,
7
+ // Layout
8
+ Divider,
9
+ Grid,
10
+ Layout,
11
+ Space,
12
+ // Navigation
13
+ Anchor,
14
+ Breadcrumb,
15
+ Dropdown,
16
+ Menu,
17
+ Pagination,
18
+ Steps,
19
+ // Data Entry
20
+ AutoComplete,
21
+ Cascader,
22
+ Checkbox,
23
+ ColorPicker,
24
+ DatePicker,
25
+ Form,
26
+ Input,
27
+ InputNumber,
28
+ Mentions,
29
+ Radio,
30
+ Rate,
31
+ Select,
32
+ Slider,
33
+ Switch,
34
+ TimePicker,
35
+ Transfer,
36
+ TreeSelect,
37
+ Upload,
38
+ // Data Display
39
+ Avatar,
40
+ Badge,
41
+ Calendar,
42
+ Card,
43
+ Carousel,
44
+ Callapse,
45
+ Descripions,
46
+ Empty,
47
+ Image,
48
+ List,
49
+ Popover,
50
+ QRCode,
51
+ Segmented,
52
+ Statistic,
53
+ Table,
54
+ Tabs,
55
+ Tag,
56
+ Timeline,
57
+ Tooltip,
58
+ Tour,
59
+ Tree,
60
+ // Feedback
61
+ Alert,
62
+ Drawer,
63
+ message,
64
+ Modal,
65
+ notification,
66
+ Popconfirm,
67
+ Progress,
68
+ Result,
69
+ Skeleton,
70
+ Spin,
71
+ Watermark,
72
+ // Other
73
+ Affix,
74
+ App,
75
+ ConfigProvider,
76
+ // Theme
77
+ theme,
78
+ } from '@alipay/bigfish/antd';
79
+ // type
80
+ import type { ButtonProps, CardProps } from '@alipay/bigfish/antd';
81
+ // es
82
+ import type { ModalProps } from 'antd/es/modal';
83
+ import type { Route } from 'antd/es/breadcrumb/Breadcrumb';
84
+ // lib
85
+ import type { TooltipProps } from 'antd/lib/tooltip';
86
+ import type { FilterDropdownProps } from 'antd/lib/table/interface';
87
+
88
+ const Demo = () => {
89
+ return <div />;
90
+ };
91
+
92
+ export default Demo;
@@ -0,0 +1,92 @@
1
+ import React from 'react';
2
+ import {
3
+ // Genaral
4
+ Button,
5
+ FloatButton,
6
+ Typography,
7
+ // Layout
8
+ Divider,
9
+ Grid,
10
+ Layout,
11
+ Space,
12
+ // Navigation
13
+ Anchor,
14
+ Breadcrumb,
15
+ Dropdown,
16
+ Menu,
17
+ Pagination,
18
+ Steps,
19
+ // Data Entry
20
+ AutoComplete,
21
+ Cascader,
22
+ Checkbox,
23
+ ColorPicker,
24
+ DatePicker,
25
+ Form,
26
+ Input,
27
+ InputNumber,
28
+ Mentions,
29
+ Radio,
30
+ Rate,
31
+ Select,
32
+ Slider,
33
+ Switch,
34
+ TimePicker,
35
+ Transfer,
36
+ TreeSelect,
37
+ Upload,
38
+ // Data Display
39
+ Avatar,
40
+ Badge,
41
+ Calendar,
42
+ Card,
43
+ Carousel,
44
+ Callapse,
45
+ Descripions,
46
+ Empty,
47
+ Image,
48
+ List,
49
+ Popover,
50
+ QRCode,
51
+ Segmented,
52
+ Statistic,
53
+ Table,
54
+ Tabs,
55
+ Tag,
56
+ Timeline,
57
+ Tooltip,
58
+ Tour,
59
+ Tree,
60
+ // Feedback
61
+ Alert,
62
+ Drawer,
63
+ message,
64
+ Modal,
65
+ notification,
66
+ Popconfirm,
67
+ Progress,
68
+ Result,
69
+ Skeleton,
70
+ Spin,
71
+ Watermark,
72
+ // Other
73
+ Affix,
74
+ App,
75
+ ConfigProvider,
76
+ // Theme
77
+ theme,
78
+ } from '@oceanbase/design';
79
+ // type
80
+ import type { ButtonProps, CardProps } from '@oceanbase/design';
81
+ // es
82
+ import type { ModalProps } from '@oceanbase/design/es/modal';
83
+ import type { Route } from '@oceanbase/design/es/breadcrumb/Breadcrumb';
84
+ // lib
85
+ import type { TooltipProps } from '@oceanbase/design/lib/tooltip';
86
+ import type { FilterDropdownProps } from '@oceanbase/design/lib/table/interface';
87
+
88
+ const Demo = () => {
89
+ return <div />;
90
+ };
91
+
92
+ export default Demo;
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import { Alert, Button, BasicLayout, Login, PageContainer } from '@alipay/ob-ui';
3
+ import type { BasicLayoutProps } from '@alipay/ob-ui/es/BasicLayout';
4
+ import type { LoginProps } from '@alipay/ob-ui/es/Login';
5
+ import type { PageContainerProps } from '@alipay/ob-ui/es/PageContainer';
6
+
7
+ const Demo = () => {
8
+ return <div />;
9
+ };
10
+
11
+ export default Demo;
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import { Alert, Button } from '@oceanbase/design';
3
+ import { BasicLayout, Login, PageContainer } from '@oceanbase/ui';
4
+ import type { BasicLayoutProps } from '@oceanbase/ui/es/BasicLayout';
5
+ import type { LoginProps } from '@oceanbase/ui/es/Login';
6
+ import type { PageContainerProps } from '@oceanbase/ui/es/PageContainer';
7
+
8
+ const Demo = () => {
9
+ return <div />;
10
+ };
11
+
12
+ export default Demo;
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import { isNullValue, sortByNumber } from '@alipay/ob-util';
3
+
4
+ const Demo = () => {
5
+ return <div />;
6
+ };
7
+
8
+ export default Demo;
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import { isNullValue, sortByNumber } from '@oceanbase/util';
3
+
4
+ const Demo = () => {
5
+ return <div />;
6
+ };
7
+
8
+ export default Demo;
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ import { PageContainer, ProTable } from '@ant-design/pro-components';
3
+ import type { PageContainerProps, ProTableProps } from '@ant-design/pro-components';
4
+
5
+ const Demo = () => {
6
+ return <div />;
7
+ };
8
+
9
+ export default Demo;
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import { ProTable } from '@ant-design/pro-components';
3
+ import { PageContainer } from '@oceanbase/ui';
4
+ import type { ProTableProps } from '@ant-design/pro-components';
5
+ import type { PageContainerProps } from '@oceanbase/ui';
6
+
7
+ const Demo = () => {
8
+ return <div />;
9
+ };
10
+
11
+ export default Demo;
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ import { PageContainer, ProTable, WelcomeCard } from '@alipay/tech-ui';
3
+ import type { PageContainerProps, ProTableProps, WelcomeCardProps } from '@alipay/tech-ui';
4
+
5
+ const Demo = () => {
6
+ return <div />;
7
+ };
8
+
9
+ export default Demo;
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import { ProTable, WelcomeCard } from '@alipay/tech-ui';
3
+ import { PageContainer } from '@oceanbase/ui';
4
+ import type { ProTableProps, WelcomeCardProps } from '@alipay/tech-ui';
5
+ import type { PageContainerProps } from '@oceanbase/ui';
6
+
7
+ const Demo = () => {
8
+ return <div />;
9
+ };
10
+
11
+ export default Demo;
@@ -0,0 +1,10 @@
1
+ import { defineTest } from 'jscodeshift/src/testUtils';
2
+
3
+ const testUnit = 'antd-charts-to-oceanbase-charts';
4
+ const tests = ['antd-charts'];
5
+
6
+ describe(testUnit, () => {
7
+ tests.forEach(test =>
8
+ defineTest(__dirname, testUnit, {}, `${testUnit}/${test}`, { parser: 'tsx' })
9
+ );
10
+ });
@@ -0,0 +1,10 @@
1
+ import { defineTest } from 'jscodeshift/src/testUtils';
2
+
3
+ const testUnit = 'antd-to-oceanbase-design';
4
+ const tests = ['antd', 'bigfish-antd'];
5
+
6
+ describe(testUnit, () => {
7
+ tests.forEach(test =>
8
+ defineTest(__dirname, testUnit, {}, `${testUnit}/${test}`, { parser: 'tsx' })
9
+ );
10
+ });
@@ -0,0 +1,10 @@
1
+ import { defineTest } from 'jscodeshift/src/testUtils';
2
+
3
+ const testUnit = 'obui-to-oceanbase-design-and-ui';
4
+ const tests = ['obui'];
5
+
6
+ describe(testUnit, () => {
7
+ tests.forEach(test =>
8
+ defineTest(__dirname, testUnit, {}, `${testUnit}/${test}`, { parser: 'tsx' })
9
+ );
10
+ });
@@ -0,0 +1,10 @@
1
+ import { defineTest } from 'jscodeshift/src/testUtils';
2
+
3
+ const testUnit = 'obutil-to-oceanbase-util';
4
+ const tests = ['obutil'];
5
+
6
+ describe(testUnit, () => {
7
+ tests.forEach(test =>
8
+ defineTest(__dirname, testUnit, {}, `${testUnit}/${test}`, { parser: 'tsx' })
9
+ );
10
+ });
@@ -0,0 +1,10 @@
1
+ import { defineTest } from 'jscodeshift/src/testUtils';
2
+
3
+ const testUnit = 'techui-to-oceanbase-ui';
4
+ const tests = ['techui', 'pro-components'];
5
+
6
+ describe(testUnit, () => {
7
+ tests.forEach(test =>
8
+ defineTest(__dirname, testUnit, {}, `${testUnit}/${test}`, { parser: 'tsx' })
9
+ );
10
+ });
@@ -0,0 +1,17 @@
1
+ const importComponent = require('./utils/import-component');
2
+
3
+ // from1: import { Line } from '@ant-design/charts';
4
+ // from2: import type { LineConfig } from '@ant-design/charts';
5
+ // to1: import { Line } from '@ant-design/charts';
6
+ // from2: import type { LineConfig } from '@ant-design/charts';
7
+ module.exports = (file, api, options) => {
8
+ return importComponent(file, api, {
9
+ ...options,
10
+ fromPkgNames: '@ant-design/charts',
11
+ toPkgList: [
12
+ {
13
+ name: '@oceanbase/charts',
14
+ },
15
+ ],
16
+ });
17
+ };
@@ -0,0 +1,17 @@
1
+ const importComponent = require('./utils/import-component');
2
+
3
+ // from1: import { Button } from 'antd';
4
+ // from2: import { Button } from '@alipay/bigfish/antd';
5
+ // to: import { Button } from '@oceanbase/design';
6
+ module.exports = (file, api, options) => {
7
+ return importComponent(file, api, {
8
+ ...options,
9
+ // order: @alipay/bigfish/antd -> antd
10
+ fromPkgNames: '@alipay/bigfish/antd,antd',
11
+ toPkgList: [
12
+ {
13
+ name: '@oceanbase/design',
14
+ },
15
+ ],
16
+ });
17
+ };
@@ -0,0 +1,50 @@
1
+ const importComponent = require('./utils/import-component');
2
+
3
+ // from: import { Button, BasicLayout } from '@alipay/ob-ui';
4
+ // to1: import { Button } from '@oceanbase/design';
5
+ // to2: import { BasicLayout } from '@oceanbase/ui';
6
+ module.exports = (file, api, options) => {
7
+ return importComponent(file, api, {
8
+ ...options,
9
+ fromPkgNames: '@alipay/ob-ui',
10
+ // order: @oceanbase/ui -> @oceanbase/design
11
+ toPkgList: [
12
+ {
13
+ name: '@oceanbase/ui',
14
+ components: [
15
+ 'PageContainer',
16
+ 'Action',
17
+ 'BackgroundTaskManager',
18
+ 'BasicLayout',
19
+ 'BatchOperationBar',
20
+ 'Boundary',
21
+ 'ContentWithQuestion',
22
+ 'Dialog',
23
+ 'DocDialog',
24
+ 'GraphToolbar',
25
+ 'Login',
26
+ 'Lottie',
27
+ 'NavMenu',
28
+ ],
29
+ types: [
30
+ 'PageContainerProps',
31
+ 'ActionProps',
32
+ 'BackgroundTaskManagerProps',
33
+ 'BasicLayoutProps',
34
+ 'BatchOperationBarProps',
35
+ 'BoundaryProps',
36
+ 'ContentWithQuestionProps',
37
+ 'DialogProps',
38
+ 'DocDialogProps',
39
+ 'GraphToolbarProps',
40
+ 'LoginProps',
41
+ 'LottieProps',
42
+ 'NavMenuProps',
43
+ ],
44
+ },
45
+ {
46
+ name: '@oceanbase/design',
47
+ },
48
+ ],
49
+ });
50
+ };
@@ -0,0 +1,15 @@
1
+ const importComponent = require('./utils/import-component');
2
+
3
+ // from: import { isNullValue, sortByNumber } from '@alipay/ob-util';
4
+ // to: import { isNullValue, sortByNumber } from '@oceanbase/util';
5
+ module.exports = (file, api, options) => {
6
+ return importComponent(file, api, {
7
+ ...options,
8
+ fromPkgNames: '@alipay/ob-util',
9
+ toPkgList: [
10
+ {
11
+ name: '@oceanbase/util',
12
+ },
13
+ ],
14
+ });
15
+ };
@@ -0,0 +1,18 @@
1
+ const importComponent = require('./utils/import-component');
2
+
3
+ // from1: import { PageContainer } from '@alipay/tech-ui';
4
+ // from2: import { PageContainer } from '@ant-design/pro-components';
5
+ // to: import { PageContainer } from '@oceanbase/ui';
6
+ module.exports = (file, api, options) => {
7
+ return importComponent(file, api, {
8
+ ...options,
9
+ fromPkgNames: '@alipay/tech-ui,@ant-design/pro-components',
10
+ toPkgList: [
11
+ {
12
+ name: '@oceanbase/ui',
13
+ components: ['PageContainer'],
14
+ types: ['PageContainerProps'],
15
+ },
16
+ ],
17
+ });
18
+ };
@@ -0,0 +1,11 @@
1
+ // https://github.com/benjamn/recast/blob/master/lib/options.ts
2
+ const printOptions = {
3
+ quote: 'single',
4
+ // remove extra empty line for insertAfter
5
+ // ref: https://github.com/benjamn/recast/issues/371#issuecomment-565786863
6
+ reuseWhitespace: false,
7
+ };
8
+
9
+ module.exports = {
10
+ printOptions,
11
+ };
@@ -0,0 +1,72 @@
1
+ const { addSubmoduleImport, removeEmptyModuleImport, parseStrToArray } = require('./index');
2
+ const { printOptions } = require('./config');
3
+
4
+ function importComponent(j, root, options) {
5
+ const { fromPkgNames, toPkgList } = options;
6
+ let hasChanged = false;
7
+
8
+ root
9
+ .find(j.ImportDeclaration)
10
+ .filter(path =>
11
+ fromPkgNames.some(fromPkgName => new RegExp(fromPkgName).test(path.value.source.value))
12
+ )
13
+ .forEach(path => {
14
+ hasChanged = true;
15
+ const fromPkgName = fromPkgNames.find(fromPkgName =>
16
+ new RegExp(fromPkgName).test(path.value.source.value)
17
+ );
18
+ path.value.specifiers.forEach(specifier => {
19
+ const toPkgByComponents = toPkgList.find(toPkg =>
20
+ toPkg.components?.includes(specifier.imported.name)
21
+ );
22
+ const toPkgByTypes = toPkgList.find(toPkg =>
23
+ toPkg.types?.includes(specifier.imported.name)
24
+ );
25
+ const toPkg = toPkgByComponents || toPkgByTypes;
26
+ if (toPkg) {
27
+ // replace to toPkg for xxx/es/xxx、xxx/lib/xxx
28
+ if (new RegExp(`${fromPkgName}/(es|lib)/`).test(path.value.source.value)) {
29
+ path.value.source.value = path.value.source.value?.replace(fromPkgName, toPkg.name);
30
+ } else {
31
+ // remove old imports
32
+ path.value.specifiers = path.value.specifiers.filter(
33
+ item => !item.imported || item.imported.name !== specifier.imported.name
34
+ );
35
+ // add new imports
36
+ addSubmoduleImport(j, root, {
37
+ moduleName: toPkg.name,
38
+ importedName: specifier.imported.name,
39
+ importKind: toPkgByTypes ? 'type' : 'value',
40
+ after: fromPkgName,
41
+ });
42
+ }
43
+ }
44
+ });
45
+ if (path.value.specifiers.length > 0) {
46
+ // replace to toPkg when specifiers still not empty
47
+ const toPkg = toPkgList.find(toPkg => !toPkg.components);
48
+ if (toPkg) {
49
+ path.value.source.value = path.value.source.value?.replace(fromPkgName, toPkg.name);
50
+ }
51
+ }
52
+ });
53
+
54
+ return hasChanged;
55
+ }
56
+
57
+ module.exports = (file, api, options) => {
58
+ const j = api.jscodeshift;
59
+ const root = j(file.source);
60
+ const fromPkgNames = parseStrToArray(options.fromPkgNames || 'antd');
61
+
62
+ let hasChanged = false;
63
+ hasChanged = importComponent(j, root, { ...options, fromPkgNames }) || hasChanged;
64
+
65
+ if (hasChanged) {
66
+ fromPkgNames.forEach(fromPkgName => {
67
+ removeEmptyModuleImport(j, root, fromPkgName);
68
+ });
69
+ }
70
+
71
+ return hasChanged ? root.toSource(options.printOptions || printOptions) : null;
72
+ };