File tree Expand file tree Collapse file tree 5 files changed +51
-1
lines changed
Expand file tree Collapse file tree 5 files changed +51
-1
lines changed Original file line number Diff line number Diff line change 33一组帮助你升级到 NutUI React 2.x 的 codemod 脚本集合,基于 [ jscodeshift] ( https://github.com/facebook/jscodeshift ) 构建。
44
55## 安装和使用
6- 在运行 codemod 脚本钱 ,请先提交你本地代码的修改。
6+ 在运行 codemod 脚本前 ,请先提交你本地代码的修改。
77
88### 针对 @nutui/nutui-react 的升级可采用下面的脚本
99``` shell
@@ -82,3 +82,27 @@ const App = () => {
8282export default App
8383
8484```
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 = [
1111 'icon-migration' ,
1212 'props-changed-migration' ,
1313]
14+ process . argv . indexOf ( '-internal' ) > - 1 &&
15+ transformers . push ( 'package-name-migration' )
1416const transformersDir = path . join ( __dirname , '../transforms' )
1517const ignoreConfig = path . join ( __dirname , './codemod.ignore' )
1618
Original file line number Diff line number Diff line change 11const pkgVersion = process . argv . indexOf ( '-taro' ) > - 1 ? 'taro' : 'h5'
22const pkgInfo = {
33 h5 : {
4+ dongDesign : '@dongdesign/ui' ,
45 icon : '@nutui/icons-react' ,
56 ui : '@nutui/nutui-react' ,
67 } ,
78 taro : {
9+ dongDesign : '@dongdesign/ui' ,
810 icon : '@nutui/icons-react-taro' ,
911 ui : '@nutui/nutui-react-taro' ,
1012 } ,
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