5
5
* LICENSE file in the root directory of this source tree.
6
6
*
7
7
*/
8
-
8
+
9
9
import fse from 'fs-extra'
10
10
import { getFileInfo , parseCode } from '../util/uast'
11
11
import { isStaticRes , base64Encode } from '../util/util'
@@ -28,6 +28,9 @@ let entryFilePath = null
28
28
* @returns {Promise<void> }
29
29
*/
30
30
export default async function ( srcpath , targetpath ) {
31
+ //如果tranComp为true,表明只是单纯的转化组件,而不是整个项目
32
+ const tranComp = global . execArgs . tranComp
33
+
31
34
const fsStat = await fse . stat ( srcpath )
32
35
if ( fsStat . isDirectory ( ) ) {
33
36
return [ ]
@@ -41,10 +44,10 @@ export default async function (srcpath, targetpath) {
41
44
if ( isRNEntry ) return [ ]
42
45
43
46
if ( isEntry && isRF ) { // 入口文件 保证入口文件一定最先处理
44
- const entryResult = handleEntry ( ast , targetpath )
47
+ const entryResult = handleEntry ( ast , targetpath )
45
48
entryFilePath = entryResult . filepath
46
49
allCompSet = entryResult . allCompSet
47
- for ( let i = 0 ; i < RFFileList . length ; i ++ ) {
50
+ for ( let i = 0 ; i < RFFileList . length ; i ++ ) {
48
51
const { ast, targetpath, srcpath, isFuncComp, isStatelessComp, done} = RFFileList [ i ]
49
52
try {
50
53
const allFilepaths = handleRF ( ast , targetpath , isFuncComp , entryFilePath , isPageComp ( targetpath , allCompSet ) , isStatelessComp )
@@ -55,13 +58,18 @@ export default async function (srcpath, targetpath) {
55
58
}
56
59
return [ targetpath ]
57
60
} else if ( isRF ) {
58
- if ( entryFilePath ) {
61
+ if ( tranComp ) {
62
+ try {
63
+ return handleRF ( ast , targetpath , isFuncComp , entryFilePath , false , isStatelessComp )
64
+ } catch ( e ) {
65
+ console . log ( colors . error ( `tran ${ srcpath } error ! reason: ` ) , e )
66
+ }
67
+ } else if ( entryFilePath ) {
59
68
try {
60
69
return handleRF ( ast , targetpath , isFuncComp , entryFilePath , isPageComp ( targetpath , allCompSet ) , isStatelessComp )
61
70
} catch ( e ) {
62
71
console . log ( colors . error ( `tran ${ srcpath } error ! reason: ` ) , e )
63
72
}
64
-
65
73
} else {
66
74
// 保证入口文件一定最先处理, 如果入口文件还未被处理,则把react文件先入队列
67
75
return new Promise ( ( resolve ) => {
@@ -92,26 +100,6 @@ export async function geneWXFileStruc(targetpath) {
92
100
await fse . copy ( mptempDir , targetpath )
93
101
}
94
102
95
- /**
96
- * 程序退出之前的操作
97
- */
98
- export async function exitStruc ( ) {
99
- // 没有入口文件
100
- if ( ! entryFilePath ) {
101
- for ( let i = 0 ; i < RFFileList . length ; i ++ ) {
102
- const { ast, targetpath, srcpath, isFuncComp, isStatelessComp} = RFFileList [ i ]
103
- try {
104
- handleRF ( ast , targetpath , isFuncComp , entryFilePath , false , isStatelessComp )
105
- } catch ( e ) {
106
- console . log ( colors . error ( `tran ${ srcpath } error ! reason: ` ) , e )
107
- }
108
- }
109
- // 以免再次触发 exitStruc
110
- entryFilePath = "DONE"
111
- }
112
- }
113
-
114
-
115
103
function isPageComp ( targetpath , allCompSet ) {
116
104
const originPath = targetpath
117
105
. replace ( global . execArgs . OUT_DIR + path . sep , '' )
0 commit comments