1+ const fs = require ( 'fs' ) ;
2+ const path = require ( 'path' ) ;
3+
4+ const importPathMap = [
5+ { from : "../../form-field" , updatedFrom : "@rdkmaster/formly/form-field" } ,
6+ { from : "../../button-bar" , updatedFrom : "@rdkmaster/formly/button-bar" } ,
7+ { from : "../../input" , updatedFrom : "@rdkmaster/formly/input" } ,
8+ { from : "../../checkbox" , updatedFrom : "@rdkmaster/formly/checkbox" } ,
9+ { from : "../../radio" , updatedFrom : "@rdkmaster/formly/radio" } ,
10+ { from : "../../switch" , updatedFrom : "@rdkmaster/formly/switch" } ,
11+ { from : "../../textarea" , updatedFrom : "@rdkmaster/formly/textarea" } ,
12+ { from : "../../select" , updatedFrom : "@rdkmaster/formly/select" } ,
13+ { from : "../../list-lite" , updatedFrom : "@rdkmaster/formly/list-lite" } ,
14+ { from : "../../tile-lite" , updatedFrom : "@rdkmaster/formly/tile-lite" } ,
15+ { from : "../../slider" , updatedFrom : "@rdkmaster/formly/slider" } ,
16+ { from : "../../cascade" , updatedFrom : "@rdkmaster/formly/cascade" } ,
17+ { from : "../../time" , updatedFrom : "@rdkmaster/formly/time" } ,
18+ { from : "../../button" , updatedFrom : "@rdkmaster/formly/button" } ,
19+ { from : "../../icon" , updatedFrom : "@rdkmaster/formly/icon" } ,
20+ { from : "../../table" , updatedFrom : "@rdkmaster/formly/table" } ,
21+ { from : "../../template" , updatedFrom : "@rdkmaster/formly/template" } ,
22+ { from : "../../header" , updatedFrom : "@rdkmaster/formly/header" } ,
23+ { from : "../../upload" , updatedFrom : "@rdkmaster/formly/upload" } ,
24+ { from : "../../repeat" , updatedFrom : "@rdkmaster/formly/repeat" } ,
25+ { from : "../../tree" , updatedFrom : "@rdkmaster/formly/tree" }
26+ ] ;
27+
28+ const directoryPath = 'src-tmp/ngx-formly' ;
29+
30+ module . exports = updateFormlyImport ;
31+
32+ if ( require . main === module ) {
33+ updateFormlyImport ( ) ;
34+ }
35+
36+ function updateFormlyImport ( ) {
37+ console . log ( "----- update formly import start -----" ) ;
38+ const startTime = new Date ( ) . getTime ( ) ;
39+ processDirectory ( directoryPath ) ;
40+ console . log ( "----- update formly import done ----- 耗时:" , new Date ( ) . getTime ( ) - startTime , "ms" ) ;
41+ }
42+
43+ function processDirectory ( dirPath ) {
44+ const files = fs . readdirSync ( dirPath ) ;
45+
46+ files . forEach ( file => {
47+ const fullPath = path . join ( dirPath , file ) ;
48+ const stat = fs . statSync ( fullPath ) ;
49+
50+ if ( stat . isDirectory ( ) ) {
51+ // 递归处理子目录
52+ processDirectory ( fullPath ) ;
53+ } else if ( path . extname ( file ) === '.ts' ) {
54+ // 处理 .ts 文件
55+ const data = fs . readFileSync ( fullPath , 'utf8' ) ;
56+
57+ let updatedData = data ;
58+ importPathMap . forEach ( ( { from, updatedFrom} ) => {
59+ const regex = new RegExp ( from , 'g' ) ;
60+ updatedData = updatedData . replace ( regex , updatedFrom ) ;
61+ } ) ;
62+
63+ fs . writeFileSync ( fullPath , updatedData , 'utf8' ) ;
64+ }
65+ } ) ;
66+ }
0 commit comments