File tree 5 files changed +51
-1
lines changed
5 files changed +51
-1
lines changed Original file line number Diff line number Diff line change 3
3
一组帮助你升级到 NutUI React 2.x 的 codemod 脚本集合,基于 [ jscodeshift] ( https://github.com/facebook/jscodeshift ) 构建。
4
4
5
5
## 安装和使用
6
- 在运行 codemod 脚本钱 ,请先提交你本地代码的修改。
6
+ 在运行 codemod 脚本前 ,请先提交你本地代码的修改。
7
7
8
8
### 针对 @nutui/nutui-react 的升级可采用下面的脚本
9
9
``` shell
@@ -82,3 +82,27 @@ const App = () => {
82
82
export default App
83
83
84
84
```
85
+
86
+ ` package-name-migration `
87
+ - 包名替换
88
+
89
+ ``` shell
90
+ # 使用 npx 直接运行
91
+ npx -p @nutui/nutui-react-codemod nutui-react-codemod src -taro -internal
92
+
93
+ # 或者使用 pnpm 直接运行
94
+ pnpm --package=@nutui/nutui-react-codemod dlx nutui-react-codemod src -taro -internal
95
+ ```
96
+
97
+ ``` diff
98
+ - import { Button, Collapse } from "@nutui/nutui-react-taro";
99
+ - import { Cell } from '@nutui/nutui-react-taro/dist/components/cell/index';
100
+ - import '@nutui/nutui-react-taro/dist/components/cell/index';
101
+ - import "@nutui/nutui-react-taro/dist/style.css";
102
+ - import NutUI from "@nutui/nutui-react-taro";
103
+ + import { Button, Collapse } from "@dongdesign/components";
104
+ + import { Cell } from "@dongdesign/components/dist/components/cell/index";
105
+ + import "@dongdesign/components/dist/components/cell/index";
106
+ + import "@dongdesign/components/dist/style.css";
107
+ + import NutUI from "@dongdesign/components";
108
+ ```
Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ const transformers = [
11
11
'icon-migration' ,
12
12
'props-changed-migration' ,
13
13
]
14
+ process . argv . indexOf ( '-internal' ) > - 1 &&
15
+ transformers . push ( 'package-name-migration' )
14
16
const transformersDir = path . join ( __dirname , '../transforms' )
15
17
const ignoreConfig = path . join ( __dirname , './codemod.ignore' )
16
18
Original file line number Diff line number Diff line change 1
1
const pkgVersion = process . argv . indexOf ( '-taro' ) > - 1 ? 'taro' : 'h5'
2
2
const pkgInfo = {
3
3
h5 : {
4
+ dongDesign : '@dongdesign/ui' ,
4
5
icon : '@nutui/icons-react' ,
5
6
ui : '@nutui/nutui-react' ,
6
7
} ,
7
8
taro : {
9
+ dongDesign : '@dongdesign/ui' ,
8
10
icon : '@nutui/icons-react-taro' ,
9
11
ui : '@nutui/nutui-react-taro' ,
10
12
} ,
Original file line number Diff line number Diff line change
1
+ const findImportDeclaration = require ( './utils/find-importDeclaration' )
2
+
3
+ module . exports = ( file , api , options ) => {
4
+ const j = api . jscodeshift
5
+ const root = j ( file . source )
6
+ const literals = findImportDeclaration ( j , root , options . pkgInfo )
7
+ literals . forEach ( ( path ) => {
8
+ path . node . source . value = path . node . source . value . replace (
9
+ options . pkgInfo . ui ,
10
+ options . pkgInfo . dongDesign
11
+ )
12
+ } )
13
+
14
+ return root . toSource ( )
15
+ }
Original file line number Diff line number Diff line change
1
+ function findImportDeclaration ( j , pathCollection , pkgInfo ) {
2
+ return pathCollection . find ( j . ImportDeclaration ) . filter ( ( path ) => {
3
+ return path . node . source && path . node . source . value . indexOf ( pkgInfo . ui ) !== - 1
4
+ } )
5
+ }
6
+
7
+ module . exports = findImportDeclaration
You can’t perform that action at this time.
0 commit comments