|
|
@@ -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文件不存在');
|