فهرست منبع

修复moules.json5文件无法自动注册路由表bug

chenritian 1 ماه پیش
والد
کامیت
2dfac0c965
2فایلهای تغییر یافته به همراه10 افزوده شده و 5 حذف شده
  1. 3 0
      features/feature/src/main/ets/pages/ChaoYiPage.ets
  2. 7 5
      hvigorfile.ts

+ 3 - 0
features/feature/src/main/ets/pages/ChaoYiPage.ets

@@ -7,6 +7,9 @@ struct ChaoYiPage {
 
   }
 }
+
+
+
 @Builder
 function ChaoYiBuilder() {
   ChaoYiPage()

+ 7 - 5
hvigorfile.ts

@@ -103,8 +103,8 @@ function customPlugin(): HvigorPlugin {
                     if (!stat.isDirectory() && file.endsWith('.ets')) {
                         try {
                             const content = fs.readFileSync(fullPath, 'utf8');
-                            console.log(`Content of ${file}:`);
-                            console.log(content);
+                            // console.log(`Content of ${file}:`);
+                            // console.log(content);
 
                             // 检查是否有@RouterPage修饰器
                             if (content.includes('@RouterPage')) {
@@ -113,7 +113,9 @@ function customPlugin(): HvigorPlugin {
                                 const builderName = fileNameWithoutExtension.replace(/Page$/, '') + 'Builder';
 
                                 // 检查是否已经存在Builder函数
-                                if (!content.includes(`@Builder\nfunction ${builderName}()`)) {
+                                const builderRegex = new RegExp(`@Builder\\s+function\\s+${builderName}\\s*\\(\\)`, 'g');
+
+                                if (!builderRegex.test(content)) {
                                     // 构造新的内容,在文件末尾添加Builder函数
                                     const structName = fileNameWithoutExtension; // 假设struct名称与文件名相同
                                     const builderFunction = `\n@Builder\nfunction ${builderName}() {\n  ${structName}()\n}\n`;
@@ -165,7 +167,7 @@ function customPlugin(): HvigorPlugin {
                         const moduleJsonContent = fs.readFileSync(moduleJsonPath, 'utf8');
 
                         // 使用正则表达式在"type": "entry"后添加routerMap字段
-                        if (moduleJsonContent.includes('"type": "entry"')) {
+                        if (moduleJsonContent.includes('"name"')) {
                             // 检查是否已经存在routerMap字段
                             if (!moduleJsonContent.includes('"routerMap"')) {
                                 // 在"type": "entry"后添加routerMap字段
@@ -180,7 +182,7 @@ function customPlugin(): HvigorPlugin {
                                 console.log('module.json5中已存在routerMap字段');
                             }
                         } else {
-                            console.log('module.json5中未找到"type": "entry"');
+                            console.log('module.json5中未找到"name": "entry"');
                         }
                     } else {
                         console.log('module.json5文件不存在');